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: 72
Joined: May 18 2019
Affiliation: IRAP

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

Post by Dournac Fabien » November 06 2022


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"):

output_root = 'explanatory'
class_path = '.'

# Dictionary with cosmological parameters
cosmo = {'h':0.67810,
       'omega_cdm': 0.1201075,
       'tau_reio': 0.05430842,
       'z_reio': 7.6711,
       'output':'mPk, tCl, lCl',

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

# Run Class

# 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)

# Save k vs Pk
k_Pk = np.vstack((kh,pk_class)).T
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 ?


Post Reply