Maths utils

This module contains some fast utility functions that are useful in the same contexts as camb. They are entirely independent of the main camb code.

camb.mathutils.chi_squared(covinv, x)[source]

Utility function to efficiently calculate x^T covinv x

Parameters:
  • covinv – symmetric inverse covariance matrix
  • x – vector
Returns:

covinv.dot(x).dot(x), but parallelized and using symmetry

camb.mathutils.pcl_coupling_matrix(P, lmax, pol=False)[source]

Get Pseudo-Cl coupling matrix from power spectrum of mask. Uses multiple threads. See Eq A31 of astro-ph/0105302

Parameters:
  • P – power spectrum of mask
  • lmax – lmax for the matrix
  • pol – whether to calculate TE, EE, BB couplings
Returns:

coupling matrix (square but not symmetric), or list of TT, TE, EE, BB if pol

camb.mathutils.scalar_coupling_matrix(P, lmax)[source]

Get scalar Pseudo-Cl coupling matrix from power spectrum of mask, or array of power masks. Uses multiple threads. See Eq A31 of astro-ph/0105302

Parameters:
  • P – power spectrum of mask, or list of mask power spectra
  • lmax – lmax for the matrix (assumed square)
Returns:

coupling matrix (square but not symmetric), or list of couplings for different masks

camb.mathutils.threej(l2, l3, m2, m3)[source]

Convenience wrapper around standard 3j function, returning array for all allowed l1 values

Parameters:
  • l2 – L_2
  • l3 – L_3
  • m2 – M_2
  • m3 – M_3
Returns:

array of 3j from max(abs(l2-l3),abs(m2+m3)) .. l2+l3

camb.mathutils.threej_coupling(W, lmax, pol=False)[source]

Calculate symmetric coupling matrix :math`Xi` for given weights \(W_{\ell}\), where \(\langle\tilde{C}_\ell\rangle = \Xi_{\ell \ell'} (2\ell'+1) C_\ell\). The weights are related to the power spectrum of the mask P by \(W_\ell = (2 \ell + 1) P_\ell / 4 \pi\). See e.g. Eq D16 of arxiv:0801.0554.

If pol is False and W is an array of weights, produces array of temperature couplings, otherwise for pol is True produces set of TT, TE, EE, EB couplings (and weights must have one spectrum - for same masks - or three).

Use scalar_coupling_matrix() or pcl_coupling_matrix() to get the coupling matrix directly from the mask power spectrum.

Parameters:
  • W – 1d array of Weights for each L, or list of arrays of weights (zero based)
  • lmax – lmax for the output matrix (assumed symmetric, though not in principle)
  • pol – if pol, produce TT, TE, EE, EB couplings for three input mask weights (or one if assuming same mask)
Returns:

symmetric coupling matrix or array of matrices