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

15 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 Tf 

7from scipy.constants import mu_0 

8 

9from .mock_get_data import MockGetData 

10 

11if TYPE_CHECKING: 

12 from . import DatabaseReader 

13 

14 

15def setup_tf( 

16 self: "DatabaseReader", 

17 pulseNo: int, 

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

19) -> Tf: 

20 """ 

21 This method initialises the Rust `Tf` class, which holds an IMAS `tf` IDS. 

22 

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

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

25 

26 **This method is specific to a mock of ST40's experimental MDSplus database.** 

27 

28 Two nodes are filled: 

29 1. `tf/r0`, the reference major radius the vacuum toroidal field is quoted at 

30 2. `tf/b_field_phi_vacuum_r`, the vacuum field times major radius, on the **experimental** 

31 timebase. `solve_grad_shafranov` interpolates it onto the reconstruction times itself, so 

32 do not interpolate it here. 

33 

34 `b_field_phi_vacuum_r` is signed: positive means counter-clockwise viewed from above. 

35 

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

37 """ 

38 

39 # Initialise the Tf Rust class 

40 tf = Tf() 

41 

42 tf.set_r0(settings["GSFIT_code_settings.json"]["vacuum_toroidal_field_reference_radius"]) 

43 

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

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

46 i_rod = typing.cast(npt.NDArray[np.float64], psu2coil.get("TF.I_ROD")) 

47 

48 # `f_vac = R0 * B_phi0 = mu_0 * i_rod / (2 * pi)`, the poloidal-current function in vacuum 

49 tf.set_b_field_phi_vacuum_r( 

50 time=time, 

51 data=mu_0 * np.asarray(i_rod) / (2.0 * np.pi), 

52 ) 

53 

54 return tf