Coverage for python/gsfit/database_readers/mock_st40_mdsplus/setup_coils.py: 0%

29 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-14 15:25 +0000

1import typing 

2from typing import TYPE_CHECKING 

3 

4import numpy as np 

5import numpy.typing as npt 

6from gsfit_rs import Coils 

7 

8from .mock_get_data import MockGetData 

9 

10if TYPE_CHECKING: 

11 from . import DatabaseReader 

12 

13 

14def setup_coils( 

15 self: "DatabaseReader", 

16 pulseNo: int, 

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

18) -> Coils: 

19 """ 

20 This method initialises the Rust `Coils` class. 

21 

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 

24 

25 **This method is specific to a mock of 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 Coils Rust class 

31 coils = Coils() 

32 

33 # Coil geometry, from the "machine description" pulse 

34 elmag = MockGetData.from_workflow(settings, pulseNo, "elmag_coils") 

35 coils_r = typing.cast(npt.NDArray[np.float64], elmag.get("COILS.R")) 

36 coils_z = typing.cast(npt.NDArray[np.float64], elmag.get("COILS.Z")) 

37 coils_d_r = typing.cast(npt.NDArray[np.float64], elmag.get("COILS.DR")) 

38 coils_d_z = typing.cast(npt.NDArray[np.float64], elmag.get("COILS.DZ")) 

39 coil_names = typing.cast(list[str], elmag.get("COILS.COIL_NAMES")) 

40 fils2coils = typing.cast(npt.NDArray[np.bool_], np.asarray(elmag.get("COILS.FILS2COILS")) == 1.0) 

41 

42 # Measured power-supply currents 

43 psu2coil = MockGetData.from_workflow(settings, pulseNo, "psu2coil") 

44 time = typing.cast(npt.NDArray[np.float64], psu2coil.get("TIME")) 

45 pf_i = typing.cast(npt.NDArray[np.float64], psu2coil.get("PF.ALL.I")) 

46 coils_connected_to_psus = typing.cast(list[list[str]], psu2coil.get("PF.ALL.COILS")) 

47 

48 n_time, n_psu = pf_i.shape 

49 for i_psu in range(0, n_psu): 

50 current_this_psu = pf_i[:, i_psu] 

51 coils_connected_to_this_psu = coils_connected_to_psus[i_psu] 

52 

53 # A single power supply can drive several coils in series 

54 for coil_name in coils_connected_to_this_psu: 

55 if coil_name != "": 

56 i_pf = coil_names.index(coil_name) 

57 i_filaments = fils2coils[:, i_pf] 

58 

59 # Add the PF coil to the Rust class 

60 coils.add_pf_coil( 

61 coil_name, 

62 coils_r[i_filaments], 

63 coils_z[i_filaments], 

64 coils_d_r[i_filaments], 

65 coils_d_z[i_filaments], 

66 time=time, 

67 measured=current_this_psu, 

68 ) 

69 

70 return coils