imas.ids_structure.IDSStructure¶
- class imas.ids_structure.IDSStructure(parent: IDSBase, metadata: IDSMetadata)¶
Bases:
IDSBaseIDS structure node
Represents a node in the IDS tree. Does not itself contain data, but contains references to leaf nodes with data (IDSPrimitive) or other node-like structures, for example other IDSStructures or IDSStructArrays
- __init__(parent: IDSBase, metadata: IDSMetadata)¶
Initialize IDSStructure from metadata specification
- Parameters:
- parent: IDSBase¶
Parent structure. Can be anything, but at database write time should be something with a path attribute
- metadata: IDSMetadata¶
IDSMetadata describing the structure of the IDS
Methods
__init__(parent, metadata)Initialize IDSStructure from metadata specification
iter_nonempty_(*[, accept_lazy])Iterate over all child nodes with non-default value.
Attributes
True if any of the children has a non-default value
Metadata of this IDS node
-
iter_nonempty_(*, accept_lazy=
False) Generator[IDSBase, None, None]¶ Iterate over all child nodes with non-default value.
Note
The name ends with an underscore so it won’t clash with IDS child names.
Caution
This method works differently for lazy-loaded IDSs.
By default, an error is raised when calling this method for lazy loaded IDSs. You may set the keyword argument
accept_lazytoTrueto iterate over all loaded child nodes with a non-default value. See below example for lazy-loaded IDSs.Examples
iter_nonempty_for fully loaded IDSs¶>>> import imas.training >>> entry = imas.training.get_training_db_entry() >>> cp = entry.get("core_profiles") >>> list(cp.iter_nonempty_()) [ <IDSStructure (IDS:core_profiles, ids_properties)>, <IDSStructArray (IDS:core_profiles, profiles_1d with 3 items)>, <IDSNumericArray (IDS:core_profiles, time, FLT_1D)> numpy.ndarray([ 3.98722186, 432.93759781, 792. ]) ]iter_nonempty_for lazy-loaded IDSs¶>>> import imas.training >>> entry = imas.training.get_training_db_entry() >>> cp = entry.get("core_profiles", lazy=True) >>> list(cp.iter_nonempty_()) RuntimeError: Iterating over non-empty nodes of a lazy loaded IDS will skip nodes that are not loaded. Set accept_lazy=True to continue. See the documentation for more information: [...] >>> list(cp.iter_nonempty_(accept_lazy=True)) [] >>> # An empty list because nothing is loaded. Load `time`: >>> cp.time <IDSNumericArray (IDS:core_profiles, time, FLT_1D)> numpy.ndarray([ 3.98722186, 432.93759781, 792. ]) >>> list(cp.iter_nonempty_(accept_lazy=True)) [<IDSNumericArray (IDS:core_profiles, time, FLT_1D)> numpy.ndarray([ 3.98722186, 432.93759781, 792. ])]- Keyword Arguments:
- accept_lazy=
False¶ Accept that this method will only yield loaded nodes of a lazy-loaded IDS. Non-empty nodes that have not been loaded from the backend are not iterated over. See detailed explanation above.
- accept_lazy=
- metadata : IDSMetadata¶
Metadata of this IDS node