Skip to content

Commit 8b6f0b0

Browse files
Refactoring warn_particle_times_outside_fieldset_time_bounds
1 parent 348dfcf commit 8b6f0b0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

parcels/particleset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from parcels.application_kernels.advection import AdvectionRK4
1616
from parcels.compilation.codecompiler import GNUCompiler
1717
from parcels.field import NestedField
18-
from parcels.fieldset import FieldSet
1918
from parcels.grid import CurvilinearGrid, GridType
2019
from parcels.interaction.interactionkernel import InteractionKernel
2120
from parcels.interaction.neighborsearch import (
@@ -175,7 +174,8 @@ def ArrayClass_init(self, *args, **kwargs):
175174
raise NotImplementedError("If fieldset.time_origin is not a date, time of a particle must be a double")
176175
time = np.array([self.time_origin.reltime(t) if _convert_to_reltime(t) else t for t in time])
177176
assert lon.size == time.size, "time and positions (lon, lat, depth) do not have the same lengths."
178-
_warn_particle_times_outside_fieldset_time_bounds(time, fieldset)
177+
if not fieldset.U.allow_time_extrapolation:
178+
_warn_particle_times_outside_fieldset_time_bounds(time, fieldset.U.grid.time_full)
179179

180180
if lonlatdepth_dtype is None:
181181
lonlatdepth_dtype = self.lonlatdepth_dtype_from_field_interp_method(fieldset.U)
@@ -1254,15 +1254,15 @@ def _warn_outputdt_release_desync(outputdt: float, starttime: float, release_tim
12541254
)
12551255

12561256

1257-
def _warn_particle_times_outside_fieldset_time_bounds(time: np.ndarray, fieldset: FieldSet):
1258-
if np.any(time):
1259-
if np.any(time < fieldset.U.grid.time_full[0]) and not fieldset.U.allow_time_extrapolation: # type: ignore[attr-defined]
1257+
def _warn_particle_times_outside_fieldset_time_bounds(release_times: np.ndarray, time_full: np.ndarray):
1258+
if np.any(release_times):
1259+
if np.any(release_times < time_full[0]):
12601260
warnings.warn(
12611261
"Some particles are set to be released before the fieldset's first time and allow_time_extrapolation is set to False.",
12621262
ParticleSetWarning,
12631263
stacklevel=2,
12641264
)
1265-
if np.any(time > fieldset.U.grid.time_full[-1]) and not fieldset.U.allow_time_extrapolation: # type: ignore[attr-defined]
1265+
if np.any(release_times > time_full[-1]):
12661266
warnings.warn(
12671267
"Some particles are set to be released after the fieldset's last time and allow_time_extrapolation is set to False.",
12681268
ParticleSetWarning,

0 commit comments

Comments
 (0)