NEDAS.core.model module

class NEDAS.core.model.Model(context: Context | None = None, io_mode: Literal['online', 'offline'] | None = None, config_file: str | None = None, parse_args: bool = False, **kwargs)[source]

Bases: Generic[GridT], ABC

Class for configuring and running a model

variables: dict[Annotated[str, 'variable name'], VarDesc]
grid: GridT
z: dict[Annotated[int, 'z level index'], ndarray]
mask: ndarray
ens_init_dir: str | None
truth_dir: str | None
ens_run_strategy: Literal['scheduler', 'batch']
nproc_per_run: int = 1
nproc_per_util: int = 1
walltime: int | None = None
run_process = None
run_status: str = 'pending'
restart_dir: str
forecast_period: int
memory: dict
io_mode: Literal['online', 'offline']
model_name: str
property c: Context
parse_kwargs(kwargs: dict[str, Any]) dict[str, Any][source]
get_mstr(member)[source]
get_tstr(time)[source]
abstractmethod read_grid(**kwargs) None[source]

Read the grid information from the model output.

Parameters:

**kwargs – Keyword arguments for reading the grid.

read_var(**kwargs) ndarray[source]

Read a variable from the model output.

Parameters:

**kwargs – Keyword arguments for reading the variable.

Returns:

The read variable.

Return type:

np.ndarray

read_var_from_file(**kwargs) ndarray[source]
read_var_from_memory(**kwargs)[source]
write_var(var, **kwargs) None[source]

Write a variable to the model output.

Parameters:
  • var (np.ndarray) – The variable to write.

  • **kwargs – Keyword arguments for writing the variable.

write_var_to_file(var, **kwargs)[source]
write_var_to_memory(var, **kwargs)[source]
save_memory(tag: str, time: datetime | None = None, path: str | None = None) None[source]
load_memory(tag: str, time: datetime | None = None, path: str | None = None) None[source]
abstractmethod 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

abstractmethod preprocess(*args, **kwargs) None[source]

Preprocess the model data.

Parameters:

**kwargs – Keyword arguments for preprocessing.

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

Postprocess the model data.

Parameters:

**kwargs – Keyword arguments for postprocessing.

abstractmethod run(*args, **kwargs) None[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) None[source]

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

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

Generate initial perturbed model states for ensemble forecasts.

Parameters:
  • nens (int) – ensemble size

  • **kwargs