Correlation functions¶
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 factors \(\ell(\ell+1)/2\pi\) (for CMB) and \([L(L+1)]^2/2\pi\) (for lensing).
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 (\(\equiv \ell\)) starting at zero and ix-0,1,2,3 in order TT, EE, BB, TE. cls should include \(\ell(\ell+1)/2\pi\) 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 \(\ell\) to calculate \(C_\ell\)
- 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 \(\ell(\ell+1)/2\pi\) 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 (\(\equiv \ell\)) starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. Should include \(\ell(\ell+1)/2\pi\) 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 \(\ell\) up to lmax. Note that \(d_{mn}\) arrays start at \(\ell_{\rm min} = \max(m,n)\), so returned arrays are different sizes
- Parameters:
lmax – maximum \(\ell\)
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 \(\ell(\ell+1)\) float array
lfacs2 – optional pre-computed \((\ell+2)*(\ell-1)\) float array
lrootfacs – optional pre-computed sqrt(lfacs*lfacs2) array
- Returns:
\((P,P'),(d_{11},d_{-1,1}), (d_{20}, d_{22}, d_{2,-2})\) as requested, where P starts at \(\ell=0\), but spin functions start at \(\ell=\ell_{\rm min}\)
- 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 \(D_\ell \equiv \ell(\ell+1)\Delta C_\ell/2\pi\) with respect to \(\ell(\ell+1)C^{\rm unlens}_\ell/2\pi\)
The difference in power in the lensed spectrum is given by dCL[ix, :, :].dot(cl), where cl is the appropriate \(\ell(\ell+1)C^{\rm unlens}_\ell/2\pi\).
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_{{\rm gl},2}\)
- Parameters:
clpp – array of \([L(L+1)]^2 C_L^{\phi\phi}/2\pi\) lensing potential power spectrum (zero based)
lmax – optional maximum L to use from the clpp array
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\left(\Delta D^{\rm ix}_\ell\right) / d D^{{\rm 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 \(D_\ell\equiv \ell(\ell+1)C_\ell/2\pi\) with respect to \(\log(C^{\phi}_L)\). To leading order (and hence not actually accurate), the lensed correction to power spectrum is 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_{{\rm 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 \(\ell(\ell+1)/2\pi\) factors.
clpp – array of \([L(L+1)]^2 C_L^{\phi\phi}/2\pi\) lensing potential power spectrum (zero based)
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[D^{\rm ix}_\ell]/ 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_{{\rm 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 \(\ell\) 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. For a faster result use get_lensed_cls_with_spectrum.
- 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 \(\ell(\ell+1)/2\pi\) factors.
clpp – array of \([L(L+1)]^2 C_L^{\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 \(\ell(\ell+1)/2\pi\) 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_{{\rm gl},2}\)
- Parameters:
cls – 2D array of unlensed cls(L,ix), with L (\(\equiv\ell\)) starting at zero and ix=0,1,2,3 in order TT, EE, BB, TE. cls should include \(\ell(\ell+1)/2\pi\) factors.
clpp – array of \([L(L+1)]^2 C_L^{\phi\phi}/2\pi\) lensing potential power spectrum (zero based)
xvals – array of \(\cos(\theta)\) values at which to calculate correlation function.
weights – if given also return lensed \(C_\ell\), 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
apodize_point_width – smoothing scale for apodization at truncation of correlation function
- 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 \equiv \frac{1}{2} \langle |\nabla \phi|^2\rangle\)
- Parameters:
clpp – array of \([L(L+1)]^2 C_L^{\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_{{\rm gl},2}(x)\) functions from the lensing power spectrum
- Parameters:
clpp – array of \([L(L+1)]^2 C_L^{\phi\phi}/2\pi\) lensing potential power spectrum (zero based)
xvals – array of \(\cos(\theta)\) values at which to calculate correlation function.
lmax – optional maximum L to use from the clpp array
- Returns:
array of \(\sigma^2(x)\), array of \(C_{{\rm gl},2}(x)\)