
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorials/graphics/plot_wave_rose.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorials_graphics_plot_wave_rose.py>`
        to download the full example code or to run this example in your browser via Binder.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorials_graphics_plot_wave_rose.py:


Wave roses of a buoy
====================

In this tutorial, we show how to:

* plot a rose of the significant wave height and the wave direction of a buoy,
* mask the bad quality data,
* compare the seasons and the peak period.

The concepts are explained in the :ref:`indepth.plot` guide.

.. GENERATED FROM PYTHON SOURCE LINES 16-18

Initialisations
---------------

.. GENERATED FROM PYTHON SOURCE LINES 18-26

.. code-block:: Python


    import matplotlib.pyplot as plt

    import xoa
    from xoa.plot import plot_rose

    plt.rcParams.update({"font.size": 9, "axes.titlesize": 10, "axes.titleweight": "bold"})








.. GENERATED FROM PYTHON SOURCE LINES 27-29

The hourly wave parameters of the Pierres Noires buoy, in the Iroise Sea, from 2013 to 2024.
The quality flag is 1 for the good values.

.. GENERATED FROM PYTHON SOURCE LINES 29-34

.. code-block:: Python


    ds = xoa.open_data_sample("OBS/WAVES/wave_buoy_6200069_2013-2024.nc")
    ds = ds.where(ds.hs_qc == 1)
    ds






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <pre>&lt;xarray.Dataset&gt; Size: 5MB
    Dimensions:       (time: 96432)
    Coordinates:
      * time          (time) datetime64[ns] 771kB 2013-07-01 ... 2024-06-30T23:00:00
    Data variables:
        hs            (time) float64 771kB 1.3 1.3 1.1 0.9 0.8 ... 0.9 1.0 1.0 1.1
        hs_qc         (time) float32 386kB 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
        tp            (time) float64 771kB 9.1 9.1 10.0 9.1 10.5 ... 7.7 7.1 8.3 7.7
        tp_qc         (time) float32 386kB 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
        tm02          (time) float64 771kB 6.5 6.9 7.0 6.7 6.6 ... 5.3 5.0 5.3 4.9
        tm02_qc       (time) float32 386kB 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
        direction     (time) float64 771kB 294.0 294.0 291.0 ... 277.0 278.0 278.0
        direction_qc  (time) float32 386kB 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
    Attributes:
        title:          Hourly wave parameters of the buoy 6200069 (Pierres Noires)
        platform_code:  6200069
        longitude:      -4.97
        latitude:       48.29
        source:         Copernicus Marine Service In Situ, product INSITU_GLO_WAV...
        institution:    Cerema (French centre for studies and expertise on risks,...</pre>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 35-38

The waves come mostly from the west. The direction is the one they come from.
:func:`~xoa.plot.plot_rose` draws the rose, which is also available as the
:meth:`~xoa.accessors.XoaPlotAccessor.rose` method of the ``plot`` accessor.

.. GENERATED FROM PYTHON SOURCE LINES 38-42

.. code-block:: Python


    rose = plot_rose(ds.hs, ds.direction)
    rose.ax.set_title("Significant wave height")




.. image-sg:: /tutorials/graphics/images/sphx_glr_plot_wave_rose_001.png
   :alt: Significant wave height
   :srcset: /tutorials/graphics/images/sphx_glr_plot_wave_rose_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    Text(0.5, 1.117602784833945, 'Significant wave height')



.. GENERATED FROM PYTHON SOURCE LINES 43-47

Winter and summer
-----------------

Waves are higher and more regular in winter. The same bins are used for both roses.

.. GENERATED FROM PYTHON SOURCE LINES 47-58

.. code-block:: Python


    edges = [0, 1, 2, 3, 4, 6, 8]
    fig = plt.figure(figsize=(9, 4.5))
    fig.subplots_adjust(right=0.72)  # room for the legend
    for i, (name, months) in enumerate({"Winter": [12, 1, 2], "Summer": [6, 7, 8]}.items()):
        sub = ds.isel(time=ds.time.dt.month.isin(months))
        rose = plot_rose(
            sub.hs, sub.direction, edges=edges, rmax=40, fig=fig, subplot=121 + i, legend=i == 1
        )
        rose.ax.set_title(name)




.. image-sg:: /tutorials/graphics/images/sphx_glr_plot_wave_rose_002.png
   :alt: Winter, Summer
   :srcset: /tutorials/graphics/images/sphx_glr_plot_wave_rose_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 59-63

Peak period
-----------

Long periods are swell and short ones are wind sea, which has wider directions.

.. GENERATED FROM PYTHON SOURCE LINES 63-66

.. code-block:: Python


    rose = plot_rose(ds.tp, ds.direction, edges=[0, 6, 8, 10, 12, 14, 16], cmap="YlOrBr")
    rose.ax.set_title("Peak period")



.. image-sg:: /tutorials/graphics/images/sphx_glr_plot_wave_rose_003.png
   :alt: Peak period
   :srcset: /tutorials/graphics/images/sphx_glr_plot_wave_rose_003.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    Text(0.5, 1.160452075892098, 'Peak period')




.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 2.115 seconds)


.. _sphx_glr_download_tutorials_graphics_plot_wave_rose.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/shom-fr/xoa/master?urlpath=lab/tree/notebooks/tutorials/graphics/plot_wave_rose.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_wave_rose.ipynb <plot_wave_rose.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_wave_rose.py <plot_wave_rose.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_wave_rose.zip <plot_wave_rose.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
