.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python_module/06_grid_manipulation/pet_hide_pixel_out_eddies.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_06_grid_manipulation_pet_hide_pixel_out_eddies.py: Select pixel in eddies ====================== .. GENERATED FROM PYTHON SOURCE LINES 6-16 .. code-block:: Python from matplotlib import pyplot as plt from matplotlib.path import Path from numpy import ones from py_eddy_tracker import data from py_eddy_tracker.dataset.grid import RegularGridDataset from py_eddy_tracker.observations.observation import EddiesObservations from py_eddy_tracker.poly import create_vertice .. GENERATED FROM PYTHON SOURCE LINES 17-18 Load an eddy file which contains contours .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python a = EddiesObservations.load_file(data.get_demo_path("Anticyclonic_20190223.nc")) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Load a grid where we want found pixels in eddies or out .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python g = RegularGridDataset( data.get_demo_path("nrt_global_allsat_phy_l4_20190223_20190226.nc"), "longitude", "latitude", ) .. GENERATED FROM PYTHON SOURCE LINES 29-30 For each contours, we will get pixels indice in contour. .. GENERATED FROM PYTHON SOURCE LINES 30-45 .. code-block:: Python fig = plt.figure(figsize=(12, 6)) ax = fig.add_axes((0.05, 0.05, 0.9, 0.9)) ax.set_aspect("equal") ax.set_xlim(10, 70) ax.set_ylim(-50, -25) # We will used the outter contour x_name, y_name = a.intern(False) adt = g.grid("adt") mask = ones(adt.shape, dtype="bool") for eddy in a: i, j = Path(create_vertice(eddy[x_name], eddy[y_name])).pixels_in(g) mask[i, j] = False adt.mask[:] += ~mask g.display(ax, "adt") a.display(ax, label="Anticyclonic", color="g", lw=1, extern_only=True) .. image-sg:: /python_module/06_grid_manipulation/images/sphx_glr_pet_hide_pixel_out_eddies_001.png :alt: pet hide pixel out eddies :srcset: /python_module/06_grid_manipulation/images/sphx_glr_pet_hide_pixel_out_eddies_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 46-54 .. code-block:: Python fig = plt.figure(figsize=(12, 6)) ax = fig.add_axes((0.05, 0.05, 0.9, 0.9)) ax.set_aspect("equal") ax.set_xlim(10, 70) ax.set_ylim(-50, -25) adt.mask[:] = mask g.display(ax, "adt") a.display(ax, label="Anticyclonic", color="g", lw=1, extern_only=True) .. image-sg:: /python_module/06_grid_manipulation/images/sphx_glr_pet_hide_pixel_out_eddies_002.png :alt: pet hide pixel out eddies :srcset: /python_module/06_grid_manipulation/images/sphx_glr_pet_hide_pixel_out_eddies_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.696 seconds) .. _sphx_glr_download_python_module_06_grid_manipulation_pet_hide_pixel_out_eddies.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/06_grid_manipulation/pet_hide_pixel_out_eddies.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pet_hide_pixel_out_eddies.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pet_hide_pixel_out_eddies.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pet_hide_pixel_out_eddies.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_