src.core module¶
Common functions and classes used in multiple places in the MDTF code.
-
class
src.core.ObjectStatus(value)¶ Bases:
src.util.basic.MDTFEnumutil.MDTFEnumused to track the status of aMDTFObjectBase:NOTSET: the object hasn’t been fully initialized.
ACTIVE: the object is currently being processed by the framework.
- INACTIVE: the object has been initialized, but isn’t being processed (e.g.,
alternate
VarlistEntrys).
- FAILED: processing of the object has encountered an error, and no further
work will be done.
-
NOTSET= 1¶
-
ACTIVE= 2¶
-
INACTIVE= 3¶
-
FAILED= 4¶
-
SUCCEEDED= 5¶
-
class
src.core.MDTFObjectBase(*args, **kwargs)[source]¶ Bases:
objectBase class providing shared functionality for the “object hierarchy”:
DataSourceBases belonging to a run of the package
Diagnostics (PODs) belonging to aDataSourceBase;
VarlistEntrys (requested model variables) belongingto a
Diagnostic.
-
_id: src.util.basic.MDTF_ID = None¶
-
_parent: Any = sentinel.Mandatory¶
-
status: src.core.ObjectStatus = 1¶
-
property
_log_name¶
-
property
full_name¶
-
property
failed¶
-
property
active¶
-
abstract property
_children¶ Iterable of child objects associated with this object.
-
iter_children(child_type=None, status=None, status_neq=None)[source]¶ Generator iterating over child objects associated with this object.
- Parameters
status – None or
ObjectStatus, default None. If None, iterates over all child objects, regardless of status. If aObjectStatusvalue is passed, only iterates over child objects with that status.status_neq – None or
ObjectStatus, default None. If set, iterates over child objects which don’t have the given status. If status is set, this setting is ignored.
-
_deactivation_log_level= 40¶
-
_abc_impl= <_abc_data object>¶
-
class
src.core.ConfigTuple(name, backup_filename, contents)¶ Bases:
tupleClass wrapping general structs used for configuration
-
_asdict()¶ Return a new OrderedDict which maps field names to their values.
-
_field_defaults= {}¶
-
_fields= ('name', 'backup_filename', 'contents')¶
-
_fields_defaults= {}¶
-
classmethod
_make(iterable)¶ Make a new ConfigTuple object from a sequence or iterable
-
_replace(**kwds)¶ Return a new ConfigTuple object replacing specified fields with new values
-
property
backup_filename¶ Alias for field number 1
-
property
contents¶ Alias for field number 2
-
property
name¶ Alias for field number 0
-
-
class
src.core.PathManager(*args, **kwargs)[source]¶ Bases:
src.util.basic.Singleton,src.util.basic.NameSpaceSingletonholding the root directories for all paths used by the code.
-
class
src.core.TempDirManager(*args, **kwargs)[source]¶ Bases:
src.util.basic.Singleton-
_prefix= 'MDTF_temp_'¶
-
-
class
src.core.TranslatedVarlistEntry(coords: dataclasses.InitVar = None, name: str = sentinel.Mandatory, standard_name: str = sentinel.Mandatory, units: src.units.Units = sentinel.Mandatory, convention: str = sentinel.Mandatory, log: Any = sentinel.Mandatory)[source]¶ Bases:
src.data_model.DMVariableClass returned by
VarlistTranslator.translate(). Marks some attributes inherited fromDMVariableas being queryable indata_manager.DataframeQueryDataSourceBase.query_dataset().-
units: src.units.Units = sentinel.Mandatory¶
-
log: Any = sentinel.Mandatory¶
-
-
class
src.core.FieldlistEntry(coords: dataclasses.InitVar = None, name: str = sentinel.Mandatory, standard_name: str = sentinel.Mandatory, units: src.units.Units = '', scalar_coord_templates: dict = <factory>)[source]¶ Bases:
src.data_model.DMDependentVariableClass corresponding to an entry in a fieldlist file.
-
_ndim_to_axes_set= {1: 'PLACEHOLDER_T_COORD', 2: ('PLACEHOLDER_Y_COORD', 'PLACEHOLDER_X_COORD'), 3: ('PLACEHOLDER_T_COORD', 'PLACEHOLDER_Y_COORD', 'PLACEHOLDER_X_COORD'), 4: ('PLACEHOLDER_T_COORD', 'PLACEHOLDER_Z_COORD', 'PLACEHOLDER_Y_COORD', 'PLACEHOLDER_X_COORD')}¶
-
_placeholder_class_dict= {'PLACEHOLDER_COORD': <class 'src.data_model.DMPlaceholderCoordinate'>, 'PLACEHOLDER_T_COORD': <class 'src.data_model.DMPlaceholderTCoordinate'>, 'PLACEHOLDER_X_COORD': <class 'src.data_model.DMPlaceholderXCoordinate'>, 'PLACEHOLDER_Y_COORD': <class 'src.data_model.DMPlaceholderYCoordinate'>, 'PLACEHOLDER_Z_COORD': <class 'src.data_model.DMPlaceholderZCoordinate'>}¶
-
-
class
src.core.Fieldlist(name: str = sentinel.Mandatory, axes: src.util.basic.WormDict = <factory>, axes_lut: src.util.basic.WormDict = <factory>, entries: src.util.basic.WormDict = <factory>, lut: src.util.basic.WormDict = <factory>, env_vars: dict = <factory>)[source]¶ Bases:
objectClass corresponding to a single variable naming convention (single file in data/fieldlist_*.jsonc).
TODO: implement more robust indexing/lookup scheme. standard_name is not a unique identifier, but should include cell_methods, etc. as well as dimensionality.
-
axes: util.WormDict¶
-
axes_lut: util.WormDict¶
-
entries: util.WormDict¶
-
lut: util.WormDict¶
-
to_CF(var_or_name)[source]¶ Returns
FieldlistEntryfor the variable having the given name in this convention.
-
to_CF_name(var_or_name)[source]¶ Like
to_CF(), but only return the CF standard name, given the name in this convention.
-
from_CF(var_or_name, axes_set=None)[source]¶ Look up
FieldlistEntrycorresponding to the given standard name, optionally providing an axes_set to resolve ambiguity.TODO: this is a hacky implementation; FieldlistEntry needs to be expanded with more ways to uniquely identify variable (eg cell methods).
-
from_CF_name(var_or_name, axes_set=None)[source]¶ Like
from_CF(), but only return the variable’s name in this convention.
-
translate_coord(coord, log=<Logger src.core (WARNING)>)[source]¶ Given a
DMCoordinate, look up the corresponding translatedDMCoordinatein this convention.
-
translate(var)[source]¶ Returns
TranslatedVarlistEntryinstance, with populated coordinate axes. Units of scalar coord slices are translated to the units of the conventions’ coordinates. Includes logic to translate and rename scalar coords/slices, e.g.VarlistEntryfor ‘ua’ (intrinsically 4D) @ 500mb could produce aTranslatedVarlistEntryfor ‘u500’ (3D slice), depending on naming convention.
-
-
class
src.core.NoTranslationFieldlist(*args, **kwargs)[source]¶ Bases:
src.util.basic.SingletonClass which partially implements the
Fieldlistinterface but does no variable translation.VarlistEntryobjects from the POD are passed through to createTranslatedVarlistEntryobjects.-
translate(var)[source]¶ Returns
TranslatedVarlistEntryinstance, populated with contents of inputVarlistEntryinstance.Note
We return a copy of the
VarlistEntrybecause logic inDefaultDatasetParseralters the translation based on the file’s actual contents.
-
-
class
src.core.VariableTranslator(*args, **kwargs)[source]¶ Bases:
src.util.basic.SingletonSingletoncontaining information for different variable naming conventions. These are defined in thedata/fieldlist_*.jsoncfiles.-
get_convention_name(conv_name)[source]¶ Resolve the naming convention associated with a given
Fieldlistobject from among a set of possible aliases.
-
get_convention(conv_name)[source]¶ Return the
Fieldlistobject containing the variable name translation logic for a given convention name.
-
-
class
src.core.MDTFFramework(*args, **kwargs)[source]¶ Bases:
src.core.MDTFObjectBase-
property
_children¶ Iterable of child objects associated with this object.
-
property
full_name¶
-
configure(cli_obj, pod_info_tuple, log_config)[source]¶ Wrapper for all configuration done based on CLI arguments.
-
parse_mdtf_args(cli_obj, pod_info_tuple)[source]¶ Parse script options returned by the CLI. For greater customizability, most of the functionality is spun out into sub-methods.
-
_abc_impl= <_abc_data object>¶
-
_print_config(cli_obj, config, paths)[source]¶ Log end result of parsing package settings. This is only for the user’s benefit; a machine-readable version which is usable for provenance/reproducibility is saved by the OutputManager as
config_save.jsonc.
-
property
failed¶ Overall success/failure of this run of the framework. Return True if any case or any POD has failed, else return False.
-
property