imas-python 0.1.dev1618__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of imas-python might be problematic. Click here for more details.
- imas/__init__.py +34 -0
- imas/__main__.py +17 -0
- imas/_util.py +260 -0
- imas/_version.py +16 -0
- imas/assets/IDSDef2MDSpreTree.xsl +161 -0
- imas/assets/IDS_fake_toplevel.xml +318 -0
- imas/assets/IDS_minimal.xml +37 -0
- imas/assets/IDS_minimal_2.xml +37 -0
- imas/assets/IDS_minimal_struct_array.xml +43 -0
- imas/assets/IDS_minimal_types.xml +169 -0
- imas/assets/ITER_134173_106_core_profiles.ids +2438 -0
- imas/assets/ITER_134173_106_equilibrium.ids +3172 -0
- imas/assets/README.md +5 -0
- imas/assets/core_profiles.ids +2438 -0
- imas/assets/equilibrium.ids +3172 -0
- imas/backends/__init__.py +12 -0
- imas/backends/db_entry_impl.py +122 -0
- imas/backends/imas_core/__init__.py +4 -0
- imas/backends/imas_core/al_context.py +391 -0
- imas/backends/imas_core/db_entry_al.py +405 -0
- imas/backends/imas_core/db_entry_helpers.py +200 -0
- imas/backends/imas_core/imas_interface.py +216 -0
- imas/backends/imas_core/mdsplus_model.py +367 -0
- imas/backends/imas_core/uda_support.py +56 -0
- imas/backends/netcdf/__init__.py +4 -0
- imas/backends/netcdf/db_entry_nc.py +176 -0
- imas/backends/netcdf/ids2nc.py +306 -0
- imas/backends/netcdf/nc2ids.py +302 -0
- imas/backends/netcdf/nc_metadata.py +357 -0
- imas/backends/netcdf/nc_validate.py +53 -0
- imas/command/cli.py +239 -0
- imas/command/db_analysis.py +290 -0
- imas/command/helpers.py +45 -0
- imas/command/timer.py +77 -0
- imas/db_entry.py +802 -0
- imas/dd_helpers.py +300 -0
- imas/dd_zip.py +297 -0
- imas/exception.py +107 -0
- imas/ids_base.py +149 -0
- imas/ids_convert.py +920 -0
- imas/ids_coordinates.py +400 -0
- imas/ids_data_type.py +115 -0
- imas/ids_defs.py +171 -0
- imas/ids_factory.py +108 -0
- imas/ids_identifiers.py +125 -0
- imas/ids_metadata.py +307 -0
- imas/ids_path.py +254 -0
- imas/ids_primitive.py +510 -0
- imas/ids_struct_array.py +233 -0
- imas/ids_structure.py +331 -0
- imas/ids_toplevel.py +381 -0
- imas/setup_logging.py +64 -0
- imas/test/test_all_dd_versions.py +28 -0
- imas/test/test_cli.py +44 -0
- imas/test/test_dbentry.py +104 -0
- imas/test/test_dd_helpers.py +134 -0
- imas/test/test_dd_zip.py +29 -0
- imas/test/test_deepcopy.py +25 -0
- imas/test/test_exception.py +12 -0
- imas/test/test_get_sample.py +388 -0
- imas/test/test_hash.py +188 -0
- imas/test/test_helpers.py +354 -0
- imas/test/test_identifiers.py +105 -0
- imas/test/test_ids2nc.py +166 -0
- imas/test/test_ids_ascii_data.py +39 -0
- imas/test/test_ids_convert.py +415 -0
- imas/test/test_ids_coordinates.py +165 -0
- imas/test/test_ids_data_type.py +40 -0
- imas/test/test_ids_factory.py +35 -0
- imas/test/test_ids_metadata.py +66 -0
- imas/test/test_ids_mixin.py +20 -0
- imas/test/test_ids_path.py +192 -0
- imas/test/test_ids_primitive.py +109 -0
- imas/test/test_ids_struct_array.py +89 -0
- imas/test/test_ids_structure.py +70 -0
- imas/test/test_ids_toplevel.py +55 -0
- imas/test/test_ids_validate.py +343 -0
- imas/test/test_latest_dd_autofill.py +74 -0
- imas/test/test_latest_dd_manual.py +38 -0
- imas/test/test_latest_dd_resample.py +102 -0
- imas/test/test_lazy_loading.py +201 -0
- imas/test/test_list_occurrences.py +82 -0
- imas/test/test_minimal.py +37 -0
- imas/test/test_minimal_conversion.py +44 -0
- imas/test/test_minimal_io.py +21 -0
- imas/test/test_minimal_struct_array_io.py +60 -0
- imas/test/test_minimal_types.py +436 -0
- imas/test/test_minimal_types_io.py +70 -0
- imas/test/test_minimal_types_io_automatic.py +66 -0
- imas/test/test_nbc_change.py +408 -0
- imas/test/test_nc_autofill.py +13 -0
- imas/test/test_nc_entry.py +28 -0
- imas/test/test_nc_metadata.py +153 -0
- imas/test/test_nc_validation.py +197 -0
- imas/test/test_snippets.py +25 -0
- imas/test/test_static_ids.py +39 -0
- imas/test/test_str_1d.py +99 -0
- imas/test/test_time_slicing.py +182 -0
- imas/test/test_uda_support.py +12 -0
- imas/test/test_util.py +209 -0
- imas/training.py +45 -0
- imas/util.py +526 -0
- imas_python-0.1.dev1618.dist-info/LICENSE.txt +165 -0
- imas_python-0.1.dev1618.dist-info/METADATA +288 -0
- imas_python-0.1.dev1618.dist-info/RECORD +108 -0
- imas_python-0.1.dev1618.dist-info/WHEEL +5 -0
- imas_python-0.1.dev1618.dist-info/entry_points.txt +3 -0
- imas_python-0.1.dev1618.dist-info/top_level.txt +1 -0
imas/ids_base.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# This file is part of imas-python.
|
|
2
|
+
# You should have received the imas-python LICENSE file with this project.
|
|
3
|
+
"""Base class for all IDS nodes.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
from typing import TYPE_CHECKING, Optional, Type
|
|
8
|
+
|
|
9
|
+
from imas.exception import ValidationError
|
|
10
|
+
from imas.ids_defs import IDS_TIME_MODE_INDEPENDENT
|
|
11
|
+
from imas.ids_metadata import IDSMetadata
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from imas.ids_toplevel import IDSToplevel
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class IDSBase:
|
|
20
|
+
"""The base class which unifies properties of structure, struct_array, toplevel
|
|
21
|
+
and data nodes."""
|
|
22
|
+
|
|
23
|
+
# Since a lot of IDSBase objects are constructed, the overhead of implementing
|
|
24
|
+
# __init__() in this class is quite significant: 5-10% runtime in some
|
|
25
|
+
# cases for a DBEntry.get()!
|
|
26
|
+
# The following attributes should be set in a derived class's __init__():
|
|
27
|
+
__slots__ = () # _parent and metadata should be slots in derived classes as well!
|
|
28
|
+
_parent: "IDSBase"
|
|
29
|
+
"""Parent object of this IDS node"""
|
|
30
|
+
metadata: IDSMetadata
|
|
31
|
+
"""Metadata of this IDS node"""
|
|
32
|
+
|
|
33
|
+
# _lazy is defined on all derived classes
|
|
34
|
+
_lazy: bool
|
|
35
|
+
"""True iff this IDS lazy-loads its data"""
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def _time_mode(self) -> int:
|
|
39
|
+
"""Retrieve the time mode from `/ids_properties/homogeneous_time`"""
|
|
40
|
+
return self._parent._time_mode
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def _dd_parent(self) -> "IDSBase":
|
|
44
|
+
"""Return the DD parent element
|
|
45
|
+
|
|
46
|
+
Usually this is the same as the _parent element, but for IDSStructArray
|
|
47
|
+
structure sub-elements, this will return the parent of the IDSStructArray.
|
|
48
|
+
|
|
49
|
+
Examples:
|
|
50
|
+
- `ids.ids_properties.provenance._dd_parent` is `ids.ids_properties`
|
|
51
|
+
- `ids.ids_properties.provenance[0]._dd_parent` is also `ids.ids_properties`
|
|
52
|
+
"""
|
|
53
|
+
return self._parent
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def _path(self) -> str:
|
|
57
|
+
"""Build relative path from the toplevel to the node
|
|
58
|
+
|
|
59
|
+
Caution:
|
|
60
|
+
Determining the path is relatively expensive in large, nested Arrays of
|
|
61
|
+
Structures: the calculation of the index suffix is O(N) in the size of the
|
|
62
|
+
AoS.
|
|
63
|
+
|
|
64
|
+
Usage of _path is (and should remain) limited to "interactive" use cases
|
|
65
|
+
(like in :mod:`imas.util` and ``__repr__``) or when reporting errors.
|
|
66
|
+
|
|
67
|
+
Examples:
|
|
68
|
+
- ``ids.ids_properties.creation_data._path`` is
|
|
69
|
+
``"ids_properties/creation_date"``
|
|
70
|
+
- ``gyrokinetics.wavevector[0].radial_component_norm._path`` is
|
|
71
|
+
``"wavevector[0]/radial_component_norm"``
|
|
72
|
+
"""
|
|
73
|
+
from imas.ids_struct_array import IDSStructArray
|
|
74
|
+
|
|
75
|
+
parent_path = self._parent._path
|
|
76
|
+
my_path = self.metadata.name
|
|
77
|
+
if isinstance(self._parent, IDSStructArray):
|
|
78
|
+
for index, item in enumerate(self._parent):
|
|
79
|
+
if item is self:
|
|
80
|
+
break
|
|
81
|
+
else:
|
|
82
|
+
# This happens when we ask the path of a struct_array
|
|
83
|
+
# child that does not have a proper parent anymore
|
|
84
|
+
# E.g. a resize
|
|
85
|
+
logger.warning(
|
|
86
|
+
"Link to parent of %s broken. Cannot reconstruct index", my_path
|
|
87
|
+
)
|
|
88
|
+
index = "?"
|
|
89
|
+
my_path = f"{parent_path}[{index}]"
|
|
90
|
+
elif parent_path != "":
|
|
91
|
+
# If we are not an IDSStructArray, we have no indexable children.
|
|
92
|
+
my_path = parent_path + "/" + my_path
|
|
93
|
+
return my_path
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def _version(self):
|
|
97
|
+
"""Return the data dictionary version of this in-memory structure."""
|
|
98
|
+
return self._parent._version
|
|
99
|
+
|
|
100
|
+
def _build_repr_start(self) -> str:
|
|
101
|
+
"""Build the start of the string derived classes need for their repr.
|
|
102
|
+
|
|
103
|
+
All derived classes need to represent the IDS they are part of,
|
|
104
|
+
and thus have a common string to start with. We collect that common logic here.
|
|
105
|
+
"""
|
|
106
|
+
my_repr = f"<{type(self).__name__}"
|
|
107
|
+
my_repr += f" (IDS:{self._toplevel.metadata.name},"
|
|
108
|
+
my_repr += f" {self._path}"
|
|
109
|
+
return my_repr
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def _toplevel(self) -> "IDSToplevel":
|
|
113
|
+
"""Return the toplevel instance this node belongs to"""
|
|
114
|
+
return self._parent._toplevel
|
|
115
|
+
|
|
116
|
+
def _validate(self) -> None:
|
|
117
|
+
"""Actual implementation of validation logic.
|
|
118
|
+
|
|
119
|
+
See also:
|
|
120
|
+
:py:meth:`imas.ids_toplevel.IDSToplevel.validate`.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
aos_indices: index_name -> index, e.g. {"i1": 1, "itime": 0}, for all parent
|
|
124
|
+
array of structures.
|
|
125
|
+
"""
|
|
126
|
+
if self.metadata.type.is_dynamic and self.has_value:
|
|
127
|
+
if self._time_mode == IDS_TIME_MODE_INDEPENDENT:
|
|
128
|
+
raise ValidationError(
|
|
129
|
+
f"Dynamic variable {self.metadata.path} is allocated, but time "
|
|
130
|
+
"mode is IDS_TIME_MODE_INDEPENDENT."
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class IDSDoc:
|
|
135
|
+
"""Helper class to show DD documentation on IDS objects.
|
|
136
|
+
|
|
137
|
+
This object implements the descriptor protocol, see:
|
|
138
|
+
https://docs.python.org/3/howto/descriptor.html.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
def __init__(self, original_doc: str) -> None:
|
|
142
|
+
self.original_doc = original_doc
|
|
143
|
+
|
|
144
|
+
def __get__(
|
|
145
|
+
self, instance: Optional[IDSBase], owner: Optional[Type[IDSBase]] = None
|
|
146
|
+
) -> str:
|
|
147
|
+
if instance is None:
|
|
148
|
+
return self.original_doc # class-level
|
|
149
|
+
return instance.metadata.documentation or self.original_doc # instance-level
|