CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-h5netcdf

tessl install tessl/pypi-h5netcdf@1.6.0

netCDF4 file access via h5py with hierarchical and legacy APIs for scientific computing

Agent Success

Agent success rate when using this tile

69%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.83x

Baseline

Agent success rate without this tile

83%

task.mdevals/scenario-2/

NetCDF File Validator

Build a validation utility that checks netCDF4 files for common errors and format compliance issues before processing them in a data pipeline.

Requirements

Your validator should check for and handle the following scenarios:

  1. Format Compliance Validation: Verify that files claiming to be in NETCDF4_CLASSIC format don't contain variables without dimensions (scalar variables are not allowed in this format).

  2. Type Validation: When working with user-defined enumeration types, verify that:

    • The type is accessible within the group hierarchy where it's being used
    • Fill values for enum variables are valid members of the enumeration
  3. Invalid Parameter Detection: Gracefully handle attempts to:

    • Access non-existent variables or groups by name
    • Create variables with invalid dimension specifications
    • Use incompatible compression settings

Your implementation should distinguish between different classes of errors (format violations, invalid parameters, missing items) and provide clear error messages for each category.

Implementation

@generates

API

def validate_netcdf_format(file_path: str, expected_format: str) -> dict:
    """
    Validates a netCDF file against format-specific constraints.

    Args:
        file_path: Path to the netCDF file to validate
        expected_format: Expected format ('NETCDF4' or 'NETCDF4_CLASSIC')

    Returns:
        Dictionary with keys:
        - 'valid': Boolean indicating if file passes validation
        - 'errors': List of error descriptions found
        - 'format': Actual format detected

    The function should catch and categorize different types of validation errors.
    """
    pass

def validate_enum_variable(file_obj, group_path: str, var_name: str) -> dict:
    """
    Validates that an enum-typed variable has proper type accessibility and fill values.

    Args:
        file_obj: Open h5netcdf File object
        group_path: Path to the group containing the variable (e.g., '/data/measurements')
        var_name: Name of the variable to validate

    Returns:
        Dictionary with keys:
        - 'valid': Boolean indicating if variable is properly configured
        - 'issues': List of validation issues found
        - 'enum_type': Name of the enum type used (if accessible)
    """
    pass

def safe_access_item(file_obj, path: str, item_type: str) -> tuple:
    """
    Safely attempts to access a variable or group, handling missing items gracefully.

    Args:
        file_obj: Open h5netcdf File object
        path: Path to the item (e.g., '/data/temperature' for variable)
        item_type: Type of item to access ('variable' or 'group')

    Returns:
        Tuple of (success: bool, item_or_error: object or str)
        If successful, returns (True, accessed_item)
        If failed, returns (False, error_message)
    """
    pass

Test Cases

Format Compliance

  • Opening a NETCDF4_CLASSIC file that incorrectly contains a scalar variable (no dimensions) should be detected during validation, with the validator reporting a format compliance error @test

Type Accessibility

  • When validating an enum variable, if the enum type is defined in a parent group, validation should succeed and report the type as accessible @test

  • When validating an enum variable with an invalid fill value (not in the enum definition), validation should fail with a clear error about the fill value @test

Error Handling

  • Attempting to safely access a non-existent variable by name should return False with an appropriate error message, not raise an exception @test

  • Attempting to safely access a non-existent group should return False with an appropriate error message indicating the group was not found @test

Dependencies { .dependencies }

h5netcdf { .dependency }

Provides netCDF4 file access with error handling and validation capabilities.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/h5netcdf@1.6.x
tile.json