CLASS is a code used to compute the matter power spectrum. The power spectrum is a key input for the cluster-toolkit. This is meant to be a very short example of how you can call CLASS to get the linear and nonlinear power spectra.


The CLASS github page is here. The CLASS documentation is found here.


CLASS uses units of \(Mpc^{-1}\) for math:k and \(Mpc^3\) for math:P.

from classy import Class
import numpy as np

#Start by specifying the cosmology
Omega_b = 0.05
Omega_m = 0.3
Omega_cdm = Omega_m - Omega_b
h = 0.7 #H0/100
A_s = 2.1e-9
n_s = 0.96

#Create a params dictionary
#Need to specify the max wavenumber
k_max = 10 #UNITS: 1/Mpc

params = {
             'non linear':'halofit',
             'z_max_pk':10. #Default value is 10

#Initialize the cosmology andcompute everything
cosmo = Class()

#Specify k and z
k = np.logspace(-5, np.log10(k_max), num=1000) #Mpc^-1
z = 1.

#Call these for the nonlinear and linear matter power spectra
Pnonlin = np.array([, z) for ki in k])
Plin = np.array([cosmo.pk_lin(ki, z) for ki in k])

#NOTE: You will need to convert these to h/Mpc and (Mpc/h)^3
#to use in the toolkit. To do this you would do:
k /= h
Plin *= h**3
Pnonlin *= h**3