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

30 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 mdsthin 

5import numpy as np 

6import numpy.typing as npt 

7from gsfit_rs import Dialoop 

8from st40_database import GetData 

9 

10if TYPE_CHECKING: 

11 from . import DatabaseReader 

12 

13 

14def setup_dialoop( 

15 self: "DatabaseReader", 

16 pulseNo: int, 

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

18) -> Dialoop: 

19 """ 

20 This method initialises the Rust `Dialoop` class. 

21 

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

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

24 

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

26 

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

28 """ 

29 

30 # Initialise the Dialoop Rust class 

31 dialoop = Dialoop() 

32 

33 # Read in the diamagnetic flux from MDSplus 

34 dialoop_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_mdsplus"]["workflow"]["dialoop"]["run_name"] 

35 mag_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_mdsplus"]["workflow"]["mag"]["run_name"] 

36 dialoop_data = GetData(pulseNo, f"DIALOOP#{dialoop_run_name}", is_fail_quiet=False) 

37 

38 # We use a single diamagnetic flux loop 

39 sensor_name = "DIALOOP" 

40 

41 # Get geometry (path of integration) directly via mdsthin from the MAG tree 

42 # (the geometry is stored in MAG, not in the DIALOOP tree) 

43 conn = mdsthin.Connection("smaug") 

44 conn.openTree("MAG", pulseNo) 

45 path_r = conn.get(f"\\MAG::TOP.{mag_run_name}.DIALOOP.L000:R_PATH").data().astype(np.float64) 

46 path_z = conn.get(f"\\MAG::TOP.{mag_run_name}.DIALOOP.L000:Z_PATH").data().astype(np.float64) 

47 

48 if sensor_name in settings["sensor_weights_dialoop.json"]: 

49 fit_settings_comment = settings["sensor_weights_dialoop.json"][sensor_name]["fit_settings"]["comment"] 

50 fit_settings_expected_value = settings["sensor_weights_dialoop.json"][sensor_name]["fit_settings"]["expected_value"] 

51 fit_settings_include = settings["sensor_weights_dialoop.json"][sensor_name]["fit_settings"]["include"] 

52 fit_settings_weight = settings["sensor_weights_dialoop.json"][sensor_name]["fit_settings"]["weight"] 

53 else: 

54 fit_settings_comment = "" 

55 fit_settings_expected_value = np.nan 

56 fit_settings_include = False 

57 fit_settings_weight = np.nan 

58 

59 # Measured signal: \DIALOOP::TOP.<run_name>.GLOBAL:PHI_DIA 

60 time = typing.cast(npt.NDArray[np.float64], dialoop_data.get("TIME")).astype(np.float64) 

61 measured = typing.cast(npt.NDArray[np.float64], dialoop_data.get("GLOBAL.PHI_DIA")).astype(np.float64) 

62 

63 # Add the sensor to the Rust class 

64 dialoop.add_sensor( 

65 name=sensor_name, 

66 r=path_r, 

67 z=path_z, 

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 dialoop