.. 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_statistics_on_identification.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_statistics_on_identification.py: Stastics on identification files ================================ Some statistics on raw identification without any tracking .. GENERATED FROM PYTHON SOURCE LINES 7-18 .. code-block:: Python from matplotlib import pyplot as plt from matplotlib.dates import date2num import numpy as np from py_eddy_tracker import start_logger from py_eddy_tracker.data import get_remote_demo_sample from py_eddy_tracker.observations.observation import EddiesObservations start_logger().setLevel("ERROR") .. GENERATED FROM PYTHON SOURCE LINES 19-34 .. 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) return ax def update_axes(ax, mappable=None): ax.grid() if mappable: plt.colorbar(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9])) .. GENERATED FROM PYTHON SOURCE LINES 35-38 We load demo sample and take only first year. Replace by a list of filename to apply on your own dataset. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python file_objects = get_remote_demo_sample( "eddies_med_adt_allsat_dt2018/Anticyclonic_2010_2011_2012" )[:365] .. GENERATED FROM PYTHON SOURCE LINES 43-44 Merge all identification datasets in one object .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python all_a = EddiesObservations.concatenate( [EddiesObservations.load_file(i) for i in file_objects] ) .. GENERATED FROM PYTHON SOURCE LINES 49-50 We define polygon bound .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: Python x0, x1, y0, y1 = 15, 20, 33, 38 xs = np.array([[x0, x1, x1, x0, x0]], dtype="f8") ys = np.array([[y0, y0, y1, y1, y0]], dtype="f8") # Polygon object created for the match function use. polygon = dict(contour_lon_e=xs, contour_lat_e=ys, contour_lon_s=xs, contour_lat_s=ys) .. GENERATED FROM PYTHON SOURCE LINES 57-58 Geographic frequency of eddies .. GENERATED FROM PYTHON SOURCE LINES 58-68 .. code-block:: Python step = 0.125 ax = start_axes("") # Count pixel encompassed in each contour g_a = all_a.grid_count(bins=((-10, 37, step), (30, 46, step)), intern=True) m = g_a.display( ax, cmap="terrain_r", vmin=0, vmax=0.75, factor=1 / all_a.nb_days, name="count" ) ax.plot(polygon["contour_lon_e"][0], polygon["contour_lat_e"][0], "r") update_axes(ax, m) .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_001.png :alt: pet statistics on identification :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-71 We use the match function to count the number of eddies that intersect the polygon defined previously `p1_area` option allow to get in c_e/c_s output, precentage of area occupy by eddies in the polygon. .. GENERATED FROM PYTHON SOURCE LINES 71-74 .. code-block:: Python i_e, j_e, c_e = all_a.match(polygon, p1_area=True, intern=False) i_s, j_s, c_s = all_a.match(polygon, p1_area=True, intern=True) .. GENERATED FROM PYTHON SOURCE LINES 75-81 .. code-block:: Python dt = np.datetime64("1970-01-01") - np.datetime64("1950-01-01") kw_hist = dict( bins=date2num(np.arange(21900, 22300).astype("datetime64") - dt), histtype="step" ) # translate julian day in datetime64 t = all_a.time.astype("datetime64") - dt .. GENERATED FROM PYTHON SOURCE LINES 82-83 Number of eddies within a polygon .. GENERATED FROM PYTHON SOURCE LINES 83-94 .. code-block:: Python ax = plt.figure(figsize=(12, 6)).add_subplot(111) ax.set_title("Different ways to count eddies within a polygon") ax.set_ylabel("Count") m = all_a.mask_from_polygons(((xs, ys),)) ax.hist(t[m], label="Eddy Center in polygon", **kw_hist) ax.hist(t[i_s[c_s > 0]], label="Intersection Speed contour and polygon", **kw_hist) ax.hist(t[i_e[c_e > 0]], label="Intersection Effective contour and polygon", **kw_hist) ax.legend() ax.set_xlim(np.datetime64("2010"), np.datetime64("2011")) ax.grid() .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_002.png :alt: Different ways to count eddies within a polygon :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 95-96 Percent of the area of interest occupied by eddies. .. GENERATED FROM PYTHON SOURCE LINES 96-106 .. code-block:: Python ax = plt.figure(figsize=(12, 6)).add_subplot(111) ax.set_title("Percent of polygon occupied by an anticyclonic eddy") ax.set_ylabel("Percent of polygon") ax.hist(t[i_s[c_s > 0]], weights=c_s[c_s > 0] * 100.0, label="speed contour", **kw_hist) ax.hist( t[i_e[c_e > 0]], weights=c_e[c_e > 0] * 100.0, label="effective contour", **kw_hist ) ax.legend(), ax.set_ylim(0, 25) ax.set_xlim(np.datetime64("2010"), np.datetime64("2011")) ax.grid() .. image-sg:: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_003.png :alt: Percent of polygon occupied by an anticyclonic eddy :srcset: /python_module/02_eddy_identification/images/sphx_glr_pet_statistics_on_identification_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.776 seconds) .. _sphx_glr_download_python_module_02_eddy_identification_pet_statistics_on_identification.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_statistics_on_identification.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_statistics_on_identification.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_statistics_on_identification.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_statistics_on_identification.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_