NCAS-CMS / cfstore

A CF compliant data store with interfaces to local and remote storage.
MIT License
2 stars 1 forks source link

CFstore subspacing #129

Open georgeoobrienNCAS opened 10 months ago

georgeoobrienNCAS commented 10 months ago

Implement subspacing for axes queries (i.e. subset of months over time) Important ones are time, latitude and longitude so just do those.

davidhassell commented 10 months ago

I've just been checking the time subspacing syntax, and thought I'd share for the record. cf.cellwi is probably the query of choice here (and for the X and Y axes, too).

>>> import cf
>>> f = cf.example_field(2)
>>> print(f)
Field: air_potential_temperature (ncvar%air_potential_temperature)
------------------------------------------------------------------
Data            : air_potential_temperature(time(36), latitude(5), longitude(8)) K
Cell methods    : area: mean
Dimension coords: time(36) = [1959-12-16 12:00:00, ..., 1962-11-16 00:00:00]
                : latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : air_pressure(1) = [850.0] hPa
>>> print(f.subspace(T=cf.cellwi(cf.dt(1959, 12, 1), cf.dt(1960, 5, 1))))
Field: air_potential_temperature (ncvar%air_potential_temperature)
------------------------------------------------------------------
Data            : air_potential_temperature(time(5), latitude(5), longitude(8)) K
Cell methods    : area: mean
Dimension coords: time(5) = [1959-12-16 12:00:00, ..., 1960-04-16 00:00:00]
                : latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : air_pressure(1) = [850.0] hPa

In this example cf.wi would give the same result but that is not always the case, since cf.wi queries representative cell values, rather than bounds extents.