Skip to content

Commit 3d1be3e

Browse files
Implementing review suggestions
Review suggestions by @reint-fischer
1 parent 597c70a commit 3d1be3e

1 file changed

Lines changed: 38 additions & 28 deletions

File tree

docs/user_guide/examples/tutorial_nestedgrids.ipynb

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@
4242
"First we define a helper function to quickly set up a nested dataset"
4343
]
4444
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "3",
48+
"metadata": {},
49+
"source": [
50+
"```{note}\n",
51+
"If your nested data come from hydrodynamic models, you only have to provide the `grid_polygons` list with polygon coordinates for each grid, but don't need to create the `ds_in` like below.\n",
52+
"```"
53+
]
54+
},
4555
{
4656
"cell_type": "code",
4757
"execution_count": null,
48-
"id": "3",
58+
"id": "4",
4959
"metadata": {},
5060
"outputs": [],
5161
"source": [
@@ -63,7 +73,7 @@
6373
},
6474
{
6575
"cell_type": "markdown",
66-
"id": "4",
76+
"id": "5",
6777
"metadata": {},
6878
"source": [
6979
"Now we create a set of zonal and meridional velocities defined on a small grid. Both the zonal (1m/s) and meridional (0 m/s) velocity are uniform."
@@ -72,7 +82,7 @@
7282
{
7383
"cell_type": "code",
7484
"execution_count": null,
75-
"id": "5",
85+
"id": "6",
7686
"metadata": {},
7787
"outputs": [],
7888
"source": [
@@ -86,7 +96,7 @@
8696
},
8797
{
8898
"cell_type": "markdown",
89-
"id": "6",
99+
"id": "7",
90100
"metadata": {},
91101
"source": [
92102
"Then, we define another set of zonal and meridional velocities on a slightly larger grid. In this case, both the zonal and meridional velocity are 1 m/s."
@@ -95,7 +105,7 @@
95105
{
96106
"cell_type": "code",
97107
"execution_count": null,
98-
"id": "7",
108+
"id": "8",
99109
"metadata": {},
100110
"outputs": [],
101111
"source": [
@@ -109,7 +119,7 @@
109119
},
110120
{
111121
"cell_type": "markdown",
112-
"id": "8",
122+
"id": "9",
113123
"metadata": {},
114124
"source": [
115125
"Finally, we define another set of velocities on an even larger grid. The zonal velocity is again 1 m/s, but the meridional velocity is now a cosine as a function of longitude."
@@ -118,7 +128,7 @@
118128
{
119129
"cell_type": "code",
120130
"execution_count": null,
121-
"id": "9",
131+
"id": "10",
122132
"metadata": {},
123133
"outputs": [],
124134
"source": [
@@ -133,7 +143,7 @@
133143
},
134144
{
135145
"cell_type": "markdown",
136-
"id": "10",
146+
"id": "11",
137147
"metadata": {},
138148
"source": [
139149
"We plot the velocity fields on top of each other, indicating the grid boundaries in red."
@@ -142,7 +152,7 @@
142152
{
143153
"cell_type": "code",
144154
"execution_count": null,
145-
"id": "11",
155+
"id": "12",
146156
"metadata": {},
147157
"outputs": [],
148158
"source": [
@@ -159,7 +169,7 @@
159169
" np.append(poly[:, 0], poly[0, 0]),\n",
160170
" np.append(poly[:, 1], poly[0, 1]),\n",
161171
" \"-r\",\n",
162-
" lw=1,\n",
172+
" lw=2,\n",
163173
" )\n",
164174
"\n",
165175
"plt.tight_layout()\n",
@@ -168,20 +178,20 @@
168178
},
169179
{
170180
"cell_type": "markdown",
171-
"id": "12",
181+
"id": "13",
172182
"metadata": {},
173183
"source": [
174184
"Note, as seen in the plot above, that the dataset domains in this case are rectangular, but the polygons that will later define the nested Grid boundaries don't have to be. They can have any shape! This means that we can also use this method to subset parts of a Grid, or to define subregions of a domain."
175185
]
176186
},
177187
{
178188
"cell_type": "markdown",
179-
"id": "13",
189+
"id": "14",
180190
"metadata": {},
181191
"source": [
182192
"## Creating a Delaunay triangulation of the nested Grids\n",
183193
"\n",
184-
"Now comes the important part: we need to create a Delaunay triangulation of the nested Grids, so that we can efficiently determine in which Grid a particle is located at any given time. We use the `triangle` package to perform the triangulation, and `shapely` to handle the geometric operations. \n",
194+
"Now comes the important part: we need to create a Delaunay triangulation of the nested Grids, so that we can efficiently determine in which Grid a particle is located at any given time. We use the [`triangle` package](https://rufat.be/triangle/delaunay.html) to perform the triangulation, and `shapely` to handle the geometric operations. \n",
185195
"\n",
186196
"Note that we need to make sure that all the edges of the polygons are also edges of the triangulation. We do this by using a [constrained (PSLG) Delaunay triangulation](https://en.wikipedia.org/wiki/Constrained_Delaunay_triangulation).\n",
187197
"\n",
@@ -191,7 +201,7 @@
191201
{
192202
"cell_type": "code",
193203
"execution_count": null,
194-
"id": "14",
204+
"id": "15",
195205
"metadata": {},
196206
"outputs": [],
197207
"source": [
@@ -247,7 +257,7 @@
247257
},
248258
{
249259
"cell_type": "markdown",
250-
"id": "15",
260+
"id": "16",
251261
"metadata": {},
252262
"source": [
253263
"We can then plot the resulting triangles to verify that they correctly cover the nested Grids."
@@ -256,7 +266,7 @@
256266
{
257267
"cell_type": "code",
258268
"execution_count": null,
259-
"id": "16",
269+
"id": "17",
260270
"metadata": {},
261271
"outputs": [],
262272
"source": [
@@ -276,7 +286,7 @@
276286
},
277287
{
278288
"cell_type": "markdown",
279-
"id": "17",
289+
"id": "18",
280290
"metadata": {},
281291
"source": [
282292
"Then, we convert the triangulation into an (unstructured) `parcels.FieldSet`."
@@ -285,7 +295,7 @@
285295
{
286296
"cell_type": "code",
287297
"execution_count": null,
288-
"id": "18",
298+
"id": "19",
289299
"metadata": {},
290300
"outputs": [],
291301
"source": [
@@ -336,7 +346,7 @@
336346
},
337347
{
338348
"cell_type": "markdown",
339-
"id": "19",
349+
"id": "20",
340350
"metadata": {},
341351
"source": [
342352
"We can confirm that the FieldSet has been created correctly by running a Parcels simulation where particles sample the `GridID` field, which indicates in which Grid each particle is located at any given time."
@@ -345,7 +355,7 @@
345355
{
346356
"cell_type": "code",
347357
"execution_count": null,
348-
"id": "20",
358+
"id": "21",
349359
"metadata": {},
350360
"outputs": [],
351361
"source": [
@@ -376,7 +386,7 @@
376386
},
377387
{
378388
"cell_type": "markdown",
379-
"id": "21",
389+
"id": "22",
380390
"metadata": {},
381391
"source": [
382392
"Indeed, the visualisation below shows that particles correctly identify the grid they are in based on their location."
@@ -385,7 +395,7 @@
385395
{
386396
"cell_type": "code",
387397
"execution_count": null,
388-
"id": "22",
398+
"id": "23",
389399
"metadata": {},
390400
"outputs": [],
391401
"source": [
@@ -411,7 +421,7 @@
411421
},
412422
{
413423
"cell_type": "markdown",
414-
"id": "23",
424+
"id": "24",
415425
"metadata": {},
416426
"source": [
417427
"## Advecting particles with nested Grid transitions\n",
@@ -424,7 +434,7 @@
424434
{
425435
"cell_type": "code",
426436
"execution_count": null,
427-
"id": "24",
437+
"id": "25",
428438
"metadata": {},
429439
"outputs": [],
430440
"source": [
@@ -445,7 +455,7 @@
445455
},
446456
{
447457
"cell_type": "markdown",
448-
"id": "25",
458+
"id": "26",
449459
"metadata": {},
450460
"source": [
451461
"We then define a custom Advection kernel that advects particles using the appropriate velocity Field based on the `GridID` at the particle's location. Note that for simplicity, we use Eulerian advection here, but in a real-world application you would typically use a higher-order scheme."
@@ -454,7 +464,7 @@
454464
{
455465
"cell_type": "code",
456466
"execution_count": null,
457-
"id": "26",
467+
"id": "27",
458468
"metadata": {},
459469
"outputs": [],
460470
"source": [
@@ -505,7 +515,7 @@
505515
{
506516
"cell_type": "code",
507517
"execution_count": null,
508-
"id": "27",
518+
"id": "28",
509519
"metadata": {},
510520
"outputs": [],
511521
"source": [
@@ -538,7 +548,7 @@
538548
},
539549
{
540550
"cell_type": "markdown",
541-
"id": "28",
551+
"id": "29",
542552
"metadata": {},
543553
"source": [
544554
"Indeed, we can see that the particles follow the cosine oscillation pattern in the coarsest grid, move northeast in the finer grid, and move purely zonally in the finest grid.\n",

0 commit comments

Comments
 (0)