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-6/

Climate Data Metadata Manager

Build a Python script that reads a netCDF4 file and manages metadata attributes for the file and its variables.

Requirements

Create a function that opens a netCDF4 file, sets metadata attributes, and verifies that attributes can be read back correctly.

Capabilities

Set File Attributes

Add metadata to the file level (global attributes):

  • Set a title attribute with a string value
  • Set a Conventions attribute with a string value (e.g., "CF-1.8")

Set Variable Attributes

Add metadata to variables within the file:

  • Set a units attribute (string) for a variable
  • Set a long_name attribute (string) for a variable
  • Set a valid_range attribute (numeric array) for a variable

Read Attributes

Retrieve metadata values that were previously set:

  • Read file-level attributes and return their values
  • Read variable-level attributes and return their values

Delete Attributes

Remove attributes from variables:

  • Delete a specific attribute from a variable
  • Verify the attribute is no longer accessible

Test Cases

  • Given a netCDF4 file with a temperature variable, after setting variable attributes (units="degC", long_name="Air Temperature", valid_range=[-50.0, 50.0]), reading these attributes returns the exact values @test
  • Given a netCDF4 file, after setting file-level attributes (title="Climate Dataset", Conventions="CF-1.8"), reading these attributes returns the exact values @test
  • After deleting a variable attribute named "comment", attempting to access that attribute raises KeyError @test

Implementation

@generates

API

def set_file_attrs(filepath: str, attributes: dict) -> None:
    """
    Set file-level (global) attributes on a netCDF4 file.

    Args:
        filepath: Path to the netCDF4 file
        attributes: Dictionary of attribute names and values to set
    """
    pass

def set_variable_attrs(filepath: str, variable_name: str, attributes: dict) -> None:
    """
    Set attributes on a specific variable in a netCDF4 file.

    Args:
        filepath: Path to the netCDF4 file
        variable_name: Name of the variable to set attributes on
        attributes: Dictionary of attribute names and values to set
    """
    pass

def get_attrs(filepath: str, variable_name: str = None) -> dict:
    """
    Read attributes from a netCDF4 file or variable.

    Args:
        filepath: Path to the netCDF4 file
        variable_name: Optional variable name. If None, returns file-level attributes.
                      If provided, returns attributes for that variable.

    Returns:
        Dictionary of attribute names and their values
    """
    pass

def delete_attr(filepath: str, variable_name: str, attr_name: str) -> None:
    """
    Delete an attribute from a variable in a netCDF4 file.

    Args:
        filepath: Path to the netCDF4 file
        variable_name: Name of the variable
        attr_name: Name of the attribute to delete
    """
    pass

Dependencies { .dependencies }

h5netcdf { .dependency }

Provides netCDF4 file-format access for reading and writing climate data files with metadata support.

Version

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