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/command/timer.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# This file is part of imas-python.
|
|
2
|
+
# You should have received the imas-python LICENSE file with this project.
|
|
3
|
+
"""Utility class to time different sections of a CLI app."""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from contextlib import contextmanager
|
|
7
|
+
|
|
8
|
+
from rich.align import Align
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Timer:
|
|
13
|
+
"""Convenience class to time sections in a CLI app.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
|
|
17
|
+
.. code-block:: python
|
|
18
|
+
|
|
19
|
+
# Construct a timer with column/row labels "X" and "Y"
|
|
20
|
+
timer = Timer("X", "Y")
|
|
21
|
+
|
|
22
|
+
# Time code
|
|
23
|
+
with timer("x-value1", "y-value1"):
|
|
24
|
+
... # Code to be timed
|
|
25
|
+
|
|
26
|
+
# Output table with timing information
|
|
27
|
+
rich.print(timer.get_table())
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, *axes):
|
|
31
|
+
self.axes = axes
|
|
32
|
+
self.axes_values = tuple({} for _ in axes)
|
|
33
|
+
self.data = {}
|
|
34
|
+
|
|
35
|
+
@contextmanager
|
|
36
|
+
def __call__(self, *items):
|
|
37
|
+
assert len(items) == len(self.axes)
|
|
38
|
+
tic = time.time()
|
|
39
|
+
yield
|
|
40
|
+
self.data[items] = time.time() - tic
|
|
41
|
+
for i, item in enumerate(items):
|
|
42
|
+
# Use dict to keep insertion order
|
|
43
|
+
self.axes_values[i][item] = None
|
|
44
|
+
|
|
45
|
+
def get_table(self, title="Timings") -> Table:
|
|
46
|
+
"""Construct a table with timing details.
|
|
47
|
+
|
|
48
|
+
Currently only implemented when timing on two axes.
|
|
49
|
+
"""
|
|
50
|
+
if len(self.axes) == 2:
|
|
51
|
+
table = Table(title=title, show_footer=True)
|
|
52
|
+
|
|
53
|
+
# Calculate totals per column
|
|
54
|
+
totals = {value: 0 for value in self.axes_values[0]}
|
|
55
|
+
for (col, _), value in self.data.items():
|
|
56
|
+
totals[col] += value
|
|
57
|
+
|
|
58
|
+
# Create columns
|
|
59
|
+
table.add_column(footer="TOTAL:", justify="right")
|
|
60
|
+
for value in self.axes_values[0]:
|
|
61
|
+
table.add_column(
|
|
62
|
+
header=Align(value, "center"),
|
|
63
|
+
footer=f"{totals[value]:.3f} s",
|
|
64
|
+
justify="right",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Fill table
|
|
68
|
+
for row in self.axes_values[1]:
|
|
69
|
+
row_values = (
|
|
70
|
+
f"{self.data[col, row]:.3f} s" if (col, row) in self.data else "-"
|
|
71
|
+
for col in self.axes_values[0]
|
|
72
|
+
)
|
|
73
|
+
table.add_row(row, *row_values)
|
|
74
|
+
|
|
75
|
+
return table
|
|
76
|
+
# non-2D is not implemented
|
|
77
|
+
raise NotImplementedError()
|