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

Climate Data Organizer

Build a hierarchical climate data management system that organizes weather station data by region and station using netCDF4 format.

Requirements

Create a Python module that manages climate data in a hierarchical structure. The module should:

  1. Create a netCDF4 file with nested group structures representing geographic regions and weather stations
  2. Support adding regions (parent groups) and stations (child groups nested within regions)
  3. Store temperature data within station groups using variables and dimensions
  4. Navigate the hierarchy to access specific stations and list all regions and stations

Structure

The file organizes data hierarchically:

  • Root level: The file itself acts as the root container
  • Regional groups: First-level groups representing geographic regions (e.g., "north", "south")
  • Station groups: Second-level groups nested within regions, representing weather stations (e.g., "station_01")
  • Station data: Each station group contains a "temperature" variable with a "time" dimension, plus latitude and longitude attributes

Functionality

Implement these functions:

  1. create_climate_file(filename): Create and return a new netCDF4 file ready for hierarchical data
  2. add_region(file_or_filename, region_name): Create a regional group in the file
  3. add_station(file_or_filename, region_path, station_name, lat, lon): Create a station group within a region with metadata attributes
  4. store_temperatures(file_or_filename, region_name, station_name, temp_values): Store temperature measurements in the station's variable
  5. get_all_regions(file_or_filename): Return a list of all region names
  6. get_region_stations(file_or_filename, region_name): Return a list of all station names within a region

Implementation

@generates

API

def create_climate_file(filename: str):
    """
    Create a new netCDF4 file for storing hierarchical climate data.

    Args:
        filename: Path to the netCDF4 file to create

    Returns:
        File object (should support context manager protocol)
    """
    pass

def add_region(file_or_filename, region_name: str) -> None:
    """
    Add a new regional group to the file.

    Args:
        file_or_filename: File object or path to netCDF4 file
        region_name: Name of the region group to create
    """
    pass

def add_station(file_or_filename, region_name: str, station_name: str,
                lat: float, lon: float) -> None:
    """
    Add a weather station group within a region, with location metadata.

    Args:
        file_or_filename: File object or path to netCDF4 file
        region_name: Name of the parent region group
        station_name: Name of the station group to create
        lat: Latitude of the station (stored as an attribute)
        lon: Longitude of the station (stored as an attribute)
    """
    pass

def store_temperatures(file_or_filename, region_name: str, station_name: str,
                      temp_values: list) -> None:
    """
    Store temperature measurements in a station's variable.

    Args:
        file_or_filename: File object or path to netCDF4 file
        region_name: Name of the region group
        station_name: Name of the station group
        temp_values: List of temperature values to store
    """
    pass

def get_all_regions(file_or_filename) -> list:
    """
    Get names of all regional groups in the file.

    Args:
        file_or_filename: File object or path to netCDF4 file

    Returns:
        List of region names
    """
    pass

def get_region_stations(file_or_filename, region_name: str) -> list:
    """
    Get names of all station groups within a region.

    Args:
        file_or_filename: File object or path to netCDF4 file
        region_name: Name of the region group

    Returns:
        List of station names
    """
    pass

Test Cases

  • Creating a file and adding a region "north" should make the region accessible as a group @test
  • Adding station "station_01" to region "north" with lat=45.0, lon=-93.0 should create a nested group with those attributes @test
  • Storing temperatures [20.5, 21.0, 19.8] for north/station_01 should create a temperature variable with data retrievable by indexing @test
  • Calling get_all_regions() on a file with "north" and "south" regions should return both region names @test
  • Calling get_region_stations("north") on a file with stations "station_01" and "station_02" should return both station names @test

Dependencies { .dependencies }

h5netcdf { .dependency }

Provides netCDF4 file format support with hierarchical group capabilities.

Version

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