Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a warn_outputdt_release_desync bug #1747

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Changes from 3 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
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 @@
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 @@
"ParticleSet.execute() will not do anything."
)

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

Check warning on line 1125 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1124-L1125

Added lines #L1124 - L1125 were not covered by tests

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

if callbackdt is None:
Expand Down Expand Up @@ -1240,12 +1240,13 @@
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]):

Check warning on line 1243 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1243

Added line #L1243 was not covered by tests
"""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):

Check warning on line 1245 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1245

Added line #L1245 was not covered by tests
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,
)
Loading