Skip to content

Conversation

@erikvansebille
Copy link
Member

As found by @sruehs and @ezekiel-lemur, parcels output can 'skip' timesteps when dt has a very high precision (i.e. many digits behind the comma). This is very likely because of the test done when considering which particles to write

https://github.com/OceanParcels/parcels/blob/a0ea4044c3ced351b65ec3a19ea3bd8d29f8bd3d/parcels/particledata.py#L322-L328

Solution is to throw an error when users provide a dt that has higher precision than 1e-6. Note that parcels before already threw an error when dt < 1e-6, now a value like dt=1+1e-6 would also be caught

The new testcase in example_globcurrent (with dt = 81.2584344538292) indeed shows how the output file misses a few time-snapshots if this error is not raised

if dt > 0 and dt <= 1e-6:
if abs(dt) <= 1e-6:
raise ValueError('Time step dt is too small')
if dt*1e6 % 1 != 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to check here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I say in the comment of the PR, we've seen that Parcels unexpectedly fails (outputfiles miss some timeslices) when dt has a precision finer than 1e-6.

So dt=3.001 works, but dt=3.0000001 doesn't.

I want to catch these latter cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a proposal for a cleaner code to do the same?

Copy link
Contributor

@VascoSch92 VascoSch92 May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok sorry. Now is clear. Perhaps just add parenthisis: (dt * 1e6) % 1 to make it more clear. Otherwise is perfect :-)

erikvansebille and others added 2 commits May 8, 2024 15:55
As not supported anymore since parcels v3.0

Also cleaning up code as suggested by @VascoSch92
@erikvansebille erikvansebille merged commit eb16b40 into master May 24, 2024
@erikvansebille erikvansebille deleted the error_when_dt_too_high_precision branch May 24, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants