How to get exactly the same matter power spectra values between classy wrapper and binary class

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

How to get exactly the same matter power spectra values between classy wrapper and binary class

Post by Dournac Fabien » November 06 2022

Hello,

I am looking for a way to produce the same data between matter power spectrum generated from Class wrapper and the one generated from direct execution with " $ ./class explanatory.ini ".

I have 3 main issues : the range is not the same for k scale, the number also is different, and finally, the precsion is no the same, values for a direct execution seems to have less decimals.

Here the script that uses Class wrapper :

Code: Select all

import numpy as np
import matplotlib.pyplot as plt
from classy import Class
import classy
import os

# Create output directory
if not os.path.exists("output"):
    os.makedirs("output")

output_root = 'explanatory'
#WILL NEED TO CHANGE YOUR PATH:
class_path = '.'

# 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,
       'z_reio': 7.6711,
       'n_s':0.9660499,
       'output':'mPk, tCl, lCl',
       'P_k_max_h/Mpc':1.0,
       'P_k_max_1/Mpc':3.0,
       'lensing':'yes'}

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

tauORz = int(input("Do you want to use z_reio(1) or tau_reio(2)?: ").strip())
pkmaxhORpkmax1 = int(input("Do you want to use P_k_max_h/Mpc(1) or P_k_max_1/Mpc(2)?: ").strip())

if tauORz == 1:
    cosmo.pop('tau_reio', None)
elif tauORz == 2:
    cosmo.pop('z_reio', None)
if pkmaxhORpkmax1 == 1:
    cosmo.pop('P_k_max_1/Mpc', None)
elif pkmaxhORpkmax1 == 2:
    cosmo.pop('P_k_max_h/Mpc', None)

"""
Now, create a CLASS object, and calculate the power spectrum
"""

# create instance of the class "Class"
LambdaCDM = Class()
# pass input parameters
LambdaCDM.set(cosmo)

# Run Class
LambdaCDM.compute()

# get P(k) at redhsift z=0
kh = np.linspace(kmin, kmax, npoints)
pk_class = [] # P(k) in (Mpc/h)**3
for k in kh:
    # function .pk(k,z)
    pk_class.append(LambdaCDM.pk(k*cosmo['h'],0.)*cosmo['h']**3) 

# Save k vs Pk
k_Pk = np.vstack((kh,pk_class)).T
np.savetxt('output/output_Matter_Power_Spectrum_DIRECT_FROM_CLASS_WRAPPER.dat',k_Pk)
Finally, how can I generate the same range (k_min=1e-4 and k_max=1), the same number of rows (1000) and same values using a direct execution with " $ ./classs explanatory.ini " ?

I guess this may be done by modifying explanatory.ini but which way ?

Regards

Post Reply