Coverage for python/gsfit/database_readers/mock_st40_mdsplus/setup_passives.py: 0%
38 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-14 15:25 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-14 15:25 +0000
1import typing
2from typing import TYPE_CHECKING
4import numpy as np
5import numpy.typing as npt
6from gsfit_rs import Passives
8from .mock_get_data import MockGetData
10if TYPE_CHECKING:
11 from . import DatabaseReader
14def setup_passives(
15 self: "DatabaseReader",
16 pulseNo: int,
17 settings: dict[str, typing.Any],
18) -> Passives:
19 """
20 This method initialises the Rust `Passives` class.
22 :param pulseNo: Pulse number, used to select which mocked MDSplus tree to read
23 :param settings: Dictionary containing the JSON settings read from the `settings` directory
25 **This method is specific to a mock of ST40's experimental MDSplus database.**
27 See `python/gsfit/database_readers/interface.py` for more details on how a new database_reader should be implemented.
28 """
30 # Initialise the Passives Rust class
31 passives = Passives()
33 elmag = MockGetData.from_workflow(settings, pulseNo, "elmag")
34 vessel_r = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.R"))
35 vessel_z = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.Z"))
36 vessel_d_r = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.DR"))
37 vessel_d_z = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.DZ"))
38 vessel_angle_1 = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.ANGLE1"))
39 vessel_angle_2 = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.ANGLE2"))
40 vessel_resistivity = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.RESISTIVITY"))
41 vessel_filaments_to_passives = typing.cast(npt.NDArray[np.float64], elmag.get("VESSEL.FILS2PASSIVE"))
42 [n_filaments, n_passives] = vessel_filaments_to_passives.shape
43 passive_names = typing.cast(list[str], elmag.get("VESSEL.PASSIVE_NAME"))
45 for i_passive in range(0, n_passives):
46 passive_name = passive_names[i_passive]
47 i_filaments = vessel_filaments_to_passives[:, i_passive].astype(bool)
49 if passive_name == "IVC":
50 current_distribution_type = "eig"
51 n_dof = settings["passive_dof_regularisation.json"]["IVC"]["n_dof"]
52 regularisations = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations"])
53 regularisations_weight = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations_weight"])
54 elif passive_name == "OVC":
55 current_distribution_type = "constant_current_density"
56 n_dof = 1
57 regularisations = np.array([[1.0]])
58 regularisations_weight = np.array([0.1])
59 else:
60 current_distribution_type = "constant_current_density"
61 n_dof = 1
62 regularisations = np.empty((0, 0))
63 regularisations_weight = np.empty(0)
65 # Add the passive to the Rust class
66 passives.add_passive(
67 name=passive_name,
68 r=vessel_r[i_filaments],
69 z=vessel_z[i_filaments],
70 d_r=vessel_d_r[i_filaments],
71 d_z=vessel_d_z[i_filaments],
72 angle_1=vessel_angle_1[i_filaments],
73 angle_2=vessel_angle_2[i_filaments],
74 resistivity=vessel_resistivity[i_passive],
75 current_distribution_type=current_distribution_type,
76 n_dof=n_dof,
77 regularisations=regularisations,
78 regularisations_weight=regularisations_weight,
79 )
81 return passives