.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python_module/02_eddy_identification/pet_eddy_detection.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_python_module_02_eddy_identification_pet_eddy_detection.py: Eddy detection : Med ==================== Script will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid) Figures will show different step to detect eddies. .. GENERATED FROM PYTHON SOURCE LINES 10-19 .. code-block:: Python from datetime import datetime from matplotlib import pyplot as plt from numpy import arange from py_eddy_tracker import data from py_eddy_tracker.dataset.grid import RegularGridDataset .. GENERATED FROM PYTHON SOURCE LINES 20-35 .. code-block:: Python def start_axes(title): fig = plt.figure(figsize=(13, 5)) ax = fig.add_axes([0.03, 0.03, 0.90, 0.94]) ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46) ax.set_aspect("equal") ax.set_title(title, weight="bold") return ax def update_axes(ax, mappable=None): ax.grid() if mappable: plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9])) .. GENERATED FROM PYTHON SOURCE LINES 36-37 Load Input grid, ADT is used to detect eddies .. GENERATED FROM PYTHON SOURCE LINES 37-47 .. code-block:: Python g = RegularGridDataset( data.get_demo_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude", ) ax = start_axes("ADT (m)") m = g.display(ax, "adt", vmin=-0.15, vmax=0.15, cmap="RdBu_r") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_001.png :alt: ADT (m) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-51 Get geostrophic speed u,v ------------------------- U/V are deduced from ADT, this algortihm is not ok near the equator (~+- 2°) .. GENERATED FROM PYTHON SOURCE LINES 51-59 .. code-block:: Python g.add_uv("adt") ax = start_axes("U/V deduce from ADT (m)") ax.set_xlim(2.5, 9), ax.set_ylim(37.5, 40) m = g.display(ax, "adt", vmin=-0.15, vmax=0.15, cmap="RdBu_r") u, v = g.grid("u").T, g.grid("v").T ax.quiver(g.x_c, g.y_c, u, v, scale=10) update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_002.png :alt: U/V deduce from ADT (m) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-63 Pre-processings --------------- Apply a high-pass filter to remove the large scale and highlight the mesoscale .. GENERATED FROM PYTHON SOURCE LINES 63-68 .. code-block:: Python g.bessel_high_filter("adt", 500) ax = start_axes("ADT (m) filtered (500km)") m = g.display(ax, "adt", vmin=-0.15, vmax=0.15, cmap="RdBu_r") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_003.png :alt: ADT (m) filtered (500km) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-72 Identification -------------- Run the identification step with slices of 2 mm .. GENERATED FROM PYTHON SOURCE LINES 72-75 .. code-block:: Python date = datetime(2016, 5, 15) a, c = g.eddy_identification("adt", "u", "v", date, 0.002, shape_error=55) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/py-eddy-tracker/conda/latest/lib/python3.12/site-packages/py_eddy_tracker/dataset/grid.py:1915: RuntimeWarning: invalid value encountered in sqrt self._speed_ev = sqrt(u * u + v * v) /home/docs/checkouts/readthedocs.org/user_builds/py-eddy-tracker/conda/latest/lib/python3.12/site-packages/numpy/lib/function_base.py:4824: UserWarning: Warning: 'partition' will ignore the 'mask' of the MaskedArray. arr.partition( .. GENERATED FROM PYTHON SOURCE LINES 76-77 Display of all closed contours found in the grid (only 1 contour every 4) .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python ax = start_axes("ADT closed contours (only 1 / 4 levels)") g.contours.display(ax, step=4) update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_004.png :alt: ADT closed contours (only 1 / 4 levels) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 82-83 Contours included in eddies .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: Python ax = start_axes("ADT contours used as eddies") g.contours.display(ax, only_used=True) update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_005.png :alt: ADT contours used as eddies :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 88-91 Post analysis ------------- Contours can be rejected for several reasons (shape error to high, several extremum in contour, ...) .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. code-block:: Python ax = start_axes("ADT rejected contours") g.contours.display(ax, only_unused=True) update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_006.png :alt: ADT rejected contours :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 96-102 Criteria for rejecting a contour: 0. - Accepted (green) 1. - Rejection for shape error (red) 2. - Masked value within contour (blue) 3. - Under or over the pixel limit bounds (black) 4. - Amplitude criterion (yellow) .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python ax = start_axes("Contours' rejection criteria") g.contours.display(ax, only_unused=True, lw=0.5, display_criterion=True) update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_007.png :alt: Contours' rejection criteria :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-108 Display the shape error of each tested contour, the limit of shape error is set to 55 % .. GENERATED FROM PYTHON SOURCE LINES 108-114 .. code-block:: Python ax = start_axes("Contour shape error") m = g.contours.display( ax, lw=0.5, field="shape_error", bins=arange(20, 90.1, 5), cmap="PRGn_r" ) update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_008.png :alt: Contour shape error :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 115-116 Some closed contours contains several eddies (aka, more than one extremum) .. GENERATED FROM PYTHON SOURCE LINES 116-131 .. code-block:: Python ax = start_axes("ADT rejected contours containing eddies") g.contours.label_contour_unused_which_contain_eddies(a) g.contours.label_contour_unused_which_contain_eddies(c) g.contours.display( ax, only_contain_eddies=True, color="k", lw=1, label="Could be a contour of interaction", ) a.display(ax, color="r", linewidth=0.75, label="Anticyclonic", ref=-10) c.display(ax, color="b", linewidth=0.75, label="Cyclonic", ref=-10) ax.legend() update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_009.png :alt: ADT rejected contours containing eddies :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 132-136 Output ------ When displaying the detected eddies, dashed lines are for effective contour, solide lines for the contour of the maximum mean speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1 .. GENERATED FROM PYTHON SOURCE LINES 136-145 .. code-block:: Python ax = start_axes("Detected Eddies") a.display( ax, color="r", linewidth=0.75, label="Anticyclonic ({nb_obs} eddies)", ref=-10 ) c.display(ax, color="b", linewidth=0.75, label="Cyclonic ({nb_obs} eddies)", ref=-10) ax.legend() update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_010.png :alt: Detected Eddies :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_010.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 146-147 Display the speed radius of the detected eddies .. GENERATED FROM PYTHON SOURCE LINES 147-153 .. code-block:: Python ax = start_axes("Speed Radius (km)") kwargs = dict(vmin=10, vmax=50, s=80, ref=-10, cmap="magma_r", factor=0.001) a.scatter(ax, "radius_s", **kwargs) m = c.scatter(ax, "radius_s", **kwargs) update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_011.png :alt: Speed Radius (km) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_011.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 154-155 Filling the effective radius contours with the effective radius values .. GENERATED FROM PYTHON SOURCE LINES 155-160 .. code-block:: Python ax = start_axes("Effective Radius (km)") kwargs = dict(vmin=10, vmax=80, cmap="magma_r", factor=0.001, lut=14, ref=-10) a.filled(ax, "effective_radius", **kwargs) m = c.filled(ax, "radius_e", **kwargs) update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_012.png :alt: Effective Radius (km) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_012.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.158 seconds) .. _sphx_glr_download_python_module_02_eddy_identification_pet_eddy_detection.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/AntSimi/py-eddy-tracker/master?urlpath=lab/tree/notebooks/python_module/02_eddy_identification/pet_eddy_detection.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_eddy_detection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_eddy_detection.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_eddy_detection.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_