Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add 3to4 conversion rule for obselescent magnetics.method
Fixes #116
  • Loading branch information
maarten-ic committed May 7, 2026
commit a2a977e7d2ea0a406941e187229b344444d49488
13 changes: 13 additions & 0 deletions imas/ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ def _apply_3to4_conversion(self, old: Element, new: Element) -> None:
# TODO: define migrations in a separate variable (as with the sign flips)?
if self.ids_name == "magnetics":
self._add_rename("bpol_probe", "b_field_pol_probe", reciprocal=False)
self._add_rename("method", "ip", reciprocal=False)
self.old_to_new.type_change["method"] = _magnetics_method_to_ip

# GH#59: To improve further the conversion of DD3 to DD4, especially the
# Machine Description part of the IDSs, we would like to add a 3to4 specific
Expand Down Expand Up @@ -1335,3 +1337,14 @@ def _equilibrium_boundary_3to4(eq3: IDSToplevel, eq4: IDSToplevel, deepcopy: boo
node[2].psi = -ts3.boundary_secondary_separatrix.psi # COCOS change
node[2].levelset.r = copy(ts3.boundary_secondary_separatrix.outline.r)
node[2].levelset.z = copy(ts3.boundary_secondary_separatrix.outline.z)


def _magnetics_method_to_ip(method: IDSBase, ip: IDSBase) -> None:
"""Convert obsolescent method(:) to ip(:) in the magnetics IDS."""
if not len(method):
return
ip.resize(len(method))
for old_item, new_item in zip(method, ip, strict=True):
new_item.method_name.value = old_item.name.value
new_item.data.value = old_item.ip.data.value
new_item.time.value = old_item.ip.time.value
18 changes: 18 additions & 0 deletions imas/test/test_ids_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ def test_3to4_deprecated_magnetics(dd4factory):
mag.bpol_probe[1].name = "name2"
mag.bpol_probe[1].voltage.data = [0.1, 0.2, 0.3]

mag.method.resize(2)
for i, method in enumerate(mag.method):
method.name = f"name{i}"
method.ip.data = [i, 1.0, 2.0]
method.ip.time = [i + 1, 2.0, 3.0]

mag4 = convert_ids(mag, None, factory=dd4factory)
assert len(mag4.b_field_pol_probe) == 2
assert mag4.b_field_pol_probe[0].name == "identifier1"
Expand All @@ -460,14 +466,26 @@ def test_3to4_deprecated_magnetics(dd4factory):
assert mag4.b_field_pol_probe[1].description == "name2"
assert array_equal(mag4.b_field_pol_probe[1].voltage.data, [0.1, 0.2, 0.3])

assert len(mag4.ip) == 2
assert mag4.ip[0].method_name == "name0"
assert array_equal(mag4.ip[0].data, [0.0, 1.0, 2.0])
assert array_equal(mag4.ip[0].time, [1.0, 2.0, 3.0])
assert mag4.ip[1].method_name == "name1"
assert array_equal(mag4.ip[1].data, [1.0, 1.0, 2.0])
assert array_equal(mag4.ip[1].time, [2.0, 2.0, 3.0])

# If both the deprecated and the "correct" quantity exist, we expect only the
# correct one to be converted to DD4:
mag.b_field_pol_probe.resize(1)
mag.b_field_pol_probe[0].name = "test"
mag.ip.resize(1)
mag.ip[0].method_name = "ip"

mag4 = convert_ids(mag, None, factory=dd4factory)
assert len(mag4.b_field_pol_probe) == 1
assert mag4.b_field_pol_probe[0].name == "test"
assert len(mag4.ip) == 1
assert mag4.ip[0].method_name == "ip"


def test_3to4_pulse_schedule():
Expand Down
Loading