Skip to content

Fix silent fail on pset sampling when time is NaN - #2823

Merged
erikvansebille merged 4 commits into
Parcels-code:mainfrom
erikvansebille:fix_pset_sampling_without_time
Aug 17, 2026
Merged

Fix silent fail on pset sampling when time is NaN#2823
erikvansebille merged 4 commits into
Parcels-code:mainfrom
erikvansebille:fix_pset_sampling_without_time

Conversation

@erikvansebille

Copy link
Copy Markdown
Member

Description

This PR fixes #2822, where field interpolation would silently fail if the particles.t included NaN values. Now, this raises a ValueError

Checklist

AI Disclosure

None

Comment on lines +396 to +398
if np.any(np.isnan(t)):
nan_indices = np.where(np.isnan(t))[0]
raise ValueError(f"Time values for particles with indices {nan_indices} cannot be NaN.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wondering whether this should be somewhere in the execute loop?

i.e., make sure that the time for each particle is set before we go into the main loop

Is there a usecase of t being nan during execution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, the point is that time is never NaN in a pset.execute (see here), but it can be before the execute loop; e.g. during an initial sampling (particles.var = fieldset.var[particles]). That is why we need this error here and not in the execute loop

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see now

@erikvansebille
erikvansebille enabled auto-merge (squash) August 17, 2026 10:15
@erikvansebille
erikvansebille merged commit 2650f07 into Parcels-code:main Aug 17, 2026
15 of 16 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Field Sampling fails when particleset has no time set yet

2 participants