Coverage for python/gsfit/database_readers/st40_astra_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# The major radius ASTRA quotes `GLOBAL:BTVAC` at 

12ASTRA_BTVAC_REFERENCE_RADIUS = 0.5 # [metre] 

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 ST40's ASTRA 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 astra_run_name = settings["GSFIT_code_settings.json"]["database_reader"]["st40_astra_mdsplus"]["workflow"]["astra"]["run_name"] 

45 conn = mdsthin.Connection("smaug") 

46 conn.openTree("ASTRA", pulseNo) 

47 time = conn.get(f"\\ASTRA::TOP.{astra_run_name}:TIME").data().astype(np.float64) 

48 bt_vac = conn.get(f"\\ASTRA::TOP.{astra_run_name}.GLOBAL:BTVAC").data().astype(np.float64) 

49 

50 # `b_field_phi_vacuum_r = R * B_phi` is invariant with R in vacuum, so the radius ASTRA 

51 # quotes `BTVAC` at cancels out and no `mu_0` round trip through a rod current is needed 

52 tf.set_b_field_phi_vacuum_r( 

53 time=time, 

54 data=bt_vac * ASTRA_BTVAC_REFERENCE_RADIUS, 

55 ) 

56 

57 return tf