glass.healpix — Array API compatible HEALPix functions

This module contains functions for working with HEALPix maps in an Array API compliant manner used with GLASS.

This module should be imported manually if used outside of GLASS:

import glass.healpix as hp

healpix Functions

glass.healpix.ang2pix(nside, theta, phi, *, lonlat=False, xp=None)[source]

Converts the angle to HEALPix pixel numbers.

Parameters:
  • nside (int) – The HEALPix nside parameter of the map.

  • theta (float | FloatArray) – Angular coordinates of a point on the sphere.

  • phi (float | FloatArray) – Angular coordinates of a point on the sphere.

  • lonlat (bool) – If True, automatically adjust latitudes to be within [-90, 90] range.

  • xp (ModuleType | None) – The array library backend to use for array operations.

Returns:

The HEALPix pixel numbers.

Return type:

IntArray

glass.healpix.ang2vec(theta, phi, *, lonlat=False, xp=None)[source]

Convert angles to 3D position vector.

Parameters:
  • theta (float | FloatArray) – Angular coordinates of a point on the sphere.

  • phi (float | FloatArray) – Angular coordinates of a point on the sphere.

  • lonlat (bool) – If True, automatically adjust latitudes to be within [-90, 90] range.

  • xp (ModuleType | None) – The array library backend to use for array operations.

Returns:

A normalised 3-vector pointing in the same direction as ang.

Return type:

tuple[FloatArray, FloatArray, FloatArray]

glass.healpix.npix2nside(npix)[source]

Give the nside parameter for the given number of pixels.

Parameters:

npix (int) – The number of pixels.

Returns:

The HEALPix nside parameter of the map.

Return type:

int

glass.healpix.nside2npix(nside)[source]

Give the number of pixels for the given nside.

Parameters:

nside (int) – The HEALPix nside parameter of the map.

Returns:

The number of pixels.

Return type:

int

glass.healpix.randang(nside, ipix, *, lonlat=False)[source]

Sample random spherical coordinates from the given HEALPix pixels.

rng is no longer a parameter as we must use the NumPy backend otherwise we run into a operand array with iterator write flag set is read-only error coming from _chp.ring2ang_uv(nside, ipix, u, v, u, v).

Parameters:
  • nside (int) – The HEALPix nside parameter of the map.

  • ipix (Any) – HEALPix pixel number.

  • lonlat (bool) – If True, automatically adjust latitudes to be within [-90, 90] range.

Returns:

A tuple theta, phi of mathematical coordinates.

Return type:

tuple[FloatArray, FloatArray]

healpy Functions

glass.healpix.alm2map(alms, nside, *, inplace=False, lmax=None, pixwin=False, pol=True)[source]

Computes a HEALPix map given the alm.

Parameters:
  • alms (ComplexArray | Sequence[ComplexArray]) – A complex array or a sequence of complex arrays.

  • nside (int) – The nside of the output map.

  • inplace (bool) – If True, input alms may be modified by pixel window function and beam smoothing.

  • lmax (int | None) – Explicitly define lmax.

  • pixwin (bool) – Smooth the alm using the pixel window functions.

  • pol (bool) – If True, assumes input alms are TEB.

Returns:

A HEALPix map in RING scheme at nside or a list of T,Q,U maps.

Return type:

FloatArray

glass.healpix.alm2map_spin(alms, nside, spin, lmax)[source]

Computes maps from a set of 2 spinned alm.

Parameters:
  • alms (Sequence[FloatArray]) – List of 2 alms.

  • nside (int) – Requested nside of the output map.

  • spin (int) – Spin of the alms.

  • lmax (int) – Maximum l of the power spectrum.

Returns:

List of 2 out maps in RING scheme as arrays.

Return type:

list[FloatArray]

glass.healpix.almxfl(alm, fl, *, inplace=False)[source]

Multiply alm by a function of l. The function is assumed to be zero where not defined.

Parameters:
  • alm (Any) – The alm to multiply.

  • fl (Any) – The function (at l=0..fl.shape[0]-1) by which alm must be multiplied.

  • inplace (bool) – If True, modify the given alm, otherwise make a copy before multiplying.

Returns:

The modified alm, either a new array or a reference to input alm.

Return type:

Any

glass.healpix.get_nside(m)[source]

Return the nside of the given map.

Parameters:

m (Any) – The map to get the nside from.

Returns:

The HEALPix nside parameter of the map.

Return type:

int

glass.healpix.map2alm(maps, *, lmax=None, pol=True, use_pixel_weights=False)[source]

Computes the alm of a HEALPix map. The input maps must all be in ring ordering.

Parameters:
  • maps (FloatArray | Sequence[FloatArray]) – The input map or a list of n input maps. Must be in ring ordering.

  • lmax (int | None) – Maximum l of the power spectrum.

  • pol (bool) – If True, assumes input maps are TQU.

  • use_pixel_weights (bool) – If True, use pixel by pixel weighting, healpy will automatically download the weights, if needed.

Returns:

alm or a tuple of 3 alm (almT, almE, almB) if polarized input.

Return type:

FloatArray

glass.healpix.pixwin(nside, *, lmax=None, pol=False, xp=None)[source]

Return the pixel window function for the given nside.

Parameters:
  • nside (int) – The nside for which to return the pixel window function.

  • lmax (int | None) – If True, return also the polar pixel window.

  • pol (bool) – Maximum l of the power spectrum.

  • xp (ModuleType | None) – The array library backend to use for array operations.

Returns:

The temperature pixel window function.

Return type:

FloatArray | tuple[FloatArray, …]

glass.healpix.query_strip(nside, thetas, *, dtype=None, xp=None)[source]

Computes a mask of the pixels whose centers lie within the colatitude range defined by thetas.

Parameters:
  • nside (int) – The nside of the HEALPix map.

  • thetas (tuple[float, float]) – Colatitudes in radians.

  • dtype (Optional[Any]) – Desired data-type for the output array.

  • xp (Optional[ModuleType]) – The array library backend to use for array operations.

Returns:

The mask of the pixels which lie within the given strip.

Return type:

Any

Rotator.rotate_map_pixel(m)[source]

Rotate a HEALPix map to a new reference frame in pixel space.

Parameters:

m (Any) – Input map, 1 map is considered I, 2 maps:[Q,U], 3 maps:[I,Q,U].

Returns:

Map in the new reference frame

Return type:

Any