Skip to content

V1.0.1 - Added terminal info query functions

Choose a tag to compare

@NarenKarthikBM NarenKarthikBM released this 16 Dec 07:28
205d85c

πŸŽ‰ Release v1.0.1 - Information Operators as Query Terminators

This release brings a major enhancement to the Query API: all CDO information operators are now available as terminating methods directly on CDOQuery. Extract metadata from processed data without intermediate files, making workflows more intuitive and efficient.

✨ New Features

Information Operators as Terminating Query Methods

All 15 CDO information operators can now be called directly on query chains, executing immediately (like .compute()) but returning metadata instead of datasets:

Variable Information Methods:

  • .showname() - Get list of variable names
  • .showcode() - Get list of variable codes
  • .showunit() - Get list of variable units
  • .showlevel() - Get list of vertical levels

Time Information Methods:

  • .showdate() - Get list of dates (YYYY-MM-DD format)
  • .showtime() - Get list of times (HH:MM:SS format)
  • .ntime() - Get number of timesteps (alias for .count())

Count Methods:

  • .nvar() - Get number of variables
  • .nlevel() - Get number of vertical levels

Structured Dataset Information:

  • .sinfo() β†’ SinfoResult - Comprehensive dataset summary
  • .info() β†’ InfoResult - Timestep-by-timestep statistics
  • .vlist() β†’ VlistResult - Variable list with metadata
  • .partab() β†’ PartabResult - Parameter table information

Grid Information:

  • .griddes() β†’ GriddesResult - Grid description
  • .zaxisdes() β†’ ZaxisdesResult - Vertical axis description

Key Benefits

  • No intermediate files needed when inspecting processed data
  • Chain processing and metadata extraction in a single pipeline
  • Consistent Query API pattern following Django ORM conventions
  • Works with or without operators in the pipeline

πŸ“Š Example Usage

from python_cdo_wrapper import CDO

cdo = CDO()

# Get variable names after processing - no intermediate file!
vars = cdo.query("data.nc").year_mean().showname()
# Returns: ['tas', 'pr', 'psl']

# Get number of timesteps after selection
n = cdo.query("data.nc").select_year(2020).ntime()
# Returns: 12

# Get dates after complex processing
dates = (
    cdo.query("data.nc")
    .select_var("tas")
    .select_year(2020, 2021)
    .showdate()
)
# Returns: ['2020-01-01', '2020-02-01', ..., '2021-12-01']

# Get comprehensive dataset info after processing

```python
# Get structured dataset info after processing
info = cdo.query("data.nc").year_mean().sinfo()
print(f"Variables: {info.var_names}")
print(f"Time range: {info.time_range}")

# Get grid info after remapping
grid = cdo.query("data.nc").remap_bil("r180x90").griddes()
print(f"Grid type: {grid.grids[0].gridtype}")
print(f"Grid size: {grid.grids[0].xsize} x {grid.grids[0].ysize}")

πŸ”§ Improvements

  • Parser Enhancements: Improved SinfoParser and PartabParser robustness

    • Fixed variable name handling in SinfoParser (sinfo only provides parameter IDs)
    • Enhanced regex patterns in PartabParser for better field extraction
    • Better error handling for optional fields and edge cases
  • Test Data Quality: Upgraded test fixtures to CF-1.8 compliant standards

    • Changed temperature β†’ tas (standard CF variable name)
    • Added proper GRIB parameter codes (tas=167, pr=228, psl=151)
    • Improved NetCDF encoding and coordinate attributes
  • Type Safety: Added proper type casting with typing.cast for better IDE support

  • Documentation: Added comprehensive example script examples/info_operators_example.py

  • Agent Configuration: Updated GitHub Copilot agent tool definitions

Backward Compatibility

Fully backward compatible - all existing code continues to work without changes. The new methods are additions to the Query API and don't affect existing functionality.

Recommended migration (optional):

# Old way (still works)
cdo.showname("data.nc")

# New way (recommended for processed data)
cdo.query("data.nc").year_mean().showname()  # No intermediate file!

Installation

pip install --upgrade python-cdo-wrapper

Full Changelog: v1.0.0...v1.0.1