1

I have a map in galactic coordinates and I need to save it in equatorial coordinates in another file . I know i can use:

import healpy as hp
map=hp.read_map('file.fits')
map_rot=hp.mollview(map, coord=['G','C'], return_projected_map=True)

and this should return a 2D numpy array stored in map_rot. But when I read map_rot, I found out it is a masked_array filled ONLY with -inf values, and mask=False , fill_value=-1.6735e+30 (so, apparently, -inf is not a mask). Moreover, the total number of elements of map_rot do not match with the number of pixels I would expect for a map (npix=12*nside**2). For example if nside=256 I would expect to obtain npix=786432, while map_rot has 400*800=320000 elements. What's going on?

(I have already seen this post, but I have a map in polarization, so I need to rotate Stokes' parameters. Since mollview knows how to do that, I was trying to obtain the new map directly from mollview. )

Community
  • 1
  • 1

1 Answers1

0

One way to go around this is to save the output, for instance with pickle

import healpy as hp, pickle
map=hp.read_map('file.fits')
map_rot=hp.mollview(map, coord=['G','C'], return_projected_map=True)
pickle.dump(map_rot, open( "/path/map.p", "wb"))

The return value of hp.mollview() has a format that can be displayed using the standard imshow() function. So next time you want to plot it, just do the following

map_rot = pickle.load(open("/path/map.p"), 'rb'))
plt.imshow(map_rot)

map_rot describes the pixels in the entire matplotlib window, including the white area (-inf color-coded with white) around the ellipsoid.

In contrast, mollview() accepts only an array of pixels which reside in the ellipsoid, i.e. array of the length.

 len(hp.pixelfunc.nside2npix(NSIDE))
alexs
  • 195
  • 3
  • 4
  • Thank you very much Alex, this partially solves my problem. I need the new map in .fits format too. – Lorenzo Zanisi Apr 04 '16 at 14:06
  • Have you tried astropy? Check out the section "Creating a FITS file from scratch" here: https://python4astronomers.github.io/astropy/fits.html . Turning map_rot into a .fits file should be doable in a few lines (with a header of your choice). – alexs Apr 05 '16 at 15:27