Coverage for python/gsfit/database_readers/st40_mdsplus/setup_passives.py: 0%
41 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 Passives
7from st40_database import GetData
9if TYPE_CHECKING:
10 from . import DatabaseReader
13def setup_passives(
14 self: "DatabaseReader",
15 pulseNo: int,
16 settings: dict[str, typing.Any],
17) -> Passives:
18 """
19 This method initialises the Rust `Passives` 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 Passives Rust class
30 passives = Passives()
32 elmag_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_mdsplus"]["workflow"]["elmag"]["run_name"]
33 elmag = GetData(pulseNo, f"ELMAG#{elmag_run_name}", is_fail_quiet=False)
35 vessel_r = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.R"))
36 vessel_z = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.Z"))
37 vessel_d_r = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.DR"))
38 vessel_d_z = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.DZ"))
39 vessel_angle_1 = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.ANGLE1"))
40 vessel_angle_2 = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.ANGLE2"))
41 vessel_resistivity = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.RESISTIVITY"))
42 vessel_fillaments_to_passives = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.FILS2PASSIVE"))
43 [n_filaments, n_passives] = vessel_fillaments_to_passives.shape
44 passive_names = typing.cast(list[str], elmag.get("VESSEL.PASSIVE_NAME"))
46 for i_passive in range(0, n_passives):
47 passive_name = passive_names[i_passive]
48 i_filaments = vessel_fillaments_to_passives[:, i_passive].astype(bool)
50 if passive_name == "IVC":
51 current_distribution_type = "eig"
52 n_dof = settings["passive_dof_regularisation.json"]["IVC"]["n_dof"]
53 regularisations = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations"])
54 regularisations_weight = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations_weight"])
56 passives.add_passive(
57 name=passive_name,
58 r=vessel_r[i_filaments],
59 z=vessel_z[i_filaments],
60 d_r=vessel_d_r[i_filaments],
61 d_z=vessel_d_z[i_filaments],
62 angle_1=vessel_angle_1[i_filaments],
63 angle_2=vessel_angle_2[i_filaments],
64 resistivity=vessel_resistivity[i_passive],
65 current_distribution_type=current_distribution_type,
66 n_dof=n_dof,
67 regularisations=regularisations,
68 regularisations_weight=regularisations_weight,
69 )
70 elif passive_name == "OVC":
71 current_distribution_type = "constant_current_density"
72 n_dof = 1
73 regularisations = np.array([[1.0]])
74 regularisations_weight = np.array([0.1])
76 passives.add_passive(
77 name=passive_name,
78 r=vessel_r[i_filaments],
79 z=vessel_z[i_filaments],
80 d_r=vessel_d_r[i_filaments],
81 d_z=vessel_d_z[i_filaments],
82 angle_1=vessel_angle_1[i_filaments],
83 angle_2=vessel_angle_2[i_filaments],
84 resistivity=vessel_resistivity[i_passive],
85 current_distribution_type=current_distribution_type,
86 n_dof=n_dof,
87 regularisations=regularisations,
88 regularisations_weight=regularisations_weight,
89 )
90 else:
91 current_distribution_type = "constant_current_density"
92 n_dof = 1
93 regularisations = np.empty((0, 0))
94 regularisations_weight = np.empty(0)
96 passives.add_passive(
97 name=passive_name,
98 r=vessel_r[i_filaments],
99 z=vessel_z[i_filaments],
100 d_r=vessel_d_r[i_filaments],
101 d_z=vessel_d_z[i_filaments],
102 angle_1=vessel_angle_1[i_filaments],
103 angle_2=vessel_angle_2[i_filaments],
104 resistivity=vessel_resistivity[i_passive],
105 current_distribution_type=current_distribution_type,
106 n_dof=n_dof,
107 regularisations=regularisations,
108 regularisations_weight=regularisations_weight,
109 )
111 return passives