Search code examples
pythonnumpyastronomyhealpy

How does Healpy pix2ang read pixel indices?


This is a continuation of this Question: How do HEALPix FITS files of CMB maps translate into ndarrays? What are the coordinates?

CMB maps come as FITS files. The map is a 1-dimensional vector of temperature values of the pixels.

I would like to use Healpy's pix2ang function to read the position of each individual pixel, and know which pixel is which.

http://healpy.readthedocs.org/en/latest/generated/healpy.pixelfunc.pix2ang.html

For this function, what exactly is the input for a "pixel index"? Do I have to translate each temperature-valued pixel into spherical harmonics first?

I know that in spherical harmonics, each a_lm corresponds to a FITS file extension created will contain one integer column with index = l^2+l+m+1. But what about an array of pixels without using l and m?


Solution

  • It has nothing to do with spherical harmonics.

    The pixel number is the position in the 1d array. So first element is pixel 0, second element is pixel 1 and so on.

    In the simplest case of a map of nside 1 (only 12 pixels):

    import healpy as hp
    nside = 1
    npix = hp.nside2npix(1)
    print("Number of pixels:")
    print(npix)
    m = 100 + np.arange(npix)
    print("Map:")
    print(m)
    print("Plot map")
    %matplotlib
    hp.mollview(m)
    print("Pixel theta (colatitude) and phi (longitude) in radians:")
    i_pix = np.arange(npix)
    theta, phi = hp.pix2ang(nside, i_pix)
    for i in range(npix):
        print("Pixel %d : [ %.2f, %.2f ]" % (i, theta[i], phi[i]))
    

    This prints:

    Pixel 0 : [ 0.84, 0.79 ]
    Pixel 1 : [ 0.84, 2.36 ]
    Pixel 2 : [ 0.84, 3.93 ]
    Pixel 3 : [ 0.84, 5.50 ]
    Pixel 4 : [ 1.57, 0.00 ]
    Pixel 5 : [ 1.57, 1.57 ]
    Pixel 6 : [ 1.57, 3.14 ]
    Pixel 7 : [ 1.57, 4.71 ]
    Pixel 8 : [ 2.30, 0.79 ]
    Pixel 9 : [ 2.30, 2.36 ]
    Pixel 10 : [ 2.30, 3.93 ]
    Pixel 11 : [ 2.30, 5.50 ]