.. 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-14 .. code-block:: Python import matplotlib.pyplot as plt from pathlib import Path import xarray as xr import trajan import coloredlogs .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python # the test data: a small extract from the Sofar dataset https://sofar-spotter-archive.s3.amazonaws.com/index.html path_to_test_data = Path.cwd().parent / "tests" / "test_data" / "xr_spotter_bulk_test_data.nc" xr_data = xr.load_dataset(path_to_test_data) # this is a ragged contiguous 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 25-30 .. 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 /home/runner/micromamba/envs/trajan/lib/python3.11/site-packages/shapely/creation.py:119: RuntimeWarning: invalid value encountered in linestrings return lib.linestrings(coords, out=out, **kwargs) .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python # it is possible to get a 2d-array dataset version using trajan: # compare: print(f"{xr_data = }") # with: xr_data_as_2darray = xr_data.traj.to_2d() print(f"{xr_data_as_2darray = }") # naturally, the 2darray version can be dumped to disk if you want: xr_data_as_2darray.to_netcdf("./xr_spotter_bulk_test_data_as_2darray.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 `_