Convert configuration of model from wrappers camb and class into respectively params.ini and explanatory.ini

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

Convert configuration of model from wrappers camb and class into respectively params.ini and explanatory.ini

Post by Dournac Fabien » June 13 2022

Hello,

I use wrappers for CAMB and CLASS. I have the following configuration to generate Matter/Angular power scpectrum.

1) for wrapper CAMB

Code: Select all

 # Dictionary with cosmological parameters
cosmo = {'h':0.67810,
       'omega_b':0.02238280,
       'omega_cdm': 0.1201075,
       'A_s':2.100549e-09,
       'tau_reio': 0.05430842,
       'n_s':0.9660499}

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

# 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=kmax, nonlinear=True)
pars.set_for_lmax(lmax - 50) # CAMB calculates 50 more than you ask it to (probably a bug)

# Calculate non-linear power spectrum
#pars.NonLinear = camb.model.NonLinear_none
pars.NonLinear = camb.model.NonLinear_both
pars.NonLinearModel.set_params(halofit_version='casarini')
results = camb.get_results(pars)
kh, z, pk_camb = results.get_matter_power_spectrum(minkh=kmin, maxkh=kmax, npoints = npoints)
1) for wrapper CLASS :

Code: Select all

# create instance of the class "Class"
LambdaCDM = Class()
# pass input parameters
LambdaCDM.set(cosmo)
LambdaCDM.set({'output':'mPk, tCl, lCl','P_k_max_1/Mpc':3.0, 'lensing':'yes', 'non linear':'halofit'})
# run class
LambdaCDM.compute()

# get P(k) at redhsift z=0
pk_class = [] # P(k) in (Mpc/h)**3
for k in kh:
    pk_class.append(LambdaCDM.pk(k*cosmo['h'],0.)*cosmo['h']**3) # function .pk(k,z)
Is there a way to generate for CAMB and CLASS respectively a params.ini and explanotary.in from their configuration above in the wrapper.

It would be a kind of exporting the configuration from a wrapper by writting the standard files params.ini and explanotary.ini.

Best regards.

Post Reply