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/util.py ADDED
@@ -0,0 +1,526 @@
1
+ # This file is part of imas-python.
2
+ # You should have received the imas-python LICENSE file with this project.
3
+ """Collection of useful helper methods when working with imas-python.
4
+ """
5
+
6
+
7
+ import logging
8
+ import re
9
+ from typing import Any, Callable, Iterator, List, Optional, Tuple, Union
10
+
11
+ import numpy
12
+
13
+ from imas.db_entry import DBEntry
14
+ from imas.ids_base import IDSBase
15
+ from imas.ids_factory import IDSFactory
16
+ from imas.ids_metadata import IDSMetadata
17
+ from imas.ids_primitive import IDSInt0D, IDSPrimitive
18
+ from imas.ids_struct_array import IDSStructArray
19
+ from imas.ids_structure import IDSStructure
20
+ from imas.ids_toplevel import IDSToplevel
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ def visit_children(
26
+ func: Callable,
27
+ node: IDSBase,
28
+ *,
29
+ leaf_only: bool = True,
30
+ visit_empty: bool = False,
31
+ accept_lazy: bool = False,
32
+ ) -> None:
33
+ """Apply a function to node and its children
34
+
35
+ imas-python objects generally live in a tree structure. Similar to Pythons
36
+ :py:func:`map`, this method can be used to apply a function to objects
37
+ within this tree structure.
38
+
39
+ Args:
40
+ func: Function to apply to each selected node.
41
+ node: Node that function :param:`func` will be applied to.
42
+ The function will be applied to the node itself and
43
+ all its descendants, depending on :param:`leaf_only`.
44
+
45
+ Keyword Args:
46
+ leaf_only: Apply function to:
47
+
48
+ * ``True``: Only leaf nodes, not internal nodes
49
+ * ``False``: All nodes, including internal nodes
50
+
51
+ visit_empty: When set to True, also apply the function to empty nodes.
52
+ accept_lazy: See documentation of :py:param:`iter_nonempty_()
53
+ <imas.ids_structure.IDSStructure.iter_nonempty_.accept_lazy>`. Only
54
+ relevant when :param:`visit_empty` is False.
55
+
56
+ Example:
57
+ .. code-block:: python
58
+
59
+ # Print all filled leaf nodes in a given imas-python IDSToplevel
60
+ visit_children(print, toplevel)
61
+
62
+ See Also:
63
+ :func:`tree_iter` for the iterator variant of this method.
64
+ """
65
+ for node in tree_iter(
66
+ node,
67
+ leaf_only=leaf_only,
68
+ visit_empty=visit_empty,
69
+ accept_lazy=accept_lazy,
70
+ include_node=True,
71
+ ):
72
+ func(node)
73
+
74
+
75
+ def tree_iter(
76
+ node: IDSBase,
77
+ *,
78
+ leaf_only: bool = True,
79
+ visit_empty: bool = False,
80
+ accept_lazy: bool = False,
81
+ include_node: bool = False,
82
+ ) -> Iterator[IDSBase]:
83
+ """Tree iterator for imas-python structures.
84
+
85
+ Iterate (depth-first) through the whole subtree of an imas-python structure.
86
+
87
+ Args:
88
+ node: Node to start iterating from.
89
+
90
+ Keyword Args:
91
+ leaf_only: Iterate over:
92
+
93
+ * ``True``: Only leaf nodes, not internal nodes
94
+ * ``False``: All nodes, including internal nodes
95
+
96
+ visit_empty: When set to True, iterate over empty nodes.
97
+ accept_lazy: See documentation of :py:param:`iter_nonempty_()
98
+ <imas.ids_structure.IDSStructure.iter_nonempty_.accept_lazy>`. Only
99
+ relevant when :param:`visit_empty` is False.
100
+ include_node: When set to True the iterator will include the provided node (if
101
+ the node is not a leaf node, it is included only when :param:`leaf_only` is
102
+ False).
103
+
104
+ Example:
105
+ .. code-block:: python
106
+
107
+ # Iterate over all filled leaf nodes in a given imas-python IDSToplevel
108
+ for node in tree_iter(toplevel):
109
+ print(node)
110
+
111
+ See Also:
112
+ :func:`visit_children` for the functional variant of this method.
113
+ """
114
+ if include_node and (not leaf_only or isinstance(node, IDSPrimitive)):
115
+ yield node
116
+ if not isinstance(node, IDSPrimitive):
117
+ yield from _tree_iter(node, leaf_only, visit_empty, accept_lazy)
118
+
119
+
120
+ def _tree_iter(
121
+ node: IDSStructure, leaf_only: bool, visit_empty: bool, accept_lazy: bool
122
+ ) -> Iterator[IDSBase]:
123
+ """Implement :func:`tree_iter` recursively."""
124
+ iterator = node
125
+ if not visit_empty and isinstance(node, IDSStructure):
126
+ # Only iterate over non-empty nodes
127
+ iterator = node.iter_nonempty_(accept_lazy=accept_lazy)
128
+
129
+ for child in iterator:
130
+ if isinstance(child, IDSPrimitive):
131
+ yield child
132
+ else:
133
+ if not leaf_only:
134
+ yield child
135
+ yield from _tree_iter(child, leaf_only, visit_empty, accept_lazy)
136
+
137
+
138
+ def idsdiff(struct1: IDSStructure, struct2: IDSStructure) -> None:
139
+ """Generate a diff betweeen two IDS structures and print the result to the terminal.
140
+
141
+ Args:
142
+ struct1: IDS or structure within an IDS.
143
+ struct2: IDS or structure within an IDS to compare against :param:`struct1`.
144
+ """
145
+ import imas._util as _util
146
+
147
+ _util.idsdiff_impl(struct1, struct2)
148
+
149
+
150
+ Difference = Tuple[str, Any, Any]
151
+
152
+
153
+ def idsdiffgen(
154
+ struct1: IDSStructure, struct2: IDSStructure, *, accept_lazy=False
155
+ ) -> Iterator[Difference]:
156
+ """Generate differences between two structures.
157
+
158
+ Args:
159
+ struct1: IDS or structure within an IDS.
160
+ struct2: IDS or structure within an IDS to compare against :param:`struct1`.
161
+
162
+ Keyword Args:
163
+ accept_lazy: See documentation of :py:param:`iter_nonempty_()
164
+ <imas.ids_structure.IDSStructure.iter_nonempty_.accept_lazy>`.
165
+
166
+ Yields:
167
+ (description_or_path, node1, node2): tuple describing a difference:
168
+
169
+ - Description of the difference (e.g. ``"Data Dictionary version"``) or path
170
+ of the IDS node.
171
+ - Node or value from struct1.
172
+ - Node or value from struct2.
173
+ """
174
+ # Compare DD versions
175
+ if struct1._version != struct2._version:
176
+ yield ("Data Dictionary version", struct1._version, struct2._version)
177
+ # Compare IDS names
178
+ if struct1._toplevel.metadata.name != struct2._toplevel.metadata.name:
179
+ yield (
180
+ "IDS name",
181
+ struct1._toplevel.metadata.name,
182
+ struct2._toplevel.metadata.name,
183
+ )
184
+ # Compare paths in the IDS
185
+ if struct1.metadata.path_string != struct2.metadata.path_string:
186
+ yield (
187
+ "Path in IDS",
188
+ struct1.metadata.path_string,
189
+ struct2.metadata.path_string,
190
+ )
191
+
192
+ # Continue with recursively comparing values
193
+ yield from _idsdiffgen(struct1, struct2, accept_lazy=accept_lazy)
194
+
195
+
196
+ def _idsdiffgen(
197
+ struct1: IDSStructure, struct2: IDSStructure, *, accept_lazy=False
198
+ ) -> Iterator[Difference]:
199
+ children1 = {
200
+ child.metadata.name: child
201
+ for child in struct1.iter_nonempty_(accept_lazy=accept_lazy)
202
+ }
203
+ children2 = {
204
+ child.metadata.name: child
205
+ for child in struct2.iter_nonempty_(accept_lazy=accept_lazy)
206
+ }
207
+
208
+ for childname, child1 in children1.items():
209
+ child2 = children2.pop(childname, None)
210
+ if child2 is None:
211
+ if isinstance(child1, IDSStructure):
212
+ for child in tree_iter(child1, accept_lazy=accept_lazy):
213
+ yield (child.metadata.path_string, child, None)
214
+ else:
215
+ yield (child1.metadata.path_string, child1, None)
216
+
217
+ elif isinstance(child1, IDSPrimitive) and isinstance(child2, IDSPrimitive):
218
+ if not numpy.array_equal(child1.value, child2.value):
219
+ try:
220
+ # NaN are equal: but this is not supported for all types
221
+ eq = numpy.array_equal(child1.value, child2.value, equal_nan=True)
222
+ except TypeError:
223
+ # TypeError is raised when child1/child2 are not float or complex
224
+ eq = False
225
+ if not eq:
226
+ yield (child1.metadata.path_string, child1, child2)
227
+
228
+ elif isinstance(child1, IDSStructure) and isinstance(child2, IDSStructure):
229
+ # Check recursively
230
+ yield from _idsdiffgen(child1, child2, accept_lazy=accept_lazy)
231
+
232
+ elif isinstance(child1, IDSStructArray) and isinstance(child2, IDSStructArray):
233
+ # Compare sizes
234
+ if len(child1) != len(child2):
235
+ yield (child1.metadata.path_string, child1, child2)
236
+ # Recursively compare child structures
237
+ for c1, c2 in zip(child1, child2):
238
+ yield from _idsdiffgen(c1, c2, accept_lazy=accept_lazy)
239
+
240
+ else:
241
+ yield (f"Incompatible types for {child1.metadata.path}", child1, child2)
242
+
243
+ for child2 in children2.values():
244
+ if isinstance(child2, IDSStructure):
245
+ for child in tree_iter(child2, accept_lazy=accept_lazy):
246
+ yield (child.metadata.path_string, None, child)
247
+ else:
248
+ yield (child2.metadata.path_string, None, child2)
249
+
250
+
251
+ def resample(node, old_time, new_time, homogeneousTime=None, inplace=False, **kwargs):
252
+ """Resample all primitives in their time dimension to a new time array"""
253
+ import imas._util as _util
254
+
255
+ return _util.resample_impl(
256
+ node, old_time, new_time, homogeneousTime, inplace, **kwargs
257
+ )
258
+
259
+
260
+ def print_tree(structure, hide_empty_nodes=True):
261
+ """Print the full tree of an IDS or IDS structure.
262
+
263
+ Caution:
264
+ With :py:param:`hide_empty_nodes` set to ``True``, lazy-loaded IDSs will only
265
+ show loaded nodes.
266
+
267
+ Args:
268
+ structure: IDS structure to print
269
+ hide_empty_nodes: Show or hide nodes without value.
270
+ """
271
+ import imas._util as _util
272
+
273
+ return _util.print_tree_impl(structure, hide_empty_nodes)
274
+
275
+
276
+ def print_metadata_tree(
277
+ structure: Union[IDSMetadata, IDSBase], maxdepth: int = 2
278
+ ) -> None:
279
+ """Print a tree of IDS metadata.
280
+
281
+ This can be used to inspect which child nodes the Data Dictionary allows for the
282
+ provided structure.
283
+
284
+ Args:
285
+ structure: IDS (structure) node or metadata belonging to an IDS node.
286
+ maxdepth: Control how deep to descend into the metadata tree. When set to 0, all
287
+ descendants are printed (caution: this can give a lot of output).
288
+
289
+ Examples:
290
+ .. code-block:: python
291
+
292
+ core_profiles = imas.IDSFactory().core_profiles()
293
+ # Print tree of the core_profiles IDS
294
+ imas.util.print_metadata_tree(core_profiles)
295
+ # Print descendants of the profiles_1d array of structure only:
296
+ imas.util.print_metadata_tree(core_profiles.metadata["profiles_1d"])
297
+ # Print descendants of the profiles_1d/electrons structure only:
298
+ electrons_metadata = core_profiles.metadata["profiles_1d/electrons"]
299
+ imas.util.print_metadata_tree(electrons_metadata)
300
+ """
301
+ import imas._util as _util
302
+
303
+ return _util.print_metadata_tree_impl(structure, maxdepth)
304
+
305
+
306
+ def inspect(ids_node, hide_empty_nodes=False):
307
+ """Inspect and print an IDS node.
308
+
309
+ Inspired by `rich.inspect`, but customized for IDS specifics.
310
+ """
311
+ import imas._util as _util
312
+
313
+ return _util.inspect_impl(ids_node, hide_empty_nodes)
314
+
315
+
316
+ def find_paths(node: IDSBase, query: str) -> List[str]:
317
+ """Find all paths in the provided DD node (including children) that match the query.
318
+
319
+ Matching is checked with :external:py:func:`re.search`.
320
+
321
+ Args:
322
+ node: An IDS node (e.g. an IDS or sub-structure) to search in.
323
+ query: Regular Expression. See the Python doumentation for :external:py:mod:`re`
324
+ for more details.
325
+
326
+ Returns:
327
+ A list of matching paths.
328
+
329
+ Example:
330
+ >>> factory = imas.IDSFactory()
331
+ >>> core_profiles = factory.new("core_profiles")
332
+ >>> imas.util.find_paths(core_profiles, "(^|/)time$")
333
+ ['profiles_1d/time', 'profiles_2d/time', 'time']
334
+ """
335
+ dd_element = node.metadata._structure_xml
336
+ pattern = re.compile(query)
337
+ matching_paths = []
338
+
339
+ for element in dd_element.iter():
340
+ path = element.get("path", "")
341
+ if pattern.search(path) is not None:
342
+ matching_paths.append(path)
343
+
344
+ return matching_paths
345
+
346
+
347
+ def calc_hash(node: IDSBase) -> bytes:
348
+ """Calculate the hash of the provided IDS object.
349
+
350
+ Hashes are calculated as follows:
351
+
352
+ 1. Data nodes:
353
+
354
+ a. ``STR_0D``: hash of value (encoded as UTF-8)
355
+ b. ``STR_1D``: hash of concatenation of
356
+
357
+ - Length of the STR_1D (64-bit little-endian integer)
358
+ - hash of value[0] (encoded as UTF-8)
359
+ - hash of value[1] (encoded as UTF-8)
360
+ - ...
361
+
362
+ c. ``INT_0D``: hash of value (32-bit little-endian signed integer)
363
+ d. ``FLT_0D``: hash of value (64-bit IEEE 754 floating point number)
364
+ e. ``CPX_0D``: hash of value (128-bit: real, imag)
365
+ f. ``ND`` arrays: hash of concatenation of
366
+
367
+ - Dimension (8-bit integer)
368
+ - Shape (dimension * 64-bits little-endian integer)
369
+ - Concatenated data (little-endian, **Fortran memory layout**)
370
+
371
+ 2. Array of structures nodes: hash of concatenation of
372
+
373
+ - Length of the AoS (64-bit little-endian integer)
374
+ - Hash of structure[0]
375
+ - Hash of structure[1]
376
+ - ...
377
+
378
+ 3. Structure nodes:
379
+
380
+ a. Sort all children alphabetically
381
+ b. Remove empty children. Children are empty when:
382
+
383
+ - ``INT_0D``: equal to ``EMPTY_INT``
384
+ - ``FLT_0D``: equal to ``EMPTY_FLOAT``
385
+ - ``CPX_0D``: equal to ``EMPTY_COMPLEX``
386
+ - ``ND`` arrays: array is empty
387
+ - ``STR_0D``: equal to ``""``
388
+ - ``STR_1D``: length is 0
389
+ - Array of structures: length is 0
390
+ - Structure: all children are empty
391
+
392
+ c. Remove ``ids_properties/version_put`` structure
393
+ d. Calculate hash of concatenation of
394
+
395
+ - Name of child[0] (encoded as UTF-8)
396
+ - Hash of child[0]
397
+ - ...
398
+
399
+ The hash function used is ``xxhash.xxh3_64`` from the ``xxhash`` package.
400
+
401
+ Example:
402
+ .. code-block:: python
403
+
404
+ cp = imas.IDSFactory().core_profiles()
405
+ cp.ids_properties.homogeneous_time = 0
406
+
407
+ print(imas.util.calc_hash(cp).hex()) # 3b9b929756a242fd
408
+ """
409
+ return node._xxhash()
410
+
411
+
412
+ def get_parent(node: IDSBase) -> Optional[IDSBase]:
413
+ """Get the parent of any IDS node.
414
+
415
+ Args:
416
+ node: Any node (structure, array of structures, data node) of an IDS.
417
+
418
+ Returns:
419
+ The parent node of the provided node, or None if the node is an IDS toplevel.
420
+
421
+ Example:
422
+ .. code-block:: python
423
+
424
+ >>> cp = imas.IDSFactory().core_profiles()
425
+ >>> cp.profiles_1d.resize(2)
426
+ >>> imas.util.get_parent(cp.profiles_1d[0].electrons.temperature)
427
+ <IDSStructure (IDS:core_profiles, profiles_1d[0]/electrons)>
428
+ >>> imas.util.get_parent(cp.profiles_1d[0].electrons)
429
+ <IDSStructure (IDS:core_profiles, profiles_1d[0])>
430
+ >>> imas.util.get_parent(cp.profiles_1d[0])
431
+ <IDSStructArray (IDS:core_profiles, profiles_1d with 2 items)>
432
+ >>> imas.util.get_parent(cp.profiles_1d)
433
+ <IDSToplevel (IDS:core_profiles)>
434
+ >>> imas.util.get_parent(cp)
435
+ >>>
436
+ """
437
+ if isinstance(node, IDSToplevel):
438
+ return None
439
+ return node._parent
440
+
441
+
442
+ def get_time_mode(node: IDSBase) -> IDSInt0D:
443
+ """Retrieve ``ids_properties/homogeneous_time`` for any node in the IDS.
444
+
445
+ Args:
446
+ node: Any node (structure, array of structures, data node) of an IDS.
447
+
448
+ Returns:
449
+ ``ids_properties/homogeneous_time``.
450
+
451
+ Example:
452
+ .. code-block:: python
453
+
454
+ >>> cp = imas.IDSFactory().core_profiles()
455
+ >>> cp.ids_properties.homogeneous_time = 0
456
+ >>> cp.profiles_1d.resize(2)
457
+ >>> imas.util.get_time_mode(cp.profiles_1d[0].electrons.temperature)
458
+ <IDSInt0D (IDS:core_profiles, ids_properties/homogeneous_time, INT_0D)>
459
+ int(0)
460
+ """
461
+ return node._time_mode
462
+
463
+
464
+ def get_toplevel(node: IDSBase) -> IDSToplevel:
465
+ """Retrieve the toplevel IDS object for any node in the IDS.
466
+
467
+ Args:
468
+ node: Any node (structure, array of structures, data node) of an IDS.
469
+
470
+ Returns:
471
+ The toplevel IDS object.
472
+
473
+ Example:
474
+ .. code-block:: python
475
+
476
+ >>> cp = imas.IDSFactory().core_profiles()
477
+ >>> cp.profiles_1d.resize(2)
478
+ >>> imas.util.get_toplevel(cp.profiles_1d[0].electrons.temperature)
479
+ <IDSToplevel (IDS:core_profiles)>
480
+ """
481
+ return node._toplevel
482
+
483
+
484
+ def is_lazy_loaded(node: IDSBase) -> bool:
485
+ """Find out if the provided (node of an) IDS is lazy loaded.
486
+
487
+ Args:
488
+ node: Any node (structure, array of structures, data node) of an IDS.
489
+ """
490
+ return node._lazy
491
+
492
+
493
+ def get_full_path(node: IDSBase) -> str:
494
+ """Get the full path (relative to the IDS toplevel) of the provided node.
495
+
496
+ Caution:
497
+ Determining the path is relatively expensive in large, nested Arrays of
498
+ Structures: the calculation of the index suffix is O(N) in the size of the AoS.
499
+
500
+ Using this function may result in a performance bottleneck for your application.
501
+
502
+ Example:
503
+ .. code-block:: python
504
+
505
+ >>> cp = imas.IDSFactory().core_profiles()
506
+ >>> cp.profiles_1d.resize(2)
507
+ >>> imas.util.get_full_path(cp.profiles_1d[1].electrons.temperature)
508
+ 'profiles_1d[1]/electrons/temperature'
509
+ """
510
+ return node._path
511
+
512
+
513
+ def get_data_dictionary_version(obj: Union[IDSBase, DBEntry, IDSFactory]) -> str:
514
+ """Find out the version of the data dictionary definitions that this object uses.
515
+
516
+ Args:
517
+ obj: Any imas-python object that is data-dictionary dependent.
518
+
519
+ Returns:
520
+ The data dictionary version, e.g. ``"3.38.1"``.
521
+ """
522
+ if isinstance(obj, (DBEntry, IDSFactory)):
523
+ return obj.dd_version
524
+ if isinstance(obj, IDSBase):
525
+ return obj._version
526
+ raise TypeError(f"Cannot get data dictionary version of '{type(obj)}'")
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.