Coverage for python/gsfit/database_readers/st40_spider_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 mdsthin 

5import numpy as np 

6from gsfit_rs import Tf 

7 

8if TYPE_CHECKING: 

9 from . import DatabaseReader 

10 

11 

12def setup_tf( 

13 self: "DatabaseReader", 

14 pulseNo: int, 

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

16) -> Tf: 

17 """ 

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

19 

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

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

22 

23 **This method is specific to ST40's SPIDER MDSplus database.** 

24 

25 Two nodes are filled: 

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

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

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

29 do not interpolate it here. 

30 

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

32 

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

34 """ 

35 

36 # Initialise the Tf Rust class 

37 tf = Tf() 

38 

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

40 

41 spider_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_spider_mdsplus"]["workflow"]["spider"]["run_name"] 

42 conn = mdsthin.Connection("smaug") 

43 conn.openTree("SPIDER", pulseNo) 

44 time = conn.get(f"\\SPIDER::TOP.{spider_run_name}:TIME").data().astype(np.float64) 

45 bt_vac = conn.get(f"\\SPIDER::TOP.{spider_run_name}.GLOBAL:BTVAC_GEO").data().astype(np.float64) 

46 r_geo = conn.get(f"\\SPIDER::TOP.{spider_run_name}.GLOBAL:RGEO").data().astype(np.float64) 

47 

48 # `b_field_phi_vacuum_r = R * B_phi` is invariant with R in vacuum, so SPIDER's field at the 

49 # geometric axis times that axis is the same quantity, with no `mu_0` round trip 

50 tf.set_b_field_phi_vacuum_r( 

51 time=time, 

52 data=bt_vac * r_geo, 

53 ) 

54 

55 return tf