cosmocore.bins module

Multipole binning for power spectrum estimation.

Provides the Bins class for defining multipole bins with configurable widths and weights. Used by QUBE for binned QML estimation, where per-bin derivative matrices replace per-ell derivatives.

When delta_ell=1, each bin contains a single multipole and the binned estimator reduces to the standard per-multipole QML estimator.

class cosmocore.bins.Bins(lmins, lmaxs, lmin_floor=2)[source]

Bases: object

Multipole binning specification.

Defines bins by their lower and upper multipole bounds. Both bounds are inclusive: a bin with lmin=2, lmax=4 contains multipoles {2, 3, 4}. Bins must not overlap and must be sorted in ascending order. Gaps between bins are allowed (those multipoles are simply excluded from the analysis).

The binning operator formalism follows Bond, Jaffe & Knox (1998). The implementation is adapted from the xQML package (Vanneste et al. 2018, Phys. Rev. D 98, 103526), extended with input validation, D_ell weighting, covariance binning, and lmin zero-padding support.

Parameters:
  • lmins (array_like) – Lower bound of each bin (inclusive). Bins with lmax < 2 are automatically discarded since CMB power spectra start at ell=2.

  • lmaxs (array_like) – Upper bound of each bin (inclusive). Must satisfy lmaxs[i] >= lmins[i] for each bin.

lmins

Lower bounds after filtering (ell >= 2).

Type:

np.ndarray

lmaxs

Upper bounds after filtering (ell >= 2).

Type:

np.ndarray

nbins

Number of bins.

Type:

int

lbin

Effective multipole for each bin (midpoint).

Type:

np.ndarray

dl

Width of each bin (lmaxs - lmins + 1).

Type:

np.ndarray

lmin

Global minimum multipole.

Type:

int

lmax

Global maximum multipole.

Type:

int

Examples

Uniform bins of width 3 from ell=2 to ell=10:

>>> bins = Bins.fromdeltal(2, 10, 3)
>>> bins.lmins
array([2, 5, 8])
>>> bins.lmaxs
array([4, 7, 10])

Custom non-uniform bins:

>>> bins = Bins([2, 5, 10], [4, 9, 20])
>>> bins.dl
array([3, 5, 11])
__init__(lmins, lmaxs, lmin_floor=2)[source]
classmethod fromdeltal(lmin, lmax, delta_ell)[source]

Create uniform bins with constant width.

lmin doubles as the bin floor; values below 2 are honoured (e.g. Bins.fromdeltal(1, 4, 1) includes the dipole).

bins()[source]

Return (lmins, lmaxs) tuple.

bin_spectra(spectra, Dl=False, lmin=0)[source]

Average spectra in bins.

Parameters:
  • spectra (array_like) – Power spectra, last axis is multipole.

  • Dl (bool) – If True, weight by ell*(ell+1)/(2*pi).

  • lmin (int) – Starting multipole of the input spectra. If > 0, the input is zero-padded for ell < lmin before binning.

Returns:

Binned spectra.

Return type:

np.ndarray

bin_covariance(clcov)[source]

Bin a covariance matrix: P @ clcov @ Q.