Skip to content

Commit 09d8369

Browse files
Merge pull request #1610 from OceanParcels/v/update-notebooks
Documentation improvements (update import statements, include scripts)
2 parents 13bcc14 + be5e757 commit 09d8369

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2492
-1658
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ ignore =
1010
E501,
1111
# ‘from module import *’ used; unable to detect undefined names
1212
F403,
13+
# incompatability with Black
14+
E203

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
# whitespace fixes
55
e99e0d170a7dc128031b82ea00cdf9e9a0164b03
6+
7+
# Run black on examples
8+
cbf96c4e1f58fa6348695d7553900ba3f7c3383b

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ repos:
1313
rev: "7.1.0"
1414
hooks:
1515
- id: flake8
16-
- repo: https://github.com/pycqa/pydocstyle
17-
rev: 6.3.0 # pick a git hash / tag to point to
16+
- repo: https://github.com/psf/black-pre-commit-mirror
17+
rev: 24.4.2
1818
hooks:
19-
- id: pydocstyle
19+
- id: black
20+
files: docs/examples
2021
- repo: https://github.com/nbQA-dev/nbQA
2122
rev: 1.8.5
2223
hooks:
@@ -28,7 +29,7 @@ repos:
2829
hooks:
2930
- id: isort
3031
name: isort (python)
31-
- repo: https://github.com/pre-commit/mirrors-prettier
32-
rev: "v4.0.0-alpha.8"
32+
- repo: https://github.com/biomejs/pre-commit
33+
rev: v0.4.0
3334
hooks:
34-
- id: prettier
35+
- id: biome-format

.readthedocs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build:
99

1010
sphinx:
1111
configuration: docs/conf.py
12+
builder: dirhtml
1213

1314
conda:
1415
environment: environment.yml

docs/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ def linkcode_resolve(domain, info):
317317
# html_use_smartypants = True
318318

319319
# Custom sidebar templates, maps document names to template names.
320-
# html_sidebars = {}
320+
321+
html_sidebars = {
322+
"**": ["sidebar-nav-bs"],
323+
"documentation/additional_examples": []
324+
}
321325

322326
# Additional templates that should be rendered to pages, maps page names to
323327
# template names.

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Your first contribution
4141
There are many ways that you can contribute to Parcels. You can:
4242

4343
- Participate in discussion about Parcels, either through the `issues <https://github.com/OceanParcels/parcels/issues>`_ or `discussions <https://github.com/OceanParcels/parcels/discussions>`_ tab
44-
- Suggest improvements to `tutorials <documentation.rst>`_
44+
- Suggest improvements to `tutorials <documentation/index.rst>`_
4545
- Suggest improvements to `documentation <index.rst>`_
4646
- Write code (fix bugs, implement features, codebase improvements, etc)
4747

docs/documentation.rst

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
example_brownian.py
2+
-------------------
3+
4+
.. literalinclude:: ../examples/example_brownian.py
5+
:language: python
6+
:linenos:
7+
8+
example_dask_chunk_OCMs.py
9+
--------------------------
10+
11+
.. literalinclude:: ../examples/example_dask_chunk_OCMs.py
12+
:language: python
13+
:linenos:
14+
15+
example_decaying_moving_eddy.py
16+
-------------------------------
17+
18+
.. literalinclude:: ../examples/example_decaying_moving_eddy.py
19+
:language: python
20+
:linenos:
21+
22+
example_globcurrent.py
23+
----------------------
24+
25+
.. literalinclude:: ../examples/example_globcurrent.py
26+
:language: python
27+
:linenos:
28+
29+
example_mitgcm.py
30+
-----------------
31+
32+
.. literalinclude:: ../examples/example_mitgcm.py
33+
:language: python
34+
:linenos:
35+
36+
example_moving_eddies.py
37+
------------------------
38+
39+
.. literalinclude:: ../examples/example_moving_eddies.py
40+
:language: python
41+
:linenos:
42+
43+
example_nemo_curvilinear.py
44+
---------------------------
45+
46+
.. literalinclude:: ../examples/example_nemo_curvilinear.py
47+
:language: python
48+
:linenos:
49+
50+
example_ofam.py
51+
---------------
52+
53+
.. literalinclude:: ../examples/example_ofam.py
54+
:language: python
55+
:linenos:
56+
57+
example_peninsula.py
58+
--------------------
59+
60+
.. literalinclude:: ../examples/example_peninsula.py
61+
:language: python
62+
:linenos:
63+
64+
example_radial_rotation.py
65+
--------------------------
66+
67+
.. literalinclude:: ../examples/example_radial_rotation.py
68+
:language: python
69+
:linenos:
70+
71+
example_stommel.py
72+
------------------
73+
74+
.. literalinclude:: ../examples/example_stommel.py
75+
:language: python
76+
:linenos:

docs/documentation/index.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Documentation and Tutorials
2+
===========================
3+
4+
Parcels has several documentation and tutorial Jupyter notebooks and scripts which go through various aspects of Parcels. Static versions of the notebooks are available below via the gallery in the site, with the interactive notebooks being available either completely online at the following `Binder link <https://mybinder.org/v2/gh/OceanParcels/parcels/master?labpath=docs%2Fexamples%2Fparcels_tutorial.ipynb>`_. Following the gallery of notebooks is a list of scripts which provide additional examples to users. You can work with the example notebooks and scripts locally by downloading :download:`parcels_tutorials.zip </_downloads/parcels_tutorials.zip>` and running with your own Parcels installation.
5+
6+
.. nbgallery::
7+
:caption: Overview
8+
:name: tutorial-overview
9+
10+
../examples/tutorial_parcels_structure.ipynb
11+
../examples/parcels_tutorial.ipynb
12+
../examples/tutorial_output.ipynb
13+
14+
15+
.. nbgallery::
16+
:caption: Setting up FieldSets
17+
:name: tutorial-fieldsets
18+
19+
../examples/documentation_indexing.ipynb
20+
../examples/tutorial_nemo_curvilinear.ipynb
21+
../examples/tutorial_nemo_3D.ipynb
22+
../examples/tutorial_NestedFields.ipynb
23+
../examples/tutorial_timevaryingdepthdimensions.ipynb
24+
../examples/tutorial_periodic_boundaries.ipynb
25+
../examples/tutorial_interpolation.ipynb
26+
../examples/tutorial_unitconverters.ipynb
27+
../examples/tutorial_timestamps.ipynb
28+
29+
30+
.. nbgallery::
31+
:caption: Creating ParticleSets
32+
:name: tutorial-particlesets
33+
34+
../examples/tutorial_jit_vs_scipy.ipynb
35+
../examples/tutorial_delaystart.ipynb
36+
37+
38+
.. nbgallery::
39+
:caption: Writing kernels to be executed on each particle
40+
:name: tutorial-kernels
41+
42+
../examples/tutorial_diffusion.ipynb
43+
../examples/tutorial_sampling.ipynb
44+
../examples/tutorial_particle_field_interaction.ipynb
45+
../examples/tutorial_interaction.ipynb
46+
../examples/tutorial_analyticaladvection.ipynb
47+
../examples/tutorial_kernelloop.ipynb
48+
49+
50+
.. nbgallery::
51+
:caption: Other tutorials
52+
:name: tutorial-other
53+
54+
../examples/documentation_MPI.ipynb
55+
../examples/documentation_stuck_particles.ipynb
56+
../examples/documentation_unstuck_Agrid.ipynb
57+
../examples/documentation_LargeRunsOutput.ipynb
58+
../examples/documentation_geospatial.ipynb
59+
../examples/documentation_advanced_zarr.ipynb
60+
61+
62+
.. nbgallery::
63+
:caption: Worked examples
64+
:name: tutorial-examples
65+
66+
../examples/tutorial_Argofloats.ipynb
67+
../examples/documentation_homepage_animation.ipynb
68+
69+
70+
Python Example Scripts
71+
----------------------
72+
73+
74+
.. toctree::
75+
76+
additional_examples

docs/examples/documentation_MPI.ipynb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@
216216
"%pylab inline\n",
217217
"import os\n",
218218
"import time\n",
219-
"from datetime import timedelta as delta\n",
219+
"from datetime import timedelta\n",
220220
"from glob import glob\n",
221221
"\n",
222222
"import matplotlib.pyplot as plt\n",
223223
"import numpy as np\n",
224224
"import psutil\n",
225225
"\n",
226-
"from parcels import AdvectionRK4, FieldSet, JITParticle, ParticleSet\n",
226+
"import parcels\n",
227227
"\n",
228228
"\n",
229229
"def set_cms_fieldset(cs):\n",
@@ -235,20 +235,24 @@
235235
"\n",
236236
" if cs not in [\"auto\", False]:\n",
237237
" cs = {\"time\": (\"time\", 1), \"lat\": (\"latitude\", cs), \"lon\": (\"longitude\", cs)}\n",
238-
" return FieldSet.from_netcdf(files, variables, dimensions, chunksize=cs)\n",
238+
" return parcels.FieldSet.from_netcdf(files, variables, dimensions, chunksize=cs)\n",
239239
"\n",
240240
"\n",
241241
"func_time = []\n",
242242
"mem_used_GB = []\n",
243243
"chunksize = [128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2610, \"auto\", False]\n",
244244
"for cs in chunksize:\n",
245245
" fieldset = set_cms_fieldset(cs)\n",
246-
" pset = ParticleSet(\n",
247-
" fieldset=fieldset, pclass=JITParticle, lon=[0], lat=[0], repeatdt=delta(hours=1)\n",
246+
" pset = parcels.ParticleSet(\n",
247+
" fieldset=fieldset,\n",
248+
" pclass=parcels.JITParticle,\n",
249+
" lon=[0],\n",
250+
" lat=[0],\n",
251+
" repeatdt=timedelta(hours=1),\n",
248252
" )\n",
249253
"\n",
250254
" tic = time.time()\n",
251-
" pset.execute(AdvectionRK4, dt=delta(hours=1))\n",
255+
" pset.execute(parcels.AdvectionRK4, dt=timedelta(hours=1))\n",
252256
" func_time.append(time.time() - tic)\n",
253257
" process = psutil.Process(os.getpid())\n",
254258
" mem_B_used = process.memory_info().rss\n",
@@ -387,19 +391,23 @@
387391
" \"lat\": (\"latitude\", cs),\n",
388392
" \"lon\": (\"longitude\", cs),\n",
389393
" }\n",
390-
" return FieldSet.from_netcdf(files, variables, dimensions, chunksize=cs)\n",
394+
" return parcels.FieldSet.from_netcdf(files, variables, dimensions, chunksize=cs)\n",
391395
"\n",
392396
"\n",
393397
"chunksize_3D = [128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2610, \"auto\", False]\n",
394398
"func_time3D = []\n",
395399
"for cs in chunksize_3D:\n",
396400
" fieldset = set_cms_fieldset_3D(cs)\n",
397-
" pset = ParticleSet(\n",
398-
" fieldset=fieldset, pclass=JITParticle, lon=[0], lat=[0], repeatdt=delta(hours=1)\n",
401+
" pset = parcels.ParticleSet(\n",
402+
" fieldset=fieldset,\n",
403+
" pclass=parcels.JITParticle,\n",
404+
" lon=[0],\n",
405+
" lat=[0],\n",
406+
" repeatdt=timedelta(hours=1),\n",
399407
" )\n",
400408
"\n",
401409
" tic = time.time()\n",
402-
" pset.execute(AdvectionRK4_3D, dt=delta(hours=1))\n",
410+
" pset.execute(AdvectionRK4_3D, dt=timedelta(hours=1))\n",
403411
" func_time3D.append(time.time() - tic)"
404412
]
405413
},

0 commit comments

Comments
 (0)