Skip to content

Commit

Permalink
Fixing a warn_outputdt_release_desync bug
Browse files Browse the repository at this point in the history
Fixing a bug where `warn_outputdt_release_desync()` was unintentially raised when startime was not 0.
  • Loading branch information
erikvansebille committed Oct 31, 2024
1 parent e728d46 commit 0dd60fd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,6 @@ def execute(
raise ValueError("Output interval should not have finer precision than 1e-6 s")
outputdt = timedelta_to_float(output_file.outputdt) if output_file else np.inf

if np.isfinite(outputdt):
_warn_outputdt_release_desync(outputdt, self.particledata.data["time_nextloop"])

if callbackdt is not None:
callbackdt = timedelta_to_float(callbackdt)

Expand Down Expand Up @@ -1124,6 +1121,9 @@ def execute(
"ParticleSet.execute() will not do anything."
)

if np.isfinite(outputdt):
_warn_outputdt_release_desync(outputdt, starttime, self.particledata.data["time_nextloop"])

self.particledata._data["dt"][:] = dt

if callbackdt is None:
Expand Down Expand Up @@ -1240,12 +1240,13 @@ def execute(
pbar.close()


def _warn_outputdt_release_desync(outputdt: float, release_times: Iterable[float]):
def _warn_outputdt_release_desync(outputdt: float, starttime: float, release_times: Iterable[float]):
"""Gives the user a warning if the release time isn't a multiple of outputdt."""
if any((np.isfinite(t) and t % outputdt != 0) for t in release_times):
if any((np.isfinite(t) and (t-starttime) % outputdt != 0) for t in release_times):
warnings.warn(
"Some of the particles have a start time that is not a multiple of outputdt. "
"This could cause the first output to be at a different time than expected.",
"Some of the particles have a start time difference that is not a multiple of outputdt. "
"This could cause the first output of some of the particles that start later "
"in the simulation to be at a different time than expected.",
FileWarning,
stacklevel=2,
)

0 comments on commit 0dd60fd

Please sign in to comment.