Skip to content

Commit 8a919f9

Browse files
committed
Always choose time <= current time; check with tolerance
1 parent a0790ac commit 8a919f9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

torax/_src/imas_tools/input/equilibrium.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ def geometry_from_IMAS(
7979
)
8080
# TODO(b/431977390): Currently only a single time slice is used, extend to
8181
# support multiple time slices.
82+
# Convert time to index
8283
if slice_time is not None:
83-
if slice_time in equilibrium.time:
84-
slice_index = np.nonzero(equilibrium.time == slice_time)[0]
85-
else:
86-
slice_index = np.searchsorted(equilibrium.time, slice_time)
87-
logging.warning(
88-
f"t={slice_time} not in equilibrium.time."
89-
f"Using t={equilibrium.time[slice_index]} instead."
84+
# Find the closest time in the IDS that is <= slice_time
85+
slice_index = (
86+
np.searchsorted(equilibrium.time, slice_time, side="right") - 1
87+
)
88+
if not np.allclose(equilibrium.time[slice_index], slice_time, atol=1e-3):
89+
logging.warn(
90+
f"Requested t={slice_time} not in IDS; "
91+
f"using t={equilibrium.time[slice_index]})"
9092
)
93+
9194
if slice_index > len(equilibrium.time_slice):
9295
raise IndexError(
9396
f"slice_index={slice_index} out of range for IDS with "

0 commit comments

Comments
 (0)