|
14 | 14 | from parcels._compat import MPI |
15 | 15 | from parcels.application_kernels.advection import AdvectionRK4 |
16 | 16 | from parcels.compilation.codecompiler import GNUCompiler |
17 | | -from parcels.field import NestedField |
| 17 | +from parcels.field import Field, NestedField |
18 | 18 | from parcels.grid import CurvilinearGrid, GridType |
19 | 19 | from parcels.interaction.interactionkernel import InteractionKernel |
20 | 20 | from parcels.interaction.neighborsearch import ( |
|
32 | 32 | from parcels.tools.global_statics import get_package_dir |
33 | 33 | from parcels.tools.loggers import logger |
34 | 34 | from parcels.tools.statuscodes import StatusCode |
35 | | -from parcels.tools.warnings import FileWarning |
| 35 | +from parcels.tools.warnings import ParticleSetWarning |
36 | 36 |
|
37 | 37 | __all__ = ["ParticleSet"] |
38 | 38 |
|
@@ -174,6 +174,8 @@ def ArrayClass_init(self, *args, **kwargs): |
174 | 174 | raise NotImplementedError("If fieldset.time_origin is not a date, time of a particle must be a double") |
175 | 175 | time = np.array([self.time_origin.reltime(t) if _convert_to_reltime(t) else t for t in time]) |
176 | 176 | assert lon.size == time.size, "time and positions (lon, lat, depth) do not have the same lengths." |
| 177 | + if isinstance(fieldset.U, Field) and (not fieldset.U.allow_time_extrapolation): |
| 178 | + _warn_particle_times_outside_fieldset_time_bounds(time, fieldset.U.grid.time_full) |
177 | 179 |
|
178 | 180 | if lonlatdepth_dtype is None: |
179 | 181 | lonlatdepth_dtype = self.lonlatdepth_dtype_from_field_interp_method(fieldset.U) |
@@ -792,7 +794,7 @@ def from_particlefile( |
792 | 794 | f"Note that the `repeatdt` argument is not retained from {filename}, and that " |
793 | 795 | "setting a new repeatdt will start particles from the _new_ particle " |
794 | 796 | "locations.", |
795 | | - FileWarning, |
| 797 | + ParticleSetWarning, |
796 | 798 | stacklevel=2, |
797 | 799 | ) |
798 | 800 |
|
@@ -1247,6 +1249,22 @@ def _warn_outputdt_release_desync(outputdt: float, starttime: float, release_tim |
1247 | 1249 | "Some of the particles have a start time difference that is not a multiple of outputdt. " |
1248 | 1250 | "This could cause the first output of some of the particles that start later " |
1249 | 1251 | "in the simulation to be at a different time than expected.", |
1250 | | - FileWarning, |
| 1252 | + ParticleSetWarning, |
1251 | 1253 | stacklevel=2, |
1252 | 1254 | ) |
| 1255 | + |
| 1256 | + |
| 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]): |
| 1260 | + warnings.warn( |
| 1261 | + "Some particles are set to be released before the fieldset's first time and allow_time_extrapolation is set to False.", |
| 1262 | + ParticleSetWarning, |
| 1263 | + stacklevel=2, |
| 1264 | + ) |
| 1265 | + if np.any(release_times > time_full[-1]): |
| 1266 | + warnings.warn( |
| 1267 | + "Some particles are set to be released after the fieldset's last time and allow_time_extrapolation is set to False.", |
| 1268 | + ParticleSetWarning, |
| 1269 | + stacklevel=2, |
| 1270 | + ) |
0 commit comments