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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_examples_plot_eddy_detect_sat.py>`
        to download the full example code.

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

.. _sphx_glr_examples_plot_eddy_detect_sat.py:


Detect eddies from satellite sea level
======================================

.. GENERATED FROM PYTHON SOURCE LINES 8-10

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

.. GENERATED FROM PYTHON SOURCE LINES 10-24

.. code-block:: Python


    # Import needed stuff.
    import time

    import cmocean  # noqa
    import matplotlib.pyplot as plt
    import xarray as xr

    from shoot.eddies.eddies2d import Eddies2D
    from shoot.plot import create_map, pcarr
    from shoot.samples import get_sample_file

    xr.set_options(display_style="text")





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

 .. code-block:: none


    <xarray.core.options.set_options object at 0x702699f69110>



.. GENERATED FROM PYTHON SOURCE LINES 25-27

Read data
---------

.. GENERATED FROM PYTHON SOURCE LINES 27-33

.. code-block:: Python


    root_path = "OBS/SATELLITE/jan2024_ionian_sea_duacs.nc"
    path = get_sample_file(root_path)
    # select one specific date for this example
    ds = xr.open_dataset(path).isel(time=0)








.. GENERATED FROM PYTHON SOURCE LINES 34-36

Detect eddies
-------------

.. GENERATED FROM PYTHON SOURCE LINES 36-43

.. code-block:: Python


    # Parameters
    # ~~~~~~~~~~

    # Window size in km to compute the LNAM and find eddy centers : Lb
    window_center = 50








.. GENERATED FROM PYTHON SOURCE LINES 44-45

Window size in km to fit SSH and make other diagnostics like contours : 10Rd suggested

.. GENERATED FROM PYTHON SOURCE LINES 45-47

.. code-block:: Python

    window_fit = 120








.. GENERATED FROM PYTHON SOURCE LINES 48-51

Minimal radius of an eddy to retain it
Mind that the radius is defined as the radius of the maximum speed contour
Preconised around Rossby radius of deformation

.. GENERATED FROM PYTHON SOURCE LINES 51-53

.. code-block:: Python

    min_radius = 10








.. GENERATED FROM PYTHON SOURCE LINES 54-57

Ellipse error
This is the percentage error from an ellipse.
For surface field it is conseil to let 5% to 10%

.. GENERATED FROM PYTHON SOURCE LINES 57-59

.. code-block:: Python

    ellipse_error = 0.05  # percentage error from an ellipse








.. GENERATED FROM PYTHON SOURCE LINES 60-65

Detection
 ~~~~~~~~~
 performed through Eddies class
 parallelisation is possible but should be perfomed with caution (refer to the docs)
###

.. GENERATED FROM PYTHON SOURCE LINES 65-80

.. code-block:: Python


    start = time.time()
    eddies = Eddies2D.detect_eddies(
        ds.ugos,
        ds.vgos,
        window_center,
        window_fit=window_fit,
        ssh=ds.adt,
        min_radius=min_radius,
        paral=False,
        ellipse_error=ellipse_error,
    )
    end = time.time()
    print("it takes %.1f s" % (end - start))





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

 .. code-block:: none

    it takes 11.2 s




.. GENERATED FROM PYTHON SOURCE LINES 81-84

Plots
-----


.. GENERATED FROM PYTHON SOURCE LINES 84-98

.. code-block:: Python

    fig, ax = create_map(ds.longitude, ds.latitude, figsize=(8, 5))
    ds.adt.plot(ax=ax, transform=pcarr, add_colorbar=False, cmap="Spectral_r", alpha=0.6)
    plt.quiver(
        ds.longitude.values,
        ds.latitude.values,
        ds.ugos.values,
        ds.vgos.values,
        transform=pcarr,
    )
    for eddy in eddies.eddies:
        # for eddy in eddies_ssh:
        eddy.plot(transform=pcarr, lw=1)
    plt.title(f"w_center {window_center} km, w_fit {window_fit}km min_rad {min_radius}km")
    plt.tight_layout()



.. image-sg:: /examples/images/sphx_glr_plot_eddy_detect_sat_001.png
   :alt: w_center 50 km, w_fit 120km min_rad 10km
   :srcset: /examples/images/sphx_glr_plot_eddy_detect_sat_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_examples_plot_eddy_detect_sat.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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