.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python_module/16_network/pet_ioannou_2017_case.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_16_network_pet_ioannou_2017_case.py: Ioannou case ============ Figure 10 from https://doi.org/10.1002/2017JC013158 We want to find the Ierapetra Eddy described above in a network demonstration run. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python from datetime import datetime, timedelta .. GENERATED FROM PYTHON SOURCE LINES 12-26 .. code-block:: Python import re from matplotlib import colors, pyplot as plt from matplotlib.animation import FuncAnimation from matplotlib.ticker import FuncFormatter from numpy import arange, array, pi, where from py_eddy_tracker.appli.gui import Anim from py_eddy_tracker.data import get_demo_path from py_eddy_tracker.generic import coordinates_to_local from py_eddy_tracker.gui import GUI_AXES from py_eddy_tracker.observations.network import NetworkObservations from py_eddy_tracker.poly import fit_ellipse .. GENERATED FROM PYTHON SOURCE LINES 27-75 .. code-block:: Python class VideoAnimation(FuncAnimation): def _repr_html_(self, *args, **kwargs): """To get video in html and have a player""" content = self.to_html5_video() return re.sub( r'width="[0-9]*"\sheight="[0-9]*"', 'width="100%" height="100%"', content ) def save(self, *args, **kwargs): if args[0].endswith("gif"): # In this case gif is used to create thumbnail which is not used but consume same time than video # So we create an empty file, to save time with open(args[0], "w") as _: pass return return super().save(*args, **kwargs) @FuncFormatter def formatter(x, pos): return (timedelta(x) + datetime(1950, 1, 1)).strftime("%d/%m/%Y") def start_axes(title=""): fig = plt.figure(figsize=(13, 6)) ax = fig.add_axes([0.03, 0.03, 0.90, 0.94], projection=GUI_AXES) ax.set_xlim(19, 29), ax.set_ylim(31, 35.5) ax.set_aspect("equal") ax.set_title(title, weight="bold") return ax def timeline_axes(title=""): fig = plt.figure(figsize=(15, 5)) ax = fig.add_axes([0.03, 0.06, 0.90, 0.88]) ax.set_title(title, weight="bold") ax.xaxis.set_major_formatter(formatter), ax.grid() return ax def update_axes(ax, mappable=None): ax.grid(True) if mappable: return plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9])) .. GENERATED FROM PYTHON SOURCE LINES 76-77 We know the network ID, we will get directly .. GENERATED FROM PYTHON SOURCE LINES 77-82 .. code-block:: Python ioannou_case = NetworkObservations.load_file(get_demo_path("network_med.nc")).network( 651 ) print(ioannou_case.infos()) .. rst-class:: sphx-glr-script-out .. code-block:: none 11948 obs 244 segments .. GENERATED FROM PYTHON SOURCE LINES 83-84 It seems that this network is huge! Our case is visible at 22E 33.5N .. GENERATED FROM PYTHON SOURCE LINES 84-88 .. code-block:: Python ax = start_axes() ioannou_case.plot(ax, color_cycle=ioannou_case.COLORS) update_axes(ax) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_001.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-92 Full Timeline ------------- The network span for many years... How to cut the interesting part? .. GENERATED FROM PYTHON SOURCE LINES 92-98 .. code-block:: Python fig = plt.figure(figsize=(15, 5)) ax = fig.add_axes([0.04, 0.05, 0.92, 0.92]) ax.xaxis.set_major_formatter(formatter), ax.grid() _ = ioannou_case.display_timeline(ax) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_002.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 99-102 Sub network and new numbering ----------------------------- Here we chose to keep only the order 3 segments relatives to our chosen eddy .. GENERATED FROM PYTHON SOURCE LINES 102-113 .. code-block:: Python i = where( (ioannou_case.lat > 33) * (ioannou_case.lat < 34) * (ioannou_case.lon > 22) * (ioannou_case.lon < 23) * (ioannou_case.time > 20630) * (ioannou_case.time < 20650) )[0][0] close_to_i3 = ioannou_case.relative(i, order=3) close_to_i3.numbering_segment() .. GENERATED FROM PYTHON SOURCE LINES 114-117 Anim ---- Quick movie to see better! .. GENERATED FROM PYTHON SOURCE LINES 117-134 .. code-block:: Python a = Anim( close_to_i3, figsize=(12, 4), cmap=colors.ListedColormap( list(close_to_i3.COLORS), name="from_list", N=close_to_i3.segment.max() + 1 ), nb_step=7, dpi=70, field_color="segment", field_txt="segment", ) a.ax.set_xlim(19, 30), a.ax.set_ylim(32, 35.25) a.txt.set_position((21.5, 32.7)) # We display in video only from the 100th day to the 500th kwargs = dict(frames=arange(*a.period)[100:501], interval=100) ani = VideoAnimation(a.fig, a.func_animation, **kwargs) .. container:: sphx-glr-animation .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 135-137 Classic display --------------- .. GENERATED FROM PYTHON SOURCE LINES 137-140 .. code-block:: Python ax = timeline_axes() _ = close_to_i3.display_timeline(ax) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_004.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 141-147 .. code-block:: Python ax = start_axes("") n_copy = close_to_i3.copy() n_copy.position_filter(2, 4) n_copy.plot(ax, color_cycle=n_copy.COLORS) update_axes(ax) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_005.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 148-150 Latitude Timeline ----------------- .. GENERATED FROM PYTHON SOURCE LINES 150-155 .. code-block:: Python ax = timeline_axes(f"Close segments ({close_to_i3.infos()})") n_copy = close_to_i3.copy() n_copy.median_filter(15, "time", "latitude") _ = n_copy.display_timeline(ax, field="lat", method="all") .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_006.png :alt: Close segments (2018 obs 24 segments) :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 156-159 Local radius timeline --------------------- Effective (bold) and Speed (thin) Radius together .. GENERATED FROM PYTHON SOURCE LINES 159-179 .. code-block:: Python n_copy.median_filter(2, "time", "radius_e") n_copy.median_filter(2, "time", "radius_s") for b0, b1 in [ (datetime(i, 1, 1), datetime(i, 12, 31)) for i in (2004, 2005, 2006, 2007) ]: ref, delta = datetime(1950, 1, 1), 20 b0_, b1_ = (b0 - ref).days, (b1 - ref).days ax = timeline_axes() ax.set_xlim(b0_ - delta, b1_ + delta) ax.set_ylim(10, 115) ax.axvline(b0_, color="k", lw=1.5, ls="--"), ax.axvline( b1_, color="k", lw=1.5, ls="--" ) n_copy.display_timeline( ax, field="radius_e", method="all", lw=4, markersize=8, factor=1e-3 ) n_copy.display_timeline( ax, field="radius_s", method="all", lw=1, markersize=3, factor=1e-3 ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_007.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_007.png :class: sphx-glr-multi-img * .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_008.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_008.png :class: sphx-glr-multi-img * .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_009.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_009.png :class: sphx-glr-multi-img * .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_010.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_010.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 180-183 Parameters timeline ------------------- Effective Radius .. GENERATED FROM PYTHON SOURCE LINES 183-188 .. code-block:: Python kw = dict(s=35, cmap=plt.get_cmap("Spectral_r", 8), zorder=10) ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, "radius_e", factor=1e-3, vmin=20, vmax=100, **kw) cb = update_axes(ax, m["scatter"]) cb.set_label("Effective radius (km)") .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_011.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_011.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 189-190 Shape error .. GENERATED FROM PYTHON SOURCE LINES 190-195 .. code-block:: Python ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, "shape_error_e", vmin=14, vmax=70, **kw) cb = update_axes(ax, m["scatter"]) cb.set_label("Effective shape error") .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_012.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_012.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 196-200 Rotation angle -------------- For each obs, fit an ellipse to the contour, with theta the angle from the x-axis, a the semi ax in x direction and b the semi ax in y dimension .. GENERATED FROM PYTHON SOURCE LINES 200-215 .. code-block:: Python theta_ = list() a_ = list() b_ = list() for obs in close_to_i3: x, y = obs["contour_lon_s"], obs["contour_lat_s"] x0_, y0_ = x.mean(), y.mean() x_, y_ = coordinates_to_local(x, y, x0_, y0_) x0, y0, a, b, theta = fit_ellipse(x_, y_) theta_.append(theta) a_.append(a) b_.append(b) a_ = array(a_) b_ = array(b_) .. GENERATED FROM PYTHON SOURCE LINES 216-217 Theta .. GENERATED FROM PYTHON SOURCE LINES 217-221 .. code-block:: Python ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, theta_, vmin=-pi / 2, vmax=pi / 2, cmap="hsv") _ = update_axes(ax, m["scatter"]) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_013.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_013.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 222-223 a .. GENERATED FROM PYTHON SOURCE LINES 223-227 .. code-block:: Python ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, a_ * 1e-3, vmin=0, vmax=80, cmap="Spectral_r") _ = update_axes(ax, m["scatter"]) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_014.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_014.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 228-229 b .. GENERATED FROM PYTHON SOURCE LINES 229-233 .. code-block:: Python ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, b_ * 1e-3, vmin=0, vmax=80, cmap="Spectral_r") _ = update_axes(ax, m["scatter"]) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_015.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_015.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 234-235 a/b .. GENERATED FROM PYTHON SOURCE LINES 235-238 .. code-block:: Python ax = timeline_axes() m = close_to_i3.scatter_timeline(ax, a_ / b_, vmin=1, vmax=2, cmap="Spectral_r") _ = update_axes(ax, m["scatter"]) .. image-sg:: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_016.png :alt: pet ioannou 2017 case :srcset: /python_module/16_network/images/sphx_glr_pet_ioannou_2017_case_016.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.043 seconds) .. _sphx_glr_download_python_module_16_network_pet_ioannou_2017_case.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/16_network/pet_ioannou_2017_case.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_ioannou_2017_case.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_ioannou_2017_case.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_ioannou_2017_case.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_