From 0dd60fd8be086b56920606a530d7074da64396cc Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Thu, 31 Oct 2024 21:14:17 +0100 Subject: [PATCH 1/2] Fixing a warn_outputdt_release_desync bug Fixing a bug where `warn_outputdt_release_desync()` was unintentially raised when startime was not 0. --- parcels/particleset.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/parcels/particleset.py b/parcels/particleset.py index ffe7eb652d..3c5268fe51 100644 --- a/parcels/particleset.py +++ b/parcels/particleset.py @@ -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) @@ -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: @@ -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, ) From 899bf61ec9bd3f1f6d89ff30cff21d08351e8393 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:15:48 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- parcels/particleset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parcels/particleset.py b/parcels/particleset.py index 3c5268fe51..86809e2887 100644 --- a/parcels/particleset.py +++ b/parcels/particleset.py @@ -1242,7 +1242,7 @@ def execute( 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-starttime) % 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 difference that is not a multiple of outputdt. " "This could cause the first output of some of the particles that start later "