Usage¶
How to drive climdata once it is installed. For what each provider needs, see Datasets; for the full signatures, the API reference.
The idea¶
A climdata run is described by a configuration, not by code. ClimData
composes that configuration from Hydra defaults plus a list of overrides, then
carries a dataset through each step you ask for:
1 2 3 4 5 6 7 8 9 10 11 | |
Each step stores its result on the extractor, so the next one needs no
arguments. calc_index() operates on what extract() produced; to_csv()
writes what to_dataframe() made.
1 2 3 | |
Every stage is also addressable by name, should you want an earlier one back:
extractor.ds, .index_ds, .impute_ds, .reprojected_ds.
Discovering what is available¶
Before extracting anything, ask what exists. None of this touches the network
except list_esm_models.
1 2 3 4 5 6 | |
For programmatic access, cd.explore.get_registry() returns the same metadata
as a dictionary.
Within a configured extractor:
1 2 3 4 5 | |
Selecting a region¶
Point, bounding box, shapefile or GeoJSON — see Selecting a region for all four with examples. In brief:
1 2 3 4 | |
Chaining steps¶
run_workflow runs a named sequence and returns everything it produced:
1 2 3 4 5 6 7 | |
The available actions are:
| Action | Does | Needs |
|---|---|---|
extract |
Fetch from the configured provider | dataset set |
upload_netcdf |
Read an existing .nc instead |
file= argument |
upload_csv |
Read an existing long-form .csv |
file= argument |
impute |
Fill gaps | a dataset, impute= set |
calc_index |
Compute the configured extreme index | a dataset, index= set |
reproject |
Regrid onto a target CRS/resolution | a dataset, a target set |
to_csv |
Convert to long form and write CSV | a dataset |
to_nc |
Write NetCDF | a dataset |
to_fair |
Write an RO-Crate | a dataset |
Steps that are configured as no-ops are skipped rather than failing:
calc_index with no index= returns None and leaves the dataset alone, as
does reproject with no target grid. That makes it safe to put them in a
standard sequence.
An action that cannot run says why:
1 2 3 | |
Extreme indices¶
Indices are declared in conf/mappings/indices.yaml and computed by xclim.
Select one with index=:
1 2 3 | |
Percentile-based indices such as tn10p are defined against a 30-year
reference period. climdata warns when the record is shorter — the number it
returns is then a percentile of too little data, not a climate statistic.
To see which indices your variables support:
1 2 | |
Regridding¶
reproject puts a dataset onto a target CRS and cell size:
1 2 3 4 5 | |
The units of target_resolution must match the axis units of
target_projection. A metric resolution has no fixed angular size — 10 km spans
0.1395° of longitude but 0.0899° of latitude at 50°N — so combining "10 km"
with a geographic CRS raises ResolutionCRSMismatch rather than silently
approximating:
1 2 3 4 5 | |
If you want the approximation anyway, cd.to_angular("10 km", latitude=52.5)
converts it explicitly — exact at that latitude and only there.
See the worked example.
Filling gaps¶
1 2 3 | |
Each grid cell is treated as an independent time series, so a cell with no valid
values of its own cannot be recovered from its neighbours. SoftImpute,
CDRec and XGBOOST work out of the box; BRITS needs PyTorch. Calling
impute() on data with no gaps returns it unchanged.
Output¶
1 2 | |
Columns: time, lat, lon, variable, value, units, source.
Tab-separated.
1 | |
One file per grid cell, foldered by column index, with CF names mapped to
the names SIMPLACE and MONICA expect (tasmax → TempMax):
1 2 | |
A self-describing directory with the data, a JSON-LD manifest and an HTML preview:
1 | |
Output filenames are generated from the configuration and the current dataset,
so they follow the data through the workflow — after calc_index() the filename
names the index rather than the input variables. The templates live under
output: in conf/config.yaml.
Working from existing files¶
1 2 | |
The CSV must have time, lat/latitude, lon/longitude, variable and
value columns; units and source are used if present. Both set the current
dataset, so the rest of the workflow follows as usual.
Plotting¶
1 2 | |
Draws on Cartopy axes with coastlines and borders; needs matplotlib and
cartopy. Point and station extractions have no grid to draw and raise a
message saying so.
Parallelism¶
Extraction is single-threaded unless you opt in:
1 | |
That starts a local Dask cluster and leaves the dataset lazy; without it, data
is materialised into memory as it loads. Close it with extractor.close_dask().
An existing client in the process is reused rather than duplicated.