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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""A testcase checking if resampling works for the latest data dictionary version.
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
import imas
|
|
7
|
+
from imas.ids_defs import IDS_TIME_MODE_HOMOGENEOUS
|
|
8
|
+
from imas.ids_factory import IDSFactory
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_single_resample_inplace():
|
|
12
|
+
nbi = IDSFactory().new("nbi")
|
|
13
|
+
nbi.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
14
|
+
nbi.time = [1, 2, 3]
|
|
15
|
+
nbi.unit.resize(1)
|
|
16
|
+
nbi.unit[0].energy.data = 2 * nbi.time
|
|
17
|
+
old_id = id(nbi.unit[0].energy.data)
|
|
18
|
+
|
|
19
|
+
assert nbi.unit[0].energy.data.coordinates.time_index == 0
|
|
20
|
+
|
|
21
|
+
imas.util.resample(
|
|
22
|
+
nbi.unit[0].energy.data,
|
|
23
|
+
nbi.time,
|
|
24
|
+
[0.5, 1.5],
|
|
25
|
+
nbi.ids_properties.homogeneous_time,
|
|
26
|
+
inplace=True,
|
|
27
|
+
fill_value="extrapolate",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
assert old_id == id(nbi.unit[0].energy.data)
|
|
31
|
+
assert np.array_equal(nbi.unit[0].energy.data, [1, 3])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_single_resample_copy():
|
|
35
|
+
nbi = IDSFactory().new("nbi")
|
|
36
|
+
nbi.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
37
|
+
nbi.time = [1, 2, 3]
|
|
38
|
+
nbi.unit.resize(1)
|
|
39
|
+
nbi.unit[0].energy.data = 2 * nbi.time
|
|
40
|
+
old_id = id(nbi.unit[0].energy.data)
|
|
41
|
+
|
|
42
|
+
assert nbi.unit[0].energy.data.coordinates.time_index == 0
|
|
43
|
+
|
|
44
|
+
new_data = imas.util.resample(
|
|
45
|
+
nbi.unit[0].energy.data,
|
|
46
|
+
nbi.time,
|
|
47
|
+
[0.5, 1.5],
|
|
48
|
+
nbi.ids_properties.homogeneous_time,
|
|
49
|
+
inplace=False,
|
|
50
|
+
fill_value="extrapolate",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
assert old_id != id(new_data)
|
|
54
|
+
assert np.array_equal(new_data, [1, 3])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_full_resample_inplace():
|
|
58
|
+
nbi = IDSFactory().new("nbi")
|
|
59
|
+
nbi.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
60
|
+
nbi.time = [1, 2, 3]
|
|
61
|
+
nbi.unit.resize(1)
|
|
62
|
+
nbi.unit[0].energy.data = 2 * nbi.time
|
|
63
|
+
old_id = id(nbi.unit[0].energy.data)
|
|
64
|
+
|
|
65
|
+
assert nbi.unit[0].energy.data.coordinates.time_index == 0
|
|
66
|
+
|
|
67
|
+
_ = imas.util.resample(
|
|
68
|
+
nbi,
|
|
69
|
+
nbi.time,
|
|
70
|
+
[0.5, 1.5],
|
|
71
|
+
nbi.ids_properties.homogeneous_time,
|
|
72
|
+
inplace=True,
|
|
73
|
+
fill_value="extrapolate",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
assert old_id == id(nbi.unit[0].energy.data)
|
|
77
|
+
assert np.array_equal(nbi.unit[0].energy.data, [1, 3])
|
|
78
|
+
assert np.array_equal(nbi.time, [0.5, 1.5])
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_full_resample_copy():
|
|
82
|
+
nbi = IDSFactory().new("nbi")
|
|
83
|
+
nbi.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
84
|
+
nbi.time = [1, 2, 3]
|
|
85
|
+
nbi.unit.resize(1)
|
|
86
|
+
nbi.unit[0].energy.data = 2 * nbi.time
|
|
87
|
+
old_id = id(nbi.unit[0].energy.data)
|
|
88
|
+
|
|
89
|
+
assert nbi.unit[0].energy.data.coordinates.time_index == 0
|
|
90
|
+
|
|
91
|
+
new_nbi = imas.util.resample(
|
|
92
|
+
nbi,
|
|
93
|
+
nbi.time,
|
|
94
|
+
[0.5, 1.5],
|
|
95
|
+
nbi.ids_properties.homogeneous_time,
|
|
96
|
+
inplace=False,
|
|
97
|
+
fill_value="extrapolate",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
assert old_id != id(new_nbi.unit[0].energy.data)
|
|
101
|
+
assert np.array_equal(new_nbi.unit[0].energy.data, [1, 3])
|
|
102
|
+
assert np.array_equal(new_nbi.time, [0.5, 1.5])
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from unittest.mock import DEFAULT, patch
|
|
3
|
+
|
|
4
|
+
import numpy
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from imas.backends.imas_core.imas_interface import ll_interface
|
|
8
|
+
from imas.db_entry import DBEntry
|
|
9
|
+
from imas.ids_defs import (
|
|
10
|
+
ASCII_BACKEND,
|
|
11
|
+
IDS_TIME_MODE_HETEROGENEOUS,
|
|
12
|
+
IDS_TIME_MODE_HOMOGENEOUS,
|
|
13
|
+
MEMORY_BACKEND,
|
|
14
|
+
PREVIOUS_INTERP,
|
|
15
|
+
)
|
|
16
|
+
from imas.ids_factory import IDSFactory
|
|
17
|
+
from imas.ids_primitive import IDSPrimitive
|
|
18
|
+
from imas.test.test_helpers import compare_children, fill_consistent, open_dbentry
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_lazy_load_aos(backend, worker_id, tmp_path, log_lowlevel_calls):
|
|
22
|
+
if backend == ASCII_BACKEND:
|
|
23
|
+
pytest.skip("Lazy loading is not supported by the ASCII backend.")
|
|
24
|
+
dbentry = open_dbentry(backend, "w", worker_id, tmp_path, dd_version="3.39.0")
|
|
25
|
+
ids = dbentry.factory.new("core_profiles")
|
|
26
|
+
ids.ids_properties.homogeneous_time = IDS_TIME_MODE_HETEROGENEOUS
|
|
27
|
+
ids.profiles_1d.resize(10)
|
|
28
|
+
for i in range(10):
|
|
29
|
+
ids.profiles_1d[i].time = i
|
|
30
|
+
dbentry.put(ids)
|
|
31
|
+
|
|
32
|
+
# Test a random access pattern of the AOS elements
|
|
33
|
+
lazy_ids = dbentry.get("core_profiles", lazy=True)
|
|
34
|
+
random_list = list(range(10))
|
|
35
|
+
random.shuffle(random_list)
|
|
36
|
+
for i in random_list:
|
|
37
|
+
assert lazy_ids.profiles_1d[i].time == i
|
|
38
|
+
# Now all profiles_1d/time are loaded, check that we use loaded values and do not
|
|
39
|
+
# read data from the lowlevel
|
|
40
|
+
to_patch = {"read_data": DEFAULT, "begin_arraystruct_action": DEFAULT}
|
|
41
|
+
with patch.multiple(ll_interface, **to_patch) as values:
|
|
42
|
+
assert len(lazy_ids.profiles_1d) == 10
|
|
43
|
+
for i in range(10):
|
|
44
|
+
assert lazy_ids.profiles_1d[i].time == i
|
|
45
|
+
for method in to_patch:
|
|
46
|
+
assert values[method].call_count == 0
|
|
47
|
+
|
|
48
|
+
# Test get_slice
|
|
49
|
+
lazy_ids_slice = dbentry.get_slice("core_profiles", 3.5, PREVIOUS_INTERP, lazy=True)
|
|
50
|
+
assert lazy_ids_slice.profiles_1d.shape == (1,)
|
|
51
|
+
assert lazy_ids_slice.profiles_1d[0].time == 3
|
|
52
|
+
|
|
53
|
+
dbentry.close()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_lazy_loading_distributions_random(backend, worker_id, tmp_path):
|
|
57
|
+
if backend == ASCII_BACKEND:
|
|
58
|
+
pytest.skip("Lazy loading is not supported by the ASCII backend.")
|
|
59
|
+
dbentry = open_dbentry(backend, "w", worker_id, tmp_path)
|
|
60
|
+
ids = IDSFactory().new("distributions")
|
|
61
|
+
fill_consistent(ids)
|
|
62
|
+
dbentry.put(ids)
|
|
63
|
+
|
|
64
|
+
def iterate(structure):
|
|
65
|
+
for child in structure:
|
|
66
|
+
if not isinstance(child, IDSPrimitive):
|
|
67
|
+
iterate(child)
|
|
68
|
+
|
|
69
|
+
lazy_ids = dbentry.get("distributions", lazy=True)
|
|
70
|
+
# Iterate over whole IDS to force-load everything
|
|
71
|
+
iterate(lazy_ids)
|
|
72
|
+
compare_children(ids, lazy_ids, accept_lazy=True)
|
|
73
|
+
|
|
74
|
+
dbentry.close()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_lazy_load_close_dbentry(requires_imas):
|
|
78
|
+
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1)
|
|
79
|
+
dbentry.create()
|
|
80
|
+
|
|
81
|
+
ids = dbentry.factory.core_profiles()
|
|
82
|
+
ids.ids_properties.homogeneous_time = IDS_TIME_MODE_HETEROGENEOUS
|
|
83
|
+
dbentry.put(ids)
|
|
84
|
+
|
|
85
|
+
lazy_ids = dbentry.get("core_profiles", lazy=True)
|
|
86
|
+
dbentry.close()
|
|
87
|
+
|
|
88
|
+
with pytest.raises(RuntimeError):
|
|
89
|
+
print(lazy_ids.time)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_lazy_load_readonly(requires_imas):
|
|
93
|
+
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1)
|
|
94
|
+
dbentry.create()
|
|
95
|
+
|
|
96
|
+
ids = dbentry.factory.core_profiles()
|
|
97
|
+
ids.ids_properties.homogeneous_time = IDS_TIME_MODE_HETEROGENEOUS
|
|
98
|
+
ids.time = [1, 2]
|
|
99
|
+
dbentry.put(ids)
|
|
100
|
+
|
|
101
|
+
lazy_ids = dbentry.get("core_profiles", lazy=True)
|
|
102
|
+
assert lazy_ids._lazy is True
|
|
103
|
+
|
|
104
|
+
# AoS modifiers
|
|
105
|
+
with pytest.raises(ValueError):
|
|
106
|
+
lazy_ids.profiles_1d.resize(1)
|
|
107
|
+
with pytest.raises(ValueError):
|
|
108
|
+
lazy_ids.profiles_1d.append(lazy_ids.profiles_1d._element_structure)
|
|
109
|
+
with pytest.raises(ValueError):
|
|
110
|
+
lazy_ids.profiles_1d[0] = None
|
|
111
|
+
|
|
112
|
+
# Set IDSPrimitive
|
|
113
|
+
with pytest.raises(ValueError):
|
|
114
|
+
lazy_ids.ids_properties.homogeneous_time = 1
|
|
115
|
+
with pytest.raises(ValueError):
|
|
116
|
+
lazy_ids.time = [1, 2]
|
|
117
|
+
# Modify numpy arrays
|
|
118
|
+
with pytest.raises(ValueError):
|
|
119
|
+
lazy_ids.time.resize(3)
|
|
120
|
+
with pytest.raises(ValueError):
|
|
121
|
+
lazy_ids.time.value[0] = 10
|
|
122
|
+
|
|
123
|
+
dbentry.close()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_lazy_load_no_put(requires_imas):
|
|
127
|
+
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1)
|
|
128
|
+
dbentry.create()
|
|
129
|
+
|
|
130
|
+
ids = dbentry.factory.core_profiles()
|
|
131
|
+
ids.ids_properties.homogeneous_time = IDS_TIME_MODE_HETEROGENEOUS
|
|
132
|
+
dbentry.put(ids)
|
|
133
|
+
|
|
134
|
+
lazy_ids = dbentry.get("core_profiles", lazy=True)
|
|
135
|
+
|
|
136
|
+
with pytest.raises(ValueError):
|
|
137
|
+
dbentry.put(lazy_ids)
|
|
138
|
+
with pytest.raises(ValueError):
|
|
139
|
+
dbentry.put_slice(lazy_ids)
|
|
140
|
+
|
|
141
|
+
dbentry.close()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_lazy_load_with_new_aos(requires_imas):
|
|
145
|
+
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, dd_version="3.30.0")
|
|
146
|
+
dbentry.create()
|
|
147
|
+
et = dbentry.factory.edge_transport()
|
|
148
|
+
|
|
149
|
+
et.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
150
|
+
et.time = [1.0]
|
|
151
|
+
et.model.resize(1)
|
|
152
|
+
et.model[0].ggd.resize(1)
|
|
153
|
+
et.model[0].ggd[0].electrons.particles.d.resize(1)
|
|
154
|
+
et.model[0].ggd[0].electrons.particles.d[0].grid_index = -1
|
|
155
|
+
dbentry.put(et)
|
|
156
|
+
|
|
157
|
+
entry2 = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, dd_version="3.39.0")
|
|
158
|
+
entry2.open()
|
|
159
|
+
lazy_et = entry2.get("edge_transport", lazy=True)
|
|
160
|
+
assert numpy.array_equal(lazy_et.time, [1.0])
|
|
161
|
+
assert lazy_et.model[0].ggd[0].electrons.particles.d[0].grid_index == -1
|
|
162
|
+
# d_radial did not exist in 3.30.0
|
|
163
|
+
assert len(lazy_et.model[0].ggd[0].electrons.particles.d_radial) == 0
|
|
164
|
+
|
|
165
|
+
dbentry.close()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def test_lazy_load_with_new_structure(requires_imas):
|
|
169
|
+
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, dd_version="3.30.0")
|
|
170
|
+
dbentry.create()
|
|
171
|
+
|
|
172
|
+
eq = dbentry.factory.equilibrium()
|
|
173
|
+
eq.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
|
|
174
|
+
eq.time = [0.0]
|
|
175
|
+
eq.time_slice.resize(1)
|
|
176
|
+
dbentry.put(eq)
|
|
177
|
+
|
|
178
|
+
entry2 = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, data_version="3", dd_version="4.0.0")
|
|
179
|
+
entry2.open()
|
|
180
|
+
lazy_eq = entry2.get("equilibrium", lazy=True)
|
|
181
|
+
assert not lazy_eq.time_slice[0].boundary.dr_dz_zero_point.r.has_value
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def test_lazy_load_multiple_ids(backend, worker_id, tmp_path):
|
|
185
|
+
if backend == ASCII_BACKEND:
|
|
186
|
+
pytest.skip("Lazy loading is not supported by the ASCII backend.")
|
|
187
|
+
|
|
188
|
+
with open_dbentry(backend, "w", worker_id, tmp_path) as dbentry:
|
|
189
|
+
cp = dbentry.factory.core_profiles()
|
|
190
|
+
cp.ids_properties.homogeneous_time = 1
|
|
191
|
+
cp.time = [0.0, 1.0]
|
|
192
|
+
dbentry.put(cp)
|
|
193
|
+
eq = dbentry.factory.equilibrium()
|
|
194
|
+
eq.ids_properties.homogeneous_time = 1
|
|
195
|
+
eq.time = [1.0, 2.0]
|
|
196
|
+
dbentry.put(eq)
|
|
197
|
+
|
|
198
|
+
lazy_cp = dbentry.get("core_profiles", lazy=True)
|
|
199
|
+
lazy_eq = dbentry.get("equilibrium", lazy=True)
|
|
200
|
+
assert all(cp.time - eq.time == -1)
|
|
201
|
+
assert all(lazy_cp.time - lazy_eq.time == -1)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from packaging.version import Version
|
|
3
|
+
|
|
4
|
+
import imas
|
|
5
|
+
from imas.backends.imas_core.imas_interface import ll_interface
|
|
6
|
+
from imas.test.test_helpers import open_dbentry
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def filled_dbentry(backend, worker_id, tmp_path):
|
|
11
|
+
if backend == imas.ids_defs.MEMORY_BACKEND:
|
|
12
|
+
pytest.skip("list_occurrences is not implemented for the MEMORY backend")
|
|
13
|
+
entry = open_dbentry(backend, "w", worker_id, tmp_path)
|
|
14
|
+
|
|
15
|
+
for i in range(3):
|
|
16
|
+
cp = entry.factory.core_profiles()
|
|
17
|
+
cp.ids_properties.homogeneous_time = 0
|
|
18
|
+
cp.ids_properties.comment = f"core_profiles occurrence {i}"
|
|
19
|
+
entry.put(cp, i)
|
|
20
|
+
|
|
21
|
+
for i in [0, 1, 3, 6]:
|
|
22
|
+
mag = entry.factory.core_sources()
|
|
23
|
+
mag.ids_properties.homogeneous_time = 0
|
|
24
|
+
mag.ids_properties.comment = f"core_sources occurrence {i}"
|
|
25
|
+
entry.put(mag, i)
|
|
26
|
+
|
|
27
|
+
yield entry
|
|
28
|
+
entry.close()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_list_occurrences_no_path(filled_dbentry):
|
|
32
|
+
if ll_interface._al_version >= Version("5.1"):
|
|
33
|
+
occurrences = filled_dbentry.list_all_occurrences("core_profiles")
|
|
34
|
+
assert occurrences == [0, 1, 2]
|
|
35
|
+
|
|
36
|
+
occurrences = filled_dbentry.list_all_occurrences("core_sources")
|
|
37
|
+
assert occurrences == [0, 1, 3, 6]
|
|
38
|
+
|
|
39
|
+
assert filled_dbentry.list_all_occurrences("magnetics") == []
|
|
40
|
+
|
|
41
|
+
else: # AL 5.0 or lower
|
|
42
|
+
with pytest.raises(RuntimeError):
|
|
43
|
+
filled_dbentry.list_all_occurrences("core_profiles")
|
|
44
|
+
with pytest.raises(RuntimeError):
|
|
45
|
+
filled_dbentry.list_all_occurrences("core_sources")
|
|
46
|
+
with pytest.raises(RuntimeError):
|
|
47
|
+
filled_dbentry.list_all_occurrences("magnetics")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_list_occurrences_with_path(backend, filled_dbentry):
|
|
51
|
+
if backend == imas.ids_defs.ASCII_BACKEND:
|
|
52
|
+
pytest.skip("Lazy loading is not supported by the ASCII backend")
|
|
53
|
+
|
|
54
|
+
comment = "ids_properties/comment"
|
|
55
|
+
if ll_interface._al_version >= Version("5.1"):
|
|
56
|
+
res = filled_dbentry.list_all_occurrences("core_profiles", comment)
|
|
57
|
+
assert res[0] == [0, 1, 2]
|
|
58
|
+
assert res[1] == [
|
|
59
|
+
"core_profiles occurrence 0",
|
|
60
|
+
"core_profiles occurrence 1",
|
|
61
|
+
"core_profiles occurrence 2",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
res = filled_dbentry.list_all_occurrences("core_sources", comment)
|
|
65
|
+
assert res[0] == [0, 1, 3, 6]
|
|
66
|
+
assert res[1] == [
|
|
67
|
+
"core_sources occurrence 0",
|
|
68
|
+
"core_sources occurrence 1",
|
|
69
|
+
"core_sources occurrence 3",
|
|
70
|
+
"core_sources occurrence 6",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
res = filled_dbentry.list_all_occurrences("magnetics", comment)
|
|
74
|
+
assert res == ([], [])
|
|
75
|
+
|
|
76
|
+
else: # AL 5.0 or lower
|
|
77
|
+
with pytest.raises(RuntimeError):
|
|
78
|
+
filled_dbentry.list_all_occurrences("core_profiles", comment)
|
|
79
|
+
with pytest.raises(RuntimeError):
|
|
80
|
+
filled_dbentry.list_all_occurrences("core_sources", comment)
|
|
81
|
+
with pytest.raises(RuntimeError):
|
|
82
|
+
filled_dbentry.list_all_occurrences("magnetics", comment)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# A minimal testcase loading an IDS file and checking that the structure built is ok
|
|
2
|
+
|
|
3
|
+
from imas.ids_factory import IDSFactory
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_load_minimal(ids_minimal):
|
|
7
|
+
minimal = IDSFactory(xml_path=ids_minimal).new("minimal")
|
|
8
|
+
|
|
9
|
+
# Check if the datatypes are loaded correctly
|
|
10
|
+
assert minimal.a.data_type == "FLT_0D"
|
|
11
|
+
assert minimal.ids_properties.comment.data_type == "STR_0D"
|
|
12
|
+
|
|
13
|
+
# Check the documentation
|
|
14
|
+
assert minimal.a.metadata.documentation == "A float"
|
|
15
|
+
assert minimal.ids_properties.metadata.documentation == "Properties of this IDS"
|
|
16
|
+
assert minimal.ids_properties.comment.metadata.documentation == "A string comment"
|
|
17
|
+
|
|
18
|
+
# Check the units
|
|
19
|
+
assert minimal.a.metadata.units == "unitless"
|
|
20
|
+
|
|
21
|
+
# Check the static/dynamic/constant annotation
|
|
22
|
+
assert minimal.a.metadata.type.value == "static"
|
|
23
|
+
assert minimal.ids_properties.comment.metadata.type.value == "constant"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_load_multiple_minimal(ids_minimal, ids_minimal_types):
|
|
27
|
+
minimal = IDSFactory(xml_path=ids_minimal).new("minimal")
|
|
28
|
+
|
|
29
|
+
# Check if the datatypes are loaded correctly
|
|
30
|
+
assert minimal.a.data_type == "FLT_0D"
|
|
31
|
+
assert minimal.ids_properties.comment.data_type == "STR_0D"
|
|
32
|
+
|
|
33
|
+
minimal2 = IDSFactory(xml_path=ids_minimal_types).new("minimal")
|
|
34
|
+
|
|
35
|
+
# Check if the datatypes are loaded correctly
|
|
36
|
+
assert minimal2.flt_0d.data_type == "FLT_0D"
|
|
37
|
+
assert minimal2.ids_properties.comment.data_type == "STR_0D"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from imas.ids_defs import IDS_TIME_MODE_INDEPENDENT, MEMORY_BACKEND
|
|
2
|
+
from imas.test.test_helpers import open_dbentry
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_minimal_io_read_flt_int(
|
|
6
|
+
backend, ids_minimal, ids_minimal2, worker_id, tmp_path
|
|
7
|
+
):
|
|
8
|
+
"""Write and then read again a number on our minimal IDS."""
|
|
9
|
+
dbentry = open_dbentry(backend, "w", worker_id, tmp_path, xml_path=ids_minimal)
|
|
10
|
+
minimal = dbentry.factory.new("minimal")
|
|
11
|
+
minimal.a = 2.4
|
|
12
|
+
minimal.ids_properties.homogeneous_time = IDS_TIME_MODE_INDEPENDENT
|
|
13
|
+
dbentry.put(minimal)
|
|
14
|
+
assert minimal.a.value == 2.4
|
|
15
|
+
|
|
16
|
+
# ids_minimal2 changed a float to an int
|
|
17
|
+
dbentry2 = open_dbentry(backend, "r", worker_id, tmp_path, xml_path=ids_minimal2)
|
|
18
|
+
minimal2 = dbentry2.get("minimal")
|
|
19
|
+
assert minimal2.a.value == 2
|
|
20
|
+
|
|
21
|
+
dbentry.close()
|
|
22
|
+
if backend != MEMORY_BACKEND: # MEM backend already cleaned up, prevent SEGFAULT
|
|
23
|
+
dbentry2.close()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_minimal_io_read_int_flt(
|
|
27
|
+
backend, ids_minimal, ids_minimal2, worker_id, tmp_path
|
|
28
|
+
):
|
|
29
|
+
"""Write and then read again a number on our minimal IDS."""
|
|
30
|
+
dbentry2 = open_dbentry(backend, "w", worker_id, tmp_path, xml_path=ids_minimal2)
|
|
31
|
+
minimal2 = dbentry2.factory.new("minimal")
|
|
32
|
+
minimal2.a = 2
|
|
33
|
+
minimal2.ids_properties.homogeneous_time = IDS_TIME_MODE_INDEPENDENT
|
|
34
|
+
dbentry2.put(minimal2)
|
|
35
|
+
assert minimal2.a.value == 2
|
|
36
|
+
|
|
37
|
+
# ids_minimal2 changed a float to an int
|
|
38
|
+
dbentry = open_dbentry(backend, "r", worker_id, tmp_path, xml_path=ids_minimal)
|
|
39
|
+
minimal = dbentry.get("minimal")
|
|
40
|
+
assert minimal.a.value == 2.0
|
|
41
|
+
|
|
42
|
+
dbentry.close()
|
|
43
|
+
if backend != MEMORY_BACKEND: # MEM backend already cleaned up, prevent SEGFAULT
|
|
44
|
+
dbentry2.close()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# A minimal testcase loading an IDS file and checking that the structure built is ok
|
|
2
|
+
from imas.ids_defs import IDS_TIME_MODE_INDEPENDENT, MEMORY_BACKEND
|
|
3
|
+
from imas.test.test_helpers import open_dbentry
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_minimal_io(backend, ids_minimal, worker_id, tmp_path):
|
|
7
|
+
"""Write and then read again a number on our minimal IDS."""
|
|
8
|
+
dbentry = open_dbentry(backend, "w", worker_id, tmp_path, xml_path=ids_minimal)
|
|
9
|
+
minimal = dbentry.factory.new("minimal")
|
|
10
|
+
minimal.a = 2.0
|
|
11
|
+
minimal.ids_properties.homogeneous_time = IDS_TIME_MODE_INDEPENDENT
|
|
12
|
+
dbentry.put(minimal)
|
|
13
|
+
assert minimal.a.value == 2.0
|
|
14
|
+
|
|
15
|
+
dbentry2 = open_dbentry(backend, "a", worker_id, tmp_path, xml_path=ids_minimal)
|
|
16
|
+
minimal2 = dbentry2.get("minimal")
|
|
17
|
+
assert minimal2.a.value == 2.0
|
|
18
|
+
|
|
19
|
+
dbentry.close()
|
|
20
|
+
if backend != MEMORY_BACKEND: # MEM backend already cleaned up, prevent SEGFAULT
|
|
21
|
+
dbentry2.close()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# A minimal testcase loading an IDS file and checking that the structure built is ok
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from imas.ids_defs import IDS_TIME_MODE_INDEPENDENT, MDSPLUS_BACKEND, MEMORY_BACKEND
|
|
5
|
+
from imas.test.test_helpers import open_dbentry
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_minimal_struct_array_maxoccur(
|
|
9
|
+
backend, ids_minimal_struct_array, worker_id, tmp_path
|
|
10
|
+
):
|
|
11
|
+
dbentry = open_dbentry(
|
|
12
|
+
backend, "w", worker_id, tmp_path, xml_path=ids_minimal_struct_array
|
|
13
|
+
)
|
|
14
|
+
minimal_struct_array = dbentry.factory.new("minimal_struct_array")
|
|
15
|
+
minimal_struct_array.ids_properties.homogeneous_time = IDS_TIME_MODE_INDEPENDENT
|
|
16
|
+
# maxoccur is 2, so this should raise an exception with the MDS+ backend
|
|
17
|
+
minimal_struct_array.struct_array.resize(3)
|
|
18
|
+
|
|
19
|
+
if backend == MDSPLUS_BACKEND:
|
|
20
|
+
with pytest.raises(RuntimeError):
|
|
21
|
+
dbentry.put(minimal_struct_array)
|
|
22
|
+
else:
|
|
23
|
+
dbentry.put(minimal_struct_array)
|
|
24
|
+
|
|
25
|
+
dbentry.close()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_minimal_struct_array_io(
|
|
29
|
+
backend, ids_minimal_struct_array, worker_id, tmp_path
|
|
30
|
+
):
|
|
31
|
+
"""Write and then read again a number on our minimal IDS."""
|
|
32
|
+
dbentry = open_dbentry(
|
|
33
|
+
backend, "w", worker_id, tmp_path, xml_path=ids_minimal_struct_array
|
|
34
|
+
)
|
|
35
|
+
minimal_struct_array = dbentry.factory.new("minimal_struct_array")
|
|
36
|
+
a = minimal_struct_array.struct_array
|
|
37
|
+
minimal_struct_array.ids_properties.homogeneous_time = IDS_TIME_MODE_INDEPENDENT
|
|
38
|
+
a.append(a._element_structure)
|
|
39
|
+
|
|
40
|
+
# TODO: these are nested one too deeply in my opinion.
|
|
41
|
+
# (a struct array contains an array of structures directly,
|
|
42
|
+
# without the intermediate one?)
|
|
43
|
+
a[0].a.flt_0d = 2.0
|
|
44
|
+
a.append(a._element_structure)
|
|
45
|
+
a[1].a.flt_0d = 4.0
|
|
46
|
+
|
|
47
|
+
dbentry.put(minimal_struct_array)
|
|
48
|
+
assert a[0].a.flt_0d.value == 2.0
|
|
49
|
+
assert a[1].a.flt_0d.value == 4.0
|
|
50
|
+
|
|
51
|
+
dbentry2 = open_dbentry(
|
|
52
|
+
backend, "a", worker_id, tmp_path, xml_path=ids_minimal_struct_array
|
|
53
|
+
)
|
|
54
|
+
minimal_struct_array2 = dbentry2.get("minimal_struct_array")
|
|
55
|
+
assert minimal_struct_array2.struct_array[0].a.flt_0d.value == 2.0
|
|
56
|
+
assert minimal_struct_array2.struct_array[1].a.flt_0d.value == 4.0
|
|
57
|
+
|
|
58
|
+
dbentry.close()
|
|
59
|
+
if backend != MEMORY_BACKEND: # MEM backend already cleaned up, prevent SEGFAULT
|
|
60
|
+
dbentry2.close()
|