Skip to content

Commit a2a977e

Browse files
committed
Add 3to4 conversion rule for obselescent magnetics.method
Fixes #116
1 parent a74f824 commit a2a977e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

imas/ids_convert.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ def _apply_3to4_conversion(self, old: Element, new: Element) -> None:
428428
# TODO: define migrations in a separate variable (as with the sign flips)?
429429
if self.ids_name == "magnetics":
430430
self._add_rename("bpol_probe", "b_field_pol_probe", reciprocal=False)
431+
self._add_rename("method", "ip", reciprocal=False)
432+
self.old_to_new.type_change["method"] = _magnetics_method_to_ip
431433

432434
# GH#59: To improve further the conversion of DD3 to DD4, especially the
433435
# Machine Description part of the IDSs, we would like to add a 3to4 specific
@@ -1335,3 +1337,14 @@ def _equilibrium_boundary_3to4(eq3: IDSToplevel, eq4: IDSToplevel, deepcopy: boo
13351337
node[2].psi = -ts3.boundary_secondary_separatrix.psi # COCOS change
13361338
node[2].levelset.r = copy(ts3.boundary_secondary_separatrix.outline.r)
13371339
node[2].levelset.z = copy(ts3.boundary_secondary_separatrix.outline.z)
1340+
1341+
1342+
def _magnetics_method_to_ip(method: IDSBase, ip: IDSBase) -> None:
1343+
"""Convert obsolescent method(:) to ip(:) in the magnetics IDS."""
1344+
if not len(method):
1345+
return
1346+
ip.resize(len(method))
1347+
for old_item, new_item in zip(method, ip, strict=True):
1348+
new_item.method_name.value = old_item.name.value
1349+
new_item.data.value = old_item.ip.data.value
1350+
new_item.time.value = old_item.ip.time.value

imas/test/test_ids_convert.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ def test_3to4_deprecated_magnetics(dd4factory):
450450
mag.bpol_probe[1].name = "name2"
451451
mag.bpol_probe[1].voltage.data = [0.1, 0.2, 0.3]
452452

453+
mag.method.resize(2)
454+
for i, method in enumerate(mag.method):
455+
method.name = f"name{i}"
456+
method.ip.data = [i, 1.0, 2.0]
457+
method.ip.time = [i + 1, 2.0, 3.0]
458+
453459
mag4 = convert_ids(mag, None, factory=dd4factory)
454460
assert len(mag4.b_field_pol_probe) == 2
455461
assert mag4.b_field_pol_probe[0].name == "identifier1"
@@ -460,14 +466,26 @@ def test_3to4_deprecated_magnetics(dd4factory):
460466
assert mag4.b_field_pol_probe[1].description == "name2"
461467
assert array_equal(mag4.b_field_pol_probe[1].voltage.data, [0.1, 0.2, 0.3])
462468

469+
assert len(mag4.ip) == 2
470+
assert mag4.ip[0].method_name == "name0"
471+
assert array_equal(mag4.ip[0].data, [0.0, 1.0, 2.0])
472+
assert array_equal(mag4.ip[0].time, [1.0, 2.0, 3.0])
473+
assert mag4.ip[1].method_name == "name1"
474+
assert array_equal(mag4.ip[1].data, [1.0, 1.0, 2.0])
475+
assert array_equal(mag4.ip[1].time, [2.0, 2.0, 3.0])
476+
463477
# If both the deprecated and the "correct" quantity exist, we expect only the
464478
# correct one to be converted to DD4:
465479
mag.b_field_pol_probe.resize(1)
466480
mag.b_field_pol_probe[0].name = "test"
481+
mag.ip.resize(1)
482+
mag.ip[0].method_name = "ip"
467483

468484
mag4 = convert_ids(mag, None, factory=dd4factory)
469485
assert len(mag4.b_field_pol_probe) == 1
470486
assert mag4.b_field_pol_probe[0].name == "test"
487+
assert len(mag4.ip) == 1
488+
assert mag4.ip[0].method_name == "ip"
471489

472490

473491
def test_3to4_pulse_schedule():

0 commit comments

Comments
 (0)