Skip to content

Commit 3cccd78

Browse files
committed
Respond to Nush's comments
1 parent 8a919f9 commit 3cccd78

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

torax/_src/geometry/pydantic_model.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class IMASConfig(torax_pydantic.BaseModelFrozen):
305305
imas_uri: str | None = None
306306
equilibrium_object: ids_toplevel.IDSToplevel | None = None
307307
slice_index: pydantic.NonNegativeInt = 0
308-
slice_time: float | None = None
308+
slice_time: pydantic.NonNegativeFloat | None = None
309309

310310
@pydantic.model_validator(mode='after')
311311
def _validate_model(self) -> typing_extensions.Self:
@@ -324,11 +324,6 @@ def _validate_model(self) -> typing_extensions.Self:
324324
'`imas_uri` or `imas_filepath` to be a valid input. Inputs provided: '
325325
f'{specified_inputs}.'
326326
)
327-
if self.slice_time is not None and self.slice_index != 0:
328-
raise ValueError(
329-
'IMAS geometry needs exactly one of `slice_time` and `slice_index`.'
330-
f'Got: slice_time={self.slice_time}, slice_index={self.slice_index}.'
331-
)
332327
return self
333328

334329
def build_geometry(self) -> standard_geometry.StandardGeometry:

torax/_src/imas_tools/input/equilibrium.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ def geometry_from_IMAS(
8585
slice_index = (
8686
np.searchsorted(equilibrium.time, slice_time, side="right") - 1
8787
)
88-
if not np.allclose(equilibrium.time[slice_index], slice_time, atol=1e-3):
88+
if not np.allclose(equilibrium.time[slice_index], slice_time, atol=1e-9):
8989
logging.warn(
9090
f"Requested t={slice_time} not in IDS; "
9191
f"using t={equilibrium.time[slice_index]})"
9292
)
9393

94-
if slice_index > len(equilibrium.time_slice):
94+
if slice_index >= len(equilibrium.time_slice):
9595
raise IndexError(
9696
f"slice_index={slice_index} out of range for IDS with "
9797
f"{len(equilibrium.time_slice)} time slices"

torax/_src/imas_tools/input/tests/equilibrium_test.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,46 +100,53 @@ def test_IMAS_input_with_equilibrium_object(self):
100100

101101
def test_IMAS_loading_specific_slice(self):
102102
filename = 'ITERhybrid_rampup_11_time_slices_COCOS17_IDS_ddv4.nc'
103-
SLICE_TIME = 40
104-
SLICE_INDEX = 5
105103
config_at_0 = geometry_pydantic_model.IMASConfig(imas_filepath=filename)
106104
config_at_slice_from_time = geometry_pydantic_model.IMASConfig(
107-
imas_filepath=filename, slice_time=SLICE_TIME
105+
imas_filepath=filename, slice_time=40
108106
)
109107
config_at_slice_from_index = geometry_pydantic_model.IMASConfig(
110-
imas_filepath=filename, slice_index=SLICE_INDEX
108+
imas_filepath=filename, slice_index=5
111109
)
110+
112111
geo_at_0 = config_at_0.build_geometry()
113112
geo_at_slice_from_time = config_at_slice_from_time.build_geometry()
114113
geo_at_slice_from_index = config_at_slice_from_index.build_geometry()
115114

116-
for key in geo_at_0.__dict__.keys():
117-
if key not in ['geometry_type', 'torax_mesh', 'R_major', 'B_0', 'rho_hires_norm', 'Phi_b_dot', 'Ip_from_parameters']:
118-
np.testing.assert_allclose(
119-
geo_at_slice_from_time.__dict__[key],
120-
geo_at_slice_from_index.__dict__[key],
121-
err_msg=f'Value {key} mismatched between slice_time and slice_index',
122-
)
123-
with self.assertRaises(AssertionError):
124-
np.testing.assert_allclose(
125-
geo_at_0.__dict__[key],
126-
geo_at_slice_from_time.__dict__[key],
127-
)
128-
with self.assertRaises(AssertionError):
115+
# Check that the geometry is not the same as at t=0
116+
with self.assertRaises(AssertionError):
117+
for key in geo_at_slice_from_time.__dict__.keys():
118+
if key not in [
119+
'geometry_type',
120+
'torax_mesh',
121+
'R_major',
122+
'B_0',
123+
'rho_hires_norm',
124+
'Phi_b_dot',
125+
'Ip_from_parameters',
126+
]:
129127
np.testing.assert_allclose(
130128
geo_at_0.__dict__[key],
131129
geo_at_slice_from_index.__dict__[key],
132130
)
133131

134-
def test_IMAS_raises_if_slice_specified_twice(self):
135-
filename = 'ITERhybrid_COCOS17_IDS_ddv4.nc'
136-
with self.assertRaisesRegex(
137-
pydantic.ValidationError,
138-
'exactly one of `slice_time` and `slice_index`',
139-
):
140-
geometry_pydantic_model.IMASConfig(
141-
imas_filepath=filename, slice_index=1, slice_time=1
142-
)
132+
# Check that the geometry at index and time are the same
133+
for key in geo_at_slice_from_time.__dict__.keys():
134+
if key not in [
135+
'geometry_type',
136+
'torax_mesh',
137+
'R_major',
138+
'B_0',
139+
'rho_hires_norm',
140+
'Phi_b_dot',
141+
'Ip_from_parameters',
142+
]:
143+
np.testing.assert_allclose(
144+
geo_at_slice_from_time.__dict__[key],
145+
geo_at_slice_from_index.__dict__[key],
146+
err_msg=(
147+
f'Value {key} mismatched between slice_time and slice_index'
148+
),
149+
)
143150

144151
def test_IMAS_raises_if_slice_out_of_range(self):
145152
filename = 'ITERhybrid_COCOS17_IDS_ddv4.nc'

torax/data/third_party/geo/README

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ All associated LICENSE files are also located in this directory.
2929
ITER_hybrid_citrin_equil_cheasedata.mat2cols: LICENSE_PINT
3030
eqdsk_cocos02.eqdsk: LICENSE_PINT
3131

32-
The IMAS netCDF file ITERhybrid_rampup_11_time_slices_COCOS17_IDS_ddv4.nc was
33-
generated with CHEASE using p' and ff' from a TORAX simulation using
34-
iterhybrid_rampup.py example config. It contains equuilibrium for each of the
35-
time slices of the TORAX simulation. The plasma boundaries outline R and Z
36-
were prescribed constant for all time slices ITERhybrid_COCOS17_IDS_ddv4.nc,
37-
based on the default CHEASE geometry file.
32+
The IMAS netCDF file TERhybrid_rampup_11_time_slices_COCOS17_IDS_ddv4.nc was generated
33+
by extracting p' and ff' profiles for each timeslice from a TORAX simulation with the
34+
iterhybrid_rampup.py config, and passing the profiles in to CHEASE.
35+
The LCFS was kept fixed for all timeslices, using the values from
36+
ITER_hybrid_citrin_equil_cheasedata.mat2cols.

0 commit comments

Comments
 (0)