cosmocore.beam module
Beam handling: window functions and beam smoothing managers.
Moved from cosmocore.harmonic (2026-05). See ADR-0002 follow-up
(architecture backlog #5) for the rename rationale.
References
- cosmocore.beam.coswinbeam(nside, ell1=None, ell2=None)[source]
Generate a cosine apodizing window beam function.
Implements the raised-cosine kernel of Akrami+ 2020 (NPIPE, Eq. 15) and Aghanim+ 2019 / Benabed+ 2009 (Planck Legacy, Eq. 4):
b(ℓ) = 1 for ℓ ≤ ℓ₁ b(ℓ) = ½ [1 + cos(π (ℓ − ℓ₁) / (ℓ₂ − ℓ₁))] for ℓ₁ < ℓ ≤ ℓ₂ b(ℓ) = 0 for ℓ > ℓ₂
Two named conventions are exposed via
BeamManager: Legacy usesell1 = nside(Benabed+ 2009; Aghanim+ 2019), NPIPE usesell1 = 1(Akrami+ 2020 §4.2; lower threshold reduced from N_side to suppress ringing in the 857-GHz maps). Both useell2 = 3 * nside.- Parameters:
- Returns:
Beam window function b(ℓ) for ℓ = 0 to ℓ = 4*nside.
- Return type:
numpy.ndarray, shape (4*nside + 1,)
- class cosmocore.beam.BeamManager(fields)[source]
Bases:
objectManages beam functions for a collection of cosmological fields.
This class handles the computation and application of instrumental beam window functions that model the finite angular resolution of cosmological surveys. It supports multiple beam types (Gaussian, cosine window, or custom from file) and manages beam assignment to different field types.
The manager computes beam functions for temperature and polarization measurements separately, as they may have different instrumental responses. It integrates with SpectraManager to apply beam smoothing to theoretical power spectra.
- Parameters:
fields (list of BaseField) – Collection of cosmological fields for which to manage beam functions. Each field should have defined labels and spin properties.
Examples
>>> from cosmocore import ScalarField, PolarizationField >>> temp_field = ScalarField(['T'], spin=0, lmax=100) >>> pol_field = PolarizationField(['E', 'B'], spin=2, lmax=100) >>> beam_mgr = BeamManager([temp_field, pol_field]) >>> # Set Gaussian beam with 5 arcmin FWHM >>> params = InputParams(lmax=100, nside=512, smoothing_type=1, fwhmarcmin=5.0) >>> beam_mgr.set_beams_from_params(params)
Notes
- Supported beam types:
“none”: No smoothing (beam = 1)
“gaussian”: Gaussian beam with specified FWHM
“cosine_legacy”: Benabed+ 2009 / Aghanim+ 2019 cosine kernel (flat to ℓ=nside, cosine roll-off to ℓ=3·nside)
“cosine_npipe”: Akrami+ 2020 NPIPE cosine kernel (flat to ℓ=1, cosine roll-off to ℓ=3·nside)
“file”: Custom beam from file
- compute_beams(lmax, nside, smoothtype, fwhmarcmin, beam_file)[source]
Compute beam functions based on smoothing type.
Parameters:
- lmaxint
Maximum multipole
- nsideint
HEALPix nside parameter
- smoothtypestr
Type of smoothing:
"none","gaussian","cosine_legacy","cosine_npipe", or"file".- fwhmarcminfloat
FWHM in arcminutes for Gaussian beam
- beam_filestr
Path to beam file for smoothtype=”file”
Returns:
: Dict[str, np.ndarray]
Dictionary with beam functions for T, E, B
- set_beams_from_params(params, lmax=None)[source]
Set beams for all fields using parameter configuration.
This method computes the appropriate beam functions based on the parameter settings and assigns them to each field in the collection. Scalar fields receive a single beam function, while polarization fields receive separate E and B mode beam functions.
- Parameters:
params (InputParams) –
Configuration object containing beam parameters including: - lmax: Maximum multipole - nside: HEALPix resolution parameter - smoothing_type: Type of beam (“none”, “gaussian”,
”cosine_legacy”, “cosine_npipe”, “file”)
fwhmarcmin: FWHM in arcminutes (for Gaussian beams)
beam_file: Path to beam file (for custom beams)
lmax (int, optional) – Maximum multipole to use. If None, uses params.lmax. This allows computing beams up to a different lmax than params.lmax.
- Return type:
Notes
The method automatically handles field-beam matching. For scalar fields, it uses the ‘T’ beam. For polarization fields, it uses ‘E’ and ‘B’ beams. If specific labels aren’t found, it falls back to available beams.
Examples
>>> params = InputParams(lmax=100, smoothing_type=1, fwhmarcmin=5.0) >>> beam_mgr.set_beams_from_params(params)
- get_beam_dict()[source]
Get dictionary mapping field labels to beam functions.
- Returns:
Dictionary with field labels as keys (e.g., ‘T’, ‘E’, ‘B’) and corresponding beam window functions as values. Each beam is an ℓ-indexed 1D array of length
lmax + 1(beam[ell]).- Return type:
- Raises:
ValueError – If beams have not been set.
Notes
For scalar fields, the dictionary contains one entry per field label. For polarization fields, the beam array is split into separate E and B mode entries.
Examples
>>> beam_dict = beam_mgr.get_beam_dict() >>> print(beam_dict.keys()) # ['T', 'E', 'B'] >>> t_beam = beam_dict['T'] # Temperature beam function
- get_beam(label)[source]
Get beam window function for a specific field label.
- Parameters:
label (str) – Field label (e.g., ‘T’, ‘E’, ‘B’).
- Returns:
Beam window function B(ℓ) for ℓ = 2 to ℓ = lmax.
- Return type:
np.ndarray
- Raises:
ValueError – If beams have not been set or if label is not found.
- apply_smoothing(spectra_manager, lmax=None)[source]
Apply beam smoothing to power spectra.
This method applies instrumental beam effects to all power spectra managed by the SpectraManager. The smoothing accounts for both the beam window functions and the geometric conversion factors.
- Parameters:
spectra_manager (SpectraManager) – The SpectraManager instance containing the power spectra to smooth. The spectra are modified in-place.
lmax (int, optional) – Maximum multipole to use. If None, uses the field’s lmax. This allows applying smoothing up to a different lmax.
- Return type:
Notes
The smoothing operation multiplies each power spectrum by: C_ℓ^smoothed = C_ℓ^theory × B₁(ℓ) × B₂(ℓ)
where B₁(ℓ) and B₂(ℓ) are the beam functions for the two fields involved in the spectrum.
Examples
>>> beam_mgr.set_beams_from_params(params) >>> spectra_mgr.set_cls_from_file('theory_cls.dat', params) >>> beam_mgr.apply_smoothing(spectra_mgr) # Apply instrumental effects