Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parcels/application_kernels/advection.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
direction = 1.0 if particle.dt > 0 else -1.0
withW = True if "W" in [f.name for f in fieldset.get_fields()] else False
withTime = True if len(fieldset.U.grid.time_full) > 1 else False
ti = fieldset.U._time_index(time)[0]
ti = fieldset.U._time_index(time)

Check warning on line 180 in parcels/application_kernels/advection.py

View check run for this annotation

Codecov / codecov/patch

parcels/application_kernels/advection.py#L180

Added line #L180 was not covered by tests
ds_t = particle.dt
if withTime:
tau = (time - fieldset.U.grid.time[ti]) / (fieldset.U.grid.time[ti + 1] - fieldset.U.grid.time[ti])
Expand Down
12 changes: 5 additions & 7 deletions parcels/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,13 @@ def _time_index(self, time):
if time_index.all():
# If given time > last known field time, use
# the last field frame without interpolation
return (len(self.grid.time) - 1, 0)
return len(self.grid.time) - 1
elif np.logical_not(time_index).all():
# If given time < any time in the field, use
# the first field frame without interpolation
return (0, 0)
return 0
else:
return (time_index.argmin() - 1 if time_index.any() else 0, 0)
return time_index.argmin() - 1 if time_index.any() else 0

def _check_velocitysampling(self):
if self.name in ["U", "V", "W"]:
Expand All @@ -997,8 +997,7 @@ def eval(self, time, z, y, x, particle=None, applyConversion=True):
conversion to the result. Note that we defer to
scipy.interpolate to perform spatial interpolation.
"""
(ti, periods) = self._time_index(time)
time -= periods * (self.grid.time_full[-1] - self.grid.time_full[0])
ti = self._time_index(time)
if self.gridindexingtype == "croco" and self not in [self.fieldset.H, self.fieldset.Zeta]:
z = _croco_from_z_to_sigma_scipy(self.fieldset, time, z, y, x, particle=particle)
if ti < self.grid.tdim - 1 and time > self.grid.time[ti]:
Expand Down Expand Up @@ -1791,8 +1790,7 @@ def eval(self, time, z, y, x, particle=None, applyConversion=True):
"freeslip": {"2D": self.spatial_slip_interpolation, "3D": self.spatial_slip_interpolation},
}
grid = self.U.grid
(ti, periods) = self.U._time_index(time)
time -= periods * (grid.time_full[-1] - grid.time_full[0])
ti = self.U._time_index(time)
if ti < grid.tdim - 1 and time > grid.time[ti]:
t0 = grid.time[ti]
t1 = grid.time[ti + 1]
Expand Down
2 changes: 1 addition & 1 deletion parcels/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _computeTimeChunk(self, f, time, signdt):
self._update_status = "updated"
if self._ti == -1:
self.time = self.time_full
self._ti, _ = f._time_index(time)
self._ti = f._time_index(time)

if signdt == -1 and self._ti > 0 and self.time_full[self._ti] == time:
self._ti -= 1
Expand Down
Loading