Search code examples
pythonastronomyhealpy

Different values of a_lm coefficients for different values of Nside in HealPix


I am using HealPix to calculate the outflow rate of particles through a sphere with some radius and I am trying to determine coefficients of spherical harmonics (basically fit some data with spherical harmonics).

The basic steps are:

#I create a HealPix map of the outflow rate (values of the rate for every pixel) called dotM_map with a resolution determined by the nside parameter.
nside = 8
dotM_map = some_function(nside, ...)

#Then I calculate a_lm coefficients of spherical harmonics for this map.
a_lm = hp.map2alm(dotM_map,lmax=2)

However, if I change the resolution of the map (change nside) for the same values of lmax I get different values of the coefficients (different values of a_lm). I tried reproducing the initial map from the coefficients

sph_harm_map = hp.alm2map(a_lm,nside=nside)

and the results are in good agreement. Why are values of a_lm different for different nside? And how can I obtain a_lm coefficients that do not depend on nside??

I tried using pixel weights as

a_lm = hp.map2alm(hpxmap,lmax=2,use_weights=True)

but there was no significant improvement. I also tried

a_lm = hp.map2alm(hpxmap,lmax=2,use_pixel_weights=True)

but I got an error: urllib.error.URLError: <urlopen error Unable to open any source! Exceptions were {'https://healpy.github.io/healpy-data/full_weights/healpix_full_weights_nside_0008.fits': <HTTPError 404: 'Not Found'>, 'https://github.com/healpy/healpy-data/releases/download/full_weights/healpix_full_weights_nside_0008.fits': <HTTPError 404: 'Not Found'>}>

Why does this happen? And if necessary I can produce a minimal example.


Solution

  • In order to get the same values of a_lm coefficients it is necessary to normalize values of individual pixels with the pixel surface - dividing with 4*pi/npix.

    Another thing, in case it might be helpful to someone. The outflow rate can be easily computed from

    npix = healpy.nside2npix(nside) # total number of Healpix pixels on the sphere at a given Nside
    pix = healpy.ang2pix(nside, theta, phi) # tells you in which pixel is each particle, considering the exact pixel boundary
    count, edge = numpy.histogram(pix, bins=np.arange(npix+1)) # count is the number of particles in each Healpix pixel
    

    and calculating (count2 - count2)/(t2-t1), where count2 = count(t2) and count1 = count(t1) are the number of particles in individual pixels at two different times.

    Credit goes to HealPix's support, Eric Hivon. Thanks!