NEDAS.models.ode_model module

Base class for small dynamical systems (ODEs, maps and 1D PDEs) used to test DA methods.

These are the toy models of DART (models/lorenz_63, 9var, ikeda, …) and DAPPER (dapper/mods): their whole state is a short vector, so a subclass only defines the dynamics (dxdt, or step for a map or a custom scheme), a reference state x0 and default settings in its own default.yml. Everything else, the io and the truth and ensemble generation, is here.

The state vector is the model variable ‘state’ on a 1D grid of its indices (Grid1D, x = 0..n-1), so synthetic observations are placed by obs_x index, and localization distances are in index units. A subclass with more than one kind of variable (lorenz96_2scale) overrides get_field and set_field to map the state vector to its variables on the grid.

Both io modes are supported: online (default) keeps the state vector of each member in self.memory, offline in a netCDF file per member and time (variable ‘state’).

Model time is nondimensional; hours_per_unit_time relates it to the hours NEDAS cycles in, following the convention of Lorenz (1996) that 0.05 time units is 6 hours (120 h per unit).

class NEDAS.models.ode_model.OdeModel(**kwargs)[source]

Bases: Model[Grid1D]

Base class of the small models: a state vector advanced by step.

Settings common to all of them (in each model’s default.yml):

Parameters:
  • dt (float) – time step in model time units (1 for a map)

  • hours_per_unit_time (float) – hours per model time unit

  • restart_dt (float) – restart interval in hours

  • spinup_time (float) – model time to run from a perturbed x0 to get a state on the attractor

  • init_sd (float) – standard deviation of the random perturbation added to x0 before the spinup

  • init_ens_mode (str) – ‘climatology’ for members that are independently spun up states, or ‘truth’ for the truth at the start time plus noise of standard deviation init_ens_sd

  • init_ens_sd (float) – see init_ens_mode

  • seed (int) – random seed for the truth; member m uses seed + 1 + m

io_mode: Literal['online', 'offline'] = 'online'
dt: float
hours_per_unit_time: float
restart_dt: float
spinup_time: float
init_sd: float
init_ens_mode: str
init_ens_sd: float
seed: int
cyclic: bool = False
memory: dict = {}
property state_size: int

length of the state vector

x0() → ndarray[source]

a reference state, perturbed and spun up to start the truth and the ensemble

dxdt(x: ndarray) → ndarray[source]

the time derivative of the state (for an ODE stepped by step)

step(x: ndarray) → ndarray[source]

one time step of length dt; RK4 of dxdt unless a subclass has its own scheme

grid_size() → int[source]

number of grid points; the state vector itself unless a subclass maps it otherwise

field_names() → list[str][source]

the NEDAS variables of the model

get_field(x: ndarray, name: str) → ndarray[source]

the variable name on the grid, from a state vector

set_field(x: ndarray, name: str, fld: ndarray) → None[source]

set the variable name in a state vector, in place

nsteps(hours: float) → int[source]

number of time steps in an interval of the given hours

advance(x: ndarray, nsteps: int) → ndarray[source]

the state after nsteps time steps from x (x is not changed)

initial_condition(seed: int) → ndarray[source]

a state on the attractor: x0 plus noise of init_sd, spun up for spinup_time

filename(**kwargs) → str[source]
read_grid(**kwargs)[source]

Read the grid information from the model output.

Parameters:

**kwargs – Keyword arguments for reading the grid.

read_mask(**kwargs)[source]
z_coords(**kwargs) → ndarray[source]

Get the vertical coordinates of the model.

Parameters:

**kwargs – Keyword arguments for getting the vertical coordinates.

Returns:

The vertical coordinates.

Return type:

np.ndarray

get_state(**kwargs) → ndarray[source]

the state vector at kwargs time and member (and tag, in memory)

set_state(x: ndarray, **kwargs) → None[source]

store the state vector at kwargs time and member (and tag, in memory)

read_var_from_file(**kwargs) → ndarray[source]
read_var_from_memory(**kwargs) → ndarray[source]
write_var_to_file(var, **kwargs) → None[source]
write_var_to_memory(var, **kwargs) → None[source]
preprocess(*args, **kwargs)[source]

Preprocess the model data.

Parameters:

**kwargs – Keyword arguments for preprocessing.

postprocess(*args, **kwargs)[source]

Postprocess the model data.

Parameters:

**kwargs – Keyword arguments for postprocessing.

run(*args, **kwargs)[source]

Run the model forward in time.

Parameters:
  • *args – Arguments

  • **kwargs – Keyword arguments

Keyword Arguments:
  • time (datetime) – current time when forecast starts

  • restart_dir (str) – directory where restart files are located

  • forecast_period (int) – forecast period in hours

If self.ens_run_strategy == ‘batch’, the method will run all ensemble members in one go, expect additional kwargs[‘nens’] to be the ensemble size. If self.ens_run_strategy == ‘scheduler’, the method runs a single member indexed by kwargs[‘member’], and kwargs[‘worker_id’] is the pid assigned by the scheduler to run this method.

generate_truth(*args, **kwargs)[source]

Generate truth (nature run) model states. Use for running synthetic observation experiments.

generate_init_ensemble(*args, **kwargs)[source]

Generate initial perturbed model states for ensemble forecasts.

Parameters:
  • nens (int) – ensemble size

  • **kwargs