Skip to content

Commit 8fcfbde

Browse files
reint-fischerreint-fischer
authored andcommitted
add formatting suggestions from review
1 parent 178e128 commit 8fcfbde

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

docs/user_guide/examples/explanation_kernelloop.md

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -137,58 +137,8 @@ plt.plot(advection_then_wind.lon.T, advection_then_wind.lat.T, "--", c="k", alph
137137
plt.show()
138138
```
139139

140-
## Warning! Avoid updating particle locations directly in Kernels
141-
140+
```{warning}
142141
It is better not to update `particles.lon` directly in a Kernel, as it can interfere with the loop above. Assigning a value to `particles.lon` in a Kernel will throw a warning.
143142
144143
Instead, update the local variable `particles.dlon`.
145-
146-
## Working with Status Codes
147-
148-
In order to capture errors in the Kernel loop, Parcels uses a Status Code system. There are several Status Codes, listed below.
149-
150-
```{code-cell}
151-
from parcels import StatusCode
152-
153-
for statuscode, val in StatusCode.__dict__.items():
154-
if statuscode.startswith("__"):
155-
continue
156-
print(f"{statuscode} = {val}")
157-
```
158-
159-
Once an error is thrown (for example, a Field Interpolation error), then the `particles.state` is updated to the corresponding status code. This gives you the flexibility to write a Kernel that checks for a status code and does something with it.
160-
161-
For example, you can write a Kernel that checks for `particles.state == StatusCode.ErrorOutOfBounds` and deletes the particle, and then append this custom Kernel to the Kernel list in `pset.execute()`.
162-
163-
```
164-
def DeleteOutOfBounds(particles, fieldset):
165-
out_of_bounds = particles.state == StatusCode.ErrorOutOfBounds
166-
particles[out_of_bounds].state = StatusCode.Delete
167-
168-
169-
def DeleteAnyError(particles, fieldset):
170-
any_error = particles.state >= 50 # This captures all Errors
171-
particles[any_error].state = StatusCode.Delete
172-
```
173-
174-
But of course, you can also write code for more sophisticated behaviour than just deleting the particle. It's up to you! Note that if you don't delete the particle, you will have to update the `particles.state = StatusCode.Success` yourself. For example:
175-
176-
```
177-
def Move1DegreeWest(particles, fieldset):
178-
out_of_bounds = particles.state == StatusCode.ErrorOutOfBounds
179-
particles[out_of_bounds].dlon -= 1.0
180-
particles[out_of_bounds].state = StatusCode.Success
181-
```
182-
183-
Or, if you want to make sure that particles don't escape through the water surface
184-
185-
```
186-
def KeepInOcean(particles, fieldset):
187-
through_surface = particles.state == StatusCode.ErrorThroughSurface
188-
particles[through_surface].dz = 0.0
189-
particles[through_surface].state = StatusCode.Success
190-
```
191-
192-
Kernel functions such as the ones above can then be added to the list of kernels in `pset.execute()`.
193-
194-
Note that these 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.
144+
```

docs/user_guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ examples/tutorial_delaystart.ipynb
4545
:titlesonly:
4646
4747
examples/explanation_kernelloop.md
48+
examples/tutorial_statuscodes.md
4849
examples/tutorial_sampling.ipynb
4950
examples/tutorial_gsw_density.ipynb
5051
examples/tutorial_Argofloats.ipynb

0 commit comments

Comments
 (0)