dartobsgen.MOM6StateProvider#

class dartobsgen.MOM6StateProvider(model_output, cache_dir, required_vars=None)[source]#

Bases: ModelStateProvider

Serve single-timeslice MOM6 states from a run’s model output.

Works with both restart-format output (Temp, Salt, … on native layers) and z-space history output (thetao, so, … on z_l levels, supported by DART’s MOM6 model_mod via use_pseudo_depth) — whatever matches model_state_variables in the run’s input.nml.

Parameters:
  • model_output (str or list[str]) – Path, glob pattern, or explicit list of paths to MOM6 output files. Files may hold one or many timeslices; the union of all slices across all files forms the available states.

  • cache_dir (str) – Directory where extracted single-timeslice files are written (created on first use). Extractions are cached by valid time, so reruns and parallel windows reuse existing slices. Files that already hold a single timeslice are used in place, uncopied.

  • required_vars (tuple of str, optional) – Variables every input file must contain; construction fails with a clear message if any are absent. Use state_vars_from_nml() to take the list straight from model_state_variables in input.nml. None (default) skips the check.

Notes

Slice selection — one slice per window: the earliest slice whose DART-visible time falls in (date0, date1]. Additional slices in the same window are ignored. The interval is open at the lower edge to match the window perfect_model_obs is given (first_obs = date0 + 1s); a slice landing exactly on date0 belongs to the previous window, and selecting it here would place every obs one second before first_obs.

Time handling — selection and valid_time use the time exactly as DART’s read_model_time computes it (see mom6_time_to_datetime()), keeping observation placement consistent with what perfect_model_obs computes.

Parallel safety — extracted slices are written to a temporary name and moved into place atomically, so concurrent workers extracting the same slice cannot corrupt the cache.

__init__(model_output, cache_dir, required_vars=None)[source]#
Parameters:

Methods

__init__(model_output, cache_dir[, ...])

available_times()

Valid times of every indexed timeslice, ascending.

state_for_window(date0, date1)

Return the model state for the window (date0, date1].

available_times()[source]#

Valid times of every indexed timeslice, ascending.

_index is already sorted by raw day number, and mom6_time_to_datetime() is monotonic, so this preserves order.

Return type:

list[datetime]

state_for_window(date0, date1)[source]#

Return the model state for the window (date0, date1].

The interval is open below and closed above, matching the window perfect_model_obs is given (first_obs = date0 + 1s, last_obs = date1). A state landing exactly on date0 belongs to the previous window; returning it here would place every observation one second before first_obs.

Returns:

None if no model state falls within the window; the window is then skipped (no obs_seq file is written).

Return type:

ModelState or None

Parameters: