Coverage for python/gsfit/database_readers/st40_mdsplus/setup_rogowski_coils.py: 0%
50 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
1import typing
2from typing import TYPE_CHECKING
4import numpy as np
5import numpy.typing as npt
6from gsfit_rs import RogowskiCoils
7from st40_database import GetData
9if TYPE_CHECKING:
10 from . import DatabaseReader
13def setup_rogowski_coils(
14 self: "DatabaseReader",
15 pulseNo: int,
16 settings: dict[str, typing.Any],
17) -> RogowskiCoils:
18 """
19 This method initialises the Rust `RogowskiCoils` class.
21 :param pulseNo: Pulse number, used to read from the database
22 :param settings: Dictionary containing the JSON settings read from the `settings` directory
24 **This method is specific to ST40's experimental MDSplus database.**
26 See `python/gsfit/database_readers/interface.py` for more details on how a new database_reader should be implemented.
27 """
29 # Initialise the RogowskiCoils Rust class
30 rogowski_coils = RogowskiCoils()
32 # Read in mag data from MDSplus
33 mag_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_mdsplus"]["workflow"]["mag"]["run_name"]
34 mag = GetData(pulseNo, f"MAG#{mag_run_name}", is_fail_quiet=False)
36 names_long = typing.cast(list[str], mag.get("ROG.ALL.NAMES"))
37 sensors_names = np.char.replace(names_long, "ROG_", "")
38 paths_r = typing.cast(npt.NDArray[np.float32], mag.get("ROG.ALL.R_PATH")).astype(np.float64)
39 paths_z = typing.cast(npt.NDArray[np.float32], mag.get("ROG.ALL.Z_PATH")).astype(np.float64)
41 n_sensors = len(sensors_names)
42 for i_sensor in range(0, n_sensors):
43 sensor_name = sensors_names[i_sensor]
44 path_r = paths_r[i_sensor, :]
45 path_z = paths_z[i_sensor, :]
47 # Remove nan's
48 # This is because in MDSplus "ALL" does not allow jagged arrays
49 path_r = path_r[~np.isnan(path_r)]
50 path_z = path_z[~np.isnan(path_z)]
52 # Don't store the "fake" Rogowski coils (e.g. the MC supports)
53 if len(path_r) > 4:
54 if sensor_name in settings["sensor_weights_rogowski_coils.json"]:
55 fit_settings_comment = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["comment"]
56 fit_settings_expected_value = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["expected_value"]
57 fit_settings_include = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["include"]
58 fit_settings_weight = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["weight"]
59 else:
60 fit_settings_comment = ""
61 fit_settings_expected_value = np.nan
62 fit_settings_include = False
63 fit_settings_weight = np.nan
65 # Measured signals
66 time = typing.cast(npt.NDArray[np.float32], mag.get("TIME")).astype(np.float64)
67 measured = typing.cast(npt.NDArray[np.float32], mag.get(f"ROG.{sensor_name}.I")).astype(np.float64)
69 # By default we don't have any gaps
70 gaps_r = np.array([])
71 gaps_z = np.array([])
72 gaps_d_r = np.array([])
73 gaps_d_z = np.array([])
74 gaps_name = []
76 # Only INIVC000 has gaps
77 if sensor_name == "INIVC000":
78 import mdsthin
80 conn = mdsthin.Connection("smaug")
81 conn.openTree("st40", 11010605)
82 gaps_r = conn.get("\\MAG::TOP.RUN14C.ROG.INIVC000.GAPS:R").data().astype(np.float64)
83 gaps_z = conn.get("\\MAG::TOP.RUN14C.ROG.INIVC000.GAPS:Z").data().astype(np.float64)
84 gaps_d_r = conn.get("\\MAG::TOP.RUN14C.ROG.INIVC000.GAPS:DR").data().astype(np.float64)
85 gaps_d_z = conn.get("\\MAG::TOP.RUN14C.ROG.INIVC000.GAPS:DZ").data().astype(np.float64)
86 gaps_name = conn.get("\\MAG::TOP.RUN14C.ROG.INIVC000.GAPS:NAME").data()
87 gaps_name = [str(gap_name).replace(" ", "")[2:-1] for gap_name in gaps_name]
89 # Add Rogowski coil to the Rust class
90 rogowski_coils.add_sensor(
91 sensor_name,
92 path_r,
93 path_z,
94 fit_settings_comment,
95 fit_settings_expected_value,
96 fit_settings_include,
97 fit_settings_weight,
98 time,
99 measured,
100 gaps_r=gaps_r,
101 gaps_z=gaps_z,
102 gaps_d_r=gaps_d_r,
103 gaps_d_z=gaps_d_z,
104 gaps_name=gaps_name,
105 )
107 return rogowski_coils