NEDAS.core.io_backend module

class NEDAS.core.io_backend.IOBackend[source]

Bases: ABC

Base class for handling runtime input/output for state and observation variables and OS-level operation such as file manipulation and running commands

Variables:
  • io_mode (IOMode) – ‘offline’ for file I/O and ‘online’ for persistent memory I/O

  • tags (list[str]) – List of names for copies of state/obs data

IOTags:

‘current’: Mutable buffer for the data, being updated by assimilation and outer-loop iterations ‘prior’: read-only snapshot, also known as background/forecast, kept for O-B statistics. ‘post’: final state after the assimilation, known as the (re)analysis. ‘truth’: truth, as reference state in synthetic OSSE experiments ‘raw’: original information. For obs it is the actual obs

io_mode: Literal['online', 'offline'] = 'offline'
tags: list[str] = ['current', 'prior', 'prior_mean', 'post', 'post_mean', 'truth', 'raw', 'z', 'z_mean']
validate_tag(tag: str)[source]
prepare_fields_storage(c: Context, tag: str) None[source]

Prepare for storage of fields data. Only needed for offline io modes: initialize the binary file that stores fields and write its metadata.

abstractmethod read_field(c: Context, tag: str, rec_id: int, mem_id: int) np.ndarray[source]

Read a 2D field data from the state

Parameters:
  • c (Context) – the runtime context

  • tag (str) – which copy of the state to read from

  • rec_id (int) – field record index

  • mem_id (int) – ensemble member index from 0 to nens-1

Returns:

the 2D field data

Return type:

np.ndarray

abstractmethod write_field(fld: np.ndarray, c: Context, tag: str, rec_id: int, mem_id: int) None[source]

Write a 2D field data to the state

Parameters:
  • fld (np.ndarray) – the 2D field data

  • c (Context) – the runtime context

  • tag (str) – which copy of the state to write to

  • rec_id (int) – field record index

  • mem_id (int) – ensemble member index

abstractmethod call_method(c: Context, tag: str, method: Callable, *args, **kwargs) Any[source]

Call a method to perform some tasks.

Parameters:
  • c (Context) – the runtime context

  • tag (str) – which copy of the model state to request io from: “prior”, “post” or “truth”

  • method (Callable) – method name

  • *args – will be passed to the method

  • **kwargs – will be passed to the method

Returns:

whatever the method(**kwargs) returns

Return type:

Any

save_ndarray(c: Context, name: str, data: np.ndarray, path: str | None = None) None[source]

Save ndarray data

Parameters:
  • c (Context) – the runtime context

  • name (str) – the name of the data

  • data (np.ndarray) – the data

  • path (str, optional) – system path to save the data to.

load_ndarray(c: Context, name: str, path: str | None = None) np.ndarray | None[source]

Load ndarray from saved data

Parameters:
  • c (Context) – the runtime context

  • name (str) – the name of the data

  • path (str, optional) – system path to the saved data.

Returns:

the data

Return type:

np.ndarray

save_debug_data(c: Context, name: str, data: dict, path: str | None = None) None[source]

Save debug data in npy format

Parameters:
  • c (Context) – the runtime context

  • name (str) – the name of the data

  • data (dict) – the data

  • path (str, optional) – system path to save the data to.

To recover the data, use np.load(file, allow_pickle=True).item()