.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_contiguous_ragged.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_contiguous_ragged.py: Reading and using a contiguous ragged dataset ================================================ .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: Python import matplotlib.pyplot as plt import xarray as xr import trajan as ta import coloredlogs .. GENERATED FROM PYTHON SOURCE LINES 14-21 .. code-block:: Python # the test data: a small extract from the Sofar dataset https://sofar-spotter-archive.s3.amazonaws.com/index.html xr_data = xr.load_dataset(ta.DATA_DIR + 'xr_spotter_bulk_test_data.nc') # this is a contiguous ragged dataset; the data variables are 1D arrays xr_data .. raw:: html
<xarray.Dataset> Size: 5kB
    Dimensions:                (index: 65, trajectory: 2)
    Coordinates:
        time                   (index) datetime64[ns] 520B 2022-03-15T04:07:25 .....
      * trajectory             (trajectory) <U11 88B 'SPOT-010102' 'SPOT-010103'
    Dimensions without coordinates: index
    Data variables:
        significantWaveHeight  (index) float64 520B 1.736 1.817 ... 1.263 1.136
        peakPeriod             (index) float64 520B 7.877 8.533 ... 7.314 7.314
        meanPeriod             (index) float64 520B 6.804 6.652 ... 6.629 6.497
        peakDirection          (index) float64 520B 147.9 155.5 ... 105.2 102.2
        peakDirectionalSpread  (index) float64 520B 30.37 25.48 26.04 ... 37.2 38.09
        meanDirection          (index) float64 520B 146.7 144.5 ... 127.3 120.8
        meanDirectionalSpread  (index) float64 520B 40.34 40.47 ... 50.39 51.12
        latitude               (index) float64 520B -16.41 -16.43 ... -12.64 -12.65
        longitude              (index) float64 520B 65.03 65.03 ... 70.15 70.14
        rowsize                (trajectory) int64 16B 20 45
    Attributes:
        title:          Sofar Spotter Data Archive - Bulk Wave Parameters
        institution:    Sofar Ocean
        source:         Spotter wave buoy
        creation_date:  2023-10-18 00:43:55.333537
        author:         Isabel A. Houghton
        email:          isabel.houghton@sofarocean.com
        references:     https://content.sofarocean.com/hubfs/Spotter%20product%20...
        modified:       modified to only keep a couple of buoys, to be used as a ...


.. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python # trajan is able to plot etc xr_data.traj.plot() plt.show() .. image-sg:: /gallery/images/sphx_glr_example_contiguous_ragged_001.png :alt: example contiguous ragged :srcset: /gallery/images/sphx_glr_example_contiguous_ragged_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Detecting trajectory dimension 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Found CF trajectory dimension "trajectory" 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG 1D storage dataset; detected: obs_dim = 'index', timecoord = 'time', trajectory_dim = 'trajectory', rowsize 2026-07-28 17:56:49 runnervmvrwv9 trajan.traj[4232] DEBUG Setting up new plot object. 2026-07-28 17:56:49 runnervmvrwv9 trajan.plot[4232] DEBUG Plotting lines 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Detecting trajectory dimension 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Found CF trajectory dimension "trajectory" 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Detecting time-variable for "index".. 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Detected obs-dim: index, detected time-variable: time. 2026-07-28 17:56:49 runnervmvrwv9 trajan.accessor[4232] DEBUG Detected Ragged trajectory dataset 2026-07-28 17:56:49 runnervmvrwv9 trajan.plot[4232] DEBUG Creating new figure and axes.. .. GENERATED FROM PYTHON SOURCE LINES 28-41 .. code-block:: Python # Convert ContiguousRaggedArray to RaggedArray (non-contiguous) dataset: # compare: print(f"{xr_data = }") # with: xr_data_as_ragged = xr_data.traj.to_ragged() print(f"{xr_data_as_ragged = }") # Dumping the Ragged dataset to disk: #xr_data_as_ragged.to_netcdf("./xr_spotter_bulk_test_data_as_ragged.nc") .. rst-class:: sphx-glr-script-out .. code-block:: none xr_data = Size: 5kB Dimensions: (index: 65, trajectory: 2) Coordinates: time (index) datetime64[ns] 520B 2022-03-15T04:07:25 ..... * trajectory (trajectory) Size: 7kB Dimensions: (trajectory: 2, obs: 45) Coordinates: * trajectory (trajectory) ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_contiguous_ragged.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_contiguous_ragged.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_