|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "# Make your own behaviour kernel\n", |
| 7 | + "# Add your own behaviour kernels\n", |
8 | 8 | "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." |
9 | 9 | ] |
10 | 10 | }, |
|
16 | 16 | "source": [ |
17 | 17 | "# Library imports\n", |
18 | 18 | "from datetime import datetime, timedelta\n", |
19 | | - "import os\n", |
20 | | - "os.chdir('../../')\n", |
| 19 | + "\n", |
21 | 20 | "# Parcels and PlasticParcels imports\n", |
22 | 21 | "import plasticparcels as pp\n", |
23 | 22 | "\n", |
24 | 23 | "# Plotting imports\n", |
25 | 24 | "import matplotlib.pyplot as plt\n", |
26 | 25 | "import cartopy.crs as ccrs\n", |
27 | 26 | "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" |
29 | 31 | ] |
30 | 32 | }, |
31 | 33 | { |
|
43 | 45 | "outputs": [], |
44 | 46 | "source": [ |
45 | 47 | "# 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", |
47 | 49 | "settings = pp.utils.load_settings(settings_file)" |
48 | 50 | ] |
49 | 51 | }, |
|
88 | 90 | "name": "stdout", |
89 | 91 | "output_type": "stream", |
90 | 92 | "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" |
92 | 98 | ] |
93 | 99 | } |
94 | 100 | ], |
95 | 101 | "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)" |
97 | 104 | ] |
98 | 105 | }, |
99 | 106 | { |
|
203 | 210 | "name": "stdout", |
204 | 211 | "output_type": "stream", |
205 | 212 | "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" |
215 | 222 | ] |
216 | 223 | } |
217 | 224 | ], |
|
238 | 245 | "output_type": "stream", |
239 | 246 | "text": [ |
240 | 247 | "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" |
242 | 249 | ] |
243 | 250 | } |
244 | 251 | ], |
|
329 | 336 | "metadata": {}, |
330 | 337 | "outputs": [], |
331 | 338 | "source": [ |
332 | | - "import math\n", |
333 | | - "\n", |
334 | 339 | "# An example kernel that applies a constant northward drift to particles\n", |
335 | 340 | "def NorthwardDrift(particle, fieldset, time):\n", |
336 | 341 | " # Only apply Northward drift if the particle is moving in the ocean\n", |
|
340 | 345 | "\n", |
341 | 346 | "def EastwardDrift(particle, fieldset, time):\n", |
342 | 347 | " # 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", |
345 | 350 | " particle_dlon += 1e-3 # Units of degrees" |
346 | 351 | ] |
347 | 352 | }, |
|
354 | 359 | "name": "stdout", |
355 | 360 | "output_type": "stream", |
356 | 361 | "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" |
366 | 371 | ] |
367 | 372 | } |
368 | 373 | ], |
|
387 | 392 | "name": "stdout", |
388 | 393 | "output_type": "stream", |
389 | 394 | "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" |
401 | 406 | ] |
402 | 407 | } |
403 | 408 | ], |
|
426 | 431 | "name": "stdout", |
427 | 432 | "output_type": "stream", |
428 | 433 | "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", |
441 | 434 | "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" |
443 | 436 | ] |
444 | 437 | } |
445 | 438 | ], |
|
0 commit comments