Coverage for python/gsfit/database_readers/st40_astra_mdsplus/astra_rogowski_coils_reader.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 13:12 +0000

1"""Rogowski coils reader for ASTRA simulations using the rogpath.dat file. 

2 

3This module reads Rogowski coil geometry from the rogpath.dat file 

4which contains coil path data in the following format: 

5 index name 

6 r values (space-separated) 

7 z values (space-separated) 

8""" 

9 

10import os 

11from typing import Any 

12 

13import numpy as np 

14import numpy.typing as npt 

15 

16 

17def astra_rogowski_coils_reader() -> dict[str, dict[str, Any]]: 

18 """ 

19 Read Rogowski coil data from the rogpath.dat file. 

20 

21 The rogpath.dat file contains Rogowski coil data with lines: 

22 - Line 1: index name (e.g., "1 ROG_BVLB") 

23 - Line 2: r values (space-separated floats) 

24 - Line 3: z values (space-separated floats) 

25 

26 This pattern repeats for each Rogowski coil. 

27 

28 :return: Dictionary mapping Rogowski coil names to their properties: 

29 - r: numpy array of radial positions 

30 - z: numpy array of vertical positions 

31 """ 

32 # Get the path to the rogpath.dat file (in the same directory as this module) 

33 # Taken from: 

34 # https://tokamak-devlin.tokamak.local/gitlab/physics/astra_te/-/blob/master/exp/equ/MCVC/rogpath.dat 

35 rogpath_dat_path = os.path.join(os.path.dirname(__file__), "rogpath.dat") 

36 

37 # Read and parse the rogpath.dat file 

38 rogowski_coils_data: dict[str, dict[str, Any]] = {} 

39 

40 with open(rogpath_dat_path, "r") as f: 

41 lines = f.readlines() 

42 

43 n_lines: int = len(lines) 

44 i_line: int = 0 

45 

46 while i_line < n_lines: 

47 # Skip empty lines 

48 line = lines[i_line].strip() 

49 if not line: 

50 i_line += 1 

51 continue 

52 

53 # Parse header line: index name 

54 parts = line.split() 

55 if len(parts) < 2: 

56 i_line += 1 

57 continue 

58 

59 name: str = parts[1].strip() 

60 

61 # Parse r values (next line) 

62 i_line += 1 

63 if i_line >= n_lines: 

64 break 

65 r_line = lines[i_line].strip() 

66 r: npt.NDArray[np.float64] = np.array([float(x) for x in r_line.split()], dtype=np.float64) 

67 

68 # Parse z values (next line) 

69 i_line += 1 

70 if i_line >= n_lines: 

71 break 

72 z_line = lines[i_line].strip() 

73 z: npt.NDArray[np.float64] = np.array([float(x) for x in z_line.split()], dtype=np.float64) 

74 

75 rogowski_coils_data[name] = { 

76 "r": r, 

77 "z": z, 

78 } 

79 

80 i_line += 1 

81 

82 return rogowski_coils_data