Note
Go to the end to download the full example code.
Analysing a drifter dataset#
import numpy as np
import lzma
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import xarray as xr
import trajan as ta
Importing a dataset with two drifters in the Barents Sea
This follows the CF convention for trajectories https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html#_multidimensional_array_representation_of_trajectories
print(ds)
<xarray.Dataset> Size: 110kB
Dimensions: (trajectory: 2, obs: 2287)
Dimensions without coordinates: trajectory, obs
Data variables:
lon (trajectory, obs) float64 37kB 29.85 29.83 ... 21.14 21.15
lat (trajectory, obs) float64 37kB 77.3 77.31 ... 74.58 74.58
time (trajectory, obs) datetime64[ns] 37kB 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
A basic plot can be made very simply with Trajan

2026-07-06 13:48:27 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:27 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:27 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:27 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:27 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:27 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
Cropping to a smaller geographical area

2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG trajectory_id is drifter_names, but dimensions have other names: {str(list(trajectory_var.sizes))}
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG No trajectory_id attribute/variable found, trying to identify by name.
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:28 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
The figure can be customized, combining functionality from Trajan, Xarray and Matplotlib
ds.isel(trajectory=1).traj.plot(color='b', label=ds.trajectory[1].values,
land='mask', margin=3)
ds.isel(trajectory=0).traj.plot(color='r', label=ds.trajectory[0].values)
plt.legend()
plt.title('Two drifters in the Barents Sea')
plt.show()

2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Single trajectory, a trajectory dimension will be added
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Using trajectory_id variable name (drifter_names) as trajectory dimension name
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:28 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:28 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:28 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Single trajectory, a trajectory dimension will be added
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Using trajectory_id variable name (drifter_names) as trajectory dimension name
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:29 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:29 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.plot[4354] DEBUG Axes already exist on existing figure.
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:29 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
Trajan includes methods to e.g. calculate the speed of the drifters
Max speed 1008.360274201437 m/s
We see that the max speed > 1000 m/s, which is a numerical error due to some cases with GPS positions reported with very small time interval. By removing all positions where time interval < 5 min, we avoid this problem.
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
Max speed 1.2873047098224348 m/s
Likewise, one can insert breaks (NaN) in the trajectories whenever the time between points exceed a desired threshold, e.g. 3 hours
ds = ds.traj.insert_nan_where(ds.traj.time_to_next()>np.timedelta64(3, 'h'))
Plotting trajectories colored by drifter speed

2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:30 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:30 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:30 runnervmkkn4f trajan.plot[4354] DEBUG Plotting trajectory 0 of 2 with color
2026-07-06 13:48:30 runnervmkkn4f trajan.plot[4354] DEBUG Plotting trajectory 1 of 2 with color
2026-07-06 13:48:31 runnervmkkn4f matplotlib.colorbar[4354] DEBUG locator: <matplotlib.ticker.AutoLocator object at 0x7ff44ed8ff50>
Histogram of drifter speeds.
speed = ds.traj.speed()
plt.hist(speed.values[~np.isnan(speed.values)], 100)
plt.xlabel('Drifter speed [m/s]')
plt.ylabel('Number')
plt.show()

The peak at speed=0m/s is from the period where one of the drifters are on land (Hopen island). This can be removed simply:
speed = speed.where(speed>0.01)
plt.hist(speed.values[~np.isnan(speed.values)], 100)
plt.xlabel('Drifter speed [m/s]')
plt.ylabel('Number')
plt.show()

The positions of GPS based drifters are normally given at slightly irregular time intervals, as drifters may be without GPS coverage for periods, and may get GPX fixes irregularly. TrajAn contains the method gridtime to interpolate positions to a regular time intervel, e.g. hourly:
dh = ds.traj.gridtime('1h')
ds.traj.plot(color='r', label='raw data', land='mask')
dh.traj.plot(color='b', label='hourly')
plt.gca().set_extent([23.8, 25.0, 76.8, 77], crs=ccrs.PlateCarree()) # Zooming in to highliht differences
plt.legend()
plt.show()

2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:31 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:31 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:31 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Axes already exist on existing figure.
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
Having the dataset on a regular time interval makes it simpler to compare with e.g. drift models, and also makes some analyses simpler
dh.isel(trajectory=0).traj.plot(color='r', label='Full trajectory')
dh.isel(trajectory=0).sel(time=slice('2022-10-10', '2022-10-12')).traj.plot(
color='k', linewidth=2, label='10-12 Oct 2022')
plt.legend()
plt.show()

2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Single trajectory, a trajectory dimension will be added
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Using trajectory_id variable name (drifter_names) as trajectory dimension name
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Single trajectory, a trajectory dimension will be added
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Using trajectory_id variable name (drifter_names) as trajectory dimension name
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG Setting up new plot object.
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Plotting lines
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:32 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.plot[4354] DEBUG Axes already exist on existing figure.
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:32 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
The original dataset had two dimensions (trajectory, obs) (see top of page), and time is a 2D variable. For the gridded dataset (as with datasets imported from some trajectory models), dimensions are (trajectory, time) and time is a 1D Xarray dimension coordinate
print(dh)
<xarray.Dataset> Size: 46kB
Dimensions: (trajectory: 2, time: 1143)
Coordinates:
* time (time) datetime64[ns] 9kB 2022-10-07 ... 2022-11-23T14:00:00
* trajectory (trajectory) int64 16B 0 1
Data variables:
lon (trajectory, time) float64 18kB nan 29.82 29.77 ... 21.14 nan
lat (trajectory, time) float64 18kB nan 77.31 77.31 ... 74.58 nan
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
Plotting the velocity spectrum for one drifter

2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Single trajectory, a trajectory dimension will be added
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Using trajectory_id variable name (drifter_names) as trajectory dimension name
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
Do a basic animation of the drift of the drifters
ds.traj.animate().show()

2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.plot[4354] DEBUG Creating new figure and axes..
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting time-variable for "obs"..
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: obs, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Ragged trajectory dataset
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:33 runnervmkkn4f trajan.animation[4354] DEBUG Gridded dataset to 0 days 00:30:00
2026-07-06 13:48:33 runnervmkkn4f trajan.animation[4354] DEBUG Building animation: 2285 frames
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detecting trajectory dimension
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected obs-dim: time, detected time-variable: time.
2026-07-06 13:48:33 runnervmkkn4f trajan.accessor[4354] DEBUG Detected Orthogonal trajectory dataset
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2026-07-06 13:48:33 runnervmkkn4f trajan.traj[4354] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..