healpy tutorial

See the Jupyter Notebook version of this tutorial at https://github.com/healpy/healpy/blob/master/doc/tutorial.ipynb

Choose the inline backend of maptlotlib to display the plots inside the Jupyter Notebook

[1]:
import matplotlib.pyplot as plt

%matplotlib inline
[2]:
import numpy as np
import healpy as hp

NSIDE and ordering

Maps are simply numpy arrays, where each array element refers to a location in the sky as defined by the Healpix pixelization schemes (see the healpix website).

Note: Running the code below in a regular Python session will not display the maps; it’s recommended to use an IPython shell or a Jupyter notebook.

The resolution of the map is defined by the NSIDE parameter, which is generally a power of 2.

[3]:
NSIDE = 32
print(
    "Approximate resolution at NSIDE {} is {:.2} deg".format(
        NSIDE, hp.nside2resol(NSIDE, arcmin=True) / 60
    )
)
Approximate resolution at NSIDE 32 is 1.8 deg

The function healpy.pixelfunc.nside2npix gives the number of pixels NPIX of the map:

[4]:
NPIX = hp.nside2npix(NSIDE)
print(NPIX)
12288

The same pixels in the map can be ordered in 2 ways, either RING, where they are numbered in the array in horizontal rings starting from the North pole:

[5]:
m = np.arange(NPIX)
hp.mollview(m, title="Mollview image RING")
hp.graticule()
0.0 180.0 -180.0 180.0
_images/tutorial_9_1.png

The standard coordinates are the colatitude \(\theta\), \(0\) at the North Pole, \(\pi/2\) at the equator and \(\pi\) at the South Pole and the longitude \(\phi\) between \(0\) and \(2\pi\) eastward, in a Mollview projection, \(\phi=0\) is at the center and increases eastward toward the left of the map.

We can also use vectors to represent coordinates, for example vec is the normalized vector that points to \(\theta=\pi/2, \phi=3/4\pi\):

[6]:
vec = hp.ang2vec(np.pi / 2, np.pi * 3 / 4)
print(vec)
[-7.07106781e-01  7.07106781e-01  6.12323400e-17]

We can find the indices of all the pixels within \(10\) degrees of that point and then change the value of the map at those indices:

[7]:
ipix_disc = hp.query_disc(nside=32, vec=vec, radius=np.radians(10))
[8]:
m = np.arange(NPIX)
m[ipix_disc] = m.max()
hp.mollview(m, title="Mollview image RING")
_images/tutorial_14_0.png

We can retrieve colatitude and longitude of each pixel using pix2ang, in this case we notice that the first 4 pixels cover the North Pole with pixel centers just ~\(1.5\) degrees South of the Pole all at the same latitude. The fifth pixel is already part of another ring of pixels.

[9]:
theta, phi = np.degrees(hp.pix2ang(nside=32, ipix=[0, 1, 2, 3, 4]))
[10]:
theta
[10]:
array([1.46197116, 1.46197116, 1.46197116, 1.46197116, 2.92418036])
[11]:
phi
[11]:
array([ 45. , 135. , 225. , 315. ,  22.5])

The RING ordering is necessary for the Spherical Harmonics transforms, the other option is NESTED ordering which is very efficient for map domain operations because scaling up and down maps is achieved just multiplying and rounding pixel indices. See below how pixel are ordered in the NESTED scheme, notice the structure of the 12 HEALPix base pixels (NSIDE 1):

[12]:
m = np.arange(NPIX)
hp.mollview(m, nest=True, title="Mollview image NESTED")
_images/tutorial_20_0.png

All healpy routines assume RING ordering, in fact as soon as you read a map with read_map, even if it was stored as NESTED, it is transformed to RING. However, you can work in NESTED ordering passing the nest=True argument to most healpy routines.

Reading and writing maps to file

For the following section, it is required to download larger maps by executing from the terminal the bash script healpy_get_wmap_maps.sh which should be available in your path.

This will download the higher resolution WMAP data into the current directory.

[13]:
!wget -c http://lambda.gsfc.nasa.gov/data/map/dr4/skymaps/7yr/raw/wmap_band_iqumap_r9_7yr_W_v4.fits;wget -c http://lambda.gsfc.nasa.gov/data/map/dr4/ancillary/masks/wmap_temperature_analysis_mask_r9_7yr_v4.fits
--2021-06-22 11:23:38--  http://lambda.gsfc.nasa.gov/data/map/dr4/skymaps/7yr/raw/wmap_band_iqumap_r9_7yr_W_v4.fits
Resolving lambda.gsfc.nasa.gov (lambda.gsfc.nasa.gov)... 129.164.179.68, 2001:4d0:2310:150::68
Connecting to lambda.gsfc.nasa.gov (lambda.gsfc.nasa.gov)|129.164.179.68|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://lambda.gsfc.nasa.gov/data/map/dr4/skymaps/7yr/raw/wmap_band_iqumap_r9_7yr_W_v4.fits [following]
--2021-06-22 11:23:39--  https://lambda.gsfc.nasa.gov/data/map/dr4/skymaps/7yr/raw/wmap_band_iqumap_r9_7yr_W_v4.fits
Connecting to lambda.gsfc.nasa.gov (lambda.gsfc.nasa.gov)|129.164.179.68|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 100676160 (96M)
Saving to: ‘wmap_band_iqumap_r9_7yr_W_v4.fits’

wmap_band_iqumap_r9 100%[===================>]  96.01M  6.04MB/s    in 16s

2021-06-22 11:23:55 (5.98 MB/s) - ‘wmap_band_iqumap_r9_7yr_W_v4.fits’ saved [100676160/100676160]

URL transformed to HTTPS due to an HSTS policy
--2021-06-22 11:23:55--  https://lambda.gsfc.nasa.gov/data/map/dr4/ancillary/masks/wmap_temperature_analysis_mask_r9_7yr_v4.fits
Resolving lambda.gsfc.nasa.gov (lambda.gsfc.nasa.gov)... 129.164.179.68, 2001:4d0:2310:150::68
Connecting to lambda.gsfc.nasa.gov (lambda.gsfc.nasa.gov)|129.164.179.68|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25174080 (24M)
Saving to: ‘wmap_temperature_analysis_mask_r9_7yr_v4.fits’

wmap_temperature_an 100%[===================>]  24.01M  6.06MB/s    in 4.3s

2021-06-22 11:24:00 (5.53 MB/s) - ‘wmap_temperature_analysis_mask_r9_7yr_v4.fits’ saved [25174080/25174080]

[14]:
wmap_map_I = hp.read_map("wmap_band_iqumap_r9_7yr_W_v4.fits")

By default, input maps are converted to RING ordering, if they are in NESTED ordering. You can otherwise specify nest=True to retrieve a map is NESTED ordering, or nest=None to keep the ordering unchanged.

By default, read_map loads the first column, for reading other columns you can specify the field keyword.

write_map writes a map to disk in FITS format, if the input map is a list of 3 maps, they are written to a single file as I,Q,U polarization components:

[15]:
hp.write_map("my_map.fits", wmap_map_I, overwrite=True)
setting the output map dtype to [dtype('>f4')]

Visualization

As shown above, mollweide projection with mollview is the most common visualization tool for HEALPIX maps. It also supports coordinate transformation, coord does Galactic to ecliptic coordinate transformation, norm='hist' sets a histogram equalized color scale and xsize increases the size of the image. graticule adds meridians and parallels.

[16]:
hp.mollview(
    wmap_map_I,
    coord=["G", "E"],
    title="Histogram equalized Ecliptic",
    unit="mK",
    norm="hist",
    min=-1,
    max=1,
)
hp.graticule()
0.0 180.0 -180.0 180.0
_images/tutorial_28_1.png

gnomview instead provides gnomonic projection around a position specified by rot, for example you can plot a projection of the galactic center, xsize and ysize change the dimension of the sky patch.

[17]:
hp.gnomview(wmap_map_I, rot=[0, 0.3], title="GnomView", unit="mK", format="%.2g")
_images/tutorial_30_0.png

mollzoom is a powerful tool for interactive inspection of a map, it provides a mollweide projection where you can click to set the center of the adjacent gnomview panel. ## Masked map, partial maps

By convention, HEALPIX uses \(-1.6375 * 10^{30}\) to mark invalid or unseen pixels. This is stored in healpy as the constant UNSEEN.

All healpy functions automatically deal with maps with UNSEEN pixels, for example mollview marks in grey those sections of a map.

There is an alternative way of dealing with UNSEEN pixel based on the numpyMaskedArray class, hp.ma loads a map as a masked array, by convention the mask is 0 where the data are masked, while numpy defines data masked when the mask is True, so it is necessary to flip the mask.

[18]:
mask = hp.read_map("wmap_temperature_analysis_mask_r9_7yr_v4.fits").astype(np.bool_)
wmap_map_I_masked = hp.ma(wmap_map_I)
wmap_map_I_masked.mask = np.logical_not(mask)

Filling a masked array fills in the UNSEEN value and return a standard array that can be used by mollview. compressed() instead removes all the masked pixels and returns a standard array that can be used for examples by the matplotlib hist() function:

[19]:
hp.mollview(wmap_map_I_masked.filled())
_images/tutorial_34_0.png
[20]:
plt.hist(wmap_map_I_masked.compressed(), bins=1000);
[20]:
(array([1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 2.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 2.0000e+00, 1.0000e+00, 1.0000e+00,
        1.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00, 1.0000e+00,
        0.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00,
        1.0000e+00, 4.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00,
        3.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 2.0000e+00,
        0.0000e+00, 4.0000e+00, 5.0000e+00, 1.0000e+00, 1.0000e+00,
        0.0000e+00, 1.0000e+00, 0.0000e+00, 1.0000e+00, 4.0000e+00,
        4.0000e+00, 1.0000e+00, 3.0000e+00, 2.0000e+00, 3.0000e+00,
        2.0000e+00, 2.0000e+00, 1.0000e+00, 1.0000e+00, 1.0000e+00,
        5.0000e+00, 3.0000e+00, 2.0000e+00, 5.0000e+00, 3.0000e+00,
        4.0000e+00, 1.0000e+00, 6.0000e+00, 2.0000e+00, 5.0000e+00,
        6.0000e+00, 4.0000e+00, 5.0000e+00, 7.0000e+00, 3.0000e+00,
        1.1000e+01, 5.0000e+00, 4.0000e+00, 8.0000e+00, 4.0000e+00,
        1.1000e+01, 1.0000e+00, 6.0000e+00, 8.0000e+00, 8.0000e+00,
        8.0000e+00, 1.0000e+01, 5.0000e+00, 5.0000e+00, 7.0000e+00,
        6.0000e+00, 7.0000e+00, 1.0000e+01, 1.0000e+01, 1.1000e+01,
        1.3000e+01, 6.0000e+00, 1.0000e+01, 1.6000e+01, 1.7000e+01,
        1.4000e+01, 1.0000e+01, 1.8000e+01, 1.4000e+01, 1.4000e+01,
        1.8000e+01, 1.7000e+01, 1.5000e+01, 1.1000e+01, 1.8000e+01,
        1.6000e+01, 2.1000e+01, 1.7000e+01, 1.8000e+01, 1.9000e+01,
        3.4000e+01, 3.2000e+01, 3.1000e+01, 2.0000e+01, 2.2000e+01,
        2.6000e+01, 2.7000e+01, 3.6000e+01, 3.2000e+01, 2.7000e+01,
        2.3000e+01, 3.5000e+01, 4.6000e+01, 4.0000e+01, 4.8000e+01,
        4.9000e+01, 3.9000e+01, 3.9000e+01, 5.8000e+01, 3.8000e+01,
        5.2000e+01, 4.7000e+01, 5.2000e+01, 4.3000e+01, 5.6000e+01,
        4.6000e+01, 5.8000e+01, 6.9000e+01, 5.2000e+01, 7.6000e+01,
        7.5000e+01, 8.4000e+01, 7.1000e+01, 7.8000e+01, 8.4000e+01,
        1.0200e+02, 8.9000e+01, 8.8000e+01, 9.4000e+01, 9.7000e+01,
        1.0400e+02, 1.2000e+02, 1.1200e+02, 1.3000e+02, 1.1200e+02,
        1.3100e+02, 1.1300e+02, 1.2800e+02, 1.0400e+02, 1.5400e+02,
        1.6000e+02, 1.3500e+02, 1.4000e+02, 1.5700e+02, 1.7000e+02,
        1.8500e+02, 1.7500e+02, 1.7200e+02, 1.6100e+02, 1.8800e+02,
        1.6400e+02, 2.2900e+02, 2.0900e+02, 1.8900e+02, 2.2400e+02,
        2.5500e+02, 2.3600e+02, 2.2500e+02, 2.4100e+02, 2.5500e+02,
        2.8800e+02, 2.5600e+02, 3.1700e+02, 2.9200e+02, 3.2600e+02,
        3.1300e+02, 3.2300e+02, 3.4200e+02, 3.1700e+02, 3.6100e+02,
        3.4100e+02, 3.5700e+02, 3.9500e+02, 4.0900e+02, 4.1500e+02,
        3.7700e+02, 4.5400e+02, 4.1500e+02, 4.5200e+02, 4.5300e+02,
        4.5600e+02, 4.9400e+02, 4.5800e+02, 5.0700e+02, 4.8900e+02,
        5.0200e+02, 5.3100e+02, 5.4700e+02, 5.7000e+02, 5.8800e+02,
        6.5300e+02, 5.8700e+02, 6.6300e+02, 6.5800e+02, 6.9200e+02,
        6.8800e+02, 6.9900e+02, 7.6100e+02, 7.6700e+02, 7.9700e+02,
        7.9200e+02, 8.3800e+02, 8.3300e+02, 8.2100e+02, 8.5600e+02,
        8.7500e+02, 9.3600e+02, 9.7500e+02, 9.7400e+02, 9.1700e+02,
        1.0550e+03, 1.0410e+03, 1.0460e+03, 1.0600e+03, 1.1860e+03,
        1.1890e+03, 1.1430e+03, 1.1310e+03, 1.2270e+03, 1.2080e+03,
        1.2530e+03, 1.3360e+03, 1.3170e+03, 1.4330e+03, 1.3770e+03,
        1.3940e+03, 1.4590e+03, 1.4850e+03, 1.5340e+03, 1.5500e+03,
        1.5740e+03, 1.6030e+03, 1.7550e+03, 1.7100e+03, 1.6730e+03,
        1.8240e+03, 1.7860e+03, 1.9280e+03, 1.9340e+03, 1.9180e+03,
        1.9520e+03, 1.9370e+03, 2.1110e+03, 2.1070e+03, 2.0830e+03,
        2.1860e+03, 2.1730e+03, 2.2320e+03, 2.3640e+03, 2.3250e+03,
        2.4270e+03, 2.4150e+03, 2.4160e+03, 2.5280e+03, 2.6160e+03,
        2.6670e+03, 2.7920e+03, 2.7070e+03, 2.8440e+03, 2.8570e+03,
        2.8550e+03, 2.9000e+03, 3.0030e+03, 2.9460e+03, 3.1140e+03,
        3.1130e+03, 3.1970e+03, 3.3250e+03, 3.2970e+03, 3.3190e+03,
        3.4510e+03, 3.5520e+03, 3.6390e+03, 3.5760e+03, 3.7280e+03,
        3.7170e+03, 3.8230e+03, 3.8080e+03, 3.9090e+03, 4.1190e+03,
        3.9960e+03, 4.1780e+03, 4.2330e+03, 4.2780e+03, 4.2460e+03,
        4.4020e+03, 4.4960e+03, 4.4170e+03, 4.6200e+03, 4.6070e+03,
        4.6520e+03, 4.7640e+03, 4.8340e+03, 4.9420e+03, 5.1610e+03,
        5.0870e+03, 5.2000e+03, 5.0890e+03, 5.1800e+03, 5.2560e+03,
        5.4660e+03, 5.4440e+03, 5.5670e+03, 5.7390e+03, 5.8440e+03,
        5.6790e+03, 5.8240e+03, 5.9700e+03, 6.0290e+03, 6.1060e+03,
        6.2010e+03, 6.2020e+03, 6.2670e+03, 6.3040e+03, 6.3560e+03,
        6.5630e+03, 6.6250e+03, 6.6450e+03, 6.7350e+03, 6.8210e+03,
        6.8810e+03, 6.7010e+03, 7.0320e+03, 7.2730e+03, 6.9730e+03,
        7.2600e+03, 7.2110e+03, 7.3440e+03, 7.4420e+03, 7.6680e+03,
        7.6110e+03, 7.7590e+03, 7.8130e+03, 7.7700e+03, 7.9740e+03,
        8.0160e+03, 8.1520e+03, 8.1780e+03, 8.1640e+03, 8.2600e+03,
        8.4810e+03, 8.4720e+03, 8.5670e+03, 8.5830e+03, 8.6560e+03,
        8.6080e+03, 8.9490e+03, 8.8820e+03, 8.8940e+03, 9.0400e+03,
        8.9440e+03, 8.9800e+03, 9.1660e+03, 9.1660e+03, 9.3060e+03,
        9.3760e+03, 9.4390e+03, 9.3740e+03, 9.7200e+03, 9.4850e+03,
        9.6390e+03, 9.5670e+03, 9.8640e+03, 9.9500e+03, 9.8620e+03,
        9.8200e+03, 9.9170e+03, 9.8950e+03, 1.0131e+04, 9.9180e+03,
        1.0267e+04, 1.0239e+04, 1.0125e+04, 1.0056e+04, 1.0475e+04,
        1.0404e+04, 1.0474e+04, 1.0526e+04, 1.0456e+04, 1.0662e+04,
        1.0419e+04, 1.0440e+04, 1.0521e+04, 1.0670e+04, 1.0578e+04,
        1.0775e+04, 1.0719e+04, 1.0798e+04, 1.0968e+04, 1.0857e+04,
        1.0968e+04, 1.0805e+04, 1.1073e+04, 1.0924e+04, 1.1142e+04,
        1.0952e+04, 1.0994e+04, 1.0979e+04, 1.0953e+04, 1.0860e+04,
        1.0994e+04, 1.0833e+04, 1.1039e+04, 1.0868e+04, 1.0881e+04,
        1.0903e+04, 1.0958e+04, 1.0902e+04, 1.0845e+04, 1.1066e+04,
        1.1027e+04, 1.1017e+04, 1.0942e+04, 1.0923e+04, 1.1133e+04,
        1.0888e+04, 1.1011e+04, 1.0794e+04, 1.1005e+04, 1.0760e+04,
        1.0592e+04, 1.0962e+04, 1.0843e+04, 1.0762e+04, 1.0826e+04,
        1.0712e+04, 1.0671e+04, 1.0744e+04, 1.0833e+04, 1.0706e+04,
        1.0594e+04, 1.0638e+04, 1.0535e+04, 1.0348e+04, 1.0363e+04,
        1.0332e+04, 1.0405e+04, 1.0335e+04, 1.0279e+04, 1.0211e+04,
        1.0030e+04, 1.0279e+04, 1.0033e+04, 1.0150e+04, 1.0024e+04,
        9.9190e+03, 9.8920e+03, 9.7940e+03, 9.6760e+03, 9.9780e+03,
        9.6700e+03, 9.4950e+03, 9.6710e+03, 9.5440e+03, 9.6010e+03,
        9.5130e+03, 9.3400e+03, 9.2590e+03, 9.2350e+03, 9.2470e+03,
        9.0930e+03, 8.9990e+03, 8.9480e+03, 8.8760e+03, 8.7940e+03,
        8.7450e+03, 8.7300e+03, 8.5570e+03, 8.6670e+03, 8.5660e+03,
        8.5490e+03, 8.5880e+03, 8.3820e+03, 8.2590e+03, 8.2730e+03,
        8.1660e+03, 7.9060e+03, 7.8710e+03, 7.8770e+03, 7.9680e+03,
        7.7110e+03, 7.8090e+03, 7.6490e+03, 7.4840e+03, 7.2790e+03,
        7.4300e+03, 7.3320e+03, 7.1590e+03, 7.3180e+03, 7.1560e+03,
        6.8790e+03, 6.8320e+03, 6.9610e+03, 6.9050e+03, 6.6480e+03,
        6.4230e+03, 6.6490e+03, 6.4950e+03, 6.4280e+03, 6.3880e+03,
        6.3240e+03, 6.1640e+03, 6.1900e+03, 5.9820e+03, 5.8970e+03,
        5.8440e+03, 5.8650e+03, 5.7110e+03, 5.6850e+03, 5.5240e+03,
        5.5240e+03, 5.4810e+03, 5.4380e+03, 5.3340e+03, 5.2670e+03,
        5.2390e+03, 5.2240e+03, 5.0440e+03, 4.9970e+03, 4.9460e+03,
        4.8030e+03, 4.5930e+03, 4.7940e+03, 4.6070e+03, 4.6170e+03,
        4.5980e+03, 4.3760e+03, 4.3600e+03, 4.3690e+03, 4.1300e+03,
        4.1280e+03, 4.1420e+03, 4.0770e+03, 3.9830e+03, 3.9770e+03,
        3.7490e+03, 3.8670e+03, 3.7660e+03, 3.6990e+03, 3.6430e+03,
        3.5190e+03, 3.4920e+03, 3.4010e+03, 3.3920e+03, 3.2990e+03,
        3.2710e+03, 3.2260e+03, 3.0640e+03, 3.0870e+03, 3.1100e+03,
        2.9580e+03, 2.9630e+03, 2.7740e+03, 2.8830e+03, 2.7890e+03,
        2.7670e+03, 2.6880e+03, 2.5900e+03, 2.5870e+03, 2.6040e+03,
        2.4690e+03, 2.5120e+03, 2.4680e+03, 2.3160e+03, 2.3690e+03,
        2.2740e+03, 2.2320e+03, 2.0920e+03, 2.1400e+03, 2.1570e+03,
        2.0650e+03, 2.0800e+03, 1.8930e+03, 1.9820e+03, 1.8870e+03,
        1.8660e+03, 1.7930e+03, 1.7810e+03, 1.7360e+03, 1.7670e+03,
        1.5970e+03, 1.6060e+03, 1.6080e+03, 1.5530e+03, 1.5400e+03,
        1.4800e+03, 1.4610e+03, 1.4070e+03, 1.4670e+03, 1.3580e+03,
        1.3960e+03, 1.3650e+03, 1.2220e+03, 1.2070e+03, 1.1720e+03,
        1.2220e+03, 1.2120e+03, 1.1270e+03, 1.1110e+03, 1.0470e+03,
        1.0400e+03, 1.0110e+03, 9.5400e+02, 9.7000e+02, 9.4400e+02,
        9.4900e+02, 9.0500e+02, 9.0300e+02, 9.0800e+02, 8.6800e+02,
        8.3900e+02, 8.1400e+02, 7.6600e+02, 7.8400e+02, 7.4200e+02,
        8.0100e+02, 6.9100e+02, 6.9900e+02, 7.1200e+02, 6.9300e+02,
        6.5100e+02, 6.5800e+02, 6.1300e+02, 6.2600e+02, 5.9100e+02,
        5.6600e+02, 5.6400e+02, 5.2300e+02, 5.1100e+02, 4.8800e+02,
        5.0100e+02, 4.7500e+02, 4.3900e+02, 4.7000e+02, 4.3500e+02,
        4.7900e+02, 4.4700e+02, 4.1000e+02, 3.8400e+02, 4.0300e+02,
        3.8600e+02, 3.9600e+02, 3.3500e+02, 3.4800e+02, 3.4000e+02,
        3.7400e+02, 3.3400e+02, 3.2700e+02, 3.3800e+02, 2.6700e+02,
        2.7600e+02, 2.9100e+02, 2.8600e+02, 2.8000e+02, 2.6100e+02,
        2.5100e+02, 2.2000e+02, 2.5400e+02, 2.0500e+02, 2.1400e+02,
        2.2300e+02, 2.1900e+02, 2.1400e+02, 1.7200e+02, 1.9200e+02,
        1.8900e+02, 1.5000e+02, 1.7500e+02, 1.5100e+02, 1.4300e+02,
        1.7000e+02, 1.8000e+02, 1.5500e+02, 1.4100e+02, 1.2800e+02,
        1.4600e+02, 1.3600e+02, 1.0000e+02, 1.1900e+02, 1.2700e+02,
        1.5000e+02, 1.1000e+02, 8.6000e+01, 1.1700e+02, 1.0800e+02,
        9.0000e+01, 1.0300e+02, 9.8000e+01, 7.6000e+01, 8.4000e+01,
        8.8000e+01, 7.8000e+01, 8.3000e+01, 5.7000e+01, 5.3000e+01,
        7.2000e+01, 7.8000e+01, 5.9000e+01, 6.7000e+01, 6.1000e+01,
        5.7000e+01, 5.5000e+01, 5.6000e+01, 4.6000e+01, 4.2000e+01,
        4.9000e+01, 4.6000e+01, 4.1000e+01, 3.9000e+01, 3.8000e+01,
        6.1000e+01, 4.0000e+01, 3.5000e+01, 3.4000e+01, 3.5000e+01,
        3.9000e+01, 3.3000e+01, 3.5000e+01, 3.0000e+01, 3.3000e+01,
        2.8000e+01, 2.8000e+01, 1.5000e+01, 2.3000e+01, 2.7000e+01,
        3.1000e+01, 2.9000e+01, 2.7000e+01, 1.4000e+01, 1.3000e+01,
        2.5000e+01, 1.9000e+01, 2.2000e+01, 1.4000e+01, 1.7000e+01,
        1.4000e+01, 1.2000e+01, 1.5000e+01, 1.6000e+01, 1.2000e+01,
        1.5000e+01, 1.0000e+01, 1.6000e+01, 1.9000e+01, 1.2000e+01,
        8.0000e+00, 1.1000e+01, 1.2000e+01, 5.0000e+00, 9.0000e+00,
        7.0000e+00, 1.4000e+01, 1.3000e+01, 1.0000e+01, 6.0000e+00,
        1.1000e+01, 8.0000e+00, 1.6000e+01, 6.0000e+00, 1.0000e+00,
        7.0000e+00, 6.0000e+00, 7.0000e+00, 5.0000e+00, 4.0000e+00,
        7.0000e+00, 9.0000e+00, 5.0000e+00, 5.0000e+00, 5.0000e+00,
        1.0000e+00, 2.0000e+00, 5.0000e+00, 2.0000e+00, 6.0000e+00,
        5.0000e+00, 3.0000e+00, 1.0000e+00, 5.0000e+00, 3.0000e+00,
        5.0000e+00, 1.0000e+00, 2.0000e+00, 3.0000e+00, 2.0000e+00,
        3.0000e+00, 5.0000e+00, 3.0000e+00, 2.0000e+00, 6.0000e+00,
        2.0000e+00, 2.0000e+00, 0.0000e+00, 2.0000e+00, 3.0000e+00,
        1.0000e+00, 2.0000e+00, 2.0000e+00, 1.0000e+00, 2.0000e+00,
        0.0000e+00, 1.0000e+00, 1.0000e+00, 0.0000e+00, 2.0000e+00,
        1.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 1.0000e+00, 2.0000e+00, 0.0000e+00, 1.0000e+00,
        1.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        1.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00,
        1.0000e+00, 1.0000e+00, 0.0000e+00, 2.0000e+00, 0.0000e+00,
        1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        1.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00, 1.0000e+00,
        0.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00,
        1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        1.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00,
        0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]),
 array([-0.5256452 , -0.5243962 , -0.52314717, ...,  0.7208714 ,
         0.7221204 ,  0.7233694 ], dtype=float32),
 <BarContainer object of 1000 artists>)
_images/tutorial_35_1.png

Spherical Harmonics transforms

healpy provides bindings to the C++ HEALPIX library for performing spherical harmonic transforms. hp.anafast computes the angular power spectrum of a map:

[21]:
LMAX = 1024
cl = hp.anafast(wmap_map_I_masked.filled(), lmax=LMAX)
ell = np.arange(len(cl))

therefore we can plot a normalized CMB spectrum and write it to disk:

[22]:
plt.figure(figsize=(10, 5))
plt.plot(ell, ell * (ell + 1) * cl)
plt.xlabel("$\ell$")
plt.ylabel("$\ell(\ell+1)C_{\ell}$")
plt.grid()
hp.write_cl("cl.fits", cl, overwrite=True)
_images/tutorial_39_0.png

Gaussian beam map smoothing is provided by hp.smoothing:

[23]:
wmap_map_I_smoothed = hp.smoothing(wmap_map_I, fwhm=np.radians(1.))
hp.mollview(wmap_map_I_smoothed, min=-1, max=1, title="Map smoothed 1 deg")
_images/tutorial_41_0.png

For more information see the HEALPix primer