Skip to content

Commit

Permalink
Add coil names and types (#16)
Browse files Browse the repository at this point in the history
* Add coil names and types

* fix tests with Jon's magic fortran string
  • Loading branch information
je-cook authored Jul 3, 2024
1 parent 97cc62d commit a92112e
Show file tree
Hide file tree
Showing 6 changed files with 1,932 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
2 changes: 1 addition & 1 deletion eqdsk/cocos.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def identify_cocos(
raise ValueError(
"The sign of qpsi is not consistent across the flux surfaces.",
)
sign_q = Sign(sign_q.max())
sign_q = Sign(int(sign_q.max()) or 1)

sign_Bp = sign_Ip * sign_psi_inc_towards_boundary
sign_rho_theta_phi = sign_Ip * sign_B0 * sign_q
Expand Down
8 changes: 6 additions & 2 deletions eqdsk/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class EQDSKInterface:
"""Safety factor values on the 1-D flux grid [dimensionless]."""
file_name: str | None = None
"""The EQDSK file the data originates from."""
coil_names: list[str] | None = None
"""Name of the coils"""
coil_types: list[str] | None = None
"""Type of the coils"""

def __post_init__(self):
"""Calculate derived parameters if they're not given."""
Expand Down Expand Up @@ -332,7 +336,7 @@ def _read_json(file_path: Path) -> dict[str, Any]:
data = json.load(file)

for k, value in data.items():
if isinstance(value, list):
if isinstance(value, list) and k not in {"coil_type", "coil_names"}:
data[k] = np.asarray(value)

# For backward compatibility where 'psinorm' was sometimes 'pnorm'
Expand Down Expand Up @@ -618,7 +622,7 @@ def write_array(fortran_format: ff.FortranRecordWriter, array: np.ndarray):
# Create FortranRecordWriter objects with the Fortran format
# edit descriptors to be used in the G-EQDSK output.
f2000 = ff.FortranRecordWriter("a48,3i4")
f2020 = ff.FortranRecordWriter("5e16.9")
f2020 = ff.FortranRecordWriter("5ES23.16e2")
f2022 = ff.FortranRecordWriter("2i5")
fCSTM = ff.FortranRecordWriter("i5")

Expand Down
2 changes: 1 addition & 1 deletion tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read_strict_geqdsk(file_path):
# Create FortranRecordReader objects with the Fortran format
# edit descriptors to be used to parse the G-EQDSK input.
f2000 = ff.FortranRecordReader("a48,3i4")
f2020 = ff.FortranRecordReader("5e16.9")
f2020 = ff.FortranRecordReader("5ES23.16e2")
f2022 = ff.FortranRecordReader("2i5")
fCSTM = ff.FortranRecordReader("i5")

Expand Down
Loading

0 comments on commit a92112e

Please sign in to comment.