The show() method of the Particelset class is capable of plotting the particle locations and velocity fields in scalar and vector form. In this notebook, we demonstrate these capabilities using the GlobCurrent dataset. We begin by importing the relevant modules.

In [1]:
from parcels import FieldSet, ParticleSet, JITParticle, AdvectionRK4
from datetime import timedelta, datetime

We then instatiate a FieldSet with the velocity field data from GlobCurrent dataset.

In [2]:
filenames = {'U': "GlobCurrent_example_data/20*.nc",
             'V': "GlobCurrent_example_data/20*.nc"}
variables = {'U': 'eastward_eulerian_current_velocity',
             'V': 'northward_eulerian_current_velocity'}
dimensions = {'lat': 'lat',
              'lon': 'lon',
              'time': 'time'}
fieldset = FieldSet.from_netcdf(filenames, variables, dimensions)
WARNING: Casting lon data to np.float32
WARNING: Casting lat data to np.float32
WARNING: Casting depth data to np.float32

Next, we instantiate a ParticeSet composed of JITParticles:

In [3]:
pset = ParticleSet.from_line(fieldset=fieldset, size=5, pclass=JITParticle,
                             start=(31, -31), finish=(32, -31), time=datetime(2002, 1, 1))

Given this ParticleSet, we can now explore the different features of the show() method. To start, let's simply call show() with no arguments.

In [4]:

Then, let's advect the particles starting on January 1, 2002 for a week.

In [5]:
pset.execute(AdvectionRK4, runtime=timedelta(days=7), dt=timedelta(minutes=5))
INFO: Compiled JITParticleAdvectionRK4 ==> /var/folders/r2/8593q8z93kd7t4j9kbb_f7p00000gn/T/parcels-501/

If we call show() again, we will see that the particles have been advected:

In [6]:

To plot the continents on the same plot, add land=True. Note that for this to work, you need to have Basemap installed.

In [8]:

To set the domain of the plot, we specify the domain argument. The format domain expects is [max lat, min lat, max lon, min lon]. Note that the plotted domain is found by interpolating the user-specified domain onto the velocity grid. For instance,

In [9]:[-30, -35, 35, 26], land=True)

We can also easily display a scalar contour plot of a single component of the velocity vector field. This is done by setting the field argument equal to the desired scalar velocity field.

In [10]:

To plot the scalar U velocity field at a different date and time, we set the argument t equal to a datetime or timedelta object or simply the number of seconds since the time origin. For instance, let's view the U field on January, 10, 2002 at 2 PM.

In [11]:, show_time=datetime(2002, 1, 10, 2))

Note that the particle locations do not change, but remain at the locations corresponding to the end of the last integration. To remove them from the plot, we set the argument particles equal to False.

In [12]:, show_time=datetime(2002, 1, 10, 2), particles=False)

By setting the field argument equal to vector, we can display the velocity in full vector form. Note that we can now also use the land=True flag (it does not presently work with plotting any other field).

In [14]:'vector', land=True)

The normalized vector field is colored by speed. To control the maximum speed value on the colorbar, set the vmax argument equal to the desired value.

In [15]:'vector', vmax=3.0, domain=[-30, -36, 33, 10], land=True)

If we want to save the file rather than show it, we set the argument savefile equal to the 'path/to/save/file'.

In [16]:'vector', vmax=3.0, domain=[-30, -36, 33, 10], land=True, savefile='particles')
INFO: Plot saved to particles.png