
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/plot_eddy_detect_croco.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_croco.py>`
        to download the full example code.

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

.. _sphx_glr_examples_plot_eddy_detect_croco.py:


Detect CROCO-GIGATL1 eddies at 1000m
====================================
In this example, eddies are detected from CROCO model currents interpolated to 1000 m
and collocated at RHO points.

.. GENERATED FROM PYTHON SOURCE LINES 11-15

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

Import needed stuff.

.. GENERATED FROM PYTHON SOURCE LINES 15-30

.. code-block:: Python

    import time

    import cmocean as cm
    import matplotlib.pyplot as plt
    import xarray as xr

    from shoot.dyn import get_relvort
    from shoot.eddies.eddies2d import Eddies2D
    from shoot.meta import set_meta_specs
    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 0x7026ac9b6dd0>



.. GENERATED FROM PYTHON SOURCE LINES 31-32

Read data

.. GENERATED FROM PYTHON SOURCE LINES 32-40

.. code-block:: Python


    # Mind that the dataarray should be 2D : single time and single depth
    set_meta_specs("croco")
    root_path = "MODELS/CROCO/GIGATL/gigatl1-1000m.nc"
    path = get_sample_file(root_path)
    ds = xr.open_dataset(path).isel(time=0)









.. GENERATED FROM PYTHON SOURCE LINES 41-47

Detect eddies
-------------
Parameters
~~~~~~~~~~

Window size in km to compute the LNAM and find eddy centers

.. GENERATED FROM PYTHON SOURCE LINES 47-49

.. code-block:: Python

    window_center = 50








.. GENERATED FROM PYTHON SOURCE LINES 50-51

Window size in km to fit SSH and make other diagnostics like contours

.. GENERATED FROM PYTHON SOURCE LINES 51-53

.. code-block:: Python

    window_fit = 120








.. GENERATED FROM PYTHON SOURCE LINES 54-55

Minimal radius of an eddy to retain it

.. GENERATED FROM PYTHON SOURCE LINES 55-57

.. code-block:: Python

    min_radius = 10








.. GENERATED FROM PYTHON SOURCE LINES 58-60

Ellipse error
preconised 1% for deep field, 5% to 10% to surface field

.. GENERATED FROM PYTHON SOURCE LINES 60-62

.. code-block:: Python


    ellipse_error = 0.02







.. GENERATED FROM PYTHON SOURCE LINES 63-65

Detection
---------

.. GENERATED FROM PYTHON SOURCE LINES 65-79

.. code-block:: Python


    start = time.time()
    eddies = Eddies2D.detect_eddies(
        ds.u,
        ds.v,
        window_center,
        window_fit=window_fit,
        min_radius=min_radius,
        paral=False,
        ellipse_error=ellipse_error,
    )
    end = time.time()
    print(f"Number of detected eddies {len(eddies.eddies)} in {end - start:.1f} s")





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

 .. code-block:: none

    Number of detected eddies 13 in 38.6 s




.. GENERATED FROM PYTHON SOURCE LINES 80-85

Plots
-----

We plot eddies with the relative vorticity as background.


.. GENERATED FROM PYTHON SOURCE LINES 85-111

.. code-block:: Python


    fig, ax = create_map(ds.lon_rho, ds.lat_rho, figsize=(8, 5))
    vort = get_relvort(ds.u, ds.v) / 1e-4
    cb = vort.plot(
        x="lon_rho",
        y="lat_rho",
        cmap=cm.cm.curl,
        ax=ax,
        add_colorbar=False,
        transform=pcarr,
    )
    plt.colorbar(cb, label=r"$\zeta/f$")
    nj = 4
    qv = plt.quiver(
        ds.lon_rho[::nj, ::nj].values,
        ds.lat_rho[::nj, ::nj].values,
        ds.u[::nj, ::nj].values,
        ds.v[::nj, ::nj].values,
        transform=pcarr,
    )
    plt.quiverkey(qv, 0.18, 0.85, 0.5, "50 cm/s", coordinates='figure')

    for eddy in eddies.eddies:
        eddy.plot(transform=pcarr, lw=1, boundary=True)
    plt.title("Relative vorticity at 1000m depth")
    plt.tight_layout()



.. image-sg:: /examples/images/sphx_glr_plot_eddy_detect_croco_001.png
   :alt: Relative vorticity at 1000m depth
   :srcset: /examples/images/sphx_glr_plot_eddy_detect_croco_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_examples_plot_eddy_detect_croco.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_croco.ipynb <plot_eddy_detect_croco.ipynb>`

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

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

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

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


.. only:: html

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

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