camb.correlations

Functions to transform CMB angular power spectra into correlation functions (cl2corr) and vice versa (corr2cl), and calculate lensed power spectra from unlensed ones.

The lensed power spectrum functions are not intended to replace those calculated by default when getting CAMB results, but may be useful for tests, e.g. using different lensing potential power spectra, partially-delensed lensing power spectra, etc.

These functions are all pure python/scipy, and operate and return cls including L(L+1)/2pi and [L(L+1)]^2/2pi factors.

  1. Lewis December 2016
camb.correlations.cl2corr(cls, xvals, lmax=None)[source]

Get the correlation function from the power spectra, evaluated at points cos(theta) = xvals. Use roots of Legendre polynomials (np.polynomial.legendre.leggauss) for accurate back integration with corr2cl. Note currently does not work at xvals=1 (can easily calculate that as special case!).

Parameters:
  • cls – 2D array cls(L,ix), with L starting at zero and ix-0,1,2,3 in order TT, EE, BB, TE. cls should include l(l+1)/2pi factors.
  • xvals – array of cos(theta) values at which to calculate correlation function.
  • lmax – optional maximum L to use from the cls arrays
Returns:

2D array of corrs[i, ix], where ix=0,1,2,3 are T, Q+U, Q-U and cross

camb.correlations.corr2cl(corrs, xvals, weights, lmax)[source]

Transform from correlation functions to power spectra. Note that using cl2corr followed by corr2cl is generally very accurate (< 1e-5 relative error) if xvals, weights = np.polynomial.legendre.leggauss(lmax+1)

Parameters:
  • corrs – 2D array, corrs[i, ix], where ix=0,1,2,3 are T, Q+U, Q-U and cross
  • xvals – values of cos(theta) at which corrs stores values
  • weights – weights for integrating each point in xvals. Typically from np.polynomial.legendre.leggauss
  • lmax – maximum L to calculate CL
Returns:

array of power spectra, cl[L, ix], where L starts at zero and ix=0,1,2,3 in order TT, EE, BB, TE. They include l(l+1)/2pi factors.

camb.correlations.gauss_legendre_correlation(cls, lmax=None, sampling_factor=1)[source]

Transform power specturm cls into correlation functions evaluated at the roots of the Legendre polynomials for Gauss-Legendre quadrature. Returns correlation function array, evaluation points and weights. Result can be passed to corr2cl for accurate back transform.

Parameters:
  • cls – 2D array cls(L,ix), with L starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. Should include l*(l+1)/2pi factors.
  • lmax – optional maximum L to use
  • sampling_factor – uses Gauss-Legendre with degree lmax*sampling_factor+1
Returns:

corrs, xvals, weights; corrs[i, ix] is 2D array where ix=0,1,2,3 are T, Q+U, Q-U and cross

camb.correlations.legendre_funcs(lmax, x, m=[0, 2], lfacs=None, lfacs2=None, lrootfacs=None)[source]

Utility function to return array of Legendre and d_{mn} functions for all L up to lmax. Note that d_{mn} arrays start at L_min = max(m,n), so returned arrays are different sizes

Parameters:
  • lmax – maximum L
  • x – scalar value of cos(theta) at which to evaluate
  • m – m values to calculate d_{m,n}, etc as relevant
  • lfacs – optional pre-computed L(L+1) float array
  • lfacs2 – optional pre-computed (L+2)*(L-1) float array
  • lrootfacs – optional pre-computed sqrt(lfacs*lfacs2) array
Returns:

(P,dP),(d11,dm11), (d20, d22, d2m2) as requested, where P starts at L=0, but spin functions start at L=Lmin

camb.correlations.lensed_cl_derivative_unlensed(clpp, lmax=None, theta_max=0.098174771875, apodize_point_width=10, sampling_factor=1.4)[source]

Get derivative dcl of lensed minus unlensed power ell(ell+1)Delta C_ell/2pi with respect to L(L+1)C^unlens_L/2pi

The difference in power in the lensed spectrum is given by dCL[ix, :, :].dot(cl), where cl is the appropriate L(L+1)C^unlens_L/2pi.

Uses the non-perturbative curved-sky results from Eqs 9.12 and 9.16-9.18 of astro-ph/0601594, to second order in C_{gl,2}

Parameters:
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum
  • lmax – optional maximum L to use from the cls arrays
  • theta_max – maximum angle (in radians) to keep in the correlation functions
  • apodize_point_width – if theta_max is set, apodize around the cut using half Gaussian of approx width apodize_point_width/lmax*pi
  • sampling_factor – npoints = int(sampling_factor*lmax)+1
Returns:

array dCL[ix, ell, L], where ix=0,1,2,3 are TT, EE, BB, TE and result is d[ell(ell+1)Delta C^ix_ell/2pi]/ d C^{unlens,j}_L where j[ix] are TT, EE, EE, TE

camb.correlations.lensed_cl_derivatives(cls, clpp, lmax=None, theta_max=0.098174771875, apodize_point_width=10, sampling_factor=1.4)[source]

Get derivative dcl of lensed ell(ell+1)C_ell/2pi with respect to log(C^phi_L). To leading order (and hence not actually accurate), the lensed correction to power spectrum ix is given by dcl[ix,:,:].dot(np.ones(clpp.shape)).

Uses the non-perturbative curved-sky results from Eqs 9.12 and 9.16-9.18 of astro-ph/0601594, to second order in C_{gl,2}

Parameters:
  • cls – 2D array of unlensed cls(L,ix), with L starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. cls should include l(l+1)/2pi factors.
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum
  • lmax – optional maximum L to use from the cls arrays
  • theta_max – maximum angle (in radians) to keep in the correlation functions
  • apodize_point_width – if theta_max is set, apodize around the cut using half Gaussian of approx width apodize_point_width/lmax*pi
  • sampling_factor – npoints = int(sampling_factor*lmax)+1
Returns:

array dCL[ix, ell, L], where ix=0,1,2,3 are T, EE, BB, TE and result is d[ell(ell+1)C^ix_ell/2pi]/ d log C^phi_L

camb.correlations.lensed_cls(cls, clpp, lmax=None, lmax_lensed=None, sampling_factor=1.4, delta_cls=False, theta_max=0.098174771875, apodize_point_width=10, leggaus=True, cache=True)[source]

Get the lensed power spectra from the unlensed power spectra and the lensing potential power. Uses the non-perturbative curved-sky results from Eqs 9.12 and 9.16-9.18 of astro-ph/0601594, to second order in C_{gl,2}.

Correlations are calculated for Gauss-Legendre integration if leggaus=True; this slows it by several seconds, but will be must faster on subsequent calls with the same lmax*sampling_factor. If Gauss-Legendre is not used, sampling_factor needs to be about 2 times larger for same accuracy.

For a reference implementation with the full integral range and no apodization set theta_max=None.

Note that this function does not pad high L with a smooth fit (like CAMB’s main functions); for accurate results should be called with lmax high enough that input cls are effectively band limited (lmax >= 2500, or higher for accurate BB to small scales). Usually lmax truncation errors are far larger than other numerical errors for lmax<4000.

Parameters:
  • cls – 2D array of unlensed cls(L,ix), with L starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. cls should include l(l+1)/2pi factors.
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum (zero based)
  • lmax – optional maximum L to use from the cls arrays
  • lmax_lensed – optional maximum L for the returned cl array (lmax_lensed <= lmax)
  • sampling_factor – npoints = int(sampling_factor*lmax)+1
  • delta_cls – if true, return the difference between lensed and unlensed (optional, default False)
  • theta_max – maximum angle (in radians) to keep in the correlation functions; default: pi/32
  • apodize_point_width – if theta_max is set, apodize around the cut using half Gaussian of approx width apodize_point_width/lmax*pi
  • leggaus – whether to use Gauss-Legendre integration (default True)
  • cache – if leggaus = True, set cache to save the x values and weights between calls (most of the time)
Returns:

2D array of cls[L, ix], with L starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. cls include l(l+1)/2pi factors.

camb.correlations.lensed_correlations(cls, clpp, xvals, weights=None, lmax=None, delta=False, theta_max=None, apodize_point_width=10)[source]

Get the lensed correlation function from the unlensed power spectra, evaluated at points cos(theta) = xvals. Use roots of Legendre polynomials (np.polynomial.legendre.leggauss) for accurate back integration with corr2cl. Note currently does not work at xvals=1 (can easily calculate that as special case!).

To get the lensed cls efficiently, set weights to the integral weights for each x value, then function returns lensed correlations and lensed cls.

Uses the non-perturbative curved-sky results from Eqs 9.12 and 9.16-9.18 of astro-ph/0601594, to second order in C_{gl,2}

Parameters:
  • cls – 2D array of unlensed cls(L,ix), with L starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. cls should include l(l+1)/2pi factors.
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum
  • xvals – array of cos(theta) values at which to calculate correlation function.
  • weights – if given also return lensed Cls, otherwise just lensed correlations
  • lmax – optional maximum L to use from the cls arrays
  • delta – if true, calculate the difference between lensed and unlensed (default False)
  • theta_max – maximum angle (in radians) to keep in the correlation functions
Returns:

2D array of corrs[i, ix], where ix=0,1,2,3 are T, Q+U, Q-U and cross; if weights is not None, then return corrs, lensed_cls

camb.correlations.lensing_R(clpp, lmax=None)[source]

Get R = 1/2 <|grad phi|^2>

Parameters:
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum
  • lmax – optional maximum L to use from the cls arrays
Returns:

R

camb.correlations.lensing_correlations(clpp, xvals, lmax=None)[source]

Get the sigma^2(x) and C_{gl,2}(x) functions from the lensing power spectrum

Parameters:
  • clpp – array of [l(l+1)]^2 C_phi_phi/2/pi lensing potential power spectrum
  • xvals – array of cos(theta) values at which to calculate correlation function.
  • lmax – optional maximum L to use from the cls arrays
Returns:

sigmasq, Cg2