Search code examples
pythoncoordinatesmaskinghealpy

Get coordinates for specific value on healpy mollview


Is it possible to find the coordinates for a specific value of a hitmap from a healpy mollview plot?

For example: If I have a smoothed out hitmap and want to use the mask:

mask = (hitmap > 2.054) & (hitmap < 2.056)

to find the required values on of the hitmap.

The hitmap is used to create a mollview plot like this:

hp.mollview(hitmap, xsize=2000)

Is it then possible to find the coordinates (lon,lat) corresponding to the pixels in the mollview plot that satisfy the mask by using the mask?

Many thanks in advance!


Solution

  • The best way to do this would be via hp.pix2ang():

    import healpy as hp
    import numpy as hp
    
    # Get the nside and number of pixels in your map
    nside = hp.get_nside(mask)
    npix = hp.nside2npix(nside)
    
    # Use pix2ang to get the (l, b) coordinates for each pixel
    glons, glats = hp.pix2ang(nside, np.arange(npix), lonlat=True)
    

    This will give you a list of all the coordinates (l, b) for each pixel in your map. To get only the ones in the mask, simply use:

    glons_eff = glons[mask]
    glats_eff = glats[mask]