Search code examples
pythonhealpy

Healpy map2alm and alm2map inconsistency?


I'm just starting to work with Healpy and have noticed that if I use a map to get alm's and then use those alm's to generate a new map, I do not get the map I started with. Here's what I'm looking at:

import numpy as np
import healpy as hp
nside = 2 # healpix nside parameter
m = np.arange(hp.nside2npix(nside)) # create a map to test
alm = hp.map2alm(m) # compute alm's
new_map = hp.alm2map(alm, nside) # create new map from computed alm's

# Let's look at two maps
print(m)
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47] # as expected

print(new_map)
[-23.30522233 -22.54434515 -21.50906755 -20.09203749 -19.48841773
-18.66392484 -16.99593867 -16.789984   -15.14587061 -14.57960049
-13.4403252  -13.35992138 -10.51368725 -10.49793946 -10.1262039
-8.6340571   -7.41789272  -6.87712224  -5.75765487  -3.75121764
-4.35825512  -1.6221964   -1.03902923  -0.41478954   0.52480646
 2.34629955   2.1511705    2.40325268   5.39576497   5.38390848
 5.78324832   7.24779083   8.4915595    9.0047257   10.15179735
 12.1306303   12.62672772  13.4512206   15.11920678  15.32516145
 16.96927483  17.53554496  18.67482024  18.75522407  20.42078855
 21.18166574  22.21694334  23.6339734 ] # not what I was expecting 

As you can see, new_map doesn't match the input map, m. I imagine there's some subtlety to these functions that I'm missing. Any idea?


Solution

  • I get a different result:

    print(new_map) [ 0.15859344, 0.91947062, 1.95474822, 3.37177828, 4.01808325, 4.84257613, 6.51056231, 6.71651698, 8.36063036, 8.92690049, 10.06617577, 10.1465796 , 12.98620654, 13.00668621, 13.3736899 , 14.87056857, 16.08200108, 16.62750343, 17.74223892, 19.75340803, 19.13441288, 21.8704716 , 22.45363877, 23.07787846, 24.01747446, 25.83896755, 25.6438385 , 25.89592068, 28.89565876, 28.88853415, 29.28314212, 30.7524165 , 31.9914533 , 32.50935137, 33.65169114, 35.63525597, 36.13322869, 36.95772158, 38.62570775, 38.83166242, 40.47577581, 41.04204594, 42.18132122, 42.26172504, 43.88460433, 44.64548151, 45.68075911, 47.09778917]

    Older versions of healpy were automatically removing a constant offset from the map before transformation, better to update healpy to the last version.

    The residual difference is related to the fact the pixelization introduces an error, this error is larger at low nside.