Skip to content

Commit 6c9e5bd

Browse files
MateoBelltheo-brown
authored andcommitted
Fix test and replace placeholder
1 parent 3823f94 commit 6c9e5bd

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

torax/_src/geometry/imas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def geometry_from_IMAS(
8181
# support multiple time slices.
8282
if slice_time is not None:
8383
if slice_time in equilibrium.time:
84-
slice_index = np.nonzero(equilibrium.time == slice_time)
84+
slice_index = np.nonzero(equilibrium.time == slice_time)[0]
8585
else:
86-
slice_index = np.searchsorted(slice_time, equilibrium.time)
86+
slice_index = np.searchsorted(equilibrium.time, slice_time)
8787
logging.warning(
8888
f"t={slice_time} not in equilibrium.time."
8989
f"Using t={equilibrium.time[slice_index]} instead."

torax/_src/geometry/tests/imas_test.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ def test_IMAS_input_with_equilibrium_object(self):
9999
config.build_geometry()
100100

101101
def test_IMAS_loading_specific_slice(self):
102-
filename = 'ITERhybrid_COCOS17_IDS_ddv4.nc'
103-
SLICE_TIME = 5
104-
SLICE_INDEX = 1
102+
filename = 'ITERhybrid_rampup_multiple_time_slices_COCOS17_IDS_ddv4.nc'
103+
SLICE_TIME = 40
104+
SLICE_INDEX = 20
105105
config_at_0 = geometry_pydantic_model.IMASConfig(imas_filepath=filename)
106106
config_at_slice_from_time = geometry_pydantic_model.IMASConfig(
107107
imas_filepath=filename, slice_time=SLICE_TIME
@@ -114,21 +114,22 @@ def test_IMAS_loading_specific_slice(self):
114114
geo_at_slice_from_index = config_at_slice_from_index.build_geometry()
115115

116116
for key in geo_at_0.__dict__.keys():
117-
np.testing.assert_allclose(
118-
geo_at_slice_from_time[key],
119-
geo_at_slice_from_index[key],
120-
err_msg=f'Value {key} mismatched between slice_time and slice_index',
121-
)
122-
with self.assertRaises(AssertionError):
123-
np.testing.assert_allclose(
124-
geo_at_0[key],
125-
geo_at_slice_from_time[key],
126-
)
127-
with self.assertRaises(AssertionError):
117+
if key not in ['geometry_type', 'torax_mesh', 'R_major', 'rho_hires_norm', 'Phi_b_dot', 'Ip_from_parameters']:
128118
np.testing.assert_allclose(
129-
geo_at_0[key],
130-
geo_at_slice_from_index[key],
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',
131122
)
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):
129+
np.testing.assert_allclose(
130+
geo_at_0.__dict__[key],
131+
geo_at_slice_from_index.__dict__[key],
132+
)
132133

133134
def test_IMAS_raises_if_slice_specified_twice(self):
134135
filename = 'ITERhybrid_COCOS17_IDS_ddv4.nc'

0 commit comments

Comments
 (0)