.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/hpx2grid.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_auto_examples_hpx2grid.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_hpx2grid.py: HealPIX Image visualization --------------------------- HealPIX maps can be viewed as a 2D image rotated by 45 deg. This is useful for quick visualization with image viewers without distorting the native pixels of the image. .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import torch .. GENERATED FROM PYTHON SOURCE LINES 29-47 .. code-block:: Python from matplotlib.colors import Normalize from PIL import Image from earth2grid.healpix import Grid grid = Grid(level=8) lat = torch.tensor(grid.lat) lat_img = grid.to_image(lat) # Use Image to save at full resolution normalizer = Normalize(vmin=np.nanmin(lat_img), vmax=np.nanmax(lat_img)) array = normalizer(lat_img) array = plt.cm.viridis(array) array = (256 * array).astype("uint8") # set transparency for nans array[..., -1] = np.where(np.isnan(lat_img), 0, 255) image = Image.fromarray(array) image.save("hpx_grid.png") .. image-sg:: /auto_examples/images/sphx_glr_hpx2grid_001.png :alt: hpx2grid :srcset: /auto_examples/images/sphx_glr_hpx2grid_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Warning, cannot find healpixpad module .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.719 seconds) .. _sphx_glr_download_auto_examples_hpx2grid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hpx2grid.ipynb <hpx2grid.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hpx2grid.py <hpx2grid.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_