CorrDiffCosmoEra5#
- class earth2studio.models.dx.CorrDiffCosmoEra5(
- era5_variables,
- output_variables,
- regression_model,
- diffusion_model,
- resolution,
- mode,
- lat_input_grid,
- lon_input_grid,
- lat_output_grid,
- lon_output_grid,
- era5_center,
- era5_scale,
- out_center,
- out_scale,
- static_invariants,
- pre_invariant_variables,
- post_invariant_variables,
- channel_transforms=None,
- constraints=None,
- number_of_samples=1,
- physical_clamp=True,
- number_of_steps=18,
- sigma_min=0.002,
- sigma_max=800.0,
- rho=7.0,
- solver='heun',
- seed=None,
- amp=False,
- hub_heights=None,
- hub_interp='linear',
- wind_levels=None,
- EUDS202680 GB
COSMO-REA downscaling model: ERA5 -> high-resolution COSMO-REA.
Diagnostic model that downscales a global ERA5 state to high-resolution COSMO-REA regional reanalysis over Europe – COSMO-REA6 (~6 km) or COSMO-REA2 (~2.2 km), selected with
resolution. The input is an ERA5 state, so it can downscale an ERA5 analysis directly or run behind a global forecast model (e.g. SFNO -> CorrDiffCosmoEra5).modeselects one of two networks trained per resolution:"mean"– a deterministic regression predicting the conditional meanE[y | x]: a single smooth field in one forward pass. Fast; a good first high-resolution look or a deterministic conditional-mean baseline."diffusion"– a generative model sampling the conditional distributionp(y | x): an ensemble ofnumber_of_samplesrealizations (seeded for reproducibility) that also captures the spread the mean cannot represent.
Both networks are PhysicsNeMo DiTs at a fixed grid resolution but crop-size agnostic, so
set_domain()returns an instance restricted to any lat/lon sub-region without retraining (bounded to the trained footprint). Each resolution ships an extended grid beyond its native footprint; for COSMO-REA2 – whose native footprint is central-European – the extended grid reaches a broad European domain, enabling 2.2 km downscaling across it. Outputs are surface and model-level (3D) fields – winds, temperature, humidity, precipitation, cloud cover, fluxes, TKE, PBL height; variables with a canonical Earth2Studio name are relabelled viaCosmoLexiconand COSMO-specific fields keep a descriptive name. Optionally emits derived hub-height wind components (seehub_heights).- Parameters:
era5_variables (Sequence[str]) – ERA5 input variable names (canonical Earth2Studio lexicon), in network order.
output_variables (Sequence[str]) – Output (COSMO-REA) variable names, in network output-channel order.
regression_model (torch.nn.Module | None) – Network for
mode="mean"(an upstream physicsnemo RoPE-NATTENDiT).diffusion_model (torch.nn.Module | None) – Network for
mode="diffusion"(an upstream physicsnemoEDMPreconditioner(ConcatConditionWrapper(DiT))).resolution ({"rea6", "rea2"}) – Which COSMO-REA resolution this package targets.
mode ({"mean", "diffusion"}) – Which model to run.
lat_input_grid (torch.Tensor) – 1D increasing regular ERA5 input grid (the native default footprint).
lon_input_grid (torch.Tensor) – 1D increasing regular ERA5 input grid (the native default footprint).
lat_output_grid (torch.Tensor) – 2D curvilinear native (rotated-pole) target grid [out_lat, out_lon].
lon_output_grid (torch.Tensor) – 2D curvilinear native (rotated-pole) target grid [out_lat, out_lon].
era5_center (torch.Tensor) – ERA5 input normalization (mean/std), size [n_era5].
era5_scale (torch.Tensor) – ERA5 input normalization (mean/std), size [n_era5].
out_center (torch.Tensor) – Output normalization (mean/std) in transformed space, size [n_out].
out_scale (torch.Tensor) – Output normalization (mean/std) in transformed space, size [n_out].
static_invariants (OrderedDict[str, torch.Tensor]) – Native, already-normalized static invariant channels (non-position), each [out_lat, out_lon] — e.g.
elevation_norm,land_fraction,z0_lu,slope_east,slope_north. Position channels (sin/cos lat/lon) andcos_zenithare computed, not stored here.pre_invariant_variables (Sequence[str]) – Names of the invariant channels before / after
cos_zenithin the background channel order.post_invariant_variables (Sequence[str]) – Names of the invariant channels before / after
cos_zenithin the background channel order.channel_transforms (dict | None) – Per-output-channel nonlinear transform spec (from the package metadata), used to invert after de-normalizing.
constraints (dict | None) – Physical-constraint spec (
metadata["constraints"]): per-channelbounds(min/max clamps) and a shortwavesza_gate(the dawn/dusk solar gate), applied in physical space in postprocess for both modes.number_of_samples (int) – Number of samples (diffusion); the
sampledim is kept (size 1) formode="mean"so both modes share an output contract. The constructor value is the default; it is settable at runtime between calls (model.number_of_samples = N).physical_clamp (bool) – Apply physical-bounds + the shortwave dawn/dusk solar gate to outputs.
number_of_steps (int) – Diffusion sampler step count (EDM Heun). Defaults to 18.
sigma_min (float) – Diffusion noise-schedule bounds. Default to 0.002 / 800.0.
sigma_max (float) – Diffusion noise-schedule bounds. Default to 0.002 / 800.0.
rho (float) – Karras noise-schedule exponent. Defaults to 7.0.
solver ({"heun", "euler"}) – Diffusion ODE solver:
"heun"(2nd-order, default) or"euler"(1st-order).seed (int | None) – Base RNG seed for diffusion sampling (a per-sample offset is added).
None(default) leaves sampling unseeded.amp (bool) – Run the network forward passes (regression patches and the diffusion denoiser) under
torch.autocastbf16. Roughly halves inference time on Ampere+ GPUs at a negligible accuracy cost; the sampler bookkeeping stays in fp64. Defaults toFalse(full precision).hub_heights (Sequence[float], optional) – Optional list of above-ground heights (m) at which to emit interpolated wind components
u{H}m/v{H}m(e.g.[100]->u100m,v100m), vertically interpolated from the model’s 3D wind levels. Wind speed is obtained by composing the stockDerivedWS(levels=["{H}m"])diagnostic on the output.None(default) -> no derived outputs and behavior/output_variablesare unchanged. Requireswind_levels. Names follow the lexiconm-suffix convention (m above surface, asu100m); arbitraryHneed not be pre-registered in the lexicon (outputs are produced, not fetched). A height outside the levels’ range is clamped (not extrapolated) and warns.hub_interp ({"linear", "log"}, optional) – Interpolation method for the hub-height wind components:
"linear"(in geometric height) or"log"(inln(height)). Both are roughness-free between levels. Defaults to"linear".wind_levels (dict, optional) – Package metadata describing the 3D wind levels for hub-height derivation: each level’s
{u, v}output channels + itsa, bheight coefficients (height = a + b*elevation_invariant) and the elevation invariant name. Supplied by the package; required whenhub_heightsis set.
Notes
The diffusion sampler controls (
number_of_steps,sigma_min,sigma_max,rho,solver) default to the package metadata but are exposed for inference tuning rather than fixed: as with any diffusion sampler, these settings can shape the sampled output distribution (e.g. ensemble spread and the representation of extremes).The models are trained on ERA5 (global input) paired with COSMO-REA regional reanalysis (high-resolution target) over Europe:
COSMO-REA6 (~6 km), DWD: https://reanalysis.meteo.uni-bonn.de/?COSMO-REA6
COSMO-REA2 (~2.2 km), DWD: https://reanalysis.meteo.uni-bonn.de/?COSMO-REA2
ERA5, ECMWF: https://www.ecmwf.int/en/forecasts/dataset/ecmwf-reanalysis-v5
- __call__(x, coords)[source]#
Run the model.
xis [batch, time, variable, lat, lon];coordscarries atimeaxis (validity times) driving the solar-zenith channel.- Parameters:
x (Tensor)
coords (OrderedDict[str, ndarray])
- Return type:
tuple[Tensor, OrderedDict[str, ndarray]]
- classmethod load_default_package()[source]#
Default pre-trained COSMO-REA downscaling package (combined rea6/rea2).
Returns the hosted package; pick the model within it via
load_model(..., mode=, resolution=)(or rely on themean/rea6defaults throughfrom_pretrained).- Return type:
- classmethod load_model(
- package,
- device=None,
- mode='mean',
- resolution='rea6',
- hub_heights=None,
- hub_interp='linear',
Load a COSMO-REA downscaling model from a package.
mode({“mean”, “diffusion”}) andresolution({“rea6”, “rea2”}) select the checkpoint within one package. All other configuration (sampler, normalization, transforms) comes from the package metadata.hub_heights/hub_interpopt into derived hub-height wind components (u{H}m/v{H}m; composeDerivedWSfor speed); they require the package to carry awind_levelsmetadata block (else requestinghub_heightsraises). See the constructor.- Parameters:
package (Package)
device (str | None)
mode (Literal['mean', 'diffusion'])
resolution (Literal['rea6', 'rea2'])
hub_heights (Sequence[float] | None)
hub_interp (Literal['linear', 'log'])
- Return type:
DiagnosticModel