Skip to content

Commit b77f7e5

Browse files
committed
Renaming the 'add your own kernel' tutorial, removing unnecessary imports, fixing kernel flag printing, and fixing the warning of repeated variables names in the kernel.
1 parent 48fd7f6 commit b77f7e5

3 files changed

Lines changed: 48 additions & 55 deletions

File tree

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ PlasticParcels has a few example notebooks, see below.
1212
examples/example_Italy_coast.ipynb
1313
examples/example_Greece_coast.ipynb
1414
examples/example_Croatian_fisheries.ipynb
15-
examples/example_make_your_own_kernel.ipynb
15+
examples/example_add_your_own_kernel.ipynb

docs/examples/example_make_your_own_kernel.ipynb renamed to docs/examples/example_add_your_own_kernel.ipynb

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Make your own behaviour kernel\n",
7+
"# Add your own behaviour kernels\n",
88
"In this example, we will show how to turn on/off existing behaviour kernels, and how to create and include your own behaviour kernel to use in `plasticparcels` simulations. We will start by importing some necessary packages."
99
]
1010
},
@@ -16,16 +16,18 @@
1616
"source": [
1717
"# Library imports\n",
1818
"from datetime import datetime, timedelta\n",
19-
"import os\n",
20-
"os.chdir('../../')\n",
19+
"\n",
2120
"# Parcels and PlasticParcels imports\n",
2221
"import plasticparcels as pp\n",
2322
"\n",
2423
"# Plotting imports\n",
2524
"import matplotlib.pyplot as plt\n",
2625
"import cartopy.crs as ccrs\n",
2726
"import cartopy.feature as cfeature\n",
28-
"import xarray as xr"
27+
"\n",
28+
"# Other imports\n",
29+
"import xarray as xr\n",
30+
"import math"
2931
]
3032
},
3133
{
@@ -43,7 +45,7 @@
4345
"outputs": [],
4446
"source": [
4547
"# Load the model settings\n",
46-
"settings_file = 'docs/examples/example_make_your_own_kernel_settings.json'\n",
48+
"settings_file = 'docs/examples/example_add_your_own_kernel_settings.json'\n",
4749
"settings = pp.utils.load_settings(settings_file)"
4850
]
4951
},
@@ -88,12 +90,17 @@
8890
"name": "stdout",
8991
"output_type": "stream",
9092
"text": [
91-
"[('use_3D', True), ('use_mixing', False), ('use_biofouling', False), ('use_stokes', False), ('use_wind', False)]\n"
93+
"('use_3D', True)\n",
94+
"('use_mixing', False)\n",
95+
"('use_biofouling', False)\n",
96+
"('use_stokes', False)\n",
97+
"('use_wind', False)\n"
9298
]
9399
}
94100
],
95101
"source": [
96-
"print([(key, value) for key, value in settings.items() if 'use_' in key.lower()])"
102+
"for key_value in [(key, value) for key, value in settings.items() if 'use_' in key.lower()]:\n",
103+
" print(key_value)"
97104
]
98105
},
99106
{
@@ -203,15 +210,15 @@
203210
"name": "stdout",
204211
"output_type": "stream",
205212
"text": [
206-
"<function PolyTEOS10_bsq at 0x7f30a098b910>\n",
207-
"<function AdvectionRK4_3D at 0x7f30a15d6d40>\n",
208-
"<function Biofouling at 0x7f30a098b880>\n",
209-
"<function StokesDrift at 0x7f30a098b6d0>\n",
210-
"<function unbeaching at 0x7f30a098ba30>\n",
211-
"<function checkThroughBathymetry at 0x7f30a098bac0>\n",
212-
"<function checkErrorThroughSurface at 0x7f30a098bbe0>\n",
213-
"<function periodicBC at 0x7f30a098bb50>\n",
214-
"<function deleteParticle at 0x7f30a098bc70>\n"
213+
"<function PolyTEOS10_bsq at 0x7f38b955f910>\n",
214+
"<function AdvectionRK4_3D at 0x7f38ba1b2d40>\n",
215+
"<function Biofouling at 0x7f38b955f880>\n",
216+
"<function StokesDrift at 0x7f38b955f6d0>\n",
217+
"<function unbeaching at 0x7f38b955fa30>\n",
218+
"<function checkThroughBathymetry at 0x7f38b955fac0>\n",
219+
"<function checkErrorThroughSurface at 0x7f38b955fbe0>\n",
220+
"<function periodicBC at 0x7f38b955fb50>\n",
221+
"<function deleteParticle at 0x7f38b955fc70>\n"
215222
]
216223
}
217224
],
@@ -238,7 +245,7 @@
238245
"output_type": "stream",
239246
"text": [
240247
"INFO: Output files are stored in example_Tunisia_fisheries_prebuilt.zarr.\n",
241-
"100%|██████████| 2592000.0/2592000.0 [34:50<00:00, 1240.09it/s]\n"
248+
"100%|██████████| 2592000.0/2592000.0 [14:30<00:00, 2977.08it/s]\n"
242249
]
243250
}
244251
],
@@ -329,8 +336,6 @@
329336
"metadata": {},
330337
"outputs": [],
331338
"source": [
332-
"import math\n",
333-
"\n",
334339
"# An example kernel that applies a constant northward drift to particles\n",
335340
"def NorthwardDrift(particle, fieldset, time):\n",
336341
" # Only apply Northward drift if the particle is moving in the ocean\n",
@@ -340,8 +345,8 @@
340345
"\n",
341346
"def EastwardDrift(particle, fieldset, time):\n",
342347
" # Only apply Eastward drift if the particle is moving in the ocean\n",
343-
" (ocean_u, ocean_v) = fieldset.UV[time, particle.depth, particle.lat, particle.lon]\n",
344-
" if math.sqrt(ocean_u**2 + ocean_v**2) > 1e-10:\n",
348+
" (ocean_U, ocean_V) = fieldset.UV[time, particle.depth, particle.lat, particle.lon]\n",
349+
" if math.sqrt(ocean_U**2 + ocean_V**2) > 1e-10:\n",
345350
" particle_dlon += 1e-3 # Units of degrees"
346351
]
347352
},
@@ -354,15 +359,15 @@
354359
"name": "stdout",
355360
"output_type": "stream",
356361
"text": [
357-
"<function PolyTEOS10_bsq at 0x7f30a098b910>\n",
358-
"<function AdvectionRK4_3D at 0x7f30a15d6d40>\n",
359-
"<function Biofouling at 0x7f30a098b880>\n",
360-
"<function StokesDrift at 0x7f30a098b6d0>\n",
361-
"<function unbeaching at 0x7f30a098ba30>\n",
362-
"<function checkThroughBathymetry at 0x7f30a098bac0>\n",
363-
"<function checkErrorThroughSurface at 0x7f30a098bbe0>\n",
364-
"<function periodicBC at 0x7f30a098bb50>\n",
365-
"<function deleteParticle at 0x7f30a098bc70>\n"
362+
"<function PolyTEOS10_bsq at 0x7f38b955f910>\n",
363+
"<function AdvectionRK4_3D at 0x7f38ba1b2d40>\n",
364+
"<function Biofouling at 0x7f38b955f880>\n",
365+
"<function StokesDrift at 0x7f38b955f6d0>\n",
366+
"<function unbeaching at 0x7f38b955fa30>\n",
367+
"<function checkThroughBathymetry at 0x7f38b955fac0>\n",
368+
"<function checkErrorThroughSurface at 0x7f38b955fbe0>\n",
369+
"<function periodicBC at 0x7f38b955fb50>\n",
370+
"<function deleteParticle at 0x7f38b955fc70>\n"
366371
]
367372
}
368373
],
@@ -387,17 +392,17 @@
387392
"name": "stdout",
388393
"output_type": "stream",
389394
"text": [
390-
"<function PolyTEOS10_bsq at 0x7f30a098b910>\n",
391-
"<function AdvectionRK4_3D at 0x7f30a15d6d40>\n",
392-
"<function Biofouling at 0x7f30a098b880>\n",
393-
"<function StokesDrift at 0x7f30a098b6d0>\n",
394-
"<function NorthwardDrift at 0x7f307007e830>\n",
395-
"<function EastwardDrift at 0x7f307007e7a0>\n",
396-
"<function unbeaching at 0x7f30a098ba30>\n",
397-
"<function checkThroughBathymetry at 0x7f30a098bac0>\n",
398-
"<function checkErrorThroughSurface at 0x7f30a098bbe0>\n",
399-
"<function periodicBC at 0x7f30a098bb50>\n",
400-
"<function deleteParticle at 0x7f30a098bc70>\n"
395+
"<function PolyTEOS10_bsq at 0x7f38b955f910>\n",
396+
"<function AdvectionRK4_3D at 0x7f38ba1b2d40>\n",
397+
"<function Biofouling at 0x7f38b955f880>\n",
398+
"<function StokesDrift at 0x7f38b955f6d0>\n",
399+
"<function NorthwardDrift at 0x7f38889ba440>\n",
400+
"<function EastwardDrift at 0x7f38889ba290>\n",
401+
"<function unbeaching at 0x7f38b955fa30>\n",
402+
"<function checkThroughBathymetry at 0x7f38b955fac0>\n",
403+
"<function checkErrorThroughSurface at 0x7f38b955fbe0>\n",
404+
"<function periodicBC at 0x7f38b955fb50>\n",
405+
"<function deleteParticle at 0x7f38b955fc70>\n"
401406
]
402407
}
403408
],
@@ -426,20 +431,8 @@
426431
"name": "stdout",
427432
"output_type": "stream",
428433
"text": [
429-
"WARNING: ocean_u declared in multiple Kernels\n",
430-
"WARNING: ocean_v declared in multiple Kernels\n",
431-
"WARNING: ocean_u declared in multiple Kernels\n",
432-
"WARNING: ocean_v declared in multiple Kernels\n",
433-
"WARNING: ocean_u declared in multiple Kernels\n",
434-
"WARNING: ocean_v declared in multiple Kernels\n",
435-
"WARNING: ocean_u declared in multiple Kernels\n",
436-
"WARNING: ocean_v declared in multiple Kernels\n",
437-
"WARNING: ocean_u declared in multiple Kernels\n",
438-
"WARNING: ocean_v declared in multiple Kernels\n",
439-
"WARNING: ocean_u declared in multiple Kernels\n",
440-
"WARNING: ocean_v declared in multiple Kernels\n",
441434
"INFO: Output files are stored in example_Tunisia_fisheries_custom.zarr.\n",
442-
"100%|██████████| 2592000.0/2592000.0 [25:23<00:00, 1701.47it/s]\n"
435+
"100%|██████████| 2592000.0/2592000.0 [15:12<00:00, 2839.68it/s]\n"
443436
]
444437
}
445438
],

docs/examples/example_make_your_own_kernel_settings.json renamed to docs/examples/example_add_your_own_kernel_settings.json

File renamed without changes.

0 commit comments

Comments
 (0)