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
Copy file name to clipboardExpand all lines: docs/getting_started/tutorial_quickstart.md
+44-16Lines changed: 44 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,15 @@ kernelspec:
6
6
7
7
# Quickstart tutorial
8
8
9
-
Welcome to the **Parcels** quickstart tutorial, in which we will go through all the necessary steps to run a simulation. The code in this notebook can be used as a starting point to run Parcels in your own environment. Along the way we will familiarize ourselves with some specific classes and methods. If you are ever confused about one of these and want to read more, we have a [concepts overview](concepts_overview.md) discussing them in more detail. Let's dive in!
9
+
Welcome to the **Parcels** quickstart tutorial, in which we will go through all the necessary steps to run a simulation.
10
+
The code in this notebook can be used as a starting point to run Parcels in your own environment. Along the way we will
11
+
familiarize ourselves with some specific classes and methods. If you are ever confused about one of these and want to
12
+
read more, we have a [concepts overview](concepts_overview.md) discussing them in more detail. Let's dive in!
10
13
11
14
## Imports
12
15
13
-
Parcels depends on `xarray`, expecting inputs in the form of [`xarray.Dataset`](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html) and writing output files that can be read with xarray.
16
+
Parcels depends on `xarray`, expecting inputs in the form of [`xarray.Dataset`](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html)
17
+
and writing output files that can be read with xarray.
14
18
15
19
```{code-cell}
16
20
import numpy as np
@@ -20,7 +24,9 @@ import parcels
20
24
21
25
## Input flow fields: `FieldSet`
22
26
23
-
A Parcels simulation of Lagrangian trajectories of virtual particles requires two inputs; the first is a set of hydrodynamics fields in which the particles are tracked. Here we provide an example using a subset of the [Global Ocean Physics Reanalysis](https://doi.org/10.48670/moi-00021) from the Copernicus Marine Service.
27
+
A Parcels simulation of Lagrangian trajectories of virtual particles requires two inputs; the first is a set of
28
+
hydrodynamics fields in which the particles are tracked. Here we provide an example using a subset of the
29
+
[Global Ocean Physics Reanalysis](https://doi.org/10.48670/moi-00021) from the Copernicus Marine Service.
@@ -32,9 +38,12 @@ ds_fields.load() # load the dataset into memory
32
38
ds_fields
33
39
```
34
40
35
-
As we can see, the reanalysis dataset contains eastward velocity `uo`, northward velocity `vo`, potential temperature (`thetao`) and salinity (`so`) fields.
41
+
As we can see, the reanalysis dataset contains eastward velocity `uo`, northward velocity `vo`, potential temperature
42
+
(`thetao`) and salinity (`so`) fields.
36
43
37
-
These hydrodynamic fields need to be stored in a `parcels.FieldSet` object. Parcels provides tooling to parse many types of models or observations into such a `parcels.FieldSet` object. Here, we use `FieldSet.from_copernicusmarine()`, which recognizes the standard names of a velocity field:
44
+
These hydrodynamic fields need to be stored in a `parcels.FieldSet` object. Parcels provides tooling to parse many types
45
+
of models or observations into such a `parcels.FieldSet` object. Here, we use `FieldSet.from_copernicusmarine()`, which
46
+
recognizes the standard names of a velocity field:
Now that we have created a `parcels.FieldSet` object from the hydrodynamic data, we need to provide our second input: the virtual particles for which we will calculate the trajectories.
61
+
Now that we have created a `parcels.FieldSet` object from the hydrodynamic data, we need to provide our second input:
62
+
the virtual particles for which we will calculate the trajectories.
53
63
54
-
We need to create a `parcels.ParticleSet` object with the particles' initial time and position. The `parcels.ParticleSet` object also needs to know about the `FieldSet` in which the particles "live". Finally, we need to specify the type of `parcels.Particle` we want to use. The default particles have `time`, `z`, `lat`, and `lon`, but you can easily add other `Variables` such as size, temperature, or age to create your own particles to mimic plastic or an [ARGO float](../user_guide/examples/tutorial_Argofloats.ipynb).
64
+
We need to create a `parcels.ParticleSet` object with the particles' initial time and position. The `parcels.ParticleSet`
65
+
object also needs to know about the `FieldSet` in which the particles "live". Finally, we need to specify the type of
66
+
`parcels.Particle` we want to use. The default particles have `time`, `z`, `lat`, and `lon`, but you can easily add
67
+
other `Variables` such as size, temperature, or age to create your own particles to mimic plastic or an [ARGO float](../user_guide/examples/tutorial_Argofloats.ipynb).
After setting up the input data and particle start locations and times, we need to specify what calculations to do with the particles. These calculations, or numerical integrations, will be performed by what we call a `Kernel`, operating on all particles in the `ParticleSet`. The most common calculation is the advection of particles through the velocity field. Parcels comes with a number of standard kernels, from which we will use the Runge-Kutta advection kernel `AdvectionRK2`:
92
+
After setting up the input data and particle start locations and times, we need to specify what calculations to do with
93
+
the particles. These calculations, or numerical integrations, will be performed by what we call a `Kernel`, operating on
94
+
all particles in the `ParticleSet`. The most common calculation is the advection of particles through the velocity field.
95
+
Parcels comes with a number of standard kernels, from which we will use the Runge-Kutta advection kernel `AdvectionRK2`:
Before starting the simulation, we must define where and how frequent we want to write the output of our simulation. We can define this in a `ParticleFile` object:
107
+
Before starting the simulation, we must define where and how frequent we want to write the output of our simulation.
The output files are in `.zarr`[format](https://zarr.readthedocs.io/en/stable/), which can be read by `xarray`. See the [Parcels output tutorial](./tutorial_output.ipynb) for more information on the zarr format. We want to choose the `outputdt` argument so that it captures the smallest timescales of our interest.
114
+
The output files are in `.zarr`[format](https://zarr.readthedocs.io/en/stable/), which can be read by `xarray`.
115
+
See the [Parcels output tutorial](./tutorial_output.ipynb) for more information on the zarr format. We want to choose
116
+
the `outputdt` argument so that it captures the smallest timescales of our interest.
98
117
99
118
## Run Simulation: `ParticleSet.execute()`
100
119
101
-
Finally, we can run the simulation by _executing_ the `ParticleSet` using the specified list of `kernels`. Additionally, we need to specify:
120
+
Finally, we can run the simulation by _executing_ the `ParticleSet` using the specified list of `kernels`.
121
+
Additionally, we need to specify:
102
122
103
123
- the `runtime`: for how long we want to simulate particles.
104
-
- the `dt`: the timestep with which to perform the numerical integration in the `kernels`. Depending on the numerical integration scheme, the accuracy of our simulation will depend on `dt`. Read [this notebook](https://github.com/Parcels-code/10year-anniversary-session2/blob/8931ef69577dbf00273a5ab4b7cf522667e146c5/advection_and_windage.ipynb) to learn more about numerical accuracy.
124
+
- the `dt`: the timestep with which to perform the numerical integration in the `kernels`. Depending on the numerical
125
+
integration scheme, the accuracy of our simulation will depend on `dt`. Read [this notebook](https://github.com/Parcels-code/10year-anniversary-session2/blob/8931ef69577dbf00273a5ab4b7cf522667e146c5/advection_and_windage.ipynb)
126
+
to learn more about numerical accuracy.
105
127
106
128
```{note}
107
129
TODO: add Michaels 10-years Parcels notebook to the user guide
The 10 particle trajectories are stored along the `trajectory` dimension, and each trajectory contains 25 observations (initial values + 24 hourly timesteps) along the `obs` dimension. The [working with Parcels output tutorial](./tutorial_output.ipynb) provides more detail about the dataset and how to analyse it.
151
+
The 10 particle trajectories are stored along the `trajectory` dimension, and each trajectory contains 25 observations
152
+
(initial values + 24 hourly timesteps) along the `obs` dimension. The [working with Parcels output tutorial](./tutorial_output.ipynb)
153
+
provides more detail about the dataset and how to analyse it.
130
154
131
155
Let's verify that Parcels has computed the advection of the virtual particles!
That looks good! The virtual particles released in a line along the 32nd meridian (dark blue) have been advected by the flow field.
170
+
That looks good! The virtual particles released in a line along the 32nd meridian (dark blue) have been advected by the
171
+
flow field.
147
172
148
173
## Running a simulation backwards in time
149
174
150
-
Now that we know how to run a simulation, we can easily run another and change one of the settings. We can trace back the particles from their current to their original position by running the simulation backwards in time. To do so, we can simply make `dt` < 0.
175
+
Now that we know how to run a simulation, we can easily run another and change one of the settings. We can trace back
176
+
the particles from their current to their original position by running the simulation backwards in time. To do so, we
177
+
can simply make `dt` < 0.
151
178
152
179
```{note}
153
-
We have not edited the `ParticleSet`, which means that the new simulation will start with the particles at their current location!
180
+
We have not edited the `ParticleSet`, which means that the new simulation will start with the particles at their current
0 commit comments