API#

Top-level API#

read_csv(f, **kwargs)

Construct a CF-compliant trajectory dataset from a CSV file.

from_dataframe(df[, lon, lat, time, name, ...])

Construct a CF-compliant trajectory dataset from a pd.DataFrame of positions.

trajectory_dict_to_dataset(trajectory_dict)

Create a CF-compatible trajectory file from dictionary of drifter positions

Classes#

class trajan.traj.orthogonal.Orthogonal(ds, trajectory_dim, obs_dim, time_varname)[source]#

A structured dataset, where each trajectory is always given at the same times. Typically the output from a model or from a gridded dataset.

distance_to(other)[source]#

Distance between trajectories or a single point.

Parameters:

other (Dataset) – Other dataset to which distance is calculated

Returns:

Dataset

Same dimensions as original dataset, containing three DataArrays from pyproj.geod.inv:

distance : distance [meters]

az_fwd : forward azimuth angle [degrees]

az_bwd : backward azimuth angle [degrees]

See also

distance_to_next

filter(method='speed', max_speed=10.0, nsigma=5.0, side_half_width=2)[source]#

Filter outlier positions from trajectories.

Parameters:
  • method (str) – Outlier detection method:

    • 'speed': walk through non-NaN positions in order and compare each to the last accepted position. Any position whose speed from the last accepted position exceeds max_speed [m/s] is masked. Crucially, when a position is masked the “last accepted” pointer is not advanced, so entire consecutive runs of invalid positions (e.g. GPS no-fix sentinel values near (0, 0)) are cleared in a single O(N) pass without falsely masking the valid positions that bracket the bad run.

    • 'nsigma_sliding': mask positions whose latitude or longitude deviates more than nsigma standard deviations from the local mean computed over a sliding window of half-width side_half_width. Applied independently to latitude and longitude. Note: this method is designed for isolated single- point spikes; it is less effective for consecutive runs of outliers.

  • max_speed (float) – Maximum allowed speed [m/s]. Used with method='speed'. Default: 10.

  • nsigma (float) – Outlier threshold in number of standard deviations. Used with method='nsigma_sliding'. Default: 5.

  • side_half_width (int) – Half-width of the sliding window (number of neighbours on each side). Used with method='nsigma_sliding'. Default: 2.

Returns:

xarray.Dataset – Dataset with outlier lat/lon positions set to NaN. Time and other variables are left unchanged.

See also

speed

Calculate the speed along trajectories.

Examples

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> filtered = ds.traj.filter(method='speed', max_speed=3.)
>>> filtered = ds.traj.filter(method='nsigma_sliding', nsigma=5., side_half_width=2)
gridtime(times, time_varname=None, round=True)[source]#

Interpolate dataset to a regular time interval or a different grid.

Parameters:
  • times (array or str) –

    Target time interval, can be either:
    • an array of times, or

    • a string specifying a Pandas daterange (e.g. ‘h’, ‘6h, ‘D’…) suitable for pd.date_range.

  • time_varname (str) – Name of new time dimension. The default is to use the same name as previously.

Returns:

Dataset – A new dataset interpolated to the target times. The dataset will be Orthogonal (i.e. gridded) and the time dimension will be named time.

is_orthogonal()[source]#

Returns True if dataset is orthogonal, i.e. time is a 1D coordinate variable.

Returns:

bool

is_ragged()[source]#

Returns True if dataset is Ragged, i.e. time is a 2D variable and not a coordinate variable.

Returns:

bool

iseltime(i)[source]#

Select observations by index (of non-nan, time, observation) across trajectories. For Orthogonal datasets prefer to use xarray.Dataset.isel.

Parameters:

i (index, list of indexes or a slice.)

Returns:

ds (Dataset) – A dataset with the selected indexes in each trajectory.

Example

Select the first and last element in each trajectory in a dataset of unstructured observations:

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> print(ds)
<xarray.Dataset> Size: 110kB
Dimensions:        (trajectory: 2, obs: 2287)
Dimensions without coordinates: trajectory, obs
Data variables:
    lon            (trajectory, obs) float64 37kB ...
    lat            (trajectory, obs) float64 37kB ...
    time           (trajectory, obs) datetime64[ns] 37kB ...
    drifter_names  (trajectory) <U16 128B ...
Attributes: (12/13)
    Conventions:          CF-1.10
    featureType:          trajectory
    geospatial_lat_min:   74.5454462
    geospatial_lat_max:   77.4774768
    geospatial_lon_min:   17.2058074
    geospatial_lon_max:   29.8523485
    ...                   ...
    time_coverage_end:    2022-11-23T13:30:28
    creator_email:        gauteh@met.no, knutfd@met.no
    creator_name:         Gaute Hope and Knut Frode Dagestad
    creator_url:          https://github.com/OpenDrift/opendrift
    summary:              Two drifters in the Barents Sea. One stranded at Ho...
    title:                Barents Sea drifters
>>> ds = ds.traj.iseltime([0, -1])
>>> print(ds)
<xarray.Dataset> Size: 224B
Dimensions:        (trajectory: 2, obs: 2)
Dimensions without coordinates: trajectory, obs
Data variables:
    lon            (trajectory, obs) float64 32B 29.85 25.11 27.82 21.15
    lat            (trajectory, obs) float64 32B 77.3 76.57 77.11 74.58
    time           (trajectory, obs) datetime64[ns] 32B 2022-10-07T00:00:38 ....
    drifter_names  (trajectory) <U16 128B 'UIB-2022-TILL-01' 'UIB-2022-TILL-02'
Attributes: (12/13)
    Conventions:          CF-1.10
    featureType:          trajectory
    geospatial_lat_min:   74.5454462
    geospatial_lat_max:   77.4774768
    geospatial_lon_min:   17.2058074
    geospatial_lon_max:   29.8523485
    ...                   ...
    time_coverage_end:    2022-11-23T13:30:28
    creator_email:        gauteh@met.no, knutfd@met.no
    creator_name:         Gaute Hope and Knut Frode Dagestad
    creator_url:          https://github.com/OpenDrift/opendrift
    summary:              Two drifters in the Barents Sea. One stranded at Ho...
    title:                Barents Sea drifters

See also

seltime, sel, isel

rotary_spectrum()[source]#

Calculate the rotary spectrum for a single trajectory.

Note

This method is not yet fully implemented.

sel(*args, **kwargs)[source]#

Select on each trajectory. On Orthogonal datasets this is just a shortcut for Dataset.sel.

Parameters:

Anything accepted by `Dataset.sel`.

Returns:

ds (Dataset) – A dataset with the selected range in each trajectory.

See also

iseltime, sel, isel

seltime(t0=None, t1=None)[source]#

Select observations in time window between t0 and t1 (inclusive). For Orthogonal datasets prefer to use xarray.Dataset.sel.

Parameters:

t0, t1 (numpy.datetime64)

Returns:

ds (Dataset) – A dataset with the selected indexes in each trajectory.

See also

iseltime, sel, isel

skill(expected, method='liu-weissberg', **kwargs)[source]#

Compare the skill score between this trajectory and an expected trajectory.

Parameters:
  • expected (Dataset) – Another trajectory dataset, normally the observed / expected.

  • method (str) – skill-score method, currently only liu-weissberg.

  • **kwargs – Passed on to the skill-score method.

Returns:

skill (DataArray) – The skill-score in the combined dimensions of both datasets.

Notes

Both datasets must have the same number of trajectories (N:N), or at least one of the datasets (normally the expected) must have a single trajectory only (1:N, N:1, 1:1).

The datasets must be sampled (or have observations) at approximately the same timesteps. Consider using gridtime() to interpolate one of the datasets to the other.

Any additional dimensions will be broadcasted, so that the result include the combined dimensions of both datasets.

Some skillscore methods (e.g. liu-weissberg) are not symmetrical. This specific skillscore is normalized on the length of the expected / observed trajectories. Thus a.traj.skill(b) will provide different numerical results than b.traj.skill(a).

Examples

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> expected = ds.copy()
>>> ds = ds.traj.gridtime('1h')
>>> expected = expected.traj.gridtime(ds.time)
>>> skill = ds.traj.skill(expected)
>>> skill  # Returns 1 since comparing to itself
<xarray.DataArray 'Skillscore' (trajectory: 2)> Size: 16B
array([1., 1.])
Coordinates:
  * trajectory  (trajectory) int64 16B 0 1
Attributes:
    method:   liu-weissberg
>>> expected = ds.isel(trajectory=0)
>>> skill = ds.traj.skill(expected)
>>> skill
<xarray.DataArray 'Skillscore' (trajectory: 2)> Size: 16B
array([1.        , 0.60805799])
Coordinates:
  * trajectory  (trajectory) int64 16B 0 1
Attributes:
    method:   liu-weissberg
skill_along_trajectory(expected, **kwargs)[source]#

_Skill score is calculated for each trajectory versus the matcing part of the expected (single) trajectory.

time_to_next()[source]#

Returns the time difference to the next observation.

Returns:

xarray.DataArray – Scalar timedelta for Orthogonal datasets with fixed timestep, or DataArray of the same shape as the dataset for Ragged datasets. Attributes include units: seconds.

See also

distance_to_next, speed

timestep()[source]#

Calculate the time step between observations.

Parameters:

average (callable(), optional) – Function to aggregate multiple time steps (e.g. np.nanmedian). Ignored for Orthogonal datasets where the time step is uniform (TODO: handle variable timestep also for Orthogonal datasets).

Returns:

pd.Timedelta – Time step between observations.

to_orthogonal()[source]#

Convert dataset into Orthogonal dataset from. This is only possible if the dataset has a single trajectory.

to_ragged(obs_dim='obs')[source]#

Convert the dataset to a Ragged representation.

Parameters:

obs_dim (str, optional) – Name of the observation dimension in the Ragged representation, by default ‘obs’.

Returns:

xarray.Dataset – Dataset with a Ragged representation of trajectories.

trim()[source]#

Remove empty positions at start and end of trajectory.

Returns:

xarray.Dataset – Trimmed dataset

velocity_spectrum()[source]#

Calculate the velocity spectrum for a single trajectory.

Returns:

xarray.DataArray – Velocity spectrum with dimensions (‘period’) and units: power attribute.

class trajan.traj.ragged.Ragged(ds, trajectory_dim, obs_dim, time_varname)[source]#

A unstructured dataset, where each trajectory may have observations at different times. Typically from a collection of drifters.

append(da, obs_dims=None)[source]#

Append trajectories from other dataset to this.

condense_obs(**kwargs)[source]#

Move all observations to the first index, so that the observation dimension is reduced to a minimum. When creating ragged arrays the observations from consecutive trajectories start at the observation index after the previous, causing a very long observation dimension.

Original:

………….. Observations —>

trajectory 1: | t01 | t02 | t03 | t04 | t05 | nan | nan | nan | nan | trajectory 2: | nan | nan | nan | nan | nan | t11 | t12 | t13 | t14 |

After condensing:

………….. Observations —>

trajectory 1: | t01 | t02 | t03 | t04 | t05 | trajectory 2: | t11 | t12 | t13 | t14 | nan |

Returns:

A new Dataset with observations condensed.

drop_where(condition)[source]#

Remove positions where the condition is True, shifting the rest of the trajectory.

Parameters:

condition (xarray.DataArray) – Boolean condition indicating positions to drop.

Returns:

xarray.Dataset – Dataset with positions removed where the condition is True.

filter(method='speed', **kwargs)[source]#

Filter outlier positions from trajectories.

Parameters:
  • method (str) – Outlier detection method:

    • 'speed': walk through non-NaN positions in order and compare each to the last accepted position. Any position whose speed from the last accepted position exceeds max_speed [m/s] is masked. Crucially, when a position is masked the “last accepted” pointer is not advanced, so entire consecutive runs of invalid positions (e.g. GPS no-fix sentinel values near (0, 0)) are cleared in a single O(N) pass without falsely masking the valid positions that bracket the bad run.

    • 'nsigma_sliding': mask positions whose latitude or longitude deviates more than nsigma standard deviations from the local mean computed over a sliding window of half-width side_half_width. Applied independently to latitude and longitude. Note: this method is designed for isolated single- point spikes; it is less effective for consecutive runs of outliers.

  • max_speed (float) – Maximum allowed speed [m/s]. Used with method='speed'. Default: 10.

  • nsigma (float) – Outlier threshold in number of standard deviations. Used with method='nsigma_sliding'. Default: 5.

  • side_half_width (int) – Half-width of the sliding window (number of neighbours on each side). Used with method='nsigma_sliding'. Default: 2.

Returns:

xarray.Dataset – Dataset with outlier lat/lon positions set to NaN. Time and other variables are left unchanged.

See also

speed

Calculate the speed along trajectories.

Examples

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> filtered = ds.traj.filter(method='speed', max_speed=3.)
>>> filtered = ds.traj.filter(method='nsigma_sliding', nsigma=5., side_half_width=2)
static from_contiguous(ds, trajectory_dim, obs_dim, time_varname, rowvar)[source]#

An unstructured dataset, where each trajectory may have observations at different times, and all the data for the different trajectories are stored in single arrays with one dimension, contiguously, one trajectory after the other. Typically from a collection of drifters.

This method converts ContinousRagged datasets into Ragged datasets.

static from_ncparticles(ds, obs_dim='obs', time_varname='time', id_varname='id', count_varname='particle_count', data_dim='data')[source]#

An unstructured dataset following the nc_particles standard (https://noaa-orr-erd.github.io/nc_particles/nc_particle_standard.html).

nc_particles files are “ragged by time”: count_varname(time) gives the number of particles present at each time step, and all per-particle data (lat, lon, depth, mass, …) is stored contiguously in a single flattened data_dim array, one time step’s worth of particles after another. id_varname(data) gives the particle ID for each entry, allowing particles created/destroyed during the run to be tracked across time even though they don’t occupy a fixed row/index.

This method inverts that “ragged-by-time” layout into the “ragged-by-trajectory” representation used by trajan, where each row holds the time-ordered observations for a single particle ID.

gridtime(**kwargs)[source]#

Interpolate dataset to a regular time interval or a different grid.

Parameters:
  • times (array or str) –

    Target time interval, can be either:
    • an array of times, or

    • a string specifying a Pandas daterange (e.g. ‘h’, ‘6h, ‘D’…) suitable for pd.date_range.

  • time_varname (str) – Name of new time dimension. The default is to use the same name as previously.

Returns:

Dataset – A new dataset interpolated to the target times. The dataset will be Orthogonal (i.e. gridded) and the time dimension will be named time.

insert_nan_where(condition)[source]#

Insert NaN values in trajectories after given positions, shifting the rest of the trajectory.

Parameters:

condition (xarray.DataArray) – Boolean condition indicating where NaN values should be inserted.

Returns:

xarray.Dataset – Dataset with NaN values inserted at specified positions.

is_orthogonal()[source]#

Returns True if dataset is orthogonal, i.e. time is a 1D coordinate variable.

Returns:

bool

is_ragged()[source]#

Returns True if dataset is Ragged, i.e. time is a 2D variable and not a coordinate variable.

Returns:

bool

iseltime(**kwargs)[source]#

Select observations by index (of non-nan, time, observation) across trajectories. For Orthogonal datasets prefer to use xarray.Dataset.isel.

Parameters:

i (index, list of indexes or a slice.)

Returns:

ds (Dataset) – A dataset with the selected indexes in each trajectory.

Example

Select the first and last element in each trajectory in a dataset of unstructured observations:

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> print(ds)
<xarray.Dataset> Size: 110kB
Dimensions:        (trajectory: 2, obs: 2287)
Dimensions without coordinates: trajectory, obs
Data variables:
    lon            (trajectory, obs) float64 37kB ...
    lat            (trajectory, obs) float64 37kB ...
    time           (trajectory, obs) datetime64[ns] 37kB ...
    drifter_names  (trajectory) <U16 128B ...
Attributes: (12/13)
    Conventions:          CF-1.10
    featureType:          trajectory
    geospatial_lat_min:   74.5454462
    geospatial_lat_max:   77.4774768
    geospatial_lon_min:   17.2058074
    geospatial_lon_max:   29.8523485
    ...                   ...
    time_coverage_end:    2022-11-23T13:30:28
    creator_email:        gauteh@met.no, knutfd@met.no
    creator_name:         Gaute Hope and Knut Frode Dagestad
    creator_url:          https://github.com/OpenDrift/opendrift
    summary:              Two drifters in the Barents Sea. One stranded at Ho...
    title:                Barents Sea drifters
>>> ds = ds.traj.iseltime([0, -1])
>>> print(ds)
<xarray.Dataset> Size: 224B
Dimensions:        (trajectory: 2, obs: 2)
Dimensions without coordinates: trajectory, obs
Data variables:
    lon            (trajectory, obs) float64 32B 29.85 25.11 27.82 21.15
    lat            (trajectory, obs) float64 32B 77.3 76.57 77.11 74.58
    time           (trajectory, obs) datetime64[ns] 32B 2022-10-07T00:00:38 ....
    drifter_names  (trajectory) <U16 128B 'UIB-2022-TILL-01' 'UIB-2022-TILL-02'
Attributes: (12/13)
    Conventions:          CF-1.10
    featureType:          trajectory
    geospatial_lat_min:   74.5454462
    geospatial_lat_max:   77.4774768
    geospatial_lon_min:   17.2058074
    geospatial_lon_max:   29.8523485
    ...                   ...
    time_coverage_end:    2022-11-23T13:30:28
    creator_email:        gauteh@met.no, knutfd@met.no
    creator_name:         Gaute Hope and Knut Frode Dagestad
    creator_url:          https://github.com/OpenDrift/opendrift
    summary:              Two drifters in the Barents Sea. One stranded at Ho...
    title:                Barents Sea drifters

See also

seltime, sel, isel

sel(*args, **kwargs)[source]#

Select on each trajectory. On Orthogonal datasets this is just a shortcut for Dataset.sel.

Parameters:

Anything accepted by `Dataset.sel`.

Returns:

ds (Dataset) – A dataset with the selected range in each trajectory.

See also

iseltime, sel, isel

seltime(t0=None, t1=None)[source]#

Select observations in time window between t0 and t1 (inclusive). For Orthogonal datasets prefer to use xarray.Dataset.sel.

Parameters:

t0, t1 (numpy.datetime64)

Returns:

ds (Dataset) – A dataset with the selected indexes in each trajectory.

See also

iseltime, sel, isel

skill()[source]#

Compare the skill score between this trajectory and an expected trajectory.

Parameters:
  • expected (Dataset) – Another trajectory dataset, normally the observed / expected.

  • method (str) – skill-score method, currently only liu-weissberg.

  • **kwargs – Passed on to the skill-score method.

Returns:

skill (DataArray) – The skill-score in the combined dimensions of both datasets.

Notes

Both datasets must have the same number of trajectories (N:N), or at least one of the datasets (normally the expected) must have a single trajectory only (1:N, N:1, 1:1).

The datasets must be sampled (or have observations) at approximately the same timesteps. Consider using gridtime() to interpolate one of the datasets to the other.

Any additional dimensions will be broadcasted, so that the result include the combined dimensions of both datasets.

Some skillscore methods (e.g. liu-weissberg) are not symmetrical. This specific skillscore is normalized on the length of the expected / observed trajectories. Thus a.traj.skill(b) will provide different numerical results than b.traj.skill(a).

Examples

>>> import xarray as xr
>>> import trajan as ta
>>> ds = xr.open_dataset(ta.DATA_DIR + 'barents.nc')
>>> expected = ds.copy()
>>> ds = ds.traj.gridtime('1h')
>>> expected = expected.traj.gridtime(ds.time)
>>> skill = ds.traj.skill(expected)
>>> skill  # Returns 1 since comparing to itself
<xarray.DataArray 'Skillscore' (trajectory: 2)> Size: 16B
array([1., 1.])
Coordinates:
  * trajectory  (trajectory) int64 16B 0 1
Attributes:
    method:   liu-weissberg
>>> expected = ds.isel(trajectory=0)
>>> skill = ds.traj.skill(expected)
>>> skill
<xarray.DataArray 'Skillscore' (trajectory: 2)> Size: 16B
array([1.        , 0.60805799])
Coordinates:
  * trajectory  (trajectory) int64 16B 0 1
Attributes:
    method:   liu-weissberg
time_to_next()[source]#

Returns the time difference to the next observation.

Returns:

xarray.DataArray – Scalar timedelta for Orthogonal datasets with fixed timestep, or DataArray of the same shape as the dataset for Ragged datasets. Attributes include units: seconds.

See also

distance_to_next, speed

timestep(average=<function nanmedian>)[source]#

Calculate the time step between observations.

Parameters:

average (callable(), optional) – Function to aggregate multiple time steps (e.g. np.nanmedian). Ignored for Orthogonal datasets where the time step is uniform (TODO: handle variable timestep also for Orthogonal datasets).

Returns:

pd.Timedelta – Time step between observations.

to_orthogonal()[source]#

Convert dataset into Orthogonal dataset from. This is only possible if the dataset has a single trajectory.

to_ragged(obs_dim='obs')[source]#

Convert the dataset to a Ragged representation.

Parameters:

obs_dim (str, optional) – Name of the observation dimension in the Ragged representation, by default ‘obs’.

Returns:

xarray.Dataset – Dataset with a Ragged representation of trajectories.

Dataset#

Attributes#

Dataset.traj.plot

See trajan.plot.Plot.

Dataset.traj.animate

Return an trajan.animation.Animation builder for this dataset.

Dataset.traj.tx

Trajectory x coordinates (usually longitude).

Dataset.traj.ty

Trajectory y coordinates (usually latitude).

Dataset.traj.tlon

Retrieve the trajectories in geographic coordinates (longitudes).

Dataset.traj.tlat

Retrieve the trajectories in geographic coordinates (latitudes).

Dataset.traj.crs

Retrieve the pyproj.crs.CRS object from the CF-defined grid-mapping in the dataset.

Dataset.traj.ccrs

Retrieve a cartopy CRS from the pyproj CRS.

Methods#

Dataset.traj.transform(to_crs)

Transform this datasets to to_crs coordinate system.

Dataset.traj.transformer(from_crs)

Create a transformer useful for transforming other coordinates to the CRS of this dataset.

Dataset.traj.set_crs(crs)

Returns a new dataset with the CF-supported grid-mapping / projection set to crs.

Dataset.traj.assign_cf_attrs([creator_name, ...])

Return a new dataset with CF-standard and common attributes set.

Dataset.traj.index_of_last()

Find the index of the last valid position along each trajectory.

Dataset.traj.speed()

Returns the speed [m/s] along trajectories.

Dataset.traj.time_to_next()

Returns the time difference to the next observation.

Dataset.traj.distance_to(other)

Distance between trajectories or a single point.

Dataset.traj.distance_to_next()

Returns distance in meters from one position to the next along trajectories.

Dataset.traj.azimuth_to_next()

Returns azimution travel direction in degrees from one position to the next.

Dataset.traj.length()

Returns distance in meters of each trajectory.

Dataset.traj.skill(expected[, method])

Compare the skill score between this trajectory and an expected trajectory.

Dataset.traj.velocity_components()

Calculate velocity components [m/s] from one position to the next.

Dataset.traj.velocity_spectrum()

Calculate the velocity spectrum for a single trajectory.

Dataset.traj.concave_hull([alpha])

Return the concave hull for all particles, in geographical coordinates.

Dataset.traj.convex_hull()

Return the scipy convex hull for all particles, in geographical coordinates.

Dataset.traj.convex_hull_contains_point(lon, lat)

Return True if given point is within the scipy convex hull for all particles.

Dataset.traj.get_area_convex_hull()

Calculate the area [m2] of the convex hull spanned by all positions.

Dataset.traj.gridtime(times[, time_varname])

Interpolate dataset to a regular time interval or a different grid.

Dataset.traj.sel(*args, **kwargs)

Select on each trajectory.

Dataset.traj.seltime([t0, t1])

Select observations in time window between t0 and t1 (inclusive).

Dataset.traj.iseltime(i)

Select observations by index (of non-nan, time, observation) across trajectories.

Dataset.traj.filter([method, max_speed, ...])

Filter outlier positions from trajectories.

Dataset.traj.append(da[, obs_dims])

Append trajectories from other dataset to this.

Dataset.traj.crop([lonmin, lonmax, latmin, ...])

Remove parts of trajectories outside of given geographical bounds.

Dataset.traj.contained_in([lonmin, lonmax, ...])

Return only trajectories fully within given geographical bounds.

Dataset.traj.is_orthogonal()

Returns True if dataset is orthogonal, i.e. time is a 1D coordinate variable.

Dataset.traj.is_ragged()

Returns True if dataset is Ragged, i.e. time is a 2D variable and not a coordinate variable.

Dataset.traj.to_orthogonal()

Convert dataset into Orthogonal dataset from.

Dataset.traj.to_ortho()

Convert dataset into Orthogonal dataset from.

Dataset.traj.to_ragged([obs_dim])

Convert the dataset to a Ragged representation.

Dataset.traj.trajectories()

Iterate over each trajectory.

Dataset.traj.condense_obs()

Move all observations to the first index, so that the observation dimension is reduced to a minimum.

Dataset.traj.make_grid(dx[, dy, z, lonmin, ...])

Make a grid that covers all elements of dataset, with given spatial resolution.

Dataset.traj.concentration(grid[, weights])

Calculate concentration of elements on a provided grid

Plotting#

plot.Plot(ds)

animation.Animation(ds)

Builder for trajectory animations.

Animation methods#

Animation.color_by(variable[, cmap, vmin, ...])

Color particles by a variable or a fixed matplotlib colour.

Animation.show_trajectories([alpha])

Draw full trajectory lines as a static background.

Animation.set_fps(fps)

Set the playback speed.

Animation.set_markersize(size)

Set the particle marker size.

Animation.set_title(title)

Control the axes title.

Animation.overlay_variable(data[, cmap, ...])

Overlay an animated gridded variable as a background field.

Animation.build([blit])

Build the matplotlib.animation.FuncAnimation.

Animation.show()

Display the animation.

Animation.save(filename[, fps])

Save the animation to a file.