xarray.Dataset.traj.trajectories#

Dataset.traj.trajectories()#

Iterate over each trajectory. This returns a xr.DataArrayGroupBy.

Returns:

DataArrayGroupBy – Each group contains exactly one trajectory, allowing computations to be made indepently.

Examples

Calculate mean position of each trajectory:

>>> import xarray as xr
>>> import trajan as _
>>> import lzma
>>> b = lzma.open('examples/barents.nc.xz')
>>> ds = xr.open_dataset(b)
>>> p = ds.traj.trajectories().map(lambda t: t.mean('obs'))
>>> p
<xarray.Dataset> Size: 160B
Dimensions:        (trajectory: 2)
Dimensions without coordinates: trajectory
Data variables:
    lon            (trajectory) float64 16B 25.81 21.45
    lat            (trajectory) float64 16B 76.85 75.64
    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