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 Python script that reads a netCDF4 file and manages metadata attributes for the file and its variables.
Create a function that opens a netCDF4 file, sets metadata attributes, and verifies that attributes can be read back correctly.
Add metadata to the file level (global attributes):
title attribute with a string valueConventions attribute with a string value (e.g., "CF-1.8")Add metadata to variables within the file:
units attribute (string) for a variablelong_name attribute (string) for a variablevalid_range attribute (numeric array) for a variableRetrieve metadata values that were previously set:
Remove attributes from variables:
@generates
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
"""
passProvides netCDF4 file-format access for reading and writing climate data files with metadata support.