States — geocatalog.states¶
Query and load model states (analyses, forecasts, ensemble members) from
a catalog built with
build_state_catalog. The
how-to is Model states.
Loading (extras: [xarray-raster])¶
geocatalog.states.load_states(catalog, slice_, *, data_vars=None, group_by=None, storage_options=None)
¶
Load forecast states as an (init_time, member, lead_time, y, x) cube.
Every row overlapping slice_ is one run and member. Each file is
clipped to the slice (bounds and valid-time interval), its valid
times are relabelled as leads, τ = v - r, and the files are
stacked by run time and member. Two runs valid at the same time stay
two states, unlike load_xarray, which keeps one valid time. A
member or lead missing from a run comes back as NaN, not as a shorter
cube, and valid_time = init_time + lead_time is a 2-D coordinate.
Members are in natural order: by number when every label is an
integer ("2" before "10"), else as text (r1i1p1f1). A run
whose file overlaps the slice without a time step inside it has no
state there and is left out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog ( |
required |
slice_
|
GeoSlice
|
The region and valid-time interval to load. Bounds may be in another CRS; they are reprojected to the catalog's. |
required |
data_vars
|
Sequence[str] | None
|
Data variables to keep. |
None
|
group_by
|
str | None
|
A row column ( |
None
|
storage_options
|
dict[str, Any] | None
|
obstore options for remote files ( |
None
|
Returns:
| Type | Description |
|---|---|
Dataset | DataTree
|
An |
Dataset | DataTree
|
y, x) |
Dataset | DataTree
|
of them when |
Dataset | DataTree
|
member) is the member |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
TypeError
|
If the catalog is not of kind |
ValueError
|
If the catalog has no state columns, no row matches,
the slice holds none of the matching files' time steps, a row
has no run time, a run and member appears twice, or the rows
are on different grids without |
Example
from geocatalog.states import forecasts, load_states cube = load_states(forecasts(catalog), aoi) cube["xch4"].dims, cube["xch4"].shape (('init_time', 'member', 'lead_time', 'lat', 'lon'), (3, 4, 2, 4, 5))
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/states.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
Typed queries¶
geocatalog.states.forecasts(catalog)
¶
The forecast rows of a state catalog (kind == "forecast").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A catalog with the reserved state columns, on either backend. |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A catalog of the same backend with the forecast rows. |
Example
fc = forecasts(catalog) load_states(fc, aoi).sizes # (init_time, member, lead_time, y, x)
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
geocatalog.states.ensemble_at(catalog, *, run_time)
¶
Every member of one forecast run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog. |
required |
run_time
|
Timestamp
|
The run's initialisation time, a |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A catalog of the forecast rows with that |
GeoCatalog
|
member file. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
members = ensemble_at(catalog, run_time=pd.Timestamp("2026-01-01"))
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
geocatalog.states.forecast_chain(catalog, *, run_time, member)
¶
One member of one forecast run: the files of a single trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog. |
required |
run_time
|
Timestamp
|
The run's initialisation time, a |
required |
member
|
str
|
The member label, as text ( |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A catalog of the forecast rows of that run and member. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
chain = forecast_chain(catalog, run_time=pd.Timestamp("2026-01-02"), ... member="0")
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
geocatalog.states.lead_window(catalog, start, end)
¶
Forecast rows whose leads overlap [start, end].
A row covers valid times [v_min, v_max], so its leads are
[v_min - run_time, v_max - run_time]; lead time is derived, not
stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog. |
required |
start
|
Timedelta
|
First lead of the window, a |
required |
end
|
Timedelta
|
Last lead of the window (inclusive). |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A catalog of the forecast rows with at least one lead in the |
GeoCatalog
|
window. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a bound is not timedelta-like. |
ValueError
|
If |
Example
day_two = lead_window(catalog, pd.Timedelta("2D"), pd.Timedelta("2D"))
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
geocatalog.states.at_time(catalog, time)
¶
States of every kind valid at time: rows whose interval contains it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog. |
required |
time
|
Timestamp
|
The valid time, a |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A catalog of the rows whose valid-time interval contains |
GeoCatalog
|
(analyses, and every run and member that reaches it). |
Example
jan3 = at_time(catalog, pd.Timestamp("2026-01-03"))
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
geocatalog.states.latest_analysis(catalog, *, before)
¶
The analysis with the latest valid time at or before before.
Filters on the reserved kind column, not on a zero lead: a lead-0
forecast row is valid at its run time too. Analyses valid at the same
time are ordered by run time, then by file path (the last wins), so
every backend returns the same row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
A state catalog. |
required |
before
|
Timestamp
|
The cut-off valid time, a |
required |
Returns:
| Type | Description |
|---|---|
CatalogRow | None
|
The |
Example
row = latest_analysis(catalog, before=pd.Timestamp("2026-01-03 06:00")) row.filepath 'ana_20260103.nc'
Source code in packages/geotoolz-catalog/src/geocatalog/_src/states.py
Columns and name maps¶
geocatalog.states.STATE_COLUMNS = ('kind', 'run_time', 'member', 'producer', 'parents')
module-attribute
¶
Row columns reserved, with fixed types, for model states (schema v1).
kind (string, a StateKind), run_time (datetime64[us], naive
UTC: the run's initialisation time), member (string: a CF realization
number written as text, or a CMIP variant label such as r1i1p1f1),
producer (string) and parents (list<string>: the URIs the
state was computed from). A state catalog is one with a run_time
column (is_state_frame), and it carries all five; in any other catalog
the names are ordinary extras. Lead time is not stored: it is the row's
valid time minus run_time.
They stay ordinary row columns (and CatalogRow.extras keys), unlike
RESERVED_COLUMNS, which every artifact carries.
geocatalog.states.StateFields
dataclass
¶
The model-state fields of one catalog row (CatalogRow.state).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str | None
|
|
run_time |
Timestamp | None
|
The run's initialisation time (naive UTC), or |
member |
str | None
|
The ensemble member as text ( |
producer |
str | None
|
What made the state (a pipeline hash, a model id), or
|
parents |
tuple[str, ...]
|
URIs of the states this one was computed from; empty when none are recorded. |
Example
row = next(catalog.iter_rows()) row.state.run_time, row.state.member (Timestamp('2026-01-02 00:00:00'), '0')
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
geocatalog.states.CF_NAMES = MappingProxyType({'valid_time': 'time', 'run_time': 'forecast_reference_time', 'member': 'realization', 'kind': 'kind', 'producer': 'producer', 'parents': 'parents'})
module-attribute
¶
Where CF files keep each state field.
The run time is the forecast_reference_time coordinate or attribute,
the member the realization one, and the valid time the time axis.
kind, producer and parents have no CF name: they are global
attributes of those names, written by the script that saves the states.
geocatalog.states.CFGRIB_NAMES = MappingProxyType({'valid_time': 'valid_time', 'run_time': 'time', 'member': 'number', 'kind': 'kind', 'producer': 'producer', 'parents': 'parents'})
module-attribute
¶
Where cfgrib-decoded GRIB keeps each state field.
cfgrib names the run time time (a scalar coordinate), the lead
step, the member number and the valid time valid_time (a
coordinate along step).