Coverage for python/gsfit/database_readers/st40_astra_mdsplus/astra_coils_reader.py: 0%
39 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 13:12 +0000
1"""Coils reader for ASTRA simulations using the coil.dat file.
3This module reads coil geometry from the coil.dat file
4which contains coil data in the following format:
5 ndi (number of divisions)
6 rc zc wc hc awc ahc ... name ...
7"""
9import os
10from typing import Any
13def astra_coils_reader() -> dict[str, dict[str, Any]]:
14 """
15 Read coil data from the coil.dat file.
17 The coil.dat file contains coil data with pairs of lines:
18 - Line 1: ndi (number of divisions)
19 - Line 2: rc zc wc hc awc ahc unknown unknown unknown name unknown
21 Where:
22 - rc: radial position of center (m)
23 - zc: vertical position of center (m)
24 - wc: projection of first side on R (m)
25 - hc: projection of second side on Z (m)
26 - awc: angle of first side with R axis (degrees)
27 - ahc: angle of second side with R axis (degrees)
28 - ndi: approximate number of cells for dividing
30 :return: Dictionary mapping coil names to their properties:
31 - rc: radial center position (float)
32 - zc: vertical center position (float)
33 - wc: radial width (float)
34 - hc: vertical height (float)
35 - awc: angle of first side (float, degrees)
36 - ahc: angle of second side (float, degrees)
37 - ndi: number of divisions (int)
38 """
39 # Get the path to the coil.dat file (in the same directory as this module)
40 # Taken from:
41 # https://tokamak-devlin.tokamak.local/gitlab/physics/astra_te/-/blob/master/exp/equ/MCVC/coil.dat
42 coil_dat_path = os.path.join(os.path.dirname(__file__), "coil.dat")
44 # Read and parse the coil.dat file
45 coils_data: dict[str, dict[str, Any]] = {}
47 with open(coil_dat_path, "r") as f:
48 lines = f.readlines()
50 n_lines: int = len(lines)
51 i_line: int = 0
53 while i_line < n_lines:
54 # Skip empty lines
55 line = lines[i_line].strip()
56 if not line:
57 i_line += 1
58 continue
60 # Parse ndi line (first line of pair)
61 try:
62 ndi: int = int(line.split()[0])
63 except (ValueError, IndexError):
64 i_line += 1
65 continue
67 # Parse coil parameters line (second line of pair)
68 i_line += 1
69 if i_line >= n_lines:
70 break
72 params_line = lines[i_line].strip()
73 parts = params_line.split()
74 if len(parts) < 10:
75 i_line += 1
76 continue
78 # Parse: rc zc wc hc awc ahc unknown unknown unknown name
79 rc: float = float(parts[0])
80 zc: float = float(parts[1])
81 wc: float = float(parts[2])
82 hc: float = float(parts[3])
83 awc: float = float(parts[4])
84 ahc: float = float(parts[5])
85 name: str = parts[9].strip()
87 # Map CS to SOL (ASTRA uses CS, but we use SOL)
88 if name == "CS":
89 name = "SOL"
91 coils_data[name] = {
92 "rc": rc,
93 "zc": zc,
94 "wc": wc,
95 "hc": hc,
96 "awc": awc,
97 "ahc": ahc,
98 "ndi": ndi,
99 }
101 i_line += 1
103 return coils_data