Healpy
Healpy is a Python package, currently at version 1.19.0, designed to handle pixelated data on the sphere. It is based on the Hierarchical Equal Area isoLatitude Pixelization (HEALPix) scheme and bundles the HEALPix C++ library. Primarily used in astrophysics and cosmology, Healpy provides tools for map manipulation, spherical harmonic transforms, and visualization of all-sky data.
Warnings
- breaking The `blm_gauss()` function in version 1.19.0 was updated to use the `l(l+1)` formula, aligning with `gauss_beam()` and standard definitions. Previously, it used the `l^2` formula. This changes the computed spherical harmonic coefficients for Gaussian beams.
- gotcha Healpy officially supports Linux and macOS. While Windows is supported through the Windows Subsystem for Linux (WSL), native Windows builds are not supported and may lead to installation or runtime issues.
- gotcha When installing from source, especially if external HEALPix C++ or `cfitsio` libraries are detected, compilation might fail if OpenMP is used by the external library but not supported by your C/C++ compiler (e.g., clang). Conflicts with `cfitsio` from HEASOFT due to a `rotmatrix.h` header clash are also known.
- deprecated Starting from `healpy` 1.15.0, the `logging` module is used for messages instead of `warnings`. All `verbose` keywords in functions are deprecated and will be removed in future versions.
- gotcha Healpy maps typically use the `hp.UNSEEN` constant (`-1.6375e+30`) to mark invalid or unseen pixels. While most `healpy` functions handle this automatically, directly working with `numpy.ma.MaskedArray` via `hp.ma` requires flipping the mask convention (NumPy's `True` means masked, `healpy`'s mask derived from `UNSEEN` might be `0` for masked).
Install
-
pip install healpy -
conda install -c conda-forge healpy
Imports
- healpy
import healpy as hp
- mollview
hp.mollview(map_data)
Quickstart
import numpy as np
import healpy as hp
import matplotlib.pyplot as plt
# Define the resolution parameter NSIDE (must be a power of 2)
NSIDE = 32
# Calculate the number of pixels
NPIX = hp.nside2npix(NSIDE)
print(f"Number of pixels for NSIDE={NSIDE}: {NPIX}")
# Create a simple map (e.g., an array with pixel indices)
m = np.arange(NPIX, dtype=float)
# Visualize the map using Mollweide projection
hp.mollview(m, title="Simple Healpix Map (RING ordering)")
hp.graticule() # Add meridians and parallels
plt.show()