Skip to content

Conversation

@reint-fischer
Copy link
Contributor

@reint-fischer reint-fischer commented Nov 25, 2025

There was a bit of documentation on statuscodes in the kernel loop explanation, but we thought it should be its own page. Since we are mainly showing how to use them in Kernels, I have written this as a how-to guide rather than an explanation. I have added an example of how the KeepInOcean Kernel stops particles from going through the surface.

I think it might be worth writing some extra text explaining the different statuscodes, either here or in an explainer. I would like to hear your thoughts on how and when to write this explanation.

Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Looks good!

through_surface = particles.state == parcels.StatusCode.ErrorThroughSurface

# move particles to surface
particles[through_surface].dz = fieldset.W.grid.depth[0] - particles[through_surface].z
Copy link
Member

Choose a reason for hiding this comment

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

This line may be a bit magical to new users. Does this need a bit of information why this works?

Or even replace with

Suggested change
particles[through_surface].dz = fieldset.W.grid.depth[0] - particles[through_surface].z
particles[through_surface].z = fieldset.W.grid.depth[0]
particles[through_surface].dz = 0

even though we advice not to change particles.z directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have expanded both the description before the code-cell and the comment slightly. I personally like adapting dz because I might forget the second line in your suggestion otherwise and would worry others do the same, but it does make things cleaner.


If we advect particles with the `AdvectionRK2_3D` kernel, Parcels will raise a `FieldOutOfBoundSurfaceError`:

```{code-cell}
Copy link
Member

Choose a reason for hiding this comment

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

Will it be a problem for the GitHub Action that this cell fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The raises-exception tag in the following line is recognized by ReadTheDocs, and all checks pass, so I think it’s fine

particles[out_of_bounds].state = parcels.StatusCode.Evaluate
```

Or, if you want to make sure that particles don't escape through the water surface
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
Or, if you want to make sure that particles don't escape through the water surface
When `particles.dz` is too large, they will be displaced through the surface, throwing an `ErrorThroughSurface`. We can adapt the particles.dz of these particles to move no further than the surface:

# find particles that move through the surface
through_surface = particles.state == parcels.StatusCode.ErrorThroughSurface

# move particles to surface
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
# move particles to surface
# move particles from current z exactly to the surface

Co-authored-by: Erik van Sebille <[email protected]>
```

```{note}
Kernels that control what to do with `particles.state` should typically be added at the _end_ of the Kernel list, because otherwise later Kernels may overwrite the `particles.state` or the `particles.dlon` variables (see [Kernel loop explanation](explanation_kernelloop.md)).
Copy link
Member

Choose a reason for hiding this comment

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

The link doesn't work; tries to go to #explanation_kernelloop on the page itself?

Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Apart from the broken link, it's good to go!

@reint-fischer reint-fischer merged commit 0d419a2 into v4-dev Nov 25, 2025
11 checks passed
@reint-fischer reint-fischer deleted the statuscodes_documentation_v4 branch November 25, 2025 10:33
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Nov 25, 2025
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.

3 participants