StormCastSDA¶
NADANWC202440 GBNVIDIAPyTorch
Import path: earth2studio.models.da.StormCastSDA
View source on GitHub View install commands
Documentation¶
Bases: Module, AutoModelMixin
StormCast with score-based data assimilation (SDA) using diffusion posterior sampling for convection-allowing regional forecasts. Combines a regression and diffusion model with DPS guidance to assimilate observations during inference. Model time step size is 1 hour, taking as input:
- High-resolution (3km) HRRR state over the central United States (99 vars)
- High-resolution land-sea mask and orography invariants
- Coarse resolution (25km) global state (26 vars)
- Point observations for data assimilation
The high-resolution grid is the HRRR Lambert conformal projection.
The caller supplies conditioning regridded to the HRRR grid, followed by
observations, in forcing_coords() order.
initialize computes the first analysis and returns explicit Torch RNG
snapshots for continuation with step. create_iterator yields analyses
only, starting at input plus one hour. Sampling uses scoped global Torch RNG
state; run stochastic components serially within a process.
Note
For more information see the following references:
Parameters:
-
regression_model(Module) –Deterministic model used to make an initial prediction
-
diffusion_model(Module) –Generative model correcting the deterministic prediciton
-
means(Tensor) –Mean value of each input high-resolution variable
-
stds(Tensor) –Standard deviation of each input high-resolution variable
-
invariants(Tensor) –Static invariant quantities
-
hrrr_lat_lim(tuple[int, int], default:(273, 785)) –HRRR grid latitude limits, defaults to be the StormCastV1 region in central United States, by default (273, 785)
-
hrrr_lon_lim(tuple[int, int], default:(579, 1219)) –HRRR grid longitude limits, defaults to be the StormCastV1 region in central United States,, by default (579, 1219)
-
variables(ndarray, default:array(VARIABLES)) –High-resolution variables, by default np.array(VARIABLES)
-
conditioning_means(Tensor | None, default:None) –Means to normalize conditioning data, by default None
-
conditioning_stds(Tensor | None, default:None) –Standard deviations to normalize conditioning data, by default None
-
conditioning_variables(ndarray, default:array(CONDITIONING_VARIABLES)) –Global variables for conditioning, by default np.array(CONDITIONING_VARIABLES)
-
time_tolerance(TimeTolerance, default:timedelta64(10, 'm')) –Time tolerance for filtering observations. Observations within the tolerance window around each requested time will be used for data assimilation, by default np.timedelta64(10, "m")
-
sampler_steps(int, default:36) –Number of diffusion sampler steps, by default 36
-
sampler_args(dict[str, float | int] | None, default:None) –Arguments to pass to the diffusion sampler, by default None
-
sda_std_obs(float, default:0.1) –Observation noise standard deviation for DPS guidance, by default 0.1
-
sda_gamma(float, default:0.001) –SDA scaling factor for DPS guidance, by default 0.001
__call__ ¶
Compute the first analysis, equivalent to initialize(...)[0].
Parameters:
-
x(DataArray) –Input state on the HRRR curvilinear grid
-
conditioning(DataArray) –Conditioning on the same grid and valid time as x, matching the first
forcing_coords()slot. Regridding is caller-owned. -
obs(DataFrame | None, default:None) –Sparse observations at the output valid time, by default None
Returns:
-
DataArray–First analysis one hour into the future, without iterator hooks.
Raises:
-
ValueError–If state or conditioning coordinates do not match their declared slots.
set_rng ¶
Seed the stream used to start new trajectories.
Parameters:
-
seed(int) –Seed for a local CPU generator. Global RNG state is unchanged.
-
reset(bool, default:True) –Restart the initialization stream when True. When False, initialize it only if absent, by default True
Notes
Existing trajectories use their explicit state and are unaffected by reseeding. Without seeding, initialization draws from the global CPU RNG.
initialize ¶
initialize(
x: DataArray,
conditioning: DataArray,
obs: DataFrame | None = None,
) -> tuple[DataArray, dict[str, Tensor]]
Compute the first analysis and start an independent trajectory.
Parameters:
-
x(DataArray) –Initial HRRR state. Fields are moved to the model device.
-
conditioning(DataArray) –Required conditioning on the same grid and valid time as x.
-
obs(DataFrame | None, default:None) –Observations at the first analysis time, by default None
Returns:
-
tuple[DataArray, dict[str, Tensor]]–First analysis at input plus one hour and serializable CPU/device RNG snapshots. Applies no hooks and does not modify inputs. Each initialization advances the model's initialization RNG stream.
Raises:
-
ValueError–If required conditioning is missing or coordinates are invalid.
step ¶
step(
y: DataArray,
conditioning: DataArray,
obs: DataFrame | None,
state: dict[str, Tensor],
) -> tuple[DataArray, dict[str, Tensor]]
Advance an analysis using its explicit RNG continuation.
Parameters:
-
y(DataArray) –Previous analysis. Fields are moved to the model device.
-
conditioning(DataArray) –Required conditioning at y's valid time on the same grid.
-
obs(DataFrame | None) –Observations at the next analysis time; None disables assimilation.
-
state(dict[str, Tensor]) –RNG snapshots returned by initialization or the previous step on the same device. Pass after the forcing slots, positionally or by keyword.
Returns:
-
tuple[DataArray, dict[str, Tensor]]–Next analysis one hour after y and updated RNG snapshots. Neither y, forcing nor state is modified; replay is independent of model reseeding and other trajectories. Applies no hooks.
Raises:
-
ValueError–If conditioning is missing, coordinates are invalid, or state lacks RNG snapshots for this device.
create_iterator ¶
create_iterator(
x: DataArray,
conditioning: DataArray,
obs: DataFrame | None = None,
) -> Generator[
DataArray,
tuple[DataArray, DataFrame | None] | None,
None,
]
Yield hourly analyses, beginning with the initialization analysis.
The generator yields states and receives conditioning and observations
via send((conditioning, obs)) in forcing-slot order. Observations
are mapped to the HRRR grid, and the diffusion model produces the next
forecast step.
Parameters:
-
x(DataArray) –Initial state on the HRRR curvilinear grid
-
conditioning(DataArray) –Required initial conditioning on x's grid and valid time.
-
obs(DataFrame | None, default:None) –Observations at the first analysis time, by default None
Yields:
-
DataArray–Complete analyses, starting one hour after x; never the initial state.
Receives:
input_coords ¶
Declare the initial state on the cropped built-in HRRR projected grid.
forcing_coords ¶
forcing_coords() -> tuple[CoordinateSystem, FrameSchema]
Declare global conditioning and sparse observation forcing.
Returns:
-
tuple[CoordinateSystem, FrameSchema]–Conditioning on the HRRR grid at the input valid time, followed by observations at the output valid time (input plus one hour), filtered with the configured tolerance. Pass None for the observation slot to run without assimilation; conditioning is always required.
output_coords ¶
Output coordinate system of the assimilation model.
Parameters:
-
input_coords(CoordinateSystem) –Coordinates of tensor used to initialize the forecast model.
Returns:
-
CoordinateSystem–Allocation-free analysis signature on the HRRR grid, one hour after the initialization lead time.
default_sources ¶
default_sources() -> (
tuple[DataSource, ForecastSource, DataFrameSource]
)
Recommend HRRR state, global conditioning, and GHCNh observations.
Returns:
-
tuple[DataSource, ForecastSource, DataFrameSource]–HRRRfor the initial state,GFS_FXfor conditioning, thenGHCNHourlyfor the surface station observation slot, restricted to the stations inside this model's domain and using the model's observation time tolerance.
load_model
classmethod
¶
load_model(
package: Package,
time_tolerance: TimeTolerance = timedelta64(10, "m"),
sampler_steps: int = 36,
sda_std_obs: float = 0.1,
sda_gamma: float = 0.001,
) -> StatefulAssimilationModel
Load assimilation from package
Parameters:
-
package(Package) –Package to load model from
-
time_tolerance(TimeTolerance, default:timedelta64(10, 'm')) –Time tolerance for filtering observations. Observations within the tolerance window around each requested time will be used for data assimilation, by default np.timedelta64(10, "m")
-
sampler_steps(int, default:36) –Number of diffusion sampler steps, by default 36
-
sda_std_obs(float, default:0.1) –Observation noise standard deviation for DPS guidance, by default 0.1
-
sda_gamma(float, default:0.001) –SDA scaling factor for DPS guidance, by default 0.001
Returns:
-
StatefulAssimilationModel–Assimilation model with explicit trajectory continuation