LT Toolbox Tutorial: 4. Ocean Parcels output 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 continue exploring 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 tutorial, we will learn how to:
Store Lagrangian trajectory output from Ocean Parcels (variables are contained in an NCEI compliant 2-dimensional array stored in netCDF file or .zarr store) in an eager TrajFrame using xarray.
Convert larger-than-memory Ocean Parcels .zarr output to a multifile .parquet store which can be used as the source for a lazy TrajFrame.
To learn about the basics of working with TrajFrames, including simple filtering and using datetimes, users should see LT Toolbox Tutorial: 2. Getting Started 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 typical output format of the OceanParcels Python package in .nc file format. Users should note that OceanParcels now outputs Lagrangian trajectory data to .zarr stores by default, however we use a .nc file here to make the example data more accessible via GitHub. The underlying data structure conntaining Lagrangian trajectory data is the same as if stored in the .zarr file format.
Below we load the output .zarr file as a DataSet with xarray, before creating a TrajFrame, traj. Note, that behind the scenes the trajectory data will be transformed from regular 2-dimensional arrays with dimensions {trajectory, obs} to a condensed tabular format where the attribute variables recorded along each trajectory are stored in lists of variable lengths.
[2]:
# Defining filepath to our example ORCA0083-GO8p7 output trajectory file:
traj_filepath = "./data/ORCA0083-GO8p7_JRA55_SPNA_1995_example.nc"
# Open output .nc file as a DataSet.
dataset = xr.open_dataset(traj_filepath)
# Let's have a look at our original dataset:
dataset
[2]:
<xarray.Dataset> Size: 701MB
Dimensions: (trajectory: 2500, obs: 3895)
Coordinates:
* obs (obs) int32 16kB 1 2 3 4 5 6 7 ... 3890 3891 3892 3893 3894 3895
* trajectory (trajectory) int64 20kB 1 12 15 21 ... 28512 28549 28956 28990
Data variables:
boxface (trajectory, obs) float64 78MB ...
mask (trajectory, obs) float64 78MB ...
so (trajectory, obs) float64 78MB ...
subvol (trajectory, obs) float64 78MB ...
thetao (trajectory, obs) float64 78MB ...
time (trajectory, obs) float64 78MB ...
x (trajectory, obs) float64 78MB ...
y (trajectory, obs) float64 78MB ...
z (trajectory, obs) float64 78MB ...
Attributes:
description: Example Lagrangian trajectory dataset including a example w...
title: ORCA0083-GO8p7_JRA55_SPNA_1995_example[3]:
# Create a TrajFrame from the DataSet:
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
[3]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'x', 'y', 'z']
<bound method DataFrame.glimpse of shape: (2_500, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ x ┆ y ┆ z │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [0.0, ┆ [3085.0, ┆ [2888.5, ┆ [46.5, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 78090.8, ┆ 3085.0, … ┆ 2888.0, … ┆ 46.42, … │
│ ┆ ┆ ┆ 35.16] ┆ ┆ … ┆ 2840.83] ┆ 2793.0] ┆ 48.03] │
│ ┆ ┆ ┆ ┆ ┆ 7.2643e7] ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, 116 ┆ [3085.0, ┆ [2888.83, ┆ [48.83, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 391.69, … ┆ 3085.34, ┆ 2888.0, … ┆ 48.14, … │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 4.1395e7] ┆ … ┆ 2797.0] ┆ 58.28] │
│ ┆ ┆ ┆ ┆ ┆ ┆ 2847.51] ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [3085.0, ┆ [2888.12, ┆ [49.87, │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 104679.2, ┆ 3085.98, ┆ 2888.07, ┆ 49.0, … │
│ ┆ ┆ ┆ 35.17] ┆ ┆ … ┆ … 2844.0] ┆ … ┆ 46.57] │
│ ┆ ┆ ┆ ┆ ┆ 3.5617e7] ┆ ┆ 2794.02] ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [3085.0, ┆ [2888.37, ┆ [49.37, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 44020.31, ┆ 3085.36, ┆ 2888.3, … ┆ 49.0, … │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ … ┆ 2794.0] ┆ 52.38] │
│ ┆ ┆ ┆ ┆ ┆ 3.6198e7] ┆ 2842.74] ┆ ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [3085.0, ┆ [2888.62, ┆ [49.12, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 14532.79, ┆ 3085.11, ┆ 2888.58, ┆ 49.0, … │
│ ┆ ┆ ┆ 35.19] ┆ ┆ … ┆ … ┆ … 2794.0] ┆ 50.7] │
│ ┆ ┆ ┆ ┆ ┆ 8.1625e7] ┆ 2843.97] ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [0.0, ┆ [3311.75, ┆ [2865.0, ┆ [37.75, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 80378.74, ┆ 3311.52, ┆ 2865.4, … ┆ 38.0, … │
│ ┆ ┆ ┆ 35.17] ┆ ┆ … ┆ … ┆ 2795.0] ┆ 54.49] │
│ ┆ ┆ ┆ ┆ ┆ 1.1211e8] ┆ 2844.18] ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [0.0, ┆ [3312.83, ┆ [2864.0, ┆ [24.5, │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 41232.2, ┆ 3312.65, ┆ 2864.56, ┆ 24.0, … │
│ ┆ ┆ ┆ 35.11] ┆ ┆ … ┆ … 2840.0] ┆ … ┆ 40.77] │
│ ┆ ┆ ┆ ┆ ┆ 8.9916e7] ┆ ┆ 2792.97] ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [0.0, ┆ [3312.5, ┆ [2864.0, ┆ [35.5, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 78200.71, ┆ 3312.0, … ┆ 2864.52, ┆ 35.47, … │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ 2844.09] ┆ … 2795.0] ┆ 47.4] │
│ ┆ ┆ ┆ ┆ ┆ 7.8223e7] ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [0.0, ┆ [3322.5, ┆ [2862.0, ┆ [11.5, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 79550.58, ┆ 3323.0, … ┆ 2862.47, ┆ 11.65, … │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ 2842.39] ┆ … 2794.0] ┆ 48.38] │
│ ┆ ┆ ┆ ┆ ┆ 1.5925e8] ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [0.0, ┆ [3323.5, ┆ [2862.0, ┆ [18.5, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 122199.1, ┆ 3324.0, … ┆ 2862.27, ┆ 18.56, … │
│ ┆ ┆ ┆ 35.19] ┆ ┆ … ┆ 2845.52] ┆ … 2795.0] ┆ 49.83] │
│ ┆ ┆ ┆ ┆ ┆ 6.5770e7] ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
What is a TrajFrame?#
At its simplest the TrajFrame, traj, is a containter for our original xarray DataSet (now transformed to a Polars 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.
[4]:
# To return details of our original condensed DataFrame.
traj.data
[4]:
| id | boxface | mask | so | subvol | thetao | time | x | y | z |
|---|---|---|---|---|---|---|---|---|---|
| i64 | list[f64] | list[f64] | list[f64] | list[f64] | list[f64] | list[f64] | list[f64] | list[f64] | list[f64] |
| 1 | [1.0, 4.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.22, 35.22, … 35.16] | [237.17, 237.17, … 237.17] | [4.35, 4.34, … 3.81] | [0.0, 78090.8, … 7.2643e7] | [3085.0, 3085.0, … 2840.83] | [2888.5, 2888.0, … 2793.0] | [46.5, 46.42, … 48.03] |
| 12 | [1.0, 4.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.25, 35.25, … 35.16] | [1208.82, 1208.82, … 1208.82] | [4.02, 4.01, … 2.84] | [0.0, 116391.69, … 4.1395e7] | [3085.0, 3085.34, … 2847.51] | [2888.83, 2888.0, … 2797.0] | [48.83, 48.14, … 58.28] |
| 15 | [1.0, 6.0, … 1.0] | [1.0, 1.0, … 0.0] | [35.25, 35.25, … 35.17] | [1833.07, 1833.07, … 1833.07] | [4.0, 4.09, … 3.56] | [0.0, 104679.2, … 3.5617e7] | [3085.0, 3085.98, … 2844.0] | [2888.12, 2888.07, … 2794.02] | [49.87, 49.0, … 46.57] |
| 21 | [1.0, 6.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.25, 35.25, … 35.18] | [1833.07, 1833.07, … 1833.07] | [4.0, 4.1, … 3.35] | [0.0, 44020.31, … 3.6198e7] | [3085.0, 3085.36, … 2842.74] | [2888.37, 2888.3, … 2794.0] | [49.37, 49.0, … 52.38] |
| 26 | [1.0, 6.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.25, 35.25, … 35.19] | [1833.07, 1833.07, … 1833.07] | [4.0, 4.1, … 3.52] | [0.0, 14532.79, … 8.1625e7] | [3085.0, 3085.11, … 2843.97] | [2888.62, 2888.58, … 2794.0] | [49.12, 49.0, … 50.7] |
| … | … | … | … | … | … | … | … | … | … |
| 28473 | [3.0, 5.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.54, 35.54, … 35.17] | [2195.11, 2195.11, … 2195.11] | [10.22, 10.2, … 3.21] | [0.0, 80378.74, … 1.1211e8] | [3311.75, 3311.52, … 2844.18] | [2865.0, 2865.4, … 2795.0] | [37.75, 38.0, … 54.49] |
| 28512 | [3.0, 6.0, … 1.0] | [1.0, 1.0, … 0.0] | [35.53, 35.53, … 35.11] | [1720.66, 1720.66, … 1720.66] | [10.27, 9.97, … 4.67] | [0.0, 41232.2, … 8.9916e7] | [3312.83, 3312.65, … 2840.0] | [2864.0, 2864.56, … 2792.97] | [24.5, 24.0, … 40.77] |
| 28549 | [3.0, 2.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.53, 35.53, … 35.18] | [2289.29, 2289.29, … 2289.29] | [10.26, 10.23, … 3.57] | [0.0, 78200.71, … 7.8223e7] | [3312.5, 3312.0, … 2844.09] | [2864.0, 2864.52, … 2795.0] | [35.5, 35.47, … 47.4] |
| 28956 | [3.0, 1.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.35, 35.33, … 35.18] | [545.0, 545.0, … 545.0] | [9.61, 8.72, … 3.69] | [0.0, 79550.58, … 1.5925e8] | [3322.5, 3323.0, … 2842.39] | [2862.0, 2862.47, … 2794.0] | [11.5, 11.65, … 48.38] |
| 28990 | [3.0, 1.0, … 4.0] | [1.0, 1.0, … 0.5] | [35.32, 35.32, … 35.19] | [446.65, 446.65, … 446.65] | [9.54, 8.65, … 3.54] | [0.0, 122199.1, … 6.5770e7] | [3323.5, 3324.0, … 2845.52] | [2862.0, 2862.27, … 2795.0] | [18.5, 18.56, … 49.83] |
[5]:
# To access the temperature column variable as a Polars Series.
traj.data['thetao']
[5]:
| 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.
[6]:
# 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
[6]:
<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[7]:
# 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
[7]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (2_500, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [0.0, ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 78090.8, ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ … ┆ 80463, … ┆ 166, … ┆ .431772, │
│ ┆ ┆ ┆ ┆ ┆ 7.2643e7] ┆ -51.5… ┆ 52.9276… ┆ … 126… │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, 116 ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 391.69, … ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 4.1395e7] ┆ 8598, … ┆ 656, … ┆ .873621, │
│ ┆ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 104679.2, ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ … ┆ 88821, … ┆ 166, … ┆ .376953, │
│ ┆ ┆ ┆ ┆ ┆ 3.5617e7] ┆ -51.3… ┆ 52.9971… ┆ … 110… │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 44020.31, ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ 47605, … ┆ 056, … ┆ 376953, … │
│ ┆ ┆ ┆ ┆ ┆ 3.6198e7] ┆ -51.4… ┆ 52.9893… ┆ 1852… │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [0.0, ┆ [-30.3822 ┆ [58.80593 ┆ [1402.855 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 14532.79, ┆ 98, -30.3 ┆ , ┆ 356, 1387 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ … ┆ 71867, … ┆ 58.80404, ┆ .376953, │
│ ┆ ┆ ┆ ┆ ┆ 8.1625e7] ┆ -51.3… ┆ … 52.9959 ┆ … 161… │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [0.0, ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 80378.74, ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ … ┆ 056, … ┆ 076, … ┆ 2561, … │
│ ┆ ┆ ┆ ┆ ┆ 1.1211e8] ┆ -51.293… ┆ 53.0483… ┆ 2180.1… │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [0.0, ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 41232.2, ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ … ┆ 296, … ┆ 754, … ┆ 30281, … │
│ ┆ ┆ ┆ ┆ ┆ 8.9916e7] ┆ -51.634… ┆ 52.9216… ┆ 613.5… │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [0.0, ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 78200.71, ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ 412, … ┆ 393, … ┆ 088, … │
│ ┆ ┆ ┆ ┆ ┆ 7.8223e7] ┆ -51.301… ┆ 53.0478… ┆ 1197.53… │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [0.0, ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 79550.58, ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ … ┆ 692, … ┆ 886, … ┆ 881, … │
│ ┆ ┆ ┆ ┆ ┆ 1.5925e8] ┆ -51.438… ┆ 52.9874… ┆ 1312.03… │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [0.0, ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 122199.1, ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ … ┆ 481, … ┆ 714, … ┆ 469, … │
│ ┆ ┆ ┆ ┆ ┆ 6.5770e7] ┆ -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.
[8]:
# 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']
[8]:
| 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.
[9]:
# Get the times and locations when particle are released.
traj_geo.get_start_time().get_start_loc()
[9]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'start_time', 'lon_start', 'lat_start', 'depth_start']
<bound method DataFrame.glimpse of shape: (2_500, 14)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ start_tim ┆ lon_start ┆ lat_start ┆ depth_sta │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ e ┆ --- ┆ --- ┆ rt │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ --- ┆ f64 ┆ f64 ┆ --- │
│ ┆ ┆ ┆ ┆ ┆ datetime[ ┆ ┆ ┆ f64 │
│ ┆ ┆ ┆ ┆ ┆ μs] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ 1995-01-0 ┆ -30.38194 ┆ 58.799782 ┆ 1098.9227 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 1 ┆ 3 ┆ ┆ 29 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1995-01-0 ┆ -30.38292 ┆ 58.816688 ┆ 1366.7193 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 1 ┆ ┆ ┆ 18 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1995-01-0 ┆ -30.38081 ┆ 58.780314 ┆ 1499.5953 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 1 ┆ 8 ┆ ┆ 77 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1995-01-0 ┆ -30.38155 ┆ 58.793122 ┆ 1435.1020 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 1 ┆ 8 ┆ ┆ 3 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1995-01-0 ┆ -30.38229 ┆ 58.80593 ┆ 1402.8553 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 1 ┆ 8 ┆ ┆ 56 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ 1995-01-0 ┆ -9.324242 ┆ 57.098342 ┆ 446.16767 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 1 ┆ ┆ ┆ 1 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ 1995-01-0 ┆ -9.235759 ┆ 57.041115 ┆ 114.01514 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 1 ┆ ┆ ┆ 1 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ 1995-01-0 ┆ -9.266052 ┆ 57.042982 ┆ 352.27565 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 1 ┆ ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ 1995-01-0 ┆ -8.371674 ┆ 56.882877 ┆ 21.093709 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 1 ┆ ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ 1995-01-0 ┆ -8.280212 ┆ 56.876928 ┆ 57.481737 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 1 ┆ ┆ ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00 ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[10]:
# Get the times and locations when particles are terminated.
traj_geo.get_end_time().get_end_loc()
[10]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'end_time', 'lon_end', 'lat_end', 'depth_end']
<bound method DataFrame.glimpse of shape: (2_500, 14)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ end_time ┆ lon_end ┆ lat_end ┆ depth_end │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ datetime[ ┆ f64 ┆ f64 ┆ f64 │
│ ┆ ┆ ┆ ┆ ┆ μs] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ 1997-04-2 ┆ -51.56379 ┆ 52.927699 ┆ 1269.5069 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 0 18:43:0 ┆ 9 ┆ ┆ 15 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 4.670 ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1996-04-2 ┆ -51.02510 ┆ 53.168843 ┆ 2826.3079 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 4 02:29:2 ┆ 9 ┆ ┆ 88 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 8.240 ┆ ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1996-02-1 ┆ -51.30044 ┆ 52.997146 ┆ 1106.3523 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 7 05:40:4 ┆ 1 ┆ ┆ 17 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 4.610 ┆ ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1996-02-2 ┆ -51.40859 ┆ 52.989307 ┆ 1852.5281 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 3 22:52:3 ┆ 7 ┆ ┆ 84 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 5.930 ┆ ┆ ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ 1997-08-0 ┆ -51.30284 ┆ 52.995958 ┆ 1611.7070 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2 17:39:3 ┆ 2 ┆ ┆ 31 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 8.190 ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ 1998-07-2 ┆ -51.29372 ┆ 53.048349 ┆ 2180.1101 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 1 14:53:4 ┆ 4 ┆ ┆ 71 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 6.360 ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ 1997-11-0 ┆ -51.63483 ┆ 52.921664 ┆ 613.59724 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 6 16:39:4 ┆ 6 ┆ ┆ 9 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 1.550 ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ 1997-06-2 ┆ -51.30146 ┆ 53.047862 ┆ 1197.5393 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 4 08:29:1 ┆ 4 ┆ ┆ 07 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 0.470 ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ 2000-01-1 ┆ -51.43866 ┆ 52.987411 ┆ 1312.0373 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 8 03:37:1 ┆ 4 ┆ ┆ 41 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 4.510 ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ 1997-01-3 ┆ -51.17850 ┆ 53.055591 ┆ 1494.4359 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 1 05:22:0 ┆ 2 ┆ ┆ 09 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 0.820 ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[11]:
# Get the maximum value of the conservative temperature variable for each trajectory.
traj_geo.get_max('thetao')
[11]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'thetao_max']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lon ┆ lat ┆ depth ┆ thetao_ma │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ x │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ --- │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ f64 │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 ┆ 4.39 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 80463, … ┆ 166, … ┆ .431772, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.5… ┆ 52.9276… ┆ … 126… ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 ┆ 4.13 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 8598, … ┆ 656, … ┆ .873621, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 ┆ 4.12 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 88821, … ┆ 166, … ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ 52.9971… ┆ … 110… ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 ┆ 4.2 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 47605, … ┆ 056, … ┆ 376953, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.4… ┆ 52.9893… ┆ 1852… ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3822 ┆ [58.80593 ┆ [1402.855 ┆ 4.1 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 98, -30.3 ┆ , ┆ 356, 1387 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 71867, … ┆ 58.80404, ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ … 52.9959 ┆ … 161… ┆ │
│ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 ┆ 10.22 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 056, … ┆ 076, … ┆ 2561, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.293… ┆ 53.0483… ┆ 2180.1… ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 ┆ 10.27 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 ┆ │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 296, … ┆ 754, … ┆ 30281, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.634… ┆ 52.9216… ┆ 613.5… ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 ┆ 10.26 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 412, … ┆ 393, … ┆ 088, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.301… ┆ 53.0478… ┆ 1197.53… ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 ┆ 9.61 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 692, … ┆ 886, … ┆ 881, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.438… ┆ 52.9874… ┆ 1312.03… ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 ┆ 9.54 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 481, … ┆ 714, … ┆ 469, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.178… ┆ 53.0555… ┆ 1494.43… ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[12]:
# Get the minimum value of the conservative temperature variable for each trajectory.
traj_geo.get_min('thetao')
[12]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'thetao_min']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lon ┆ lat ┆ depth ┆ thetao_mi │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ n │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ --- │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ f64 │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 ┆ 3.29 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 80463, … ┆ 166, … ┆ .431772, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.5… ┆ 52.9276… ┆ … 126… ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 ┆ 2.81 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 8598, … ┆ 656, … ┆ .873621, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 ┆ 3.48 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 88821, … ┆ 166, … ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ 52.9971… ┆ … 110… ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 ┆ 3.07 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 47605, … ┆ 056, … ┆ 376953, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.4… ┆ 52.9893… ┆ 1852… ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3822 ┆ [58.80593 ┆ [1402.855 ┆ 3.43 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 98, -30.3 ┆ , ┆ 356, 1387 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 71867, … ┆ 58.80404, ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ … 52.9959 ┆ … 161… ┆ │
│ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 ┆ 2.94 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 056, … ┆ 076, … ┆ 2561, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.293… ┆ 53.0483… ┆ 2180.1… ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 ┆ 3.37 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 ┆ │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 296, … ┆ 754, … ┆ 30281, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.634… ┆ 52.9216… ┆ 613.5… ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 ┆ 3.31 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 412, … ┆ 393, … ┆ 088, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.301… ┆ 53.0478… ┆ 1197.53… ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 ┆ 3.55 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 692, … ┆ 886, … ┆ 881, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.438… ┆ 52.9874… ┆ 1312.03… ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 ┆ 3.27 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 481, … ┆ 714, … ┆ 469, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.178… ┆ 53.0555… ┆ 1494.43… ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[13]:
# Get the value of the temp variable for each trajectory on 1995-06-01.
traj_geo.get_values('thetao', '1995-01-01')
[13]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'thetao_i']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬────────────┬───────────┬───────────┬──────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lon ┆ lat ┆ depth ┆ thetao_i │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ f64 │
╞═══════╪════════════╪════════════╪════════════╪═══╪════════════╪═══════════╪═══════════╪══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [-30.38194 ┆ [58.79978 ┆ [1098.922 ┆ 4.35 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 3, -30.380 ┆ 2, 58.774 ┆ 729, 1090 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 463, … ┆ 166, … ┆ .431772, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.5… ┆ 52.9276… ┆ … 126… ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.38292 ┆ [58.81668 ┆ [1366.719 ┆ 4.02 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ , -30.3485 ┆ 8, 58.774 ┆ 318, 1282 ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 98, … ┆ 656, … ┆ .873621, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.38081 ┆ [58.78031 ┆ [1499.595 ┆ 4.0 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 8, -30.288 ┆ 4, 58.779 ┆ 377, 1387 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 821, … ┆ 166, … ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ 52.9971… ┆ … 110… ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.38155 ┆ [58.79312 ┆ [1435.102 ┆ 4.0 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 8, -30.347 ┆ 2, 58.790 ┆ 03, 1387. ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 605, … ┆ 056, … ┆ 376953, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.4… ┆ 52.9893… ┆ 1852… ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.38229 ┆ [58.80593 ┆ [1402.855 ┆ 4.0 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 8, -30.371 ┆ , ┆ 356, 1387 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 867, … ┆ 58.80404, ┆ .376953, ┆ │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ … 52.9959 ┆ … 161… ┆ │
│ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [-9.324242 ┆ [57.09834 ┆ [446.1676 ┆ 10.22 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ , ┆ 2, 57.120 ┆ 71, 457.6 ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ -9.341056, ┆ 076, … ┆ 2561, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ … -51.293… ┆ 53.0483… ┆ 2180.1… ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.235759 ┆ [57.04111 ┆ [114.0151 ┆ 10.27 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ , ┆ 5, 57.070 ┆ 41, 108.0 ┆ │
│ ┆ ┆ ┆ 35.11] ┆ ┆ -9.246296, ┆ 754, … ┆ 30281, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ … -51.634… ┆ 52.9216… ┆ 613.5… ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.266052 ┆ [57.04298 ┆ [352.2756 ┆ 10.26 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ , ┆ 2, 57.072 ┆ 5, 351.17 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ -9.306412, ┆ 393, … ┆ 088, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ … -51.301… ┆ 53.0478… ┆ 1197.53… ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [-8.371674 ┆ [56.88287 ┆ [21.09370 ┆ 9.61 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ , ┆ 7, 56.903 ┆ 9, 21.592 ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ -8.320692, ┆ 886, … ┆ 881, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ … -51.438… ┆ 52.9874… ┆ 1312.03… ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [-8.280212 ┆ [56.87692 ┆ [57.48173 ┆ 9.54 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ , ┆ 8, 56.887 ┆ 7, 57.917 ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ -8.231481, ┆ 714, … ┆ 469, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ … -51.178… ┆ 53.0555… ┆ 1494.43… ┆ │
└───────┴────────────┴────────────┴────────────┴───┴────────────┴───────────┴───────────┴──────────┘>
[14]:
# Get the duration of each trajectory, t_total.
traj_geo.get_duration()
[14]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'dt']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lon ┆ lat ┆ depth ┆ dt │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ duration[ │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ μs] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 ┆ 840d 18h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 ┆ 43m 4s │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 80463, … ┆ 166, … ┆ .431772, ┆ 670ms │
│ ┆ ┆ ┆ ┆ ┆ -51.5… ┆ 52.9276… ┆ … 126… ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 ┆ 479d 2h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 ┆ 29m 28s │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 8598, … ┆ 656, … ┆ .873621, ┆ 240ms │
│ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 ┆ 412d 5h │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 ┆ 40m 44s │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 88821, … ┆ 166, … ┆ .376953, ┆ 610ms │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ 52.9971… ┆ … 110… ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 ┆ 418d 22h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. ┆ 52m 35s │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 47605, … ┆ 056, … ┆ 376953, … ┆ 930ms │
│ ┆ ┆ ┆ ┆ ┆ -51.4… ┆ 52.9893… ┆ 1852… ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3822 ┆ [58.80593 ┆ [1402.855 ┆ 944d 17h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 98, -30.3 ┆ , ┆ 356, 1387 ┆ 39m 38s │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 71867, … ┆ 58.80404, ┆ .376953, ┆ 190ms │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ … 52.9959 ┆ … 161… ┆ │
│ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 ┆ 1297d 14h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 ┆ 53m 46s │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 056, … ┆ 076, … ┆ 2561, … ┆ 360ms │
│ ┆ ┆ ┆ ┆ ┆ -51.293… ┆ 53.0483… ┆ 2180.1… ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 ┆ 1040d 16h │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 ┆ 39m 41s │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 296, … ┆ 754, … ┆ 30281, … ┆ 550ms │
│ ┆ ┆ ┆ ┆ ┆ -51.634… ┆ 52.9216… ┆ 613.5… ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 ┆ 905d 8h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 ┆ 29m 10s │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 412, … ┆ 393, … ┆ 088, … ┆ 470ms │
│ ┆ ┆ ┆ ┆ ┆ -51.301… ┆ 53.0478… ┆ 1197.53… ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 ┆ 1843d 3h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 ┆ 37m 14s │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 692, … ┆ 886, … ┆ 881, … ┆ 510ms │
│ ┆ ┆ ┆ ┆ ┆ -51.438… ┆ 52.9874… ┆ 1312.03… ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 ┆ 761d 5h │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 ┆ 22m 820ms │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 481, … ┆ 714, … ┆ 469, … ┆ │
│ ┆ ┆ ┆ ┆ ┆ -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:
Users can either provide a list of values to instantiate a new column variable.
Users can define a new column variable using the polars expression syntax.
[15]:
# 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)
[15]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'thetao_max', 'temp_max_K']
<bound method DataFrame.glimpse of shape: (2_500, 12)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lat ┆ depth ┆ thetao_ma ┆ temp_max_ │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ x ┆ K │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ --- ┆ --- │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ f64 ┆ f64 │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [58.79978 ┆ [1098.922 ┆ 4.39 ┆ 277.54 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 2, 58.774 ┆ 729, 1090 ┆ ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 166, … ┆ .431772, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9276… ┆ … 126… ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.81668 ┆ [1366.719 ┆ 4.13 ┆ 277.28 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 8, 58.774 ┆ 318, 1282 ┆ ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 656, … ┆ .873621, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.1688… ┆ … 282… ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.78031 ┆ [1499.595 ┆ 4.12 ┆ 277.27 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 4, 58.779 ┆ 377, 1387 ┆ ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 166, … ┆ .376953, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9971… ┆ … 110… ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.79312 ┆ [1435.102 ┆ 4.2 ┆ 277.35 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, 58.790 ┆ 03, 1387. ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 056, … ┆ 376953, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9893… ┆ 1852… ┆ ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.80593 ┆ [1402.855 ┆ 4.1 ┆ 277.25 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ , ┆ 356, 1387 ┆ ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 58.80404, ┆ .376953, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ … 52.9959 ┆ … 161… ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [57.09834 ┆ [446.1676 ┆ 10.22 ┆ 283.37 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, 57.120 ┆ 71, 457.6 ┆ ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 076, … ┆ 2561, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.0483… ┆ 2180.1… ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [57.04111 ┆ [114.0151 ┆ 10.27 ┆ 283.42 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 5, 57.070 ┆ 41, 108.0 ┆ ┆ │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 754, … ┆ 30281, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9216… ┆ 613.5… ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [57.04298 ┆ [352.2756 ┆ 10.26 ┆ 283.41 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, 57.072 ┆ 5, 351.17 ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 393, … ┆ 088, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.0478… ┆ 1197.53… ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [56.88287 ┆ [21.09370 ┆ 9.61 ┆ 282.76 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 7, 56.903 ┆ 9, 21.592 ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 886, … ┆ 881, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9874… ┆ 1312.03… ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [56.87692 ┆ [57.48173 ┆ 9.54 ┆ 282.69 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 8, 56.887 ┆ 7, 57.917 ┆ ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 714, … ┆ 469, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.0555… ┆ 1494.43… ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[16]:
# OPTION 2. Using Polars expression:
(traj_geo
.get_max('thetao')
.add_variable(name='temp_max_K', expr=pl.col('thetao_max') + 273.15)
)
[16]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'thetao_max', 'temp_max_K']
<bound method DataFrame.glimpse of shape: (2_500, 12)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lat ┆ depth ┆ thetao_ma ┆ temp_max_ │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ x ┆ K │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ --- ┆ --- │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ f64 ┆ f64 │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [58.79978 ┆ [1098.922 ┆ 4.39 ┆ 277.54 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 2, 58.774 ┆ 729, 1090 ┆ ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 166, … ┆ .431772, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9276… ┆ … 126… ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.81668 ┆ [1366.719 ┆ 4.13 ┆ 277.28 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 8, 58.774 ┆ 318, 1282 ┆ ┆ │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 656, … ┆ .873621, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.1688… ┆ … 282… ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.78031 ┆ [1499.595 ┆ 4.12 ┆ 277.27 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 4, 58.779 ┆ 377, 1387 ┆ ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 166, … ┆ .376953, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9971… ┆ … 110… ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.79312 ┆ [1435.102 ┆ 4.2 ┆ 277.35 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, 58.790 ┆ 03, 1387. ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 056, … ┆ 376953, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9893… ┆ 1852… ┆ ┆ │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [58.80593 ┆ [1402.855 ┆ 4.1 ┆ 277.25 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ , ┆ 356, 1387 ┆ ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 58.80404, ┆ .376953, ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ … 52.9959 ┆ … 161… ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [57.09834 ┆ [446.1676 ┆ 10.22 ┆ 283.37 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, 57.120 ┆ 71, 457.6 ┆ ┆ │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 076, … ┆ 2561, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.0483… ┆ 2180.1… ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [57.04111 ┆ [114.0151 ┆ 10.27 ┆ 283.42 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 5, 57.070 ┆ 41, 108.0 ┆ ┆ │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 754, … ┆ 30281, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9216… ┆ 613.5… ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [57.04298 ┆ [352.2756 ┆ 10.26 ┆ 283.41 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, 57.072 ┆ 5, 351.17 ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 393, … ┆ 088, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 53.0478… ┆ 1197.53… ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [56.88287 ┆ [21.09370 ┆ 9.61 ┆ 282.76 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 7, 56.903 ┆ 9, 21.592 ┆ ┆ │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 886, … ┆ 881, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 52.9874… ┆ 1312.03… ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [56.87692 ┆ [57.48173 ┆ 9.54 ┆ 282.69 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 8, 56.887 ┆ 7, 57.917 ┆ ┆ │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 714, … ┆ 469, … ┆ ┆ │
│ ┆ ┆ ┆ ┆ ┆ 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.
[17]:
# 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)
[17]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2196
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (2_196, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[date ┆ list[f64] ┆ list[f64] ┆ list[f64] │
│ ┆ ┆ ┆ ┆ ┆ time[μs]] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [1995-01- ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 01 ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 80463, … ┆ 166, … ┆ .431772, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.5… ┆ 52.9276… ┆ … 126… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 8598, … ┆ 656, … ┆ .873621, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.02… ┆ 53.1688… ┆ … 282… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 01 ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 88821, … ┆ 166, … ┆ .376953, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ 52.9971… ┆ … 110… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 47605, … ┆ 056, … ┆ 376953, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.4… ┆ 52.9893… ┆ 1852… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 32 ┆ [1.0, 1.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3807 ┆ [58.77928 ┆ [1611.707 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 59, -30.2 ┆ 9, 58.778 ┆ 031, 1534 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 86917, … ┆ 683, … ┆ .070276, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ 52.9948… ┆ … 131… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [1995-01- ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 01 ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 056, … ┆ 076, … ┆ 2561, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.293… ┆ 53.0483… ┆ 2180.1… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 01 ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 00:00:00, ┆ 296, … ┆ 754, … ┆ 30281, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.634… ┆ 52.9216… ┆ 613.5… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 01 ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 412, … ┆ 393, … ┆ 088, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.301… ┆ 53.0478… ┆ 1197.53… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [1995-01- ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 01 ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 692, … ┆ 886, … ┆ 881, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.438… ┆ 52.9874… ┆ 1312.03… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [1995-01- ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 01 ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00, ┆ 481, … ┆ 714, … ┆ 469, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.178… ┆ 53.0555… ┆ 1494.43… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[18]:
# 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
))
[18]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2196
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (2_196, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[date ┆ list[f64] ┆ list[f64] ┆ list[f64] │
│ ┆ ┆ ┆ ┆ ┆ time[μs]] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [1995-01- ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 01 ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 80463, … ┆ 166, … ┆ .431772, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.5… ┆ 52.9276… ┆ … 126… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 8598, … ┆ 656, … ┆ .873621, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.02… ┆ 53.1688… ┆ … 282… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 01 ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 88821, … ┆ 166, … ┆ .376953, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ 52.9971… ┆ … 110… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 47605, … ┆ 056, … ┆ 376953, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.4… ┆ 52.9893… ┆ 1852… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 32 ┆ [1.0, 1.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01- ┆ [-30.3807 ┆ [58.77928 ┆ [1611.707 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 01 ┆ 59, -30.2 ┆ 9, 58.778 ┆ 031, 1534 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 86917, … ┆ 683, … ┆ .070276, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ 52.9948… ┆ … 131… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [1995-01- ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 01 ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 056, … ┆ 076, … ┆ 2561, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.293… ┆ 53.0483… ┆ 2180.1… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 01 ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 00:00:00, ┆ 296, … ┆ 754, … ┆ 30281, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.634… ┆ 52.9216… ┆ 613.5… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 01 ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 412, … ┆ 393, … ┆ 088, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.301… ┆ 53.0478… ┆ 1197.53… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [1995-01- ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 01 ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 692, … ┆ 886, … ┆ 881, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.438… ┆ 52.9874… ┆ 1312.03… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [1995-01- ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 01 ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00, ┆ 481, … ┆ 714, … ┆ 469, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.178… ┆ 53.0555… ┆ 1494.43… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[19]:
# 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)
[19]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 4
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (4, 10)
┌─────┬────────────┬────────────┬────────────┬───┬────────────┬────────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[datet ┆ list[f64] ┆ list[f64] ┆ list[f64] │
│ ┆ ┆ ┆ ┆ ┆ ime[μs]] ┆ ┆ ┆ │
╞═════╪════════════╪════════════╪════════════╪═══╪════════════╪════════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [1995-01-0 ┆ [-30.38194 ┆ [58.79978 ┆ [1098.922 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 1 ┆ 3, -30.380 ┆ 2, 58.774 ┆ 729, 1090 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 463, … ┆ 166, … ┆ .431772, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-01 ┆ -51.5… ┆ 52.9276… ┆ … 126… │
│ ┆ ┆ ┆ ┆ ┆ … ┆ ┆ ┆ │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01-0 ┆ [-30.38292 ┆ [58.81668 ┆ [1366.719 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 1 ┆ , -30.3485 ┆ 8, 58.774 ┆ 318, 1282 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 00:00:00, ┆ 98, … ┆ 656, … ┆ .873621, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-02 ┆ -51.02… ┆ 53.1688… ┆ … 282… │
│ ┆ ┆ ┆ ┆ ┆ … ┆ ┆ ┆ │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01-0 ┆ [-30.38081 ┆ [58.78031 ┆ [1499.595 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 1 ┆ 8, -30.288 ┆ 4, 58.779 ┆ 377, 1387 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 821, … ┆ 166, … ┆ .376953, │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-02 ┆ -51.3… ┆ 52.9971… ┆ … 110… │
│ ┆ ┆ ┆ ┆ ┆ … ┆ ┆ ┆ │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1995-01-0 ┆ [-30.38155 ┆ [58.79312 ┆ [1435.102 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 1 ┆ 8, -30.347 ┆ 2, 58.790 ┆ 03, 1387. │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 605, … ┆ 056, … ┆ 376953, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-01 ┆ -51.4… ┆ 52.9893… ┆ 1852… │
│ ┆ ┆ ┆ ┆ ┆ … ┆ ┆ ┆ │
└─────┴────────────┴────────────┴────────────┴───┴────────────┴────────────┴───────────┴───────────┘>
Filtering trajectories which intersect a polygon.#
[20]:
# 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)
[20]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 323
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (323, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[date ┆ list[f64] ┆ list[f64] ┆ list[f64] │
│ ┆ ┆ ┆ ┆ ┆ time[μs]] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 17470 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.38, ┆ … ┆ [1995-01- ┆ [-23.2379 ┆ [57.96416 ┆ [44.19595 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.41, … ┆ ┆ 01 ┆ 15, -23.1 ┆ 7, ┆ 9, 44.195 │
│ ┆ ┆ ┆ 35.2] ┆ ┆ 00:00:00, ┆ 66898, … ┆ 57.99151, ┆ 959, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ … ┆ 1678.32… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ 52.99298… ┆ │
│ 18666 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.42, ┆ … ┆ [1995-01- ┆ [-21.3149 ┆ [57.98904 ┆ [317.3751 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.38, … ┆ ┆ 01 ┆ 07, -21.2 ┆ 1, 57.997 ┆ 68, 314.7 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 98514, … ┆ 077, … ┆ 37143, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.1… ┆ 53.0832… ┆ 1512.… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 18708 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.4, ┆ … ┆ [1995-01- ┆ [-21.2523 ┆ [57.98792 ┆ [50.53126 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.37, … ┆ ┆ 01 ┆ 5, -21.20 ┆ 8, 58.003 ┆ 5, 50.132 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 4594, … ┆ 725, … ┆ 941, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -50.90… ┆ 53.2153… ┆ 2555.82… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 18901 ┆ [1.0, 1.0, ┆ [1.0, 1.0, ┆ [35.41, ┆ … ┆ [1995-01- ┆ [-21.1151 ┆ [57.94172 ┆ [286.1219 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.38, … ┆ ┆ 01 ┆ 25, -21.0 ┆ 3, ┆ 48, 283.7 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 19358, … ┆ 57.97795, ┆ 59458, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.2… ┆ … ┆ 2189.… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ 53.05013… ┆ │
│ 18902 ┆ [1.0, 3.0, ┆ [1.0, 1.0, ┆ [35.41, ┆ … ┆ [1995-01- ┆ [-21.1139 ┆ [57.95940 ┆ [286.1219 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.38, … ┆ ┆ 01 ┆ 83, -21.0 ┆ 2, 57.984 ┆ 48, 284.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 48845, … ┆ 223, … ┆ 45392, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.5… ┆ 52.9291… ┆ 1156.… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [1995-01- ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 01 ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 056, … ┆ 076, … ┆ 2561, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.293… ┆ 53.0483… ┆ 2180.1… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 01 ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 00:00:00, ┆ 296, … ┆ 754, … ┆ 30281, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.634… ┆ 52.9216… ┆ 613.5… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 01 ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 412, … ┆ 393, … ┆ 088, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.301… ┆ 53.0478… ┆ 1197.53… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [1995-01- ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 01 ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 692, … ┆ 886, … ┆ 881, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.438… ┆ 52.9874… ┆ 1312.03… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [1995-01- ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 01 ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00, ┆ 481, … ┆ 714, … ┆ 469, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.178… ┆ 53.0555… ┆ 1494.43… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[21]:
# 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)
)
[21]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 323
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth']
<bound method DataFrame.glimpse of shape: (323, 10)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ time ┆ lon ┆ lat ┆ depth │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[date ┆ list[f64] ┆ list[f64] ┆ list[f64] │
│ ┆ ┆ ┆ ┆ ┆ time[μs]] ┆ ┆ ┆ │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 17470 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.38, ┆ … ┆ [1995-01- ┆ [-23.2379 ┆ [57.96416 ┆ [44.19595 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.41, … ┆ ┆ 01 ┆ 15, -23.1 ┆ 7, ┆ 9, 44.195 │
│ ┆ ┆ ┆ 35.2] ┆ ┆ 00:00:00, ┆ 66898, … ┆ 57.99151, ┆ 959, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.3… ┆ … ┆ 1678.32… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ 52.99298… ┆ │
│ 18666 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.42, ┆ … ┆ [1995-01- ┆ [-21.3149 ┆ [57.98904 ┆ [317.3751 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.38, … ┆ ┆ 01 ┆ 07, -21.2 ┆ 1, 57.997 ┆ 68, 314.7 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 98514, … ┆ 077, … ┆ 37143, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.1… ┆ 53.0832… ┆ 1512.… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 18708 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.4, ┆ … ┆ [1995-01- ┆ [-21.2523 ┆ [57.98792 ┆ [50.53126 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.37, … ┆ ┆ 01 ┆ 5, -21.20 ┆ 8, 58.003 ┆ 5, 50.132 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 4594, … ┆ 725, … ┆ 941, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -50.90… ┆ 53.2153… ┆ 2555.82… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 18901 ┆ [1.0, 1.0, ┆ [1.0, 1.0, ┆ [35.41, ┆ … ┆ [1995-01- ┆ [-21.1151 ┆ [57.94172 ┆ [286.1219 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.38, … ┆ ┆ 01 ┆ 25, -21.0 ┆ 3, ┆ 48, 283.7 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 19358, … ┆ 57.97795, ┆ 59458, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.2… ┆ … ┆ 2189.… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ 53.05013… ┆ │
│ 18902 ┆ [1.0, 3.0, ┆ [1.0, 1.0, ┆ [35.41, ┆ … ┆ [1995-01- ┆ [-21.1139 ┆ [57.95940 ┆ [286.1219 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.38, … ┆ ┆ 01 ┆ 83, -21.0 ┆ 2, 57.984 ┆ 48, 284.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 48845, … ┆ 223, … ┆ 45392, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.5… ┆ 52.9291… ┆ 1156.… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [1995-01- ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 01 ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 00:00:00, ┆ 056, … ┆ 076, … ┆ 2561, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.293… ┆ 53.0483… ┆ 2180.1… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 01 ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 00:00:00, ┆ 296, … ┆ 754, … ┆ 30281, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.634… ┆ 52.9216… ┆ 613.5… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [1995-01- ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 01 ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 412, … ┆ 393, … ┆ 088, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.301… ┆ 53.0478… ┆ 1197.53… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [1995-01- ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 01 ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 00:00:00, ┆ 692, … ┆ 886, … ┆ 881, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.438… ┆ 52.9874… ┆ 1312.03… │
│ ┆ ┆ ┆ ┆ ┆ 1… ┆ ┆ ┆ │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [1995-01- ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 01 ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 00:00:00, ┆ 481, … ┆ 714, … ┆ 469, … │
│ ┆ ┆ ┆ ┆ ┆ 1995-01-0 ┆ -51.178… ┆ 53.0555… ┆ 1494.43… │
│ ┆ ┆ ┆ ┆ ┆ 2… ┆ ┆ ┆ │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
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.
[22]:
traj_geo.compute_distance(cum_dist=True, unit='km')
[22]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'dist']
<bound method DataFrame.glimpse of shape: (2_500, 11)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ lon ┆ lat ┆ depth ┆ dist │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [-30.3819 ┆ [58.79978 ┆ [1098.922 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 43, -30.3 ┆ 2, 58.774 ┆ 729, 1090 ┆ 2.849612, │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 80463, … ┆ 166, … ┆ .431772, ┆ … 4991.74 │
│ ┆ ┆ ┆ ┆ ┆ -51.5… ┆ 52.9276… ┆ … 126… ┆ 1675] │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3829 ┆ [58.81668 ┆ [1366.719 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 2, -30.34 ┆ 8, 58.774 ┆ 318, 1282 ┆ 5.074755, │
│ ┆ ┆ ┆ 35.16] ┆ ┆ 8598, … ┆ 656, … ┆ .873621, ┆ … 4453.99 │
│ ┆ ┆ ┆ ┆ ┆ -51.02… ┆ 53.1688… ┆ … 282… ┆ 8629] │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3808 ┆ [58.78031 ┆ [1499.595 ┆ [0.0, │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 18, -30.2 ┆ 4, 58.779 ┆ 377, 1387 ┆ 5.303854, │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 88821, … ┆ 166, … ┆ .376953, ┆ … 4179.00 │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ 52.9971… ┆ … 110… ┆ 1615] │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3815 ┆ [58.79312 ┆ [1435.102 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 58, -30.3 ┆ 2, 58.790 ┆ 03, 1387. ┆ 1.985706, │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 47605, … ┆ 056, … ┆ 376953, … ┆ … 4300.74 │
│ ┆ ┆ ┆ ┆ ┆ -51.4… ┆ 52.9893… ┆ 1852… ┆ 3084] │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [-30.3822 ┆ [58.80593 ┆ [1402.855 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 98, -30.3 ┆ , ┆ 356, 1387 ┆ 0.636479, │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 71867, … ┆ 58.80404, ┆ .376953, ┆ … 4256.91 │
│ ┆ ┆ ┆ ┆ ┆ -51.3… ┆ … 52.9959 ┆ … 161… ┆ 3051] │
│ ┆ ┆ ┆ ┆ ┆ ┆ 58… ┆ ┆ │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [-9.32424 ┆ [57.09834 ┆ [446.1676 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 2, -9.341 ┆ 2, 57.120 ┆ 71, 457.6 ┆ 2.621375, │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 056, … ┆ 076, … ┆ 2561, … ┆ … 8333.87 │
│ ┆ ┆ ┆ ┆ ┆ -51.293… ┆ 53.0483… ┆ 2180.1… ┆ 9955] │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.23575 ┆ [57.04111 ┆ [114.0151 ┆ [0.0, │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 9, -9.246 ┆ 5, 57.070 ┆ 41, 108.0 ┆ 3.356731, │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 296, … ┆ 754, … ┆ 30281, … ┆ … 7813.79 │
│ ┆ ┆ ┆ ┆ ┆ -51.634… ┆ 52.9216… ┆ 613.5… ┆ 468] │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [-9.26605 ┆ [57.04298 ┆ [352.2756 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 2, -9.306 ┆ 2, 57.072 ┆ 5, 351.17 ┆ 4.080607, │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 412, … ┆ 393, … ┆ 088, … ┆ … 6487.44 │
│ ┆ ┆ ┆ ┆ ┆ -51.301… ┆ 53.0478… ┆ 1197.53… ┆ 7868] │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [-8.37167 ┆ [56.88287 ┆ [21.09370 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 4, -8.320 ┆ 7, 56.903 ┆ 9, 21.592 ┆ 3.878721, │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 692, … ┆ 886, … ┆ 881, … ┆ … 7409.43 │
│ ┆ ┆ ┆ ┆ ┆ -51.438… ┆ 52.9874… ┆ 1312.03… ┆ 3642] │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [-8.28021 ┆ [56.87692 ┆ [57.48173 ┆ [0.0, │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 2, -8.231 ┆ 8, 56.887 ┆ 7, 57.917 ┆ 3.194232, │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 481, … ┆ 714, … ┆ 469, … ┆ … 6896.99 │
│ ┆ ┆ ┆ ┆ ┆ -51.178… ┆ 53.0555… ┆ 1494.43… ┆ 589] │
└───────┴────────────┴────────────┴────────────┴───┴───────────┴───────────┴───────────┴───────────┘>
[23]:
# Compute velocity in of water parcels in km/h:
traj_geo.compute_distance(cum_dist=False, unit='m').compute_velocity()
[23]:
<TrajFrame object>
----- Trajectory DataFrame -----
Trajectories: 2500
Variables: ['id', 'boxface', 'mask', 'so', 'subvol', 'thetao', 'time', 'lon', 'lat', 'depth', 'dist', 'direction', 'speed']
<bound method DataFrame.glimpse of shape: (2_500, 13)
┌───────┬────────────┬────────────┬────────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ id ┆ boxface ┆ mask ┆ so ┆ … ┆ depth ┆ dist ┆ direction ┆ speed │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ ┆ list[f64] ┆ list[f64] ┆ list[f64] ┆ list[f64] │
╞═══════╪════════════╪════════════╪════════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.22, ┆ … ┆ [1098.922 ┆ [0.0, 284 ┆ [178.2842 ┆ [3.6491e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.22, … ┆ ┆ 729, 1090 ┆ 9.611641, ┆ 49, 178.2 ┆ 8, 5.7515 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ .431772, ┆ … 6392.23 ┆ 67656, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ … 126… ┆ 554] ┆ null] ┆ null] │
│ 12 ┆ [1.0, 4.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1366.719 ┆ [0.0, 507 ┆ [157.0543 ┆ [4.3601e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 318, 1282 ┆ 4.755019, ┆ 16, 178.8 ┆ 8, 5.6856 │
│ ┆ ┆ ┆ 35.16] ┆ ┆ .873621, ┆ … 5788.67 ┆ 1487, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ … 282… ┆ 5377… ┆ null] ┆ null] │
│ 15 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1499.595 ┆ [0.0, 530 ┆ [91.33937 ┆ [5.0668e- │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.25, … ┆ ┆ 377, 1387 ┆ 3.854406, ┆ 6, 157.54 ┆ 8, 5.8513 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ .376953, ┆ … 6141.35 ┆ 8076, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ … 110… ┆ 2623… ┆ null] ┆ null] │
│ 21 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1435.102 ┆ [0.0, 198 ┆ [99.87104 ┆ [4.5109e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 03, 1387. ┆ 5.706058, ┆ 2, 160.75 ┆ 8, 5.3642 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 376953, … ┆ … 6154.45 ┆ 5952, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 1852… ┆ 2063… ┆ null] ┆ null] │
│ 26 ┆ [1.0, 6.0, ┆ [1.0, 1.0, ┆ [35.25, ┆ … ┆ [1402.855 ┆ [0.0, 636 ┆ [109.2748 ┆ [4.3796e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.25, … ┆ ┆ 356, 1387 ┆ .479079, ┆ 35, 159.3 ┆ 8, 4.8727 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ .376953, ┆ … 6223.45 ┆ 38217, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ … 161… ┆ 8116] ┆ null] ┆ null] │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 28473 ┆ [3.0, 5.0, ┆ [1.0, 1.0, ┆ [35.54, ┆ … ┆ [446.1676 ┆ [0.0, 262 ┆ [-22.7812 ┆ [3.2613e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.54, … ┆ ┆ 71, 457.6 ┆ 1.374792, ┆ 27, -61.0 ┆ 8, 3.8570 │
│ ┆ ┆ ┆ 35.17] ┆ ┆ 2561, … ┆ … 2885.76 ┆ 18354, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 2180.1… ┆ 1444… ┆ null] ┆ null] │
│ 28512 ┆ [3.0, 6.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [114.0151 ┆ [0.0, 335 ┆ [-10.9376 ┆ [8.1410e- │
│ ┆ … 1.0] ┆ … 0.0] ┆ 35.53, … ┆ ┆ 41, 108.0 ┆ 6.730944, ┆ 82, -11.9 ┆ 8, 8.0141 │
│ ┆ ┆ ┆ 35.11] ┆ ┆ 30281, … ┆ … 207.180 ┆ 27438, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 613.5… ┆ 391] ┆ null] ┆ null] │
│ 28549 ┆ [3.0, 2.0, ┆ [1.0, 1.0, ┆ [35.53, ┆ … ┆ [352.2756 ┆ [0.0, 408 ┆ [-36.7143 ┆ [5.2181e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.53, … ┆ ┆ 5, 351.17 ┆ 0.606819, ┆ 89, -5.02 ┆ 8, 6.0189 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 088, … ┆ … 1416.25 ┆ 6343, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 1197.53… ┆ 7441… ┆ null] ┆ null] │
│ 28956 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.35, ┆ … ┆ [21.09370 ┆ [0.0, 387 ┆ [52.94505 ┆ [4.8758e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.33, … ┆ ┆ 9, 21.592 ┆ 8.721142, ┆ 6, 60.957 ┆ 8, 3.4927 │
│ ┆ ┆ ┆ 35.18] ┆ ┆ 881, … ┆ … 5573.29 ┆ 532, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 1312.03… ┆ 7087… ┆ null] ┆ null] │
│ 28990 ┆ [3.0, 1.0, ┆ [1.0, 1.0, ┆ [35.32, ┆ … ┆ [57.48173 ┆ [0.0, 319 ┆ [67.92673 ┆ [2.6140e- │
│ ┆ … 4.0] ┆ … 0.5] ┆ 35.32, … ┆ ┆ 7, 57.917 ┆ 4.232016, ┆ 2, 84.146 ┆ 8, 1.7682 │
│ ┆ ┆ ┆ 35.19] ┆ ┆ 469, … ┆ … 6221.43 ┆ 086, … ┆ e-8, … │
│ ┆ ┆ ┆ ┆ ┆ 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.
[24]:
# 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
)
)
[25]:
# 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,
)
)
Converting larger-than-memory OceanParcels output .zarr stores to multiple-file .parquet stores#
You probably noticed that, compared with the creation of a TrajFrame from a Polars DataFrame read eagerly from a .parquet file, using an eager xarray DataSet is noticably slower. This is because of the overheads required to transform the Lagrangian trajectory data output from OceanParcels from the {trajectory, obs} 2-D array format into the condensed tabular format used in the TrajFrame.
Although this may initially appear inconvinent, the perfomance improvement from working with the Polars DataFrame library (written in Rust) coupled with the inefficient nature of 2D arrays for storing what are often unnevely sampled positions and properties along Lagragian trajectories (sparse arrays are often needed) makes this worth pursuing. To help users with larger-than-memory Lagrangian trajectory datasets in .zarr stores, we have added the functionality to write the data contained in a larger-than-memory .zarr store to a multi-file .parquet store which can then be used in the creation of lazy TrajFrames.
Below we illustrate how to use the conversions module of the LT-Toolbox and deemonstrate the syntax to convert a large .zarr store to a multi-file .parquet store:
[ ]:
from lt_toolbox.conversions import export_zarr_to_mfparquet
# Exporting a Zarr file to a multi-file .parquet store:
export_zarr_to_mfparquet(zarr_filename='/data/ORCA0083-GO8p7_JRA55_SPNA_1995_example.zarr',
parquet_filedir='/data/',
parquet_filename='ORCA0083-GO8p7_JRA55_SPNA_1995_mf_example.parquet',
npartitions=10,
read_options={'chunk_size': 'auto'},
write_options={'use_pyarrow': True},
)