Skip to content

Fix CUDB equilibrium time unit so g-file header time is correct#86

Open
kripnerl wants to merge 1 commit into
developfrom
fix/cudb-equilibrium-time-unit-seconds
Open

Fix CUDB equilibrium time unit so g-file header time is correct#86
kripnerl wants to merge 1 commit into
developfrom
fix/cudb-equilibrium-time-unit-seconds

Conversation

@kripnerl

Copy link
Copy Markdown
Owner

Problem

Equilibria loaded from CUDB (Fiesta) via pleque.io.compass.cudb / get_ds_from_cudb carry their time axis in seconds. However, Equilibrium.__init__ defaults time_unit to "ms" whenever the input dataset does not explicitly state it. geqdsk.write then encodes the header time as int(time) seconds interpreted as milliseconds:

if equilibrium.time_unit == 's':
    time = int(equilibrium.time * 1000)
else:
    time = int(equilibrium.time)   # <-- 0.65 s written as 0 ms

So writing a GEQDSK file for e.g. COMPASS-U shot 11600 at t = 0.65 s produced a header stamped 0ms instead of 650ms.

Fix

  • pleque/io/compass.pyget_ds_from_cudb now records time_unit = 's' on the dataset, symmetric with the existing dst['shot'] = int(shot) handling. This makes CUDB-loaded equilibria self-describing.
  • pleque/core/equilibrium.pytime_unit read from a dataset is now normalised to a plain str (it was previously stored as a raw 0-d xarray.DataArray).
  • tests/test_gfile.py — added test_time_unit_from_dataset_seconds, a regression test built on the existing test00.nc fixture (whose time is in seconds), asserting time_unit == 's' (a str) and that the GEQDSK header carries the correct millisecond value.

Verification

pytest tests/test_gfile.py tests/test_equilibria.py tests/test_omas.py tests/test_cocos.py tests/test_io.py107 passed, no regressions.

🤖 Generated with Claude Code

Equilibria loaded from CUDB (Fiesta) carry their time axis in seconds, but
`Equilibrium.__init__` defaulted `time_unit` to "ms" whenever the dataset did
not state it. `geqdsk.write` then encodes `int(time)` seconds as the header
time, so e.g. a t = 0.65 s slice was written as 0 ms.

- `get_ds_from_cudb` now records `time_unit = 's'` on the dataset, mirroring
  the existing `shot` handling.
- `Equilibrium` normalises `time_unit` read from a dataset to a plain `str`
  (it was previously stored as a 0-d `DataArray`).
- Add a regression test built on the `test00.nc` fixture (time in seconds).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant