tessl install tessl/pypi-h5netcdf@1.6.0netCDF4 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%
Build a validation utility that checks netCDF4 files for common errors and format compliance issues before processing them in a data pipeline.
Your validator should check for and handle the following scenarios:
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).
Type Validation: When working with user-defined enumeration types, verify that:
Invalid Parameter Detection: Gracefully handle attempts to:
Your implementation should distinguish between different classes of errors (format violations, invalid parameters, missing items) and provide clear error messages for each category.
@generates
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)
"""
passWhen 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
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
Provides netCDF4 file access with error handling and validation capabilities.
@satisfied-by