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

16 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 

8from st40_database import GetData 

9 

10if TYPE_CHECKING: 

11 from . import DatabaseReader 

12 

13 

14def setup_tf( 

15 self: "DatabaseReader", 

16 pulseNo: int, 

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

18) -> Tf: 

19 """ 

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

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 Two nodes are filled: 

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

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

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

31 do not interpolate it here. 

32 

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

34 

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

36 """ 

37 

38 # Initialise the Tf Rust class 

39 tf = Tf() 

40 

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

42 

43 psu2coil_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_mdsplus"]["workflow"]["psu2coil"]["run_name"] 

44 psu2coil = GetData(pulseNo, f"PSU2COIL#{psu2coil_run_name}", is_fail_quiet=False, use_redis=False) 

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 * i_rod / (2.0 * np.pi), 

52 ) 

53 

54 return tf