Coverage for python/gsfit/database_readers/st40_mdsplus/setup_bp_probes.py: 0%

31 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 BpProbes 

7from st40_database import GetData 

8 

9if TYPE_CHECKING: 

10 from . import DatabaseReader 

11 

12 

13def setup_bp_probes( 

14 self: "DatabaseReader", 

15 pulseNo: int, 

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

17) -> BpProbes: 

18 """ 

19 This method initialises the Rust `BpProbes` class (Mirnov coils). 

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 BpProbes Rust class 

30 bp_probes = BpProbes() 

31 

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) 

35 

36 # Bp-probes 

37 names_long = typing.cast(list[str], mag.get("BPPROBE.ALL.NAMES")) 

38 sensors_names = np.char.replace(names_long, "BPPROBE_", "P") 

39 sensors_r = typing.cast(npt.NDArray[np.float64], mag.get("BPPROBE.ALL.R")) 

40 sensors_z = typing.cast(npt.NDArray[np.float64], mag.get("BPPROBE.ALL.Z")) 

41 sensors_angle_pol = typing.cast(npt.NDArray[np.float64], mag.get("BPPROBE.ALL.THETA")) 

42 

43 n_sensors = len(sensors_names) 

44 for i_sensor in range(0, n_sensors): 

45 sensor_name = sensors_names[i_sensor] 

46 

47 if sensor_name in settings["sensor_weights_bp_probe.json"]: 

48 fit_settings_comment = settings["sensor_weights_bp_probe.json"][sensor_name]["fit_settings"]["comment"] 

49 fit_settings_expected_value = settings["sensor_weights_bp_probe.json"][sensor_name]["fit_settings"]["expected_value"] 

50 fit_settings_include = settings["sensor_weights_bp_probe.json"][sensor_name]["fit_settings"]["include"] 

51 fit_settings_weight = settings["sensor_weights_bp_probe.json"][sensor_name]["fit_settings"]["weight"] 

52 else: 

53 fit_settings_comment = "" 

54 fit_settings_expected_value = np.nan 

55 fit_settings_include = False 

56 fit_settings_weight = np.nan 

57 

58 # Measured values 

59 time = typing.cast(npt.NDArray[np.float32], mag.get("TIME")).astype(np.float64) 

60 measured = typing.cast(npt.NDArray[np.float32], mag.get(f"BPPROBE.{sensor_name}.B")).astype(np.float64) 

61 

62 # Add the sensor to the Rust class 

63 bp_probes.add_sensor( 

64 name=sensor_name, 

65 geometry_angle_pol=sensors_angle_pol[i_sensor], 

66 geometry_r=sensors_r[i_sensor], 

67 geometry_z=sensors_z[i_sensor], 

68 fit_settings_comment=fit_settings_comment, 

69 fit_settings_expected_value=fit_settings_expected_value, 

70 fit_settings_include=fit_settings_include, 

71 fit_settings_weight=fit_settings_weight, 

72 time=time, 

73 measured=measured, 

74 ) 

75 

76 return bp_probes