Spherical Harmonic Transforms Module
Spherical Harmonic Transforms Module
This module provides fast spherical harmonic transforms using the DUCC0 library for HEALPix maps. It offers significant performance improvements over healpy’s default implementation, especially for high-resolution maps.
The module supports: - Forward transforms (map2alm) for spin-0 and spin-2 fields - Adjoint/inverse transforms (alm2map) - Automatic pixel weighting for accurate transforms - Beam smoothing operations - Multi-threaded execution
Classes
- HealpixDUCC
Main class for performing spherical harmonic transforms on HEALPix maps using the DUCC0 library.
Example
from cobi.sht import HealpixDUCC import numpy as np
# Initialize for nside=512 hp_ducc = HealpixDUCC(nside=512)
# Transform Q/U polarization maps to E/B alms qu_maps = np.array([q_map, u_map]) eb_alms = hp_ducc.map2alm(qu_maps, lmax=1500, nthreads=4)
# Smooth and transform back smoothed_maps = hp_ducc.smoothing(qu_maps, lmax=1500, fwhm=5.0, nthreads=4)
Notes
This module is imported from https://github.com/antolonappan/PyNILC/blob/main/pynilc/sht.py and provides a high-performance alternative to healpy for spherical harmonic transforms.
- class HealpixDUCC(nside)[source]
Bases:
objectA class to handle HEALPix geometry and perform spherical harmonic transforms. Attributes: ———- nside : int
The HEALPix nside parameter.
- getsize(lmax, mmax)[source]
Get size of the alm array for a given lmax and mmax. Parameters: ———– lmax : int
Maximum l.
- mmaxint
Maximum m.
- __tomap__(alm, spin, lmax, mmax, nthreads, map=None, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform. Parameters: ———– alm : np.ndarray
The input alm array.
- spinint
The spin of the field.
- lmaxint
Maximum l.
- mmaxint
Maximum m.
- nthreadsint
Number of threads to use.
- mapnp.ndarray
The output map array.
- Parameters:
alm (numpy.ndarray)
spin (int)
lmax (int)
mmax (int)
nthreads (int)
map (numpy.ndarray | None)
- __toalm__(m, spin, lmax, mmax, nthreads, alm=None, apply_weights=True, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform. Parameters: ———– m : np.ndarray
The input map array.
- spinint
The spin of the field.
- lmaxint
Maximum l.
- mmaxint
Maximum m.
- nthreadsint
Number of threads to use.
- almnp.ndarray
The output alm array.
- apply_weightsbool
Whether to apply the weights.
- Parameters:
m (numpy.ndarray)
spin (int)
lmax (int)
mmax (int)
nthreads (int)
- __alm2map_spin2__(alm, lmax, nthreads, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform for spin-2 fields. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- __map2alm_spin2__(m, lmax, nthreads, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform for spin-2 fields. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- __alm2map_spin0__(alm, lmax, nthreads, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform for spin-0 fields. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- __map2alm_spin0__(m, lmax, nthreads, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform for spin-0 fields. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- alm2map(alm, lmax, nthreads, **kwargs)[source]
Perform the forward spherical harmonic transform. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- map2alm(m, lmax, nthreads, **kwargs)[source]
Perform the adjoint spherical harmonic transform. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- smoothing_alms(alms, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the alm array. Parameters: ———– alms : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
alms (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)
- smoothing_maps(map, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the map array. Parameters: ———– map : np.ndarray
The input map array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
map (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)
- smoothing(data, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the Map or alm. Parameters: ———– data : np.ndarray
The input data array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
data (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)
HealpixDUCC Class
- class HealpixDUCC(nside)[source]
A class to handle HEALPix geometry and perform spherical harmonic transforms. Attributes: ———- nside : int
The HEALPix nside parameter.
- getsize(lmax, mmax)[source]
Get size of the alm array for a given lmax and mmax. Parameters: ———– lmax : int
Maximum l.
- mmaxint
Maximum m.
- __tomap__(alm, spin, lmax, mmax, nthreads, map=None, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform. Parameters: ———– alm : np.ndarray
The input alm array.
- spinint
The spin of the field.
- lmaxint
Maximum l.
- mmaxint
Maximum m.
- nthreadsint
Number of threads to use.
- mapnp.ndarray
The output map array.
- Parameters:
alm (numpy.ndarray)
spin (int)
lmax (int)
mmax (int)
nthreads (int)
map (numpy.ndarray | None)
- __toalm__(m, spin, lmax, mmax, nthreads, alm=None, apply_weights=True, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform. Parameters: ———– m : np.ndarray
The input map array.
- spinint
The spin of the field.
- lmaxint
Maximum l.
- mmaxint
Maximum m.
- nthreadsint
Number of threads to use.
- almnp.ndarray
The output alm array.
- apply_weightsbool
Whether to apply the weights.
- Parameters:
m (numpy.ndarray)
spin (int)
lmax (int)
mmax (int)
nthreads (int)
- __alm2map_spin2__(alm, lmax, nthreads, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform for spin-2 fields. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- __map2alm_spin2__(m, lmax, nthreads, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform for spin-2 fields. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- __alm2map_spin0__(alm, lmax, nthreads, **kwargs)[source]
A helper function to perform the forward spherical harmonic transform for spin-0 fields. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- __map2alm_spin0__(m, lmax, nthreads, **kwargs)[source]
A helper function to perform the adjoint spherical harmonic transform for spin-0 fields. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- alm2map(alm, lmax, nthreads, **kwargs)[source]
Perform the forward spherical harmonic transform. Parameters: ———– alm : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
alm (numpy.ndarray)
lmax (int)
nthreads (int)
- map2alm(m, lmax, nthreads, **kwargs)[source]
Perform the adjoint spherical harmonic transform. Parameters: ———– m : np.ndarray
The input map array.
- lmaxint
Maximum l.
- nthreadsint
Number of threads to use.
- Parameters:
m (numpy.ndarray)
lmax (int)
nthreads (int)
- smoothing_alms(alms, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the alm array. Parameters: ———– alms : np.ndarray
The input alm array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
alms (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)
- smoothing_maps(map, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the map array. Parameters: ———– map : np.ndarray
The input map array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
map (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)
- smoothing(data, lmax, fwhm, nthreads, **kwargs)[source]
Smooth the Map or alm. Parameters: ———– data : np.ndarray
The input data array.
- lmaxint
Maximum l.
- fwhmfloat
The full width at half maximum of the beam.
- nthreadsint
Number of threads to use.
- Parameters:
data (numpy.ndarray)
lmax (int)
fwhm (float)
nthreads (int)