.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_concat.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_example_concat.py: Concatenating drifter datasets ============================== .. GENERATED FROM PYTHON SOURCE LINES 5-13 .. code-block:: Python import numpy as np import lzma import matplotlib.pyplot as plt import cartopy.crs as ccrs import xarray as xr import pandas as pd import trajan as ta .. GENERATED FROM PYTHON SOURCE LINES 14-15 Importing a dataset with two drifters in the Barents Sea .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python with lzma.open('barents.nc.xz') as barents: ds = xr.open_dataset(barents) ds.load() assert 'obs' in ds.dims .. rst-class:: sphx-glr-script-out .. code-block:: none 2025-06-24 13:41:18 fv-az1280-93 h5py._conv[2414] DEBUG Creating converter from 7 to 5 2025-06-24 13:41:18 fv-az1280-93 h5py._conv[2414] DEBUG Creating converter from 5 to 7 2025-06-24 13:41:18 fv-az1280-93 h5py._conv[2414] DEBUG Creating converter from 7 to 5 2025-06-24 13:41:18 fv-az1280-93 h5py._conv[2414] DEBUG Creating converter from 5 to 7 2025-06-24 13:41:18 fv-az1280-93 h5py._conv[2414] DEBUG Creating converter from 3 to 5 .. GENERATED FROM PYTHON SOURCE LINES 22-23 Split into two observational datasets for this example .. GENERATED FROM PYTHON SOURCE LINES 23-32 .. code-block:: Python ds = ds.rename(drifter_names='trajectory').traj.condense_obs() print(ds) d1 = ds.isel(trajectory=0).traj.to_1d().traj.to_2d() d2 = ds.isel(trajectory=1).traj.to_1d().traj.to_2d() print("d1=", d1) print("d2=", d2) .. rst-class:: sphx-glr-script-out .. code-block:: none 2025-06-24 13:41:18 fv-az1280-93 trajan.accessor[2414] DEBUG Detecting trajectory dimension 2025-06-24 13:41:18 fv-az1280-93 trajan.accessor[2414] DEBUG Detecting time-variable for "obs".. 2025-06-24 13:41:18 fv-az1280-93 trajan.accessor[2414] DEBUG Detected obs-dim: obs, detected time-variable: time. 2025-06-24 13:41:18 fv-az1280-93 trajan.accessor[2414] DEBUG Detected un-structured (2D) trajectory dataset 2025-06-24 13:41:18 fv-az1280-93 trajan.traj2d[2414] DEBUG Condensing 2287 observations. 2025-06-24 13:41:18 fv-az1280-93 trajan.traj2d[2414] DEBUG Condensed observations from: 2287 to 2287 Size: 128kB Dimensions: (trajectory: 2, obs: 2287) Coordinates: trajectory (trajectory) Size: 33kB Dimensions: (trajectory: 1, obs: 1027) Coordinates: * trajectory (trajectory) Size: 73kB Dimensions: (trajectory: 1, obs: 2287) Coordinates: * trajectory (trajectory) Size: 128kB Dimensions: (trajectory: 2, obs: 2287) Coordinates: * trajectory (trajectory) Size: 25kB Dimensions: (trajectory: 1, time: 1027) Coordinates: * time (time) datetime64[ns] 8kB 2022-10-07T00:00:38 ... 2022-11-17T... * trajectory (trajectory) Size: 127kB Dimensions: (trajectory: 2, time: 3163) Coordinates: * time (time) datetime64[ns] 25kB 2022-10-07T00:00:38 ... 2022-11-23... * trajectory (trajectory) Size: 128kB Dimensions: (trajectory: 2, obs: 2287) Coordinates: * trajectory (trajectory) ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_concat.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_concat.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_