LT Toolbox Tutorial: 1. Getting Started with Trajectory Frames#

Welcome to the Lagrangian Trajectories Toolbox tutorial!

The LT Toolbox is a Python library dedicated to the post-processing, visualisation and analysis of Lagrangian water parcel trajectories. The toolbox offers users two structures for working with Lagrangian trajectories: Trajectory Arrays (TrajArrays) and Trajectory Frames (TrajFrames). In this tutorial, we explore TrajFrames, which make use of Polars blazingly fast DataFrames to store column variables associated with trajectories (e.g. lat, lon, in-situ temperature etc.).

In this first tutorial, we will learn how to:

  • Store the output of an example simulation of the TRACMASS Lagrangian trajectory code in a TrajFrame object.

  • Add new variables, such as potential density recorded along-stream, to your TrajFrame.

  • Filter trajectories using any column variable contained in your TrajFrame.

  • Get existing features, including trajectory start/end times, start/end locations and durations.

  • Compute metrics, such as distance travelled and velocities from trajectories.

  • Plot trajectories and properties in the form of maps and time series.

To learn about more advanced filtering, computation and plotting with TrajFrames, users should see LT Toolbox Tutorial: 3. Advanced Analysis with Trajectory Frames.

Getting Started#

Let us begin by importing the relevant packages we’ll need to get started with the LT Toolbox.

Note: Since lt_toolbox is still undergoing unit testing, the package is not yet available on PyPi, we use pip to install a local development version.

[1]:
# Import relevant Python packages:
import xarray as xr
import numpy as np
import polars as pl

# Following pip installation as shown on the LT Toolbox github:
import lt_toolbox as ltt

Storing Trajectory Data#

To explore the functionality of the LT Toolbox, we will use example output from a Lagrangian particle tracking experiment using the eddy-rich ORCA0083-GO8p7 JRA55 ocean sea-ice hindcast (Megann et al. 2022). Trajectories were advected forwards-in-time from the full-depth northward inflows across the Overturning in the Subpolar North Atlantic (OSNAP) East array.

We have provided some example trajectory output for the January 1995 initialisation in the .parquet file format.

Below we load the output .parquet file as a DataFrame with Polars, before creating a TrajFrame, traj.

[2]:
# Defining filepath to our example ORCA0083-GO8p7 output trajectory file:
traj_filepath = "./data/ORCA0083-GO8p7_JRA55_SPNA_1995_example.parquet"

# Open output .parquet file as a DataFrame.
dataset = pl.read_parquet(traj_filepath, use_pyarrow=True)

# Create a TrajFrame from the DataFrame:
traj = ltt.TrajFrame(source=dataset, condense=True)

# Here we see how condensing a TrajFrame will store all observations in
# lists per trajectory (rows) instead of in a row per observation.
traj
[2]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'x', 'y', 'z', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (2_500, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ x          ┆ y          ┆ z          ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [3085.0,   ┆ [2888.5,   ┆ [46.5,     ┆ … ┆ [1, 4, …  ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     │
│       ┆ 3085.0, …  ┆ 2888.0, …  ┆ 46.42, …   ┆   ┆ 4]        ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    │
│       ┆ 2840.83]   ┆ 2793.0]    ┆ 48.03]     ┆   ┆           ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      │
│ 12    ┆ [3085.0,   ┆ [2888.83,  ┆ [48.83,    ┆ … ┆ [1, 4, …  ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ 3085.34, … ┆ 2888.0, …  ┆ 48.14, …   ┆   ┆ 4]        ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 2847.51]   ┆ 2797.0]    ┆ 58.28]     ┆   ┆           ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      │
│ 15    ┆ [3085.0,   ┆ [2888.12,  ┆ [49.87,    ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 3085.98, … ┆ 2888.07, … ┆ 49.0, …    ┆   ┆ 1]        ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 2844.0]    ┆ 2794.02]   ┆ 46.57]     ┆   ┆           ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      │
│ 21    ┆ [3085.0,   ┆ [2888.37,  ┆ [49.37,    ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 3085.36, … ┆ 2888.3, …  ┆ 49.0, …    ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 2842.74]   ┆ 2794.0]    ┆ 52.38]     ┆   ┆           ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      │
│ 26    ┆ [3085.0,   ┆ [2888.62,  ┆ [49.12,    ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 3085.11, … ┆ 2888.58, … ┆ 49.0, …    ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 2843.97]   ┆ 2794.0]    ┆ 50.7]      ┆   ┆           ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [3311.75,  ┆ [2865.0,   ┆ [37.75,    ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ 3311.52, … ┆ 2865.4, …  ┆ 38.0, …    ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ 2844.18]   ┆ 2795.0]    ┆ 54.49]     ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│ 28512 ┆ [3312.83,  ┆ [2864.0,   ┆ [24.5,     ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ 3312.65, … ┆ 2864.56, … ┆ 24.0, …    ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ 2840.0]    ┆ 2792.97]   ┆ 40.77]     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│ 28549 ┆ [3312.5,   ┆ [2864.0,   ┆ [35.5,     ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ 3312.0, …  ┆ 2864.52, … ┆ 35.47, …   ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ 2844.09]   ┆ 2795.0]    ┆ 47.4]      ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│ 28956 ┆ [3322.5,   ┆ [2862.0,   ┆ [11.5,     ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ 3323.0, …  ┆ 2862.47, … ┆ 11.65, …   ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ 2842.39]   ┆ 2794.0]    ┆ 48.38]     ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│ 28990 ┆ [3323.5,   ┆ [2862.0,   ┆ [18.5,     ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ 3324.0, …  ┆ 2862.27, … ┆ 18.56, …   ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ 2845.52]   ┆ 2795.0]    ┆ 49.83]     ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

What is a TrajFrame?#

At its simplest the TrajFrame, traj, is a containter for our original DataFrame accessible as an attribute with traj.data.

The columns of the DataFrame represent variables and each row represents a single Lagrangian trajectory. Yet, in constrast to our original DataFrame, each row-element of our DataFrame is now a list containing the individual values of each variable recorded along the whole trajectory.

The true value of a TrajFrame comes with the use of the built-in functions specifically designed for post-processing, visualisation and analysis of Lagrangain water parcel trajectories.

Exploring our TrajFrame#

By accessing the .data attribute of our TrajFrame above, we can see the original Polars DataFrame containing our Lagrangian trajectories.

[3]:
# To return details of our original condensed DataFrame.
traj.data
[3]:
shape: (2_500, 10)
idxyzsubvoltimeboxfacethetaosomask
i64list[f64]list[f64]list[f64]list[f64]list[f64]list[i64]list[f64]list[f64]list[f64]
1[3085.0, 3085.0, … 2840.83][2888.5, 2888.0, … 2793.0][46.5, 46.42, … 48.03][237.17, 237.17, … 237.17][0.0, 78090.8, … 7.2643e7][1, 4, … 4][4.35, 4.34, … 3.81][35.22, 35.22, … 35.16][1.0, 1.0, … 0.5]
12[3085.0, 3085.34, … 2847.51][2888.83, 2888.0, … 2797.0][48.83, 48.14, … 58.28][1208.82, 1208.82, … 1208.82][0.0, 116391.69, … 4.1395e7][1, 4, … 4][4.02, 4.01, … 2.84][35.25, 35.25, … 35.16][1.0, 1.0, … 0.5]
15[3085.0, 3085.98, … 2844.0][2888.12, 2888.07, … 2794.02][49.87, 49.0, … 46.57][1833.07, 1833.07, … 1833.07][0.0, 104679.2, … 3.5617e7][1, 6, … 1][4.0, 4.09, … 3.56][35.25, 35.25, … 35.17][1.0, 1.0, … 0.0]
21[3085.0, 3085.36, … 2842.74][2888.37, 2888.3, … 2794.0][49.37, 49.0, … 52.38][1833.07, 1833.07, … 1833.07][0.0, 44020.31, … 3.6198e7][1, 6, … 4][4.0, 4.1, … 3.35][35.25, 35.25, … 35.18][1.0, 1.0, … 0.5]
26[3085.0, 3085.11, … 2843.97][2888.62, 2888.58, … 2794.0][49.12, 49.0, … 50.7][1833.07, 1833.07, … 1833.07][0.0, 14532.79, … 8.1625e7][1, 6, … 4][4.0, 4.1, … 3.52][35.25, 35.25, … 35.19][1.0, 1.0, … 0.5]
28473[3311.75, 3311.52, … 2844.18][2865.0, 2865.4, … 2795.0][37.75, 38.0, … 54.49][2195.11, 2195.11, … 2195.11][0.0, 80378.74, … 1.1211e8][3, 5, … 4][10.22, 10.2, … 3.21][35.54, 35.54, … 35.17][1.0, 1.0, … 0.5]
28512[3312.83, 3312.65, … 2840.0][2864.0, 2864.56, … 2792.97][24.5, 24.0, … 40.77][1720.66, 1720.66, … 1720.66][0.0, 41232.2, … 8.9916e7][3, 6, … 1][10.27, 9.97, … 4.67][35.53, 35.53, … 35.11][1.0, 1.0, … 0.0]
28549[3312.5, 3312.0, … 2844.09][2864.0, 2864.52, … 2795.0][35.5, 35.47, … 47.4][2289.29, 2289.29, … 2289.29][0.0, 78200.71, … 7.8223e7][3, 2, … 4][10.26, 10.23, … 3.57][35.53, 35.53, … 35.18][1.0, 1.0, … 0.5]
28956[3322.5, 3323.0, … 2842.39][2862.0, 2862.47, … 2794.0][11.5, 11.65, … 48.38][545.0, 545.0, … 545.0][0.0, 79550.58, … 1.5925e8][3, 1, … 4][9.61, 8.72, … 3.69][35.35, 35.33, … 35.18][1.0, 1.0, … 0.5]
28990[3323.5, 3324.0, … 2845.52][2862.0, 2862.27, … 2795.0][18.5, 18.56, … 49.83][446.65, 446.65, … 446.65][0.0, 122199.1, … 6.5770e7][3, 1, … 4][9.54, 8.65, … 3.54][35.32, 35.32, … 35.19][1.0, 1.0, … 0.5]
[4]:
# To access the temperature column variable as a Polars Series.
traj.data['thetao']

[4]:
shape: (2_500,)
thetao
list[f64]
[4.35, 4.34, … 3.81]
[4.02, 4.01, … 2.84]
[4.0, 4.09, … 3.56]
[4.0, 4.1, … 3.35]
[4.0, 4.1, … 3.52]
[10.22, 10.2, … 3.21]
[10.27, 9.97, … 4.67]
[10.26, 10.23, … 3.57]
[9.61, 8.72, … 3.69]
[9.54, 8.65, … 3.54]

Transforming x,y,z variables to lon,lat,depth in a TrajFrame.#

In our example TrajFrame, we have stored the positions of each trajectory as indices referring to the original numerical model grid (eORCA12). However, we can easily transform these model coordinates to geographical coordinates using the .transform_trajectory_coords() method which uses bi-linear interpolation to determine each trajectories geographical position.

[5]:
# Importing eORCA12 ocean model grid from a NetCDF file using xarray:
ds_grid = xr.open_dataset('/home/snapdragon/HadGEM3-GC31-MM/Proj_Future_Pathways/src/Software/lt_toolbox/docs/tutorials/data/ORCA0083-GO8p7_JRA55_model_grid.nc')

ds_grid
[5]:
<xarray.Dataset> Size: 125MB
Dimensions:  (y: 3606, x: 4322, z: 75)
Dimensions without coordinates: y, x, z
Data variables:
    nav_lat  (y, x) float32 62MB ...
    nav_lon  (y, x) float32 62MB ...
    nav_lev  (z) float32 300B ...
Attributes:
    file_name:  mesh_mask.nc
    TimeStamp:  30/09/2016 08:33:26 +0000
[6]:
# Transform the TrajFrame to geographical coordinates and store as new TrajFrame object:
traj_geo = traj.transform_trajectory_coords(lon=ds_grid.nav_lon.values,
                                            lat=ds_grid.nav_lat.values,
                                            depth=ds_grid.nav_lev.values,
                                            )

traj_geo
[6]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (2_500, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [1, 4, …  ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4]        ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆           ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [1, 4, …  ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4]        ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆           ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1]        ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆           ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆           ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆           ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

Transforming time variable to datetime format in a TrajFrame.#

We can transform a time variable defined in terms of time elapsed since water parcel seeding into a datetime using the .use_datetime() method.

[7]:
# Using datetime64 format for time instead of timedelta64.
# Start date of simulation is 1995-01-01
traj_geo = traj_geo.use_datetime(start_date='1995-01-01', unit='s')

traj_geo.data['time']
[7]:
shape: (2_500,)
time
list[datetime[μs]]
[1995-01-01 00:00:00, 1995-01-01 21:41:30.800, … 1997-04-20 18:43:04.670]
[1995-01-01 00:00:00, 1995-01-02 08:19:51.690, … 1996-04-24 02:29:28.240]
[1995-01-01 00:00:00, 1995-01-02 05:04:39.200, … 1996-02-17 05:40:44.610]
[1995-01-01 00:00:00, 1995-01-01 12:13:40.310, … 1996-02-23 22:52:35.930]
[1995-01-01 00:00:00, 1995-01-01 04:02:12.790, … 1997-08-02 17:39:38.190]
[1995-01-01 00:00:00, 1995-01-01 22:19:38.740, … 1998-07-21 14:53:46.360]
[1995-01-01 00:00:00, 1995-01-01 11:27:12.200, … 1997-11-06 16:39:41.550]
[1995-01-01 00:00:00, 1995-01-01 21:43:20.710, … 1997-06-24 08:29:10.470]
[1995-01-01 00:00:00, 1995-01-01 22:05:50.580, … 2000-01-18 03:37:14.510]
[1995-01-01 00:00:00, 1995-01-02 09:56:39.100, … 1997-01-31 05:22:00.820]

Getting existing features from a TrajFrame.#

The LT Toolbox includes a range of .get_ methods to extract important features from existing attribute variables in a TrajFrame.

[8]:
# Get the times and locations when particle are released.
traj_geo.get_start_time().get_start_loc()

[8]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'start_time', 'lon_start', 'lat_start', 'depth_start']
<bound method DataFrame.glimpse of shape: (2_500, 14)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ start_tim ┆ lon_start ┆ lat_start ┆ depth_sta │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ e         ┆ ---       ┆ ---       ┆ rt        │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ ---       ┆ f64       ┆ f64       ┆ ---       │
│       ┆            ┆            ┆            ┆   ┆ datetime[ ┆           ┆           ┆ f64       │
│       ┆            ┆            ┆            ┆   ┆ μs]       ┆           ┆           ┆           │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ 1995-01-0 ┆ -30.38194 ┆ 58.799782 ┆ 1098.9227 │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 1         ┆ 3         ┆           ┆ 29        │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ 1995-01-0 ┆ -30.38292 ┆ 58.816688 ┆ 1366.7193 │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 1         ┆           ┆           ┆ 18        │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ 1995-01-0 ┆ -30.38081 ┆ 58.780314 ┆ 1499.5953 │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1         ┆ 8         ┆           ┆ 77        │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ 1995-01-0 ┆ -30.38155 ┆ 58.793122 ┆ 1435.1020 │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 1         ┆ 8         ┆           ┆ 3         │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ 1995-01-0 ┆ -30.38229 ┆ 58.80593  ┆ 1402.8553 │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 1         ┆ 8         ┆           ┆ 56        │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ 1995-01-0 ┆ -9.324242 ┆ 57.098342 ┆ 446.16767 │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 1         ┆           ┆           ┆ 1         │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ 1995-01-0 ┆ -9.235759 ┆ 57.041115 ┆ 114.01514 │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1         ┆           ┆           ┆ 1         │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ 1995-01-0 ┆ -9.266052 ┆ 57.042982 ┆ 352.27565 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1         ┆           ┆           ┆           │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ 1995-01-0 ┆ -8.371674 ┆ 56.882877 ┆ 21.093709 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1         ┆           ┆           ┆           │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ 1995-01-0 ┆ -8.280212 ┆ 56.876928 ┆ 57.481737 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1         ┆           ┆           ┆           │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 00:00:00  ┆           ┆           ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[9]:
# Get the times and locations when particles are terminated.
traj_geo.get_end_time().get_end_loc()
[9]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'end_time', 'lon_end', 'lat_end', 'depth_end']
<bound method DataFrame.glimpse of shape: (2_500, 14)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ end_time  ┆ lon_end   ┆ lat_end   ┆ depth_end │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ datetime[ ┆ f64       ┆ f64       ┆ f64       │
│       ┆            ┆            ┆            ┆   ┆ μs]       ┆           ┆           ┆           │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ 1997-04-2 ┆ -51.56379 ┆ 52.927699 ┆ 1269.5069 │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 0 18:43:0 ┆ 9         ┆           ┆ 15        │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 4.670     ┆           ┆           ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ 1996-04-2 ┆ -51.02510 ┆ 53.168843 ┆ 2826.3079 │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4 02:29:2 ┆ 9         ┆           ┆ 88        │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 8.240     ┆           ┆           ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ 1996-02-1 ┆ -51.30044 ┆ 52.997146 ┆ 1106.3523 │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 7 05:40:4 ┆ 1         ┆           ┆ 17        │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 4.610     ┆           ┆           ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ 1996-02-2 ┆ -51.40859 ┆ 52.989307 ┆ 1852.5281 │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 3 22:52:3 ┆ 7         ┆           ┆ 84        │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 5.930     ┆           ┆           ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ 1997-08-0 ┆ -51.30284 ┆ 52.995958 ┆ 1611.7070 │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 2 17:39:3 ┆ 2         ┆           ┆ 31        │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 8.190     ┆           ┆           ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ 1998-07-2 ┆ -51.29372 ┆ 53.048349 ┆ 2180.1101 │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 1 14:53:4 ┆ 4         ┆           ┆ 71        │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 6.360     ┆           ┆           ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ 1997-11-0 ┆ -51.63483 ┆ 52.921664 ┆ 613.59724 │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 6 16:39:4 ┆ 6         ┆           ┆ 9         │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 1.550     ┆           ┆           ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ 1997-06-2 ┆ -51.30146 ┆ 53.047862 ┆ 1197.5393 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4 08:29:1 ┆ 4         ┆           ┆ 07        │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 0.470     ┆           ┆           ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ 2000-01-1 ┆ -51.43866 ┆ 52.987411 ┆ 1312.0373 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8 03:37:1 ┆ 4         ┆           ┆ 41        │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 4.510     ┆           ┆           ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ 1997-01-3 ┆ -51.17850 ┆ 53.055591 ┆ 1494.4359 │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1 05:22:0 ┆ 2         ┆           ┆ 09        │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 0.820     ┆           ┆           ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[10]:
# Get the maximum value of the conservative temperature variable for each trajectory.
traj_geo.get_max('thetao')
[10]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'thetao_max']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ thetao    ┆ so        ┆ mask      ┆ thetao_ma │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ x         │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ---       │
│       ┆            ┆            ┆            ┆   ┆           ┆           ┆           ┆ f64       │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     ┆ 4.39      │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    ┆           │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     ┆ 4.13      │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 4.12      │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 4.2       │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 4.1       │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     ┆ 10.22     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    ┆           │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     ┆ 10.27     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    ┆           │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     ┆ 10.26     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    ┆           │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     ┆ 9.61      │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    ┆           │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     ┆ 9.54      │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    ┆           │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[11]:
# Get the minimum value of the conservative temperature variable for each trajectory.
traj_geo.get_min('thetao')
[11]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'thetao_min']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ thetao    ┆ so        ┆ mask      ┆ thetao_mi │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ n         │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ---       │
│       ┆            ┆            ┆            ┆   ┆           ┆           ┆           ┆ f64       │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     ┆ 3.29      │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    ┆           │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     ┆ 2.81      │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 3.48      │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 3.07      │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 3.43      │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆           │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     ┆ 2.94      │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    ┆           │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     ┆ 3.37      │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    ┆           │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     ┆ 3.31      │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    ┆           │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     ┆ 3.55      │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    ┆           │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     ┆ 3.27      │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    ┆           │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[12]:
# Get the value of the temp variable for each trajectory on 1995-06-01.
traj_geo.get_values('thetao', '1995-01-01')
[12]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'thetao_i']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬────────────┬───────────┬───────────┬──────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ thetao     ┆ so        ┆ mask      ┆ thetao_i │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---        ┆ ---       ┆ ---       ┆ ---      │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64]  ┆ list[f64] ┆ list[f64] ┆ f64      │
╞═══════╪════════════╪════════════╪════════════╪═══╪════════════╪═══════════╪═══════════╪══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [4.35,     ┆ [35.22,   ┆ [1.0,     ┆ 4.35     │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4.34, …    ┆ 35.22, …  ┆ 1.0, …    ┆          │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 3.81]      ┆ 35.16]    ┆ 0.5]      ┆          │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆            ┆           ┆           ┆          │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [4.02,     ┆ [35.25,   ┆ [1.0,     ┆ 4.02     │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4.01, …    ┆ 35.25, …  ┆ 1.0, …    ┆          │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 2.84]      ┆ 35.16]    ┆ 0.5]      ┆          │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆            ┆           ┆           ┆          │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [4.0,      ┆ [35.25,   ┆ [1.0,     ┆ 4.0      │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 4.09, …    ┆ 35.25, …  ┆ 1.0, …    ┆          │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 3.56]      ┆ 35.17]    ┆ 0.0]      ┆          │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆            ┆           ┆           ┆          │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [4.0, 4.1, ┆ [35.25,   ┆ [1.0,     ┆ 4.0      │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ … 3.35]    ┆ 35.25, …  ┆ 1.0, …    ┆          │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆            ┆ 35.18]    ┆ 0.5]      ┆          │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆            ┆           ┆           ┆          │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [4.0, 4.1, ┆ [35.25,   ┆ [1.0,     ┆ 4.0      │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ … 3.52]    ┆ 35.25, …  ┆ 1.0, …    ┆          │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆            ┆ 35.19]    ┆ 0.5]      ┆          │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆            ┆           ┆           ┆          │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …          ┆ …         ┆ …         ┆ …        │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [10.22,    ┆ [35.54,   ┆ [1.0,     ┆ 10.22    │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 10.2, …    ┆ 35.54, …  ┆ 1.0, …    ┆          │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 3.21]      ┆ 35.17]    ┆ 0.5]      ┆          │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆            ┆           ┆           ┆          │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [10.27,    ┆ [35.53,   ┆ [1.0,     ┆ 10.27    │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 9.97, …    ┆ 35.53, …  ┆ 1.0, …    ┆          │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 4.67]      ┆ 35.11]    ┆ 0.0]      ┆          │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆            ┆           ┆           ┆          │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [10.26,    ┆ [35.53,   ┆ [1.0,     ┆ 10.26    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 10.23, …   ┆ 35.53, …  ┆ 1.0, …    ┆          │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 3.57]      ┆ 35.18]    ┆ 0.5]      ┆          │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆            ┆           ┆           ┆          │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [9.61,     ┆ [35.35,   ┆ [1.0,     ┆ 9.61     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.72, …    ┆ 35.33, …  ┆ 1.0, …    ┆          │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 3.69]      ┆ 35.18]    ┆ 0.5]      ┆          │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆            ┆           ┆           ┆          │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [9.54,     ┆ [35.32,   ┆ [1.0,     ┆ 9.54     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.65, …    ┆ 35.32, …  ┆ 1.0, …    ┆          │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 3.54]      ┆ 35.19]    ┆ 0.5]      ┆          │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆            ┆           ┆           ┆          │
└───────┴────────────┴────────────┴────────────┴───┴────────────┴───────────┴───────────┴──────────┘>
[13]:
# Get the duration of each trajectory, t_total.
traj_geo.get_duration()
[13]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'dt']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ thetao    ┆ so        ┆ mask      ┆ dt        │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ duration[ │
│       ┆            ┆            ┆            ┆   ┆           ┆           ┆           ┆ μs]       │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     ┆ 840d 18h  │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    ┆ 43m 4s    │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      ┆ 670ms     │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     ┆ 479d 2h   │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    ┆ 29m 28s   │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      ┆ 240ms     │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 412d 5h   │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    ┆ 40m 44s   │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      ┆ 610ms     │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 418d 22h  │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆ 52m 35s   │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      ┆ 930ms     │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ 944d 17h  │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆ 39m 38s   │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      ┆ 190ms     │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     ┆ 1297d 14h │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    ┆ 53m 46s   │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      ┆ 360ms     │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     ┆ 1040d 16h │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    ┆ 39m 41s   │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      ┆ 550ms     │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     ┆ 905d 8h   │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    ┆ 29m 10s   │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      ┆ 470ms     │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     ┆ 1843d 3h  │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    ┆ 37m 14s   │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      ┆ 510ms     │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     ┆ 761d 5h   │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    ┆ 22m 820ms │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

Adding new attribute variables to our TrajFrame.#

To add a new attribute variable to a TrajFrame use the .add_variable() method.

There are two ways to use the .add_variable() method:

  1. Users can either provide a list of values to instantiate a new column variable.

  2. Users can define a new column variable using the polars expression syntax.

[14]:
# Consider now if we wanted to create a new attribute variable, temp_max_K,
# to store the maximum along-path temperature in Kelvin.

# OPTION 1.
# Define a list of values for the temperature .
traj_add = traj_geo.get_max('thetao')
temp_max_k = (traj_add.data['thetao_max'] + 273.15).to_list()
traj_add.add_variable(name='temp_max_K', values=temp_max_k)

[14]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'thetao_max', 'temp_max_K']
<bound method DataFrame.glimpse of shape: (2_500, 12)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ so        ┆ mask      ┆ thetao_ma ┆ temp_max_ │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ x         ┆ K         │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ ---       ┆ ---       │
│       ┆            ┆            ┆            ┆   ┆           ┆           ┆ f64       ┆ f64       │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [35.22,   ┆ [1.0,     ┆ 4.39      ┆ 277.54    │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 35.22, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 35.16]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.13      ┆ 277.28    │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 35.16]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.12      ┆ 277.27    │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 35.17]    ┆ 0.0]      ┆           ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.2       ┆ 277.35    │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.1       ┆ 277.25    │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 35.19]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [35.54,   ┆ [1.0,     ┆ 10.22     ┆ 283.37    │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 35.54, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 35.17]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [35.53,   ┆ [1.0,     ┆ 10.27     ┆ 283.42    │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 35.53, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 35.11]    ┆ 0.0]      ┆           ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [35.53,   ┆ [1.0,     ┆ 10.26     ┆ 283.41    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.53, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [35.35,   ┆ [1.0,     ┆ 9.61      ┆ 282.76    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.33, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [35.32,   ┆ [1.0,     ┆ 9.54      ┆ 282.69    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.32, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 35.19]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[15]:
# OPTION 2. Using Polars expression:
(traj_geo
 .get_max('thetao')
 .add_variable(name='temp_max_K', expr=pl.col('thetao_max') + 273.15)
 )
[15]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'thetao_max', 'temp_max_K']
<bound method DataFrame.glimpse of shape: (2_500, 12)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ so        ┆ mask      ┆ thetao_ma ┆ temp_max_ │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ x         ┆ K         │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ ---       ┆ ---       │
│       ┆            ┆            ┆            ┆   ┆           ┆           ┆ f64       ┆ f64       │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [35.22,   ┆ [1.0,     ┆ 4.39      ┆ 277.54    │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 35.22, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 35.16]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.13      ┆ 277.28    │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 35.16]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.12      ┆ 277.27    │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 35.17]    ┆ 0.0]      ┆           ┆           │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.2       ┆ 277.35    │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [35.25,   ┆ [1.0,     ┆ 4.1       ┆ 277.25    │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 35.25, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 35.19]    ┆ 0.5]      ┆           ┆           │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [35.54,   ┆ [1.0,     ┆ 10.22     ┆ 283.37    │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 35.54, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 35.17]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [35.53,   ┆ [1.0,     ┆ 10.27     ┆ 283.42    │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 35.53, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 35.11]    ┆ 0.0]      ┆           ┆           │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [35.53,   ┆ [1.0,     ┆ 10.26     ┆ 283.41    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.53, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [35.35,   ┆ [1.0,     ┆ 9.61      ┆ 282.76    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.33, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 35.18]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [35.32,   ┆ [1.0,     ┆ 9.54      ┆ 282.69    │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 35.32, …  ┆ 1.0, …    ┆           ┆           │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 35.19]    ┆ 0.5]      ┆           ┆           │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

Filtering trajectories using a column variable.#

Filtering our trajectories to include only those complete trajectories where a specific criteria is met is integral to Lagrangian analysis.

The LT Toolbox includes two primary methods .filter() and filter_isin() to allow users to filter on any attribute variable conatined in their TrajFrame.

[16]:
# OPTION 1: String Query Syntax.
# Filtering all our trajectories to include only those which are advected north of 65 N:
traj_geo.filter(expr='lat > 65', drop=False)

[16]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2196
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (2_196, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [1, 4, …  ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4]        ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆           ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [1, 4, …  ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4]        ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆           ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1]        ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆           ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆           ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 32    ┆ [-30.38075 ┆ [58.779289 ┆ [1611.7070 ┆ … ┆ [1, 1, …  ┆ [3.99,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ 9, -30.286 ┆ ,          ┆ 31, 1534.0 ┆   ┆ 4]        ┆ 4.04, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 917, …     ┆ 58.778683, ┆ 70276, …   ┆   ┆           ┆ 3.53]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.3…     ┆ … 52.9948… ┆ 131…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[17]:
# OPTION 2: Polars Expression Syntax for Lists.
(traj_geo
 .filter(
     expr=(pl.col('lat').list.eval(pl.element() > pl.lit('65').cast(pl.Float64)).list.any()),
     drop=False
     ))
[17]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2196
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (2_196, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [1, 4, …  ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4]        ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆           ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆           │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [1, 4, …  ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4]        ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆           ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆           │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1]        ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆           ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆           │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [1, 6, …  ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4]        ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆           ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆           │
│ 32    ┆ [-30.38075 ┆ [58.779289 ┆ [1611.7070 ┆ … ┆ [1, 1, …  ┆ [3.99,    ┆ [35.25,   ┆ [1.0,     │
│       ┆ 9, -30.286 ┆ ,          ┆ 31, 1534.0 ┆   ┆ 4]        ┆ 4.04, …   ┆ 35.25, …  ┆ 1.0, …    │
│       ┆ 917, …     ┆ 58.778683, ┆ 70276, …   ┆   ┆           ┆ 3.53]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.3…     ┆ … 52.9948… ┆ 131…       ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[18]:
# Filtering all of our trajectories according to the unique IDs
# contained in a given list:
traj_geo.filter_isin('id', [1, 12, 15, 21], drop=False)
[18]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 4
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (4, 10)
┌─────┬────────────┬────────────┬────────────┬───┬────────────┬────────────┬───────────┬───────────┐
│ id  ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface    ┆ thetao     ┆ so        ┆ mask      │
│ --- ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---        ┆ ---        ┆ ---       ┆ ---       │
│ i64 ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64]  ┆ list[f64]  ┆ list[f64] ┆ list[f64] │
╞═════╪════════════╪════════════╪════════════╪═══╪════════════╪════════════╪═══════════╪═══════════╡
│ 1   ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [1, 4, …   ┆ [4.35,     ┆ [35.22,   ┆ [1.0,     │
│     ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4]         ┆ 4.34, …    ┆ 35.22, …  ┆ 1.0, …    │
│     ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆            ┆ 3.81]      ┆ 35.16]    ┆ 0.5]      │
│     ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆            ┆            ┆           ┆           │
│ 12  ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [1, 4, …   ┆ [4.02,     ┆ [35.25,   ┆ [1.0,     │
│     ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4]         ┆ 4.01, …    ┆ 35.25, …  ┆ 1.0, …    │
│     ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆            ┆ 2.84]      ┆ 35.16]    ┆ 0.5]      │
│     ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆            ┆            ┆           ┆           │
│ 15  ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [1, 6, …   ┆ [4.0,      ┆ [35.25,   ┆ [1.0,     │
│     ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1]         ┆ 4.09, …    ┆ 35.25, …  ┆ 1.0, …    │
│     ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆            ┆ 3.56]      ┆ 35.17]    ┆ 0.0]      │
│     ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆            ┆            ┆           ┆           │
│ 21  ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [1, 6, …   ┆ [4.0, 4.1, ┆ [35.25,   ┆ [1.0,     │
│     ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4]         ┆ … 3.35]    ┆ 35.25, …  ┆ 1.0, …    │
│     ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆            ┆            ┆ 35.18]    ┆ 0.5]      │
│     ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆            ┆            ┆           ┆           │
└─────┴────────────┴────────────┴────────────┴───┴────────────┴────────────┴───────────┴───────────┘>

Filtering trajectories which intersect a polygon.#

[19]:
# Defining longitude and latitude coordinates of square polygon:
x_square = [-15, -5, -5, -5, -15]
y_square = [58, 61, 61, 58, 58]

# Filter trajectories to only include those which pass through the square polygon:
traj_geo.filter_polygon(xy_vars=['lon','lat'], x_poly=x_square, y_poly=y_square, drop=False)
[19]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 323
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (323, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 17470 ┆ [-23.23791 ┆ [57.964167 ┆ [44.195959 ┆ … ┆ [3, 1, …  ┆ [10.56,   ┆ [35.38,   ┆ [1.0,     │
│       ┆ 5, -23.166 ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.41, …  ┆ 1.0, …    │
│       ┆ 898, …     ┆ 57.99151,  ┆ 44.195959, ┆   ┆           ┆ 3.58]     ┆ 35.2]     ┆ 0.5]      │
│       ┆ -51.3…     ┆ …          ┆ … 1678.32… ┆   ┆           ┆           ┆           ┆           │
│       ┆            ┆ 52.99298…  ┆            ┆   ┆           ┆           ┆           ┆           │
│ 18666 ┆ [-21.31490 ┆ [57.989041 ┆ [317.37516 ┆ … ┆ [3, 1, …  ┆ [10.31,   ┆ [35.42,   ┆ [1.0,     │
│       ┆ 7, -21.298 ┆ ,          ┆ 8, 314.737 ┆   ┆ 1]        ┆ 9.94, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 514, …     ┆ 57.997077, ┆ 143, …     ┆   ┆           ┆ 3.45]     ┆ 35.18]    ┆ 0.0]      │
│       ┆ -51.1…     ┆ … 53.0832… ┆ 1512.…     ┆   ┆           ┆           ┆           ┆           │
│ 18708 ┆ [-21.25235 ┆ [57.987928 ┆ [50.531265 ┆ … ┆ [3, 1, …  ┆ [10.35,   ┆ [35.4,    ┆ [1.0,     │
│       ┆ , -21.2045 ┆ ,          ┆ ,          ┆   ┆ 1]        ┆ 9.92, …   ┆ 35.37, …  ┆ 1.0, …    │
│       ┆ 94, …      ┆ 58.003725, ┆ 50.132941, ┆   ┆           ┆ 3.13]     ┆ 35.17]    ┆ 0.0]      │
│       ┆ -50.90…    ┆ … 53.2153… ┆ … 2555.82… ┆   ┆           ┆           ┆           ┆           │
│ 18901 ┆ [-21.11512 ┆ [57.941723 ┆ [286.12194 ┆ … ┆ [1, 1, …  ┆ [10.43,   ┆ [35.41,   ┆ [1.0,     │
│       ┆ 5, -21.019 ┆ ,          ┆ 8, 283.759 ┆   ┆ 4]        ┆ 9.87, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 358, …     ┆ 57.97795,  ┆ 458, …     ┆   ┆           ┆ 3.23]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.2…     ┆ …          ┆ 2189.…     ┆   ┆           ┆           ┆           ┆           │
│       ┆            ┆ 53.05013…  ┆            ┆   ┆           ┆           ┆           ┆           │
│ 18902 ┆ [-21.11398 ┆ [57.959402 ┆ [286.12194 ┆ … ┆ [1, 3, …  ┆ [10.43,   ┆ [35.41,   ┆ [1.0,     │
│       ┆ 3, -21.048 ┆ ,          ┆ 8, 284.645 ┆   ┆ 4]        ┆ 9.92, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 845, …     ┆ 57.984223, ┆ 392, …     ┆   ┆           ┆ 3.91]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ -51.5…     ┆ … 52.9291… ┆ 1156.…     ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[20]:
# Filter trajectories to only include those which pass through the square polygon:
(traj_geo
    .filter_polygon(xy_vars=['lon','lat'], x_poly=x_square, y_poly=y_square, drop=False)
)
[20]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 323
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask']
<bound method DataFrame.glimpse of shape: (323, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ boxface   ┆ thetao    ┆ so        ┆ mask      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[i64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 17470 ┆ [-23.23791 ┆ [57.964167 ┆ [44.195959 ┆ … ┆ [3, 1, …  ┆ [10.56,   ┆ [35.38,   ┆ [1.0,     │
│       ┆ 5, -23.166 ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.41, …  ┆ 1.0, …    │
│       ┆ 898, …     ┆ 57.99151,  ┆ 44.195959, ┆   ┆           ┆ 3.58]     ┆ 35.2]     ┆ 0.5]      │
│       ┆ -51.3…     ┆ …          ┆ … 1678.32… ┆   ┆           ┆           ┆           ┆           │
│       ┆            ┆ 52.99298…  ┆            ┆   ┆           ┆           ┆           ┆           │
│ 18666 ┆ [-21.31490 ┆ [57.989041 ┆ [317.37516 ┆ … ┆ [3, 1, …  ┆ [10.31,   ┆ [35.42,   ┆ [1.0,     │
│       ┆ 7, -21.298 ┆ ,          ┆ 8, 314.737 ┆   ┆ 1]        ┆ 9.94, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 514, …     ┆ 57.997077, ┆ 143, …     ┆   ┆           ┆ 3.45]     ┆ 35.18]    ┆ 0.0]      │
│       ┆ -51.1…     ┆ … 53.0832… ┆ 1512.…     ┆   ┆           ┆           ┆           ┆           │
│ 18708 ┆ [-21.25235 ┆ [57.987928 ┆ [50.531265 ┆ … ┆ [3, 1, …  ┆ [10.35,   ┆ [35.4,    ┆ [1.0,     │
│       ┆ , -21.2045 ┆ ,          ┆ ,          ┆   ┆ 1]        ┆ 9.92, …   ┆ 35.37, …  ┆ 1.0, …    │
│       ┆ 94, …      ┆ 58.003725, ┆ 50.132941, ┆   ┆           ┆ 3.13]     ┆ 35.17]    ┆ 0.0]      │
│       ┆ -50.90…    ┆ … 53.2153… ┆ … 2555.82… ┆   ┆           ┆           ┆           ┆           │
│ 18901 ┆ [-21.11512 ┆ [57.941723 ┆ [286.12194 ┆ … ┆ [1, 1, …  ┆ [10.43,   ┆ [35.41,   ┆ [1.0,     │
│       ┆ 5, -21.019 ┆ ,          ┆ 8, 283.759 ┆   ┆ 4]        ┆ 9.87, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 358, …     ┆ 57.97795,  ┆ 458, …     ┆   ┆           ┆ 3.23]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ -51.2…     ┆ …          ┆ 2189.…     ┆   ┆           ┆           ┆           ┆           │
│       ┆            ┆ 53.05013…  ┆            ┆   ┆           ┆           ┆           ┆           │
│ 18902 ┆ [-21.11398 ┆ [57.959402 ┆ [286.12194 ┆ … ┆ [1, 3, …  ┆ [10.43,   ┆ [35.41,   ┆ [1.0,     │
│       ┆ 3, -21.048 ┆ ,          ┆ 8, 284.645 ┆   ┆ 4]        ┆ 9.92, …   ┆ 35.38, …  ┆ 1.0, …    │
│       ┆ 845, …     ┆ 57.984223, ┆ 392, …     ┆   ┆           ┆ 3.91]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ -51.5…     ┆ … 52.9291… ┆ 1156.…     ┆   ┆           ┆           ┆           ┆           │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [3, 5, …  ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 4]        ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆           ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆           │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [3, 6, …  ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1]        ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆           ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆           │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [3, 2, …  ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆           ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆           │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [3, 1, …  ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆           ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆           │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [3, 1, …  ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 4]        ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆           ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆           │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

Computing diagnostic metrics for trajectories.#

Computation is another important feature of the LT toolbox.

In particular, there are .compute methods available to compute the distance travelled by particles along their trajectories, particle displacements (zonal/meridional/vertical) and Lagrangian velocities (zonal/meridional/vertical).

Below we show how to combine filter, compute and plot methods to efficiently generate visualisations of output data.

[21]:
traj_geo.compute_distance(cum_dist=True, unit='km')
[21]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'dist']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ thetao    ┆ so        ┆ mask      ┆ dist      │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [4.35,    ┆ [35.22,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 4.34, …   ┆ 35.22, …  ┆ 1.0, …    ┆ 2.849612, │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 3.81]     ┆ 35.16]    ┆ 0.5]      ┆ … 4991.74 │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆           ┆           ┆ 1675]     │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [4.02,    ┆ [35.25,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 4.01, …   ┆ 35.25, …  ┆ 1.0, …    ┆ 5.074755, │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 2.84]     ┆ 35.16]    ┆ 0.5]      ┆ … 4453.99 │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆           ┆           ┆ 8629]     │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 4.09, …   ┆ 35.25, …  ┆ 1.0, …    ┆ 5.303854, │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 3.56]     ┆ 35.17]    ┆ 0.0]      ┆ … 4179.00 │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆           ┆           ┆ 1615]     │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆ 1.985706, │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 3.35]     ┆ 35.18]    ┆ 0.5]      ┆ … 4300.74 │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆           ┆           ┆ 3084]     │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [4.0,     ┆ [35.25,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 4.1, …    ┆ 35.25, …  ┆ 1.0, …    ┆ 0.636479, │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 3.52]     ┆ 35.19]    ┆ 0.5]      ┆ … 4256.91 │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆           ┆           ┆ 3051]     │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [10.22,   ┆ [35.54,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 10.2, …   ┆ 35.54, …  ┆ 1.0, …    ┆ 2.621375, │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 3.21]     ┆ 35.17]    ┆ 0.5]      ┆ … 8333.87 │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆           ┆           ┆ 9955]     │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [10.27,   ┆ [35.53,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 9.97, …   ┆ 35.53, …  ┆ 1.0, …    ┆ 3.356731, │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 4.67]     ┆ 35.11]    ┆ 0.0]      ┆ … 7813.79 │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆           ┆           ┆ 468]      │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [10.26,   ┆ [35.53,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 10.23, …  ┆ 35.53, …  ┆ 1.0, …    ┆ 4.080607, │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 3.57]     ┆ 35.18]    ┆ 0.5]      ┆ … 6487.44 │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆           ┆           ┆ 7868]     │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [9.61,    ┆ [35.35,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.72, …   ┆ 35.33, …  ┆ 1.0, …    ┆ 3.878721, │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 3.69]     ┆ 35.18]    ┆ 0.5]      ┆ … 7409.43 │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆           ┆           ┆ 3642]     │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [9.54,    ┆ [35.32,   ┆ [1.0,     ┆ [0.0,     │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 8.65, …   ┆ 35.32, …  ┆ 1.0, …    ┆ 3.194232, │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 3.54]     ┆ 35.19]    ┆ 0.5]      ┆ … 6896.99 │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆           ┆           ┆ 589]      │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[22]:
# Compute velocity in of water parcels in km/h:
traj_geo.compute_distance(cum_dist=False, unit='m').compute_velocity()
[22]:
<TrajFrame object>

----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'lon', 'lat', 'depth', 'subvol', 'time', 'boxface', 'thetao', 'so', 'mask', 'dist', 'direction', 'speed']
<bound method DataFrame.glimpse of shape: (2_500, 13)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id    ┆ lon        ┆ lat        ┆ depth      ┆ … ┆ mask      ┆ dist      ┆ direction ┆ speed     │
│ ---   ┆ ---        ┆ ---        ┆ ---        ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ i64   ┆ list[f64]  ┆ list[f64]  ┆ list[f64]  ┆   ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1     ┆ [-30.38194 ┆ [58.799782 ┆ [1098.9227 ┆ … ┆ [1.0,     ┆ [0.0, 284 ┆ [178.2842 ┆ [3.6491e- │
│       ┆ 3, -30.380 ┆ ,          ┆ 29, 1090.4 ┆   ┆ 1.0, …    ┆ 9.611641, ┆ 49, 178.2 ┆ 8, 5.7515 │
│       ┆ 463, …     ┆ 58.774166, ┆ 31772, …   ┆   ┆ 0.5]      ┆ … 6392.23 ┆ 67656, …  ┆ e-8, …    │
│       ┆ -51.5…     ┆ … 52.9276… ┆ 126…       ┆   ┆           ┆ 554]      ┆ null]     ┆ null]     │
│ 12    ┆ [-30.38292 ┆ [58.816688 ┆ [1366.7193 ┆ … ┆ [1.0,     ┆ [0.0, 507 ┆ [157.0543 ┆ [4.3601e- │
│       ┆ , -30.3485 ┆ ,          ┆ 18, 1282.8 ┆   ┆ 1.0, …    ┆ 4.755019, ┆ 16, 178.8 ┆ 8, 5.6856 │
│       ┆ 98, …      ┆ 58.774656, ┆ 73621, …   ┆   ┆ 0.5]      ┆ … 5788.67 ┆ 1487, …   ┆ e-8, …    │
│       ┆ -51.02…    ┆ … 53.1688… ┆ 282…       ┆   ┆           ┆ 5377…     ┆ null]     ┆ null]     │
│ 15    ┆ [-30.38081 ┆ [58.780314 ┆ [1499.5953 ┆ … ┆ [1.0,     ┆ [0.0, 530 ┆ [91.33937 ┆ [5.0668e- │
│       ┆ 8, -30.288 ┆ ,          ┆ 77, 1387.3 ┆   ┆ 1.0, …    ┆ 3.854406, ┆ 6, 157.54 ┆ 8, 5.8513 │
│       ┆ 821, …     ┆ 58.779166, ┆ 76953, …   ┆   ┆ 0.0]      ┆ … 6141.35 ┆ 8076, …   ┆ e-8, …    │
│       ┆ -51.3…     ┆ … 52.9971… ┆ 110…       ┆   ┆           ┆ 2623…     ┆ null]     ┆ null]     │
│ 21    ┆ [-30.38155 ┆ [58.793122 ┆ [1435.1020 ┆ … ┆ [1.0,     ┆ [0.0, 198 ┆ [99.87104 ┆ [4.5109e- │
│       ┆ 8, -30.347 ┆ ,          ┆ 3, 1387.37 ┆   ┆ 1.0, …    ┆ 5.706058, ┆ 2, 160.75 ┆ 8, 5.3642 │
│       ┆ 605, …     ┆ 58.790056, ┆ 6953, …    ┆   ┆ 0.5]      ┆ … 6154.45 ┆ 5952, …   ┆ e-8, …    │
│       ┆ -51.4…     ┆ … 52.9893… ┆ 1852…      ┆   ┆           ┆ 2063…     ┆ null]     ┆ null]     │
│ 26    ┆ [-30.38229 ┆ [58.80593, ┆ [1402.8553 ┆ … ┆ [1.0,     ┆ [0.0, 636 ┆ [109.2748 ┆ [4.3796e- │
│       ┆ 8, -30.371 ┆ 58.80404,  ┆ 56, 1387.3 ┆   ┆ 1.0, …    ┆ .479079,  ┆ 35, 159.3 ┆ 8, 4.8727 │
│       ┆ 867, …     ┆ …          ┆ 76953, …   ┆   ┆ 0.5]      ┆ … 6223.45 ┆ 38217, …  ┆ e-8, …    │
│       ┆ -51.3…     ┆ 52.995958… ┆ 161…       ┆   ┆           ┆ 8116]     ┆ null]     ┆ null]     │
│ …     ┆ …          ┆ …          ┆ …          ┆ … ┆ …         ┆ …         ┆ …         ┆ …         │
│ 28473 ┆ [-9.324242 ┆ [57.098342 ┆ [446.16767 ┆ … ┆ [1.0,     ┆ [0.0, 262 ┆ [-22.7812 ┆ [3.2613e- │
│       ┆ ,          ┆ ,          ┆ 1,         ┆   ┆ 1.0, …    ┆ 1.374792, ┆ 27, -61.0 ┆ 8, 3.8570 │
│       ┆ -9.341056, ┆ 57.120076, ┆ 457.62561, ┆   ┆ 0.5]      ┆ … 2885.76 ┆ 18354, …  ┆ e-8, …    │
│       ┆ … -51.293… ┆ … 53.0483… ┆ … 2180.1…  ┆   ┆           ┆ 1444…     ┆ null]     ┆ null]     │
│ 28512 ┆ [-9.235759 ┆ [57.041115 ┆ [114.01514 ┆ … ┆ [1.0,     ┆ [0.0, 335 ┆ [-10.9376 ┆ [8.1410e- │
│       ┆ ,          ┆ ,          ┆ 1, 108.030 ┆   ┆ 1.0, …    ┆ 6.730944, ┆ 82, -11.9 ┆ 8, 8.0141 │
│       ┆ -9.246296, ┆ 57.070754, ┆ 281, …     ┆   ┆ 0.0]      ┆ … 207.180 ┆ 27438, …  ┆ e-8, …    │
│       ┆ … -51.634… ┆ … 52.9216… ┆ 613.5…     ┆   ┆           ┆ 391]      ┆ null]     ┆ null]     │
│ 28549 ┆ [-9.266052 ┆ [57.042982 ┆ [352.27565 ┆ … ┆ [1.0,     ┆ [0.0, 408 ┆ [-36.7143 ┆ [5.2181e- │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1.0, …    ┆ 0.606819, ┆ 89, -5.02 ┆ 8, 6.0189 │
│       ┆ -9.306412, ┆ 57.072393, ┆ 351.17088, ┆   ┆ 0.5]      ┆ … 1416.25 ┆ 6343, …   ┆ e-8, …    │
│       ┆ … -51.301… ┆ … 53.0478… ┆ … 1197.53… ┆   ┆           ┆ 7441…     ┆ null]     ┆ null]     │
│ 28956 ┆ [-8.371674 ┆ [56.882877 ┆ [21.093709 ┆ … ┆ [1.0,     ┆ [0.0, 387 ┆ [52.94505 ┆ [4.8758e- │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1.0, …    ┆ 8.721142, ┆ 6, 60.957 ┆ 8, 3.4927 │
│       ┆ -8.320692, ┆ 56.903886, ┆ 21.592881, ┆   ┆ 0.5]      ┆ … 5573.29 ┆ 532, …    ┆ e-8, …    │
│       ┆ … -51.438… ┆ … 52.9874… ┆ … 1312.03… ┆   ┆           ┆ 7087…     ┆ null]     ┆ null]     │
│ 28990 ┆ [-8.280212 ┆ [56.876928 ┆ [57.481737 ┆ … ┆ [1.0,     ┆ [0.0, 319 ┆ [67.92673 ┆ [2.6140e- │
│       ┆ ,          ┆ ,          ┆ ,          ┆   ┆ 1.0, …    ┆ 4.232016, ┆ 2, 84.146 ┆ 8, 1.7682 │
│       ┆ -8.231481, ┆ 56.887714, ┆ 57.917469, ┆   ┆ 0.5]      ┆ … 6221.43 ┆ 086, …    ┆ e-8, …    │
│       ┆ … -51.178… ┆ … 53.0555… ┆ … 1494.43… ┆   ┆           ┆ 4117…     ┆ null]     ┆ null]     │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>

Plotting Lagrangian trajectories and properties.#

Now we know how to compute diagnostics along our trajectories, so next we need to learn how to visualise our Lagrangian trajectories interactively.

[23]:
# Plotting a sample of Lagrangian trajectories which intersect a given square polygon,
# including hover data for trajectory ID, longitude, latitude, conservative temperature:
(traj_geo
    .filter_polygon(xy_vars=['lon','lat'], x_poly=x_square, y_poly=y_square, drop=False)
    .plot_trajectories(sample_size=10,
                       projection='orthographic',
                       hover_data=['id', 'lon', 'lat', 'thetao', 'so', 'depth'],
                       width=6E2,
                       height=6E2
                       )
)
[24]:
# Plotting a timeseries of the conservative temperature variable for a sample of trajectories
# which intersect a given square polygon:
(traj_geo
    .filter_polygon(xy_vars=['lon','lat'], x_poly=x_square, y_poly=y_square, drop=False)
    .plot_timeseries(var='thetao',
                     sample_size=10,
                     width=7E2,
                     height=7E2,
                     )
)