.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python_module/10_tracking_diagnostics/pet_groups.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_10_tracking_diagnostics_pet_groups.py: Groups distribution =================== .. GENERATED FROM PYTHON SOURCE LINES 6-12 .. code-block:: Python from matplotlib import pyplot as plt from numpy import arange, ones, percentile import py_eddy_tracker_sample from py_eddy_tracker.observations.tracking import TrackEddiesObservations .. GENERATED FROM PYTHON SOURCE LINES 13-14 Load an experimental med atlas over a period of 26 years (1993-2019) .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: Python a = TrackEddiesObservations.load_file( py_eddy_tracker_sample.get_demo_path( "eddies_med_adt_allsat_dt2018/Anticyclonic.zarr" ) ) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Group distribution .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python groups = dict() bins_time = [10, 20, 30, 60, 90, 180, 360, 100000] for t0, t1 in zip(bins_time[:-1], bins_time[1:]): groups[f"lifetime_{t0}_{t1}"] = lambda dataset, t0=t0, t1=t1: ( dataset.lifetime >= t0 ) * (dataset.lifetime < t1) bins_percentile = arange(0, 100.0001, 5) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Function to build stats .. GENERATED FROM PYTHON SOURCE LINES 33-61 .. code-block:: Python def stats_compilation(dataset, groups, field, bins, filter=None): datas = dict(ref=dataset.bins_stat(field, bins=bins, mask=filter)[1], y=dict()) for k, index in groups.items(): i = dataset.merge_filters(filter, index) x, datas["y"][k] = dataset.bins_stat(field, bins=bins, mask=i) datas["x"], datas["bins"] = x, bins return datas def plot_stats(ax, bins, x, y, ref, box=False, cmap=None, percentiles=None, **kw): base, ref = ones(x.shape) * 100.0, ref / 100.0 x = arange(bins.shape[0]).repeat(2)[1:-1] if box else x y0 = base if cmap is not None: cmap, nb_groups = plt.get_cmap(cmap), len(y) keys = tuple(y.keys()) for i, k in enumerate(keys[::-1]): y1 = y0 - y[k] / ref args = (y0.repeat(2), y1.repeat(2)) if box else (y0, y1) if cmap is not None: kw["color"] = cmap(1 - i / (nb_groups - 1)) ax.fill_between(x, *args, label=k, **kw) y0 = y1 if percentiles: for b in bins: ax.axvline(b, **percentiles) .. GENERATED FROM PYTHON SOURCE LINES 62-63 Speed radius by track period .. GENERATED FROM PYTHON SOURCE LINES 63-72 .. code-block:: Python stats = stats_compilation( a, groups, "radius_s", percentile(a.radius_s, bins_percentile) ) fig = plt.figure() ax = fig.add_subplot(111) plot_stats(ax, **stats, cmap="magma", percentiles=dict(color="gray", ls="-.", lw=0.4)) ax.set_xlabel("Speed radius (m)"), ax.set_ylabel("% of class"), ax.set_ylim(0, 100) ax.grid(), ax.legend() .. image-sg:: /python_module/10_tracking_diagnostics/images/sphx_glr_pet_groups_001.png :alt: pet groups :srcset: /python_module/10_tracking_diagnostics/images/sphx_glr_pet_groups_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (None, ) .. GENERATED FROM PYTHON SOURCE LINES 73-74 Amplitude by track period .. GENERATED FROM PYTHON SOURCE LINES 74-82 .. code-block:: Python stats = stats_compilation( a, groups, "amplitude", percentile(a.amplitude, bins_percentile) ) fig = plt.figure() ax = fig.add_subplot(111) plot_stats(ax, **stats, cmap="magma") ax.set_xlabel("Amplitude (m)"), ax.set_ylabel("% of class"), ax.set_ylim(0, 100) ax.grid(), ax.legend() .. image-sg:: /python_module/10_tracking_diagnostics/images/sphx_glr_pet_groups_002.png :alt: pet groups :srcset: /python_module/10_tracking_diagnostics/images/sphx_glr_pet_groups_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (None, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.999 seconds) .. _sphx_glr_download_python_module_10_tracking_diagnostics_pet_groups.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/10_tracking_diagnostics/pet_groups.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_groups.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_groups.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_groups.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_