CAMB wrapper generates more multipoles than asked

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Dournac Fabien
Posts: 72
Joined: May 18 2019
Affiliation: IRAP

CAMB wrapper generates more multipoles than asked

Post by Dournac Fabien » February 21 2022

Hi !

1) I have a little issue about the number of [math] that generates CAMB 1.3.5.

Indeed, if I apply the following code snippet :

Code: Select all

kmin = 1e-4 # Mpc
kmax = 1 # Mpc
npoints = 1000 # Number of elements in the Pk array
lmax = 2500 # Maximum multipole calculated for the CLs

Create a CAMB results object, and use it to calculate the power spectrum

# Start a CAMB parameters object
pars = camb.CAMBparams()
# Specify the parameters
pars.set_cosmology(H0=cosmo['h']*100, ombh2=cosmo['omega_b'], omch2=cosmo['omega_cdm'], tau=cosmo['tau_reio'])
pars.InitPower.set_params(As=cosmo['A_s'], ns=cosmo['n_s'])
pars.set_matter_power(redshifts=[0.], kmax=2.0)
pars.set_for_lmax(lmax - 50) # CAMB calculates 50 more than 2500 that I ask it to (to fix)
As you can see, I am obliged to reduce the number of multipoles since CAMB generates 2650 on the line :

Code: Select all

and I get :

Code: Select all

print('pars.get_for_lmax = ', pars.max_l)
Question 1: how to fix in pars.set_for_lmax(lmax) in order to get really lmax=2500 values ? Is it related to kmin or kmax ?

2) But if I want to angular power spectrum with classt wrapper of CLASS, I do :

Code: Select all

# Get the Cls for Class
cls = LambdaCDM.lensed_cl(lmax)
ell = cls['ell'][2:]
and I print number of ell and len(ell) :

Code: Select all

len(clTT_camb) =  2499
So, despite the fact that I have initially

Code: Select all

=2600, I can plot the 2 angular power spectra (camb and classy) :

Code: Select all

# Get the Cls for CAMB
powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
clTT_camb = totCL[2:,0]
# %%

Plot them

# %%
# plot C_l^TT
plt.ylabel(r'$[\ell(\ell+1)/2\pi]  C_\ell^\mathrm{TT}$')
plt.plot(ell,clTT_class, 'r-', label = 'CLASS')
plt.plot(ell,clTT_camb,'k--', label = 'CAMB')
Question 2: how the function results.get_cmb_power_spectra can produce only 2500 values and not 2499 or 2600 as in point 1) above ?

If anyone could make suggestions or explanations ...

Last edited by Dournac Fabien on February 21 2022, edited 1 time in total.

Antony Lewis
Posts: 1852
Joined: September 23 2004
Affiliation: University of Sussex

Re: CAMB wrapper generates more multipoles than asked

Post by Antony Lewis » February 21 2022

You can pass lmax argument to get_cmb_power_spectra and related functions. CAMB C_L arrays always start at L=0.

Internally it gets to higher lmax than you ask to ensure that the lensed spectrum is accurate at lmax after interpolation

Post Reply