Skip to content

Commit dc1809c

Browse files
Merge pull request #2472 from Parcels-code/tutorials_cleanup
Cleaning up the documentation
2 parents f644537 + 52ed981 commit dc1809c

13 files changed

+179
-217
lines changed

docs/getting_started/explanation_concepts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,23 @@ def Age(particles, fieldset):
143143
particles.age += particles.dt
144144

145145
# define all kernels to be executed on particles using an (ordered) list
146-
kernels = [Age, parcels.kernels.AdvectionRK4]
146+
kernels = [Age, parcels.kernels.AdvectionRK2]
147147
```
148148

149149
```{note}
150150
Every Kernel must be a function with the following (and only those) arguments: `(particles, fieldset)`
151151
```
152152

153153
```{warning}
154-
We have to be careful with writing kernels for vector fields on Curvilinear grids. While Parcels automatically rotates the "U" and "V" field when necessary, this is not the case for other fields such as Stokes drift. [This guide](../user_guide/examples/tutorial_nemo_curvilinear.ipynb) describes how to use a curvilinear grid in Parcels.
154+
We have to be careful with kernels that sample velocities on "spherical" grids (so with longitude and latitude in degrees). Parcels can automatically convert velocities from m s<sup>-1</sup> to degrees s<sup>-1</sup>, but only when using `VectorFields`. [This guide](../user_guide/examples/tutorial_velocityconversion.ipynb) describes how to use velocities on a "spherical" grid in Parcels.
155155
```
156156

157157
```{admonition} 📖 Read more about the Kernel loop
158158
:class: seealso
159159
- [The Kernel loop](../user_guide/examples/explanation_kernelloop.md)
160160
```
161161

162-
```{admonition} 🖥️ Learn how to write kernels
162+
```{admonition} 🖥️ Learn how to write Kernels
163163
:class: seealso
164164
- [Sample fields like temperature](../user_guide/examples/tutorial_sampling.ipynb).
165165
- [Mimic the behaviour of ARGO floats](../user_guide/examples/tutorial_Argofloats.ipynb).

docs/getting_started/tutorial_output.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"outputs": [],
121121
"source": [
122122
"pset.execute(\n",
123-
" parcels.kernels.AdvectionRK4,\n",
123+
" parcels.kernels.AdvectionRK2,\n",
124124
" runtime=np.timedelta64(48, \"h\"),\n",
125125
" dt=np.timedelta64(5, \"m\"),\n",
126126
" output_file=output_file,\n",

docs/getting_started/tutorial_quickstart.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)
5454
fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)
5555
```
5656

57+
You can inspect the `fieldset` by simply printing it:
58+
59+
```{code-cell}
60+
:tags: [hide-output]
61+
print(fieldset)
62+
```
63+
5764
The subset contains a region of the Agulhas current along the southeastern coast of Africa:
5865

5966
```{code-cell}
@@ -85,6 +92,15 @@ pset = parcels.ParticleSet(
8592
)
8693
```
8794

95+
Again, you can inspect the `pset` by printing it:
96+
97+
```{code-cell}
98+
:tags: [hide-output]
99+
print(pset)
100+
```
101+
102+
And you can plot the particles on top of the temperature and velocity field:
103+
88104
```{code-cell}
89105
temperature = ds_fields.isel(time=0, depth=0).thetao.plot(cmap="magma")
90106
velocity = ds_fields.isel(time=0, depth=0).plot.quiver(x="longitude", y="latitude", u="uo", v="vo")

docs/user_guide/examples/explanation_kernelloop.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ kernelspec:
44
name: python3
55
---
66

7-
# 📖 The Parcels Kernel loop
7+
# 📖 Kernel loop
88

9-
On this page we discuss Parcels' execution loop, and what happens under the hood when you combine multiple Kernels.
9+
On this page we discuss how Parcels executes the Kernel loop, and what happens under the hood when you combine multiple Kernels.
1010

11-
This is not very relevant when you only use the built-in Advection kernels, but can be important when you are writing and combining your own Kernels!
11+
This is not very relevant when you only use the built-in Advection Kernels, but can be important when you are writing and combining your own Kernels!
1212

1313
## Background
1414

1515
When you run a Parcels simulation (i.e. a call to `pset.execute()`), the Kernel loop is the main part of the code that is executed. This part of the code loops through time and executes the Kernels for all particle.
1616

17-
In order to make sure that the displacements of a particle in the different Kernels can be summed, all Kernels add to a _change_ in position (`particles.dlon`, `particles.dlat`, and `particles.dz`). This is important, because there are situations where movement kernels would otherwise not commute. Take the example of advecting particles by currents _and_ winds. If the particle would first be moved by the currents and then by the winds, the result could be different from first moving by the winds and then by the currents. Instead, by summing the _changes_ in position, the ordering of the Kernels has no consequence on the particle displacement.
17+
In order to make sure that the displacements of a particle in the different Kernels can be summed, all Kernels add to a _change_ in position (`particles.dlon`, `particles.dlat`, and `particles.dz`). This is important, because there are situations where movement Kernels would otherwise not commute. Take the example of advecting particles by currents _and_ winds. If the particle would first be moved by the currents and then by the winds, the result could be different from first moving by the winds and then by the currents. Instead, by summing the _changes_ in position, the ordering of the Kernels has no consequence on the particle displacement.
1818

1919
## Basic implementation
2020

@@ -91,7 +91,7 @@ windvector = parcels.VectorField(
9191
fieldset.add_field(windvector)
9292
```
9393

94-
Now we define a wind kernel that uses a forward Euler method to apply the wind forcing. Note that we update the `particles.dlon` and `particles.dlat` variables, rather than `particles.lon` and `particles.lat` directly.
94+
Now we define a wind Kernel that uses a forward Euler method to apply the wind forcing. Note that we update the `particles.dlon` and `particles.dlat` variables, rather than `particles.lon` and `particles.lat` directly.
9595

9696
```{code-cell}
9797
def wind_kernel(particles, fieldset):
@@ -100,7 +100,7 @@ def wind_kernel(particles, fieldset):
100100
particles.dlat += vwind * particles.dt
101101
```
102102

103-
First run a simulation where we apply kernels as `[AdvectionRK4, wind_kernel]`
103+
First run a simulation where we apply Kernels as `[AdvectionRK2, wind_kernel]`
104104

105105
```{code-cell}
106106
:tags: [hide-output]
@@ -114,14 +114,14 @@ output_file = parcels.ParticleFile(
114114
store="advection_then_wind.zarr", outputdt=np.timedelta64(6,'h')
115115
)
116116
pset.execute(
117-
[parcels.kernels.AdvectionRK4, wind_kernel],
117+
[parcels.kernels.AdvectionRK2, wind_kernel],
118118
runtime=np.timedelta64(5,'D'),
119119
dt=np.timedelta64(1,'h'),
120120
output_file=output_file,
121121
)
122122
```
123123

124-
Then also run a simulation where we apply the kernels in the reverse order as `[wind_kernel, AdvectionRK4]`
124+
Then also run a simulation where we apply the Kernels in the reverse order as `[wind_kernel, AdvectionRK2]`
125125

126126
```{code-cell}
127127
:tags: [hide-output]
@@ -132,7 +132,7 @@ output_file_reverse = parcels.ParticleFile(
132132
store="wind_then_advection.zarr", outputdt=np.timedelta64(6,"h")
133133
)
134134
pset_reverse.execute(
135-
[wind_kernel, parcels.kernels.AdvectionRK4],
135+
[wind_kernel, parcels.kernels.AdvectionRK2],
136136
runtime=np.timedelta64(5,"D"),
137137
dt=np.timedelta64(1,"h"),
138138
output_file=output_file_reverse,

docs/user_guide/examples/tutorial_Argofloats.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"source": [
1616
"This tutorial shows how simple it is to construct a Kernel in Parcels that mimics the [vertical movement of Argo floats](https://www.aoml.noaa.gov/phod/argo/images/argo_float_mission.jpg).\n",
1717
"\n",
18-
"We first define the kernels for each phase of the Argo cycle."
18+
"We first define the Kernel for the vertical movement cycle of the Argo float."
1919
]
2020
},
2121
{
@@ -90,7 +90,7 @@
9090
"cell_type": "markdown",
9191
"metadata": {},
9292
"source": [
93-
"And then we can run Parcels with this 'custom kernel'.\n",
93+
"And then we can run Parcels with this `ArgoVerticalMovement` Kernel.\n",
9494
"\n",
9595
"Below we use the horizontal velocity fields of CopernicusMarine, which are provided as example_data with Parcels.\n"
9696
]
@@ -152,10 +152,10 @@
152152
" z=[fieldset.mindepth],\n",
153153
")\n",
154154
"\n",
155-
"# combine Argo vertical movement kernel with built-in Advection kernel\n",
155+
"# combine Argo vertical movement Kernel with built-in Advection Kernel\n",
156156
"kernels = [\n",
157157
" ArgoVerticalMovement,\n",
158-
" parcels.kernels.AdvectionRK4,\n",
158+
" parcels.kernels.AdvectionRK2,\n",
159159
"]\n",
160160
"\n",
161161
"# Create a ParticleFile object to store the output\n",
@@ -165,7 +165,7 @@
165165
" chunks=(1, 500), # setting to write in chunks of 500 observations\n",
166166
")\n",
167167
"\n",
168-
"# Now execute the kernels for 30 days, saving data every 30 minutes\n",
168+
"# Now execute the Kernels for 30 days, saving data every 30 minutes\n",
169169
"pset.execute(\n",
170170
" kernels,\n",
171171
" runtime=timedelta(days=30),\n",
@@ -248,7 +248,7 @@
248248
],
249249
"metadata": {
250250
"kernelspec": {
251-
"display_name": "test-notebooks",
251+
"display_name": "docs",
252252
"language": "python",
253253
"name": "python3"
254254
},
@@ -262,7 +262,7 @@
262262
"name": "python",
263263
"nbconvert_exporter": "python",
264264
"pygments_lexer": "ipython3",
265-
"version": "3.11.0"
265+
"version": "3.14.2"
266266
}
267267
},
268268
"nbformat": 4,

docs/user_guide/examples/tutorial_delaystart.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
")\n",
121121
"\n",
122122
"pset.execute(\n",
123-
" parcels.kernels.AdvectionRK4,\n",
123+
" parcels.kernels.AdvectionRK2,\n",
124124
" runtime=np.timedelta64(24, \"h\"),\n",
125125
" dt=np.timedelta64(5, \"m\"),\n",
126126
" output_file=output_file,\n",
@@ -259,7 +259,7 @@
259259
")\n",
260260
"\n",
261261
"pset.execute(\n",
262-
" parcels.kernels.AdvectionRK4,\n",
262+
" parcels.kernels.AdvectionRK2,\n",
263263
" runtime=np.timedelta64(24, \"h\"),\n",
264264
" dt=np.timedelta64(5, \"h\"),\n",
265265
" output_file=output_file,\n",
@@ -366,7 +366,7 @@
366366
"\n",
367367
"output_file = parcels.ParticleFile(outfilepath, outputdt=np.timedelta64(2, \"h\"))\n",
368368
"pset.execute(\n",
369-
" parcels.kernels.AdvectionRK4,\n",
369+
" parcels.kernels.AdvectionRK2,\n",
370370
" endtime=ds_fields.time.values[0] + np.timedelta64(4, \"h\"),\n",
371371
" dt=np.timedelta64(1, \"h\"),\n",
372372
" output_file=output_file,\n",
@@ -423,7 +423,7 @@
423423
" )\n",
424424
" output_file = parcels.ParticleFile(outfilepath, outputdt=np.timedelta64(2, \"h\"))\n",
425425
" pset.execute(\n",
426-
" parcels.kernels.AdvectionRK4,\n",
426+
" parcels.kernels.AdvectionRK2,\n",
427427
" runtime=np.timedelta64(4, \"h\"),\n",
428428
" dt=np.timedelta64(1, \"h\"),\n",
429429
" output_file=output_file,\n",

docs/user_guide/examples/tutorial_diffusion.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
"cell_type": "markdown",
546546
"metadata": {},
547547
"source": [
548-
"In the example, particles are released at one location and simulated for 2 days using advection (`AdvectionRK4`) and diffusion (`smagdiff`) kernels."
548+
"In the example, particles are released at one location and simulated for 2 days using advection (`AdvectionRK2`) and diffusion (`smagdiff`) kernels."
549549
]
550550
},
551551
{
@@ -578,7 +578,7 @@
578578
"np.random.seed(1636) # Random seed for reproducibility\n",
579579
"\n",
580580
"pset.execute(\n",
581-
" [parcels.kernels.AdvectionRK4, smagdiff],\n",
581+
" [parcels.kernels.AdvectionRK2, smagdiff],\n",
582582
" runtime=np.timedelta64(2, \"D\"),\n",
583583
" dt=np.timedelta64(5, \"m\"),\n",
584584
" output_file=output_file,\n",

docs/user_guide/examples/tutorial_manipulating_field_data.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
" store=\"summed_advection_wind.zarr\", outputdt=np.timedelta64(6, \"h\")\n",
136136
")\n",
137137
"pset.execute(\n",
138-
" [parcels.kernels.AdvectionRK4],\n",
138+
" [parcels.kernels.AdvectionRK2],\n",
139139
" runtime=np.timedelta64(5, \"D\"),\n",
140140
" dt=np.timedelta64(1, \"h\"),\n",
141141
" output_file=output_file,\n",

0 commit comments

Comments
 (0)