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 and a configurable lmin_floor for monopole/dipole-aware analyses.

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 (bins below lmin_floor dropped).

Type:

np.ndarray

lmaxs

Upper bounds after filtering (bins below lmin_floor dropped).

Type:

np.ndarray

nbins

Number of bins.

Type:

int

lmid

Bin midpoint (lmins + lmaxs) / 2. This is a cheap label, not the effective multipole: where a bandpower sits depends on the noise, mask and Fisher weighting, none of which Bins knows. For the effective multipole use Fisher.get_effective_ells() (ADR-0019).

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).

property lbin

Deprecated alias for lmid.

Renamed because lbin implied an effective multipole, which Bins cannot know (ADR-0019). Kept for one release as a warn-and-forward shim per the post-1.0 deprecation policy (ADR-0018); removed in the next release.

shape_weights(convention='Cl')[source]

Per-ℓ bandpower shape weight w_ℓ (ADR-0019).

The weight declares the in-bin spectrum shape the binned QML derivative assumes: dC^b = Σ_{ℓ∈b} w_ℓ · b²_ℓ · dC^ℓ.

Parameters:

convention ({"Cl", "Dl"}) – "Cl" declares a flat-C_ℓ shape (w_ℓ = 1); "Dl" declares a flat-D_ℓ shape (w_ℓ = / (ℓ(ℓ+1))). Case-insensitive.

Returns:

Weight vector indexed by multipole, shape (lmax + 1,). The weight is a pure function of ℓ, so entries at ℓ outside any bin still carry a value (1 for "Cl"; 2π/(ℓ(ℓ+1)) for "Dl", with w[0] = 0). The binned derivative sum reads only ℓ that fall inside a bin, so those gap entries are never consumed.

Return type:

np.ndarray

Raises:

ValueError – If convention is not "Cl" or "Dl", or if the "Dl" shape is requested while a bin includes ℓ = 0 (D_ℓ is undefined at the monopole). ℓ = 1 is well defined (w = π).