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.

Files changed (108) hide show
  1. imas/__init__.py +34 -0
  2. imas/__main__.py +17 -0
  3. imas/_util.py +260 -0
  4. imas/_version.py +16 -0
  5. imas/assets/IDSDef2MDSpreTree.xsl +161 -0
  6. imas/assets/IDS_fake_toplevel.xml +318 -0
  7. imas/assets/IDS_minimal.xml +37 -0
  8. imas/assets/IDS_minimal_2.xml +37 -0
  9. imas/assets/IDS_minimal_struct_array.xml +43 -0
  10. imas/assets/IDS_minimal_types.xml +169 -0
  11. imas/assets/ITER_134173_106_core_profiles.ids +2438 -0
  12. imas/assets/ITER_134173_106_equilibrium.ids +3172 -0
  13. imas/assets/README.md +5 -0
  14. imas/assets/core_profiles.ids +2438 -0
  15. imas/assets/equilibrium.ids +3172 -0
  16. imas/backends/__init__.py +12 -0
  17. imas/backends/db_entry_impl.py +122 -0
  18. imas/backends/imas_core/__init__.py +4 -0
  19. imas/backends/imas_core/al_context.py +391 -0
  20. imas/backends/imas_core/db_entry_al.py +405 -0
  21. imas/backends/imas_core/db_entry_helpers.py +200 -0
  22. imas/backends/imas_core/imas_interface.py +216 -0
  23. imas/backends/imas_core/mdsplus_model.py +367 -0
  24. imas/backends/imas_core/uda_support.py +56 -0
  25. imas/backends/netcdf/__init__.py +4 -0
  26. imas/backends/netcdf/db_entry_nc.py +176 -0
  27. imas/backends/netcdf/ids2nc.py +306 -0
  28. imas/backends/netcdf/nc2ids.py +302 -0
  29. imas/backends/netcdf/nc_metadata.py +357 -0
  30. imas/backends/netcdf/nc_validate.py +53 -0
  31. imas/command/cli.py +239 -0
  32. imas/command/db_analysis.py +290 -0
  33. imas/command/helpers.py +45 -0
  34. imas/command/timer.py +77 -0
  35. imas/db_entry.py +802 -0
  36. imas/dd_helpers.py +300 -0
  37. imas/dd_zip.py +297 -0
  38. imas/exception.py +107 -0
  39. imas/ids_base.py +149 -0
  40. imas/ids_convert.py +920 -0
  41. imas/ids_coordinates.py +400 -0
  42. imas/ids_data_type.py +115 -0
  43. imas/ids_defs.py +171 -0
  44. imas/ids_factory.py +108 -0
  45. imas/ids_identifiers.py +125 -0
  46. imas/ids_metadata.py +307 -0
  47. imas/ids_path.py +254 -0
  48. imas/ids_primitive.py +510 -0
  49. imas/ids_struct_array.py +233 -0
  50. imas/ids_structure.py +331 -0
  51. imas/ids_toplevel.py +381 -0
  52. imas/setup_logging.py +64 -0
  53. imas/test/test_all_dd_versions.py +28 -0
  54. imas/test/test_cli.py +44 -0
  55. imas/test/test_dbentry.py +104 -0
  56. imas/test/test_dd_helpers.py +134 -0
  57. imas/test/test_dd_zip.py +29 -0
  58. imas/test/test_deepcopy.py +25 -0
  59. imas/test/test_exception.py +12 -0
  60. imas/test/test_get_sample.py +388 -0
  61. imas/test/test_hash.py +188 -0
  62. imas/test/test_helpers.py +354 -0
  63. imas/test/test_identifiers.py +105 -0
  64. imas/test/test_ids2nc.py +166 -0
  65. imas/test/test_ids_ascii_data.py +39 -0
  66. imas/test/test_ids_convert.py +415 -0
  67. imas/test/test_ids_coordinates.py +165 -0
  68. imas/test/test_ids_data_type.py +40 -0
  69. imas/test/test_ids_factory.py +35 -0
  70. imas/test/test_ids_metadata.py +66 -0
  71. imas/test/test_ids_mixin.py +20 -0
  72. imas/test/test_ids_path.py +192 -0
  73. imas/test/test_ids_primitive.py +109 -0
  74. imas/test/test_ids_struct_array.py +89 -0
  75. imas/test/test_ids_structure.py +70 -0
  76. imas/test/test_ids_toplevel.py +55 -0
  77. imas/test/test_ids_validate.py +343 -0
  78. imas/test/test_latest_dd_autofill.py +74 -0
  79. imas/test/test_latest_dd_manual.py +38 -0
  80. imas/test/test_latest_dd_resample.py +102 -0
  81. imas/test/test_lazy_loading.py +201 -0
  82. imas/test/test_list_occurrences.py +82 -0
  83. imas/test/test_minimal.py +37 -0
  84. imas/test/test_minimal_conversion.py +44 -0
  85. imas/test/test_minimal_io.py +21 -0
  86. imas/test/test_minimal_struct_array_io.py +60 -0
  87. imas/test/test_minimal_types.py +436 -0
  88. imas/test/test_minimal_types_io.py +70 -0
  89. imas/test/test_minimal_types_io_automatic.py +66 -0
  90. imas/test/test_nbc_change.py +408 -0
  91. imas/test/test_nc_autofill.py +13 -0
  92. imas/test/test_nc_entry.py +28 -0
  93. imas/test/test_nc_metadata.py +153 -0
  94. imas/test/test_nc_validation.py +197 -0
  95. imas/test/test_snippets.py +25 -0
  96. imas/test/test_static_ids.py +39 -0
  97. imas/test/test_str_1d.py +99 -0
  98. imas/test/test_time_slicing.py +182 -0
  99. imas/test/test_uda_support.py +12 -0
  100. imas/test/test_util.py +209 -0
  101. imas/training.py +45 -0
  102. imas/util.py +526 -0
  103. imas_python-0.1.dev1618.dist-info/LICENSE.txt +165 -0
  104. imas_python-0.1.dev1618.dist-info/METADATA +288 -0
  105. imas_python-0.1.dev1618.dist-info/RECORD +108 -0
  106. imas_python-0.1.dev1618.dist-info/WHEEL +5 -0
  107. imas_python-0.1.dev1618.dist-info/entry_points.txt +3 -0
  108. 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