Search code examples
pythonhealpy

How can I partially plot a Healpix map using Healpy?


When working with healpy, I am able to plot a Healpix map in Mollview using

import healpy
map = 'filename.fits'
healpy.visufunc.mollview(map)

or as in the tutorial

>>> import numpy as np
>>> import healpy as hp
>>> NSIDE = 32
>>> m = np.arange(hp.nside2npix(NSIDE))
>>> hp.mollview(m, title="Mollview image RING")

which outputs

enter image description here

Is there a way to display only certain regions of the map? For example, only the upper hemisphere, or only the left side?

What I have in mind is viewing only small patches of the sky to see small point sources, or something like the "half-sky" projection from LSST

enter image description here


Solution

  • You can use a mask, which is a boolean map of the same size, where 1 are masked, 0 are not masked:

    http://healpy.readthedocs.org/en/latest/tutorial.html#masked-map-partial-maps

    Example:

    import numpy as np
    import healpy as hp
    NSIDE = 32
    m = hp.ma(np.arange(hp.nside2npix(NSIDE), dtype=np.double))
    mask = np.zeros(hp.nside2npix(NSIDE), dtype=np.bool)
    pixel_theta, pixel_phi = hp.pix2ang(NSIDE, np.arange(hp.nside2npix(NSIDE)))
    mask[pixel_theta > np.pi/2] = 1
    m.mask = mask
    hp.mollview(m)
    

    enter image description here