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

52 statements  

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

1# mypy: ignore-errors 

2# TODO: need to fix mypy errors 

3 

4import typing 

5from typing import TYPE_CHECKING 

6 

7import mdsthin 

8import numpy as np 

9import numpy.typing as npt 

10from gsfit_rs import RogowskiCoils 

11from st40_database import GetData 

12 

13if TYPE_CHECKING: 

14 from . import DatabaseReader 

15 

16 

17def setup_rogowski_coils( 

18 self: "DatabaseReader", 

19 pulseNo: int, 

20 settings: dict[str, typing.Any], 

21) -> RogowskiCoils: 

22 """ 

23 This method initialises the Rust `RogowskiCoils` class. 

24 

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

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

27 

28 **This method is specific to ST40's SPIDER stored on MDSplus.** 

29 

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

31 """ 

32 

33 # Initialise the RogowskiCoils Rust class 

34 rogowski_coils = RogowskiCoils() 

35 

36 # Extract the spider_run_name from settings 

37 spider_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_spider_mdsplus"]["workflow"]["spider"]["run_name"] 

38 

39 # Connect to MDSplus 

40 conn = mdsthin.Connection("smaug") 

41 conn.openTree("SPIDER", pulseNo) 

42 

43 # SPIDER rogowki_coils from MDSplus 

44 time = conn.get(f"\\SPIDER::TOP.{spider_run_name}:TIME").data().astype(np.float64) 

45 measurements = conn.get(f"\\SPIDER::TOP.{spider_run_name}.ROG.ALL:I").data().astype(np.float64) 

46 names = conn.get(f"\\SPIDER::TOP.{spider_run_name}.ROG.ALL:NAME").data().astype(str) 

47 

48 # Read in mag data from MDSplus 

49 # FIXME: using a fixed shot is not a good idea! 

50 mag = GetData(12050, "MAG#BEST", is_fail_quiet=False) 

51 

52 names_long = mag.get("ROG.ALL.NAMES") 

53 sensors_names = np.char.replace(names_long, "ROG_", "") 

54 paths_r = mag.get("ROG.ALL.R_PATH").astype(np.float64) # BUXTON: need to fix these data types in MDSplus! 

55 paths_z = mag.get("ROG.ALL.Z_PATH").astype(np.float64) 

56 

57 n_sensors = len(sensors_names) 

58 for i_sensor in range(0, n_sensors): 

59 sensor_name = sensors_names[i_sensor] 

60 path_r = paths_r[i_sensor, :] 

61 path_z = paths_z[i_sensor, :] 

62 

63 # Remove nan's 

64 # This is because in MDSplus "ALL" does not allow jagged arrays 

65 path_r = path_r[~np.isnan(path_r)] 

66 path_z = path_z[~np.isnan(path_z)] 

67 

68 # Don't store the "fake" Rogowski coils (e.g. the MC supports) 

69 if len(path_r) > 4: 

70 if sensor_name in settings["sensor_weights_rogowski_coils.json"]: 

71 fit_settings_comment = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["comment"] 

72 fit_settings_expected_value = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["expected_value"] 

73 fit_settings_include = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["include"] 

74 fit_settings_weight = settings["sensor_weights_rogowski_coils.json"][sensor_name]["fit_settings"]["weight"] 

75 else: 

76 fit_settings_comment = "" 

77 fit_settings_expected_value = np.nan 

78 fit_settings_include = False 

79 fit_settings_weight = np.nan 

80 

81 # Measured values 

82 index = names == "ROG_" + sensor_name 

83 measured = measurements[:, index].squeeze() 

84 

85 if sensor_name == "INIVC000": 

86 measured = measured * 0.0 + 436_884.0 + 11.0 * 2.0 * -0.00012086e6 

87 if sensor_name == "BVLB" or sensor_name == "BVLT": 

88 measured = measured * 0.0 - 9059.47387218 * 4.0 * 4.0 

89 if sensor_name == "DIVT" or sensor_name == "DIVB": 

90 measured = measured * 0.0 + 6946.69410586 * 4.0 * 7.0 

91 

92 # ASTRA does not include gaps in Rogowski coils 

93 gaps_r = np.array([]) 

94 gaps_z = np.array([]) 

95 gaps_d_r = np.array([]) 

96 gaps_d_z = np.array([]) 

97 gaps_name = [] 

98 

99 # Add Rogowski coil to the Rust class 

100 rogowski_coils.add_sensor( 

101 name=sensor_name, 

102 r=path_r, 

103 z=path_z, 

104 fit_settings_comment=fit_settings_comment, 

105 fit_settings_expected_value=fit_settings_expected_value, 

106 fit_settings_include=fit_settings_include, 

107 fit_settings_weight=fit_settings_weight, 

108 time=time, 

109 measured=measured, 

110 gaps_r=gaps_r, 

111 gaps_z=gaps_z, 

112 gaps_d_r=gaps_d_r, 

113 gaps_d_z=gaps_d_z, 

114 gaps_name=gaps_name, 

115 ) 

116 

117 return rogowski_coils