.. 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_shape_gallery.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_shape_gallery.py: Shape error gallery =================== Gallery of contours with shape error .. GENERATED FROM PYTHON SOURCE LINES 8-17 .. code-block:: Python from matplotlib import pyplot as plt from numpy import arange, cos, linspace, radians, sin from py_eddy_tracker import data from py_eddy_tracker.dataset.grid import RegularGridDataset from py_eddy_tracker.eddy_feature import Contours from py_eddy_tracker.generic import local_to_coordinates .. GENERATED FROM PYTHON SOURCE LINES 18-19 Method to built circle from center coordinates .. GENERATED FROM PYTHON SOURCE LINES 19-25 .. code-block:: Python def build_circle(x0, y0, r): angle = radians(linspace(0, 360, 50)) x_norm, y_norm = cos(angle), sin(angle) return local_to_coordinates(x_norm * r, y_norm * r, x0, y0) .. GENERATED FROM PYTHON SOURCE LINES 26-27 We iterate over closed contours and sort with regards of shape error .. GENERATED FROM PYTHON SOURCE LINES 27-42 .. code-block:: Python g = RegularGridDataset( data.get_demo_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude", ) c = Contours(g.x_c, g.y_c, g.grid("adt") * 100, arange(-50, 50, 0.2)) contours = dict() for coll in c.iter(): for current_contour in coll.get_paths(): _, _, _, aerr = current_contour.fit_circle() i = int(aerr // 4) + 1 if i not in contours: contours[i] = list() contours[i].append(current_contour) .. rst-class:: sphx-glr-script-out .. code-block:: none We assume pixel position of grid is centered for /home/docs/checkouts/readthedocs.org/user_builds/py-eddy-tracker/conda/latest/lib/python3.12/site-packages/py_eddy_tracker/data/dt_med_allsat_phy_l4_20160515_20190101.nc .. GENERATED FROM PYTHON SOURCE LINES 43-46 Shape error gallery ------------------- For each contour display, we display circle fitted, we work at different latitude circle could have distorsion .. GENERATED FROM PYTHON SOURCE LINES 46-65 .. code-block:: Python fig = plt.figure(figsize=(12, 12)) for i in range(1, 26): e_min, e_max = (i - 1) * 4, i * 4 ax = plt.subplot(5, 5, i, title=f" {e_min} < err < {e_max}") ax.xaxis.set_ticklabels([]) ax.yaxis.set_ticklabels([]) ax.set_aspect("equal") ax.grid() if i in contours: for contour in contours[i]: x, y = contour.lon, contour.lat x0, y0, radius, _ = contour.fit_circle() if x.shape[0] > 30 and 30000 < radius < 70000: # Plot only first contour found m = ax.plot(x, y, "r")[0] ax.plot(*build_circle(x0, y0, radius), "g--") ax.plot(x0, y0, "k.") break plt.tight_layout() .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_shape_gallery_001.png :alt: 0 < err < 4, 4 < err < 8, 8 < err < 12, 12 < err < 16, 16 < err < 20, 20 < err < 24, 24 < err < 28, 28 < err < 32, 32 < err < 36, 36 < err < 40, 40 < err < 44, 44 < err < 48, 48 < err < 52, 52 < err < 56, 56 < err < 60, 60 < err < 64, 64 < err < 68, 68 < err < 72, 72 < err < 76, 76 < err < 80, 80 < err < 84, 84 < err < 88, 88 < err < 92, 92 < err < 96, 96 < err < 100 :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_shape_gallery_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.848 seconds) .. _sphx_glr_download_python_module_02_eddy_identification_pet_shape_gallery.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_shape_gallery.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_shape_gallery.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_shape_gallery.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_shape_gallery.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_