You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Warning! Avoid updating particle locations directly in Kernels
141
-
140
+
```{warning}
142
141
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.
143
142
144
143
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()`.
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:
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.
0 commit comments