.. 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_gulf_stream.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_gulf_stream.py: Eddy detection : Gulf stream ============================ 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-20 .. 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 from py_eddy_tracker.eddy_feature import Contours .. GENERATED FROM PYTHON SOURCE LINES 21-36 .. code-block:: Python def start_axes(title): fig = plt.figure(figsize=(13, 8)) ax = fig.add_axes([0.03, 0.03, 0.90, 0.94]) ax.set_xlim(279, 304), ax.set_ylim(29, 44) 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 37-38 Load Input grid, ADT is used to detect eddies .. GENERATED FROM PYTHON SOURCE LINES 38-57 .. code-block:: Python margin = 30 g = RegularGridDataset( data.get_demo_path("nrt_global_allsat_phy_l4_20190223_20190226.nc"), "longitude", "latitude", # Manual area subset indexs=dict( longitude=slice(1116 - margin, 1216 + margin), latitude=slice(476 - margin, 536 + margin), ), ) ax = start_axes("ADT (m)") m = g.display(ax, "adt", vmin=-1, vmax=1, cmap="RdBu_r") # Draw line on the gulf stream front great_current = Contours(g.x_c, g.y_c, g.grid("adt"), levels=(0.35,), keep_unclose=True) great_current.display(ax, color="k") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_001.png :alt: ADT (m) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-61 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 61-63 .. code-block:: Python g.add_uv("adt") .. GENERATED FROM PYTHON SOURCE LINES 64-67 Pre-processings --------------- Apply a high-pass filter to remove the large scale and highlight the mesoscale .. GENERATED FROM PYTHON SOURCE LINES 67-73 .. code-block:: Python g.bessel_high_filter("adt", 700) ax = start_axes("ADT (m) filtered (700km)") m = g.display(ax, "adt", vmin=-0.4, vmax=0.4, cmap="RdBu_r") great_current.display(ax, color="k") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_002.png :alt: ADT (m) filtered (700km) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 74-77 Identification -------------- Run the identification step with slices of 2 mm .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. 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 81-82 Display of all closed contours found in the grid (only 1 contour every 5) .. GENERATED FROM PYTHON SOURCE LINES 82-87 .. code-block:: Python ax = start_axes("ADT closed contours (only 1 / 5 levels)") g.contours.display(ax, step=5, lw=1) great_current.display(ax, color="k") update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_003.png :alt: ADT closed contours (only 1 / 5 levels) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 88-89 Contours included in eddies .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: Python ax = start_axes("ADT contours used as eddies") g.contours.display(ax, only_used=True, lw=0.25) great_current.display(ax, color="k") update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_004.png :alt: ADT contours used as eddies :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 95-98 Post analysis ------------- Contours can be rejected for several reasons (shape error to high, several extremum in contour, ...) .. GENERATED FROM PYTHON SOURCE LINES 98-103 .. code-block:: Python ax = start_axes("ADT rejected contours") g.contours.display(ax, only_unused=True, lw=0.25) great_current.display(ax, color="k") update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_005.png :alt: ADT rejected contours :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-110 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 110-114 .. 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_gulf_stream_006.png :alt: Contours' rejection criteria :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 115-116 Display the shape error of each tested contour, the limit of shape error is set to 55 % .. GENERATED FROM PYTHON SOURCE LINES 116-122 .. 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_gulf_stream_007.png :alt: Contour shape error :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 123-124 Some closed contours contains several eddies (aka, more than one extremum) .. GENERATED FROM PYTHON SOURCE LINES 124-139 .. 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_gulf_stream_008.png :alt: ADT rejected contours containing eddies :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 140-144 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 144-155 .. code-block:: Python ax = start_axes("Eddies detected") 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() great_current.display(ax, color="k") update_axes(ax) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_009.png :alt: Eddies detected :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 156-157 Display the effective radius of the detected eddies .. GENERATED FROM PYTHON SOURCE LINES 157-162 .. code-block:: Python ax = start_axes("Effective radius (km)") a.filled(ax, "radius_e", vmin=10, vmax=150, cmap="magma_r", factor=0.001, lut=14) m = c.filled(ax, "radius_e", vmin=10, vmax=150, cmap="magma_r", factor=0.001, lut=14) great_current.display(ax, color="k") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_010.png :alt: Effective radius (km) :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_eddy_detection_gulf_stream_010.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.087 seconds) .. _sphx_glr_download_python_module_02_eddy_identification_pet_eddy_detection_gulf_stream.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_gulf_stream.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_eddy_detection_gulf_stream.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_eddy_detection_gulf_stream.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_eddy_detection_gulf_stream.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_