Coverage for python/gsfit/database_readers/st40_spider_mdsplus/setup_passives.py: 0%

50 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 13:12 +0000

1import typing 

2from typing import TYPE_CHECKING 

3 

4import numpy as np 

5import numpy.typing as npt 

6from gsfit_rs import Passives 

7from st40_database import GetData 

8 

9if TYPE_CHECKING: 

10 from . import DatabaseReader 

11 

12 

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. 

20 

21 :param pulseNo: Pulse number, used to read from the database 

22 :param settings: Dictionary containing the JSON settings read from the `settings` directory 

23 

24 **This method is specific to ST40's experimental MDSplus database.** 

25 

26 See `python/gsfit/database_readers/interface.py` for more details on how a new database_reader should be implemented. 

27 """ 

28 

29 # Initialise the Passives Rust class 

30 passives = Passives() 

31 

32 elmag_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_spider_mdsplus"]["workflow"]["elmag"]["run_name"] 

33 elmag = GetData(13321, f"ELMAG#{elmag_run_name}", is_fail_quiet=False) 

34 

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")) 

45 

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(int) == True 

49 

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"]) 

55 

56 # BUXTON: temporary fix to use PFIT eigenvalues 

57 from MDSplus import Connection # type: ignore 

58 

59 conn = Connection("smaug") 

60 conn.openTree("elmag", 206) 

61 tmp_vessel_r = conn.get("\\ELMAG::TOP.VESSEL:R").data()[0:480] 

62 tmp_vessel_z = conn.get("\\ELMAG::TOP.VESSEL:Z").data()[0:480] 

63 tmp_vessel_d_r = conn.get("\\ELMAG::TOP.VESSEL:DR").data()[0:480] 

64 tmp_vessel_d_z = conn.get("\\ELMAG::TOP.VESSEL:DZ").data()[0:480] 

65 tmp_vessel_angle_1 = 0.0 * tmp_vessel_r 

66 tmp_vessel_angle_2 = 0.0 * tmp_vessel_r 

67 

68 passives.add_passive( 

69 name=passive_name, 

70 r=tmp_vessel_r, 

71 z=tmp_vessel_z, 

72 d_r=tmp_vessel_d_r, 

73 d_z=tmp_vessel_d_z, 

74 angle_1=tmp_vessel_angle_1, 

75 angle_2=tmp_vessel_angle_2, 

76 resistivity=vessel_resistivity[i_passive], 

77 current_distribution_type=current_distribution_type, 

78 n_dof=n_dof, 

79 regularisations=regularisations, 

80 regularisations_weight=regularisations_weight, 

81 ) 

82 elif passive_name == "OVC": 

83 current_distribution_type = "constant_current_density" 

84 n_dof = 1 

85 regularisations = np.array([[1.0]]) 

86 regularisations_weight = np.array([0.1]) 

87 

88 passives.add_passive( 

89 name=passive_name, 

90 r=vessel_r[i_filaments], 

91 z=vessel_z[i_filaments], 

92 d_r=vessel_d_r[i_filaments], 

93 d_z=vessel_d_z[i_filaments], 

94 angle_1=vessel_angle_1[i_filaments], 

95 angle_2=vessel_angle_2[i_filaments], 

96 resistivity=vessel_resistivity[i_passive], 

97 current_distribution_type=current_distribution_type, 

98 n_dof=n_dof, 

99 regularisations=regularisations, 

100 regularisations_weight=regularisations_weight, 

101 ) 

102 else: 

103 current_distribution_type = "constant_current_density" 

104 n_dof = 1 

105 regularisations = np.empty((0, 0)) 

106 regularisations_weight = np.empty(0) 

107 

108 passives.add_passive( 

109 name=passive_name, 

110 r=vessel_r[i_filaments], 

111 z=vessel_z[i_filaments], 

112 d_r=vessel_d_r[i_filaments], 

113 d_z=vessel_d_z[i_filaments], 

114 angle_1=vessel_angle_1[i_filaments], 

115 angle_2=vessel_angle_2[i_filaments], 

116 resistivity=vessel_resistivity[i_passive], 

117 current_distribution_type=current_distribution_type, 

118 n_dof=n_dof, 

119 regularisations=regularisations, 

120 regularisations_weight=regularisations_weight, 

121 ) 

122 

123 return passives