Skip to content

Commit

Permalink
Merge pull request #1397 from OceanParcels/removing_inbuilt_plotting_…
Browse files Browse the repository at this point in the history
…methods

Removing inbuilt plotting methods
  • Loading branch information
erikvansebille authored Jul 17, 2023
2 parents d8c4547 + dec5407 commit 9573623
Show file tree
Hide file tree
Showing 41 changed files with 74,597 additions and 8,413 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ out-*
**/*.zarr/*

.idea/*
.env
Profile.prof
**/.ipynb_checkpoints/*
.cache/*
Expand Down
Binary file added docs/_static/globe-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
"""Sphinx configuration file for Parcels documentation."""
# parcels documentation build configuration file, created by
# sphinx-quickstart on Tue Oct 20 09:58:20 2015.
#
Expand Down Expand Up @@ -209,6 +209,7 @@


def make_filename_safe(filename: str, safe_char: str = '_') -> str:
"""Make a filename safe for saving to disk."""
# Replace any characters that are not allowed in a filename with the safe character
safe_filename = re.sub(r'[\\/:*?"<>|]', safe_char, filename)
return safe_filename
Expand Down Expand Up @@ -356,9 +357,9 @@ def linkcode_resolve(domain, info):
'examples/tutorial_timestamps': '_static/calendar-icon.jpg',
'examples/tutorial_jit_vs_scipy': '_static/clock-icon.png',
'examples/documentation_homepage_animation': '_images/homepage.gif',
'examples/tutorial_Agulhasparticles': '_images/globcurrent_fullyseeded.gif',
'examples/tutorial_interaction': '_static/pulled_particles_twoatractors_line.gif',
'examples/documentation_LargeRunsOutput': '_static/harddrive.png',
'examples/tutorial_unitconverters': '_static/globe-icon.jpg',
'examples/documentation_geospatial': '_images/tutorial_geospatial_google_earth.png'
}
# -- Options for LaTeX output ---------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions docs/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Parcels has several documentation and tutorial Jupyter notebooks which go throug
examples/documentation_unstuck_Agrid.ipynb
examples/documentation_LargeRunsOutput.ipynb
examples/documentation_geospatial.ipynb
examples/tutorial_plotting.ipynb
examples/documentation_advanced_zarr.ipynb


Expand All @@ -68,4 +67,3 @@ Parcels has several documentation and tutorial Jupyter notebooks which go throug

examples/tutorial_Argofloats.ipynb
examples/documentation_homepage_animation.ipynb
examples/tutorial_Agulhasparticles.ipynb
5 changes: 2 additions & 3 deletions docs/examples/documentation_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb Cell 5\u001b[0m in \u001b[0;36m<cell line: 29>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m variables \u001b[39m=\u001b[39m {\u001b[39m\"\u001b[39m\u001b[39mU\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39muo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mV\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mvo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mW\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mwo\u001b[39m\u001b[39m\"\u001b[39m}\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m dimensions \u001b[39m=\u001b[39m {\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=8'>9</a>\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mU\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlon\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mnav_lon\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=25'>26</a>\u001b[0m },\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=26'>27</a>\u001b[0m }\n\u001b[0;32m---> <a href='vscode-notebook-cell:/Users/erik/Codes/ParcelsCode/docs/examples/documentation_indexing.ipynb#W4sZmlsZQ%3D%3D?line=28'>29</a>\u001b[0m fieldset \u001b[39m=\u001b[39m FieldSet\u001b[39m.\u001b[39;49mfrom_nemo(filenames, variables, dimensions)\n",
"Cell \u001b[0;32mIn[2], line 29\u001b[0m\n\u001b[1;32m 7\u001b[0m variables \u001b[39m=\u001b[39m {\u001b[39m\"\u001b[39m\u001b[39mU\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39muo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mV\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mvo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mW\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mwo\u001b[39m\u001b[39m\"\u001b[39m}\n\u001b[1;32m 8\u001b[0m dimensions \u001b[39m=\u001b[39m {\n\u001b[1;32m 9\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mU\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[1;32m 10\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlon\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mnav_lon\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 26\u001b[0m },\n\u001b[1;32m 27\u001b[0m }\n\u001b[0;32m---> 29\u001b[0m fieldset \u001b[39m=\u001b[39m FieldSet\u001b[39m.\u001b[39;49mfrom_nemo(filenames, variables, dimensions)\n",
"File \u001b[0;32m~/Codes/ParcelsCode/parcels/fieldset.py:561\u001b[0m, in \u001b[0;36mFieldSet.from_nemo\u001b[0;34m(cls, filenames, variables, dimensions, indices, mesh, allow_time_extrapolation, time_periodic, tracer_interp_method, chunksize, **kwargs)\u001b[0m\n\u001b[1;32m 559\u001b[0m \u001b[39mif\u001b[39;00m kwargs\u001b[39m.\u001b[39mpop(\u001b[39m'\u001b[39m\u001b[39mgridindexingtype\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mnemo\u001b[39m\u001b[39m'\u001b[39m) \u001b[39m!=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mnemo\u001b[39m\u001b[39m'\u001b[39m:\n\u001b[1;32m 560\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mgridindexingtype must be \u001b[39m\u001b[39m'\u001b[39m\u001b[39mnemo\u001b[39m\u001b[39m'\u001b[39m\u001b[39m in FieldSet.from_nemo(). Use FieldSet.from_c_grid_dataset otherwise\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 561\u001b[0m fieldset \u001b[39m=\u001b[39m \u001b[39mcls\u001b[39;49m\u001b[39m.\u001b[39;49mfrom_c_grid_dataset(filenames, variables, dimensions, mesh\u001b[39m=\u001b[39;49mmesh, indices\u001b[39m=\u001b[39;49mindices, time_periodic\u001b[39m=\u001b[39;49mtime_periodic,\n\u001b[1;32m 562\u001b[0m allow_time_extrapolation\u001b[39m=\u001b[39;49mallow_time_extrapolation, tracer_interp_method\u001b[39m=\u001b[39;49mtracer_interp_method,\n\u001b[1;32m 563\u001b[0m chunksize\u001b[39m=\u001b[39;49mchunksize, gridindexingtype\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mnemo\u001b[39;49m\u001b[39m'\u001b[39;49m, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 564\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(fieldset, \u001b[39m'\u001b[39m\u001b[39mW\u001b[39m\u001b[39m'\u001b[39m):\n\u001b[1;32m 565\u001b[0m fieldset\u001b[39m.\u001b[39mW\u001b[39m.\u001b[39mset_scaling_factor(\u001b[39m-\u001b[39m\u001b[39m1.\u001b[39m)\n",
"File \u001b[0;32m~/Codes/ParcelsCode/parcels/fieldset.py:672\u001b[0m, in \u001b[0;36mFieldSet.from_c_grid_dataset\u001b[0;34m(cls, filenames, variables, dimensions, indices, mesh, allow_time_extrapolation, time_periodic, tracer_interp_method, gridindexingtype, chunksize, **kwargs)\u001b[0m\n\u001b[1;32m 600\u001b[0m \u001b[39m\"\"\"Initialises FieldSet object from NetCDF files of Curvilinear NEMO fields.\u001b[39;00m\n\u001b[1;32m 601\u001b[0m \n\u001b[1;32m 602\u001b[0m \u001b[39mSee `here <../examples/documentation_indexing.ipynb>`__\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 669\u001b[0m \u001b[39m Keyword arguments passed to the :func:`Fieldset.from_netcdf` constructor.\u001b[39;00m\n\u001b[1;32m 670\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 671\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39m'\u001b[39m\u001b[39mU\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m dimensions \u001b[39mand\u001b[39;00m \u001b[39m'\u001b[39m\u001b[39mV\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m dimensions \u001b[39mand\u001b[39;00m dimensions[\u001b[39m'\u001b[39m\u001b[39mU\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m!=\u001b[39m dimensions[\u001b[39m'\u001b[39m\u001b[39mV\u001b[39m\u001b[39m'\u001b[39m]:\n\u001b[0;32m--> 672\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mOn a C-grid, the dimensions of velocities should be the corners (f-points) of the cells, so the same for U and V. \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 673\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mSee also ../examples/documentation_indexing.ipynb\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 674\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39m'\u001b[39m\u001b[39mU\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m dimensions \u001b[39mand\u001b[39;00m \u001b[39m'\u001b[39m\u001b[39mW\u001b[39m\u001b[39m'\u001b[39m \u001b[39min\u001b[39;00m dimensions \u001b[39mand\u001b[39;00m dimensions[\u001b[39m'\u001b[39m\u001b[39mU\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m!=\u001b[39m dimensions[\u001b[39m'\u001b[39m\u001b[39mW\u001b[39m\u001b[39m'\u001b[39m]:\n\u001b[1;32m 675\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mOn a C-grid, the dimensions of velocities should be the corners (f-points) of the cells, so the same for U, V and W. \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 676\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mSee also ../examples/documentation_indexing.ipynb\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: On a C-grid, the dimensions of velocities should be the corners (f-points) of the cells, so the same for U and V. See also ../examples/documentation_indexing.ipynb"
Expand Down Expand Up @@ -216,7 +216,6 @@
}
],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.mplot3d import Axes3D # noqa\n",
"\n",
Expand Down Expand Up @@ -293,7 +292,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example_decaying_moving_eddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decaying_moving_example(fieldset, outfile, mode='scipy', method=AdvectionRK4
runtime = delta(days=2)
outputdt = delta(hours=1)

pset.execute(method, runtime=runtime, dt=dt, moviedt=None,
pset.execute(method, runtime=runtime, dt=dt,
output_file=pset.ParticleFile(name=outfile, outputdt=outputdt))

return pset
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/example_moving_eddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ def moving_eddies_example(fieldset, outfile, npart=2, mode='jit', verbose=False,
runtime = delta(days=7)
print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime)))
pset.execute(method, runtime=runtime, dt=delta(hours=1),
output_file=pset.ParticleFile(name=outfile, outputdt=delta(hours=1)),
moviedt=None)
output_file=pset.ParticleFile(name=outfile, outputdt=delta(hours=1)))

if verbose:
print(f"Final particle positions:\n{pset}")
Expand Down
31 changes: 6 additions & 25 deletions docs/examples/example_nemo_curvilinear.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Example script that runs a set of particles in a NEMO curvilinear grid."""
from argparse import ArgumentParser
from datetime import timedelta as delta
from glob import glob
Expand All @@ -21,7 +22,7 @@


def run_nemo_curvilinear(mode, outfile, advtype='RK4'):
"""Function that shows how to read in curvilinear grids, in this case from NEMO."""
"""Run parcels on the NEMO curvilinear grid."""
data_folder = download_example_dataset('NemoCurvilinear_data')

filenames = {'U': {'lon': f'{data_folder}/mesh_mask.nc4',
Expand Down Expand Up @@ -58,41 +59,21 @@ def periodicBC(particle, fieldSet, time):
assert np.allclose(pset.lat - latp, 0, atol=2e-2)


def make_plot(trajfile):
import cartopy
import matplotlib.pyplot as plt
import xarray as xr

class ParticleData:
def __init__(self):
self.id = []

def load_particles_file(fname, varnames):
T = ParticleData()
ds = xr.open_zarr(fname)
T.id = ds['trajectory'][:]
for v in varnames:
setattr(T, v, ds[v][:])
return T

T = load_particles_file(trajfile, ['lon', 'lat', 'time'])
plt.axes(projection=cartopy.crs.PlateCarree())
plt.scatter(T.lon, T.lat, c=T.time, s=10)
plt.show()


@pytest.mark.parametrize('mode', ['jit']) # Only testing jit as scipy is very slow
def test_nemo_curvilinear(mode, tmpdir):
"""Test the NEMO curvilinear example."""
outfile = tmpdir.join('nemo_particles')
run_nemo_curvilinear(mode, outfile)


def test_nemo_curvilinear_AA(tmpdir):
"""Test the NEMO curvilinear example with analytical advection."""
outfile = tmpdir.join('nemo_particlesAA')
run_nemo_curvilinear('scipy', outfile, 'AA')


def test_nemo_3D_samegrid():
"""Test that the same grid is used for U and V in 3D NEMO fields."""
data_folder = download_example_dataset('NemoNorthSeaORCA025-N006_data')
ufiles = sorted(glob(f'{data_folder}/ORCA*U.nc'))
vfiles = sorted(glob(f'{data_folder}/ORCA*V.nc'))
Expand All @@ -116,6 +97,7 @@ def test_nemo_3D_samegrid():


def main(args=None):
"""Run the example with given arguments."""
p = ArgumentParser(description="""Chose the mode using mode option""")
p.add_argument('mode', choices=('scipy', 'jit'), nargs='?', default='jit',
help='Execution mode for performing computation')
Expand All @@ -124,7 +106,6 @@ def main(args=None):
outfile = "nemo_particles"

run_nemo_curvilinear(args.mode, outfile)
make_plot(outfile+'.zarr')


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example_radial_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def rotation_example(fieldset, outfile, mode='jit', method=AdvectionRK4):
dt = delta(minutes=5)
outputdt = delta(hours=1)

pset.execute(method, runtime=runtime, dt=dt, moviedt=None,
pset.execute(method, runtime=runtime, dt=dt,
output_file=pset.ParticleFile(name=outfile, outputdt=outputdt))

return pset
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example_stommel.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MyParticle(ParticleClass):
timer.psetinit.stop()
timer.psetrun = timer.Timer('Pset_run', parent=timer.pset)
pset.execute(method + pset.Kernel(UpdateP) + pset.Kernel(AgeP), runtime=runtime, dt=dt,
moviedt=None, output_file=pset.ParticleFile(name=outfile, outputdt=outputdt))
output_file=pset.ParticleFile(name=outfile, outputdt=outputdt))

if verbose:
print(f"Final particle positions:\n{pset}")
Expand Down
Binary file removed docs/examples/images/globcurrent_fullyseeded.gif
Binary file not shown.
13,861 changes: 12,931 additions & 930 deletions docs/examples/parcels_tutorial.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 9573623

Please sign in to comment.