Skip to content

Commit 5752fa2

Browse files
Making _search_time_index return a dictionary like grid.search
1 parent dbcd331 commit 5752fa2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/parcels/_core/field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
217217
_ei = particles.ei[:, self.igrid]
218218

219219
position = {"time": time, "z": z, "lat": y, "lon": x}
220-
(position["ti"], position["tau"]) = _search_time_index(self, time)
220+
position.update(_search_time_index(self, time))
221221
position.update(self.grid.search(z, y, x, ei=_ei))
222222
_update_particles_ei(particles, position, self)
223223
_update_particle_states_position(particles, position)
@@ -302,7 +302,7 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
302302
_ei = particles.ei[:, self.igrid]
303303

304304
position = {"time": time, "z": z, "lat": y, "lon": x}
305-
(position["ti"], position["tau"]) = _search_time_index(self.U, time)
305+
position.update(_search_time_index(self.U, time))
306306
position.update(self.grid.search(z, y, x, ei=_ei))
307307
_update_particles_ei(particles, position, self)
308308
_update_particle_states_position(particles, position)

src/parcels/_core/index_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def _search_time_index(field: Field, time: datetime):
7575
if the sampled value is outside the time value range.
7676
"""
7777
if field.time_interval is None:
78-
return np.zeros(shape=time.shape, dtype=np.int32), np.zeros(shape=time.shape, dtype=np.float32)
78+
return {"ti": np.zeros(shape=time.shape, dtype=np.int32), "tau": np.zeros(shape=time.shape, dtype=np.float32)}
7979

8080
if not field.time_interval.is_all_time_in_interval(time):
8181
_raise_time_extrapolation_error(time, field=None)
8282

8383
ti = np.searchsorted(field.data.time.data, time, side="right") - 1
8484
tau = (time - field.data.time.data[ti]) / (field.data.time.data[ti + 1] - field.data.time.data[ti])
85-
return np.atleast_1d(ti), np.atleast_1d(tau)
85+
return {"ti": np.atleast_1d(ti), "tau": np.atleast_1d(tau)}
8686

8787

8888
def curvilinear_point_in_cell(grid, y: np.ndarray, x: np.ndarray, yi: np.ndarray, xi: np.ndarray):

tests/test_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def field():
8585
def test_raw_2d_interpolation(field, func, t, z, y, x, expected):
8686
"""Test the interpolation functions on the Field."""
8787
position = field.grid.search(z, y, x)
88-
(position["ti"], position["tau"]) = _search_time_index(field, t)
88+
position.update(_search_time_index(field, t))
8989

9090
value = func(position, field)
9191
np.testing.assert_equal(value, expected)

0 commit comments

Comments
 (0)