dartobsgen.MOM6StateProvider#
- class dartobsgen.MOM6StateProvider(model_output, cache_dir, required_vars=None)[source]#
Bases:
ModelStateProviderServe 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, … onz_llevels, supported by DART’s MOM6 model_mod viause_pseudo_depth) — whatever matchesmodel_state_variablesin the run’sinput.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 frommodel_state_variablesininput.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 windowperfect_model_obsis given (first_obs = date0 + 1s); a slice landing exactly ondate0belongs to the previous window, and selecting it here would place every obs one second beforefirst_obs.Time handling — selection and
valid_timeuse the time exactly as DART’sread_model_timecomputes it (seemom6_time_to_datetime()), keeping observation placement consistent with whatperfect_model_obscomputes.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.
Methods
__init__(model_output, cache_dir[, ...])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.
_indexis already sorted by raw day number, andmom6_time_to_datetime()is monotonic, so this preserves order.
- 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_obsis given (first_obs = date0 + 1s,last_obs = date1). A state landing exactly ondate0belongs to the previous window; returning it here would place every observation one second beforefirst_obs.- Returns:
Noneif no model state falls within the window; the window is then skipped (no obs_seq file is written).- Return type:
ModelState or None
- Parameters: