CAMB: Calculating the power spectrum of adiabatic perturbations of cold dark matter

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Ian DSouza
Posts: 3
Joined: September 27 2023
Affiliation: University of Canterbury

CAMB: Calculating the power spectrum of adiabatic perturbations of cold dark matter

Post by Ian DSouza »

I am trying to use the Python version of CAMB. I installed CAMB package using pip. I want to find the power spectrum of adiabatic perturbations of cold dark matter. I am using the following code:

Code: Select all

import numpy as np
import camb

pars = camb.CAMBparams()
pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122)

ks_h = np.geomspace(1e-8, 1e4, 131)
PK = camb.get_matter_power_interpolator(pars, var1="delta_cdm");
zs = [0, 3600]
Ps = PK.P(zs, ks_h)

plt.rcParams["mathtext.fontset"] = "cm"
plt.loglog(ks_h, Ps[0,:], label=r"$z=0$")
plt.loglog(ks_h, Ps[1,:], label=r"$z=3600$")
plt.xlabel(r"$k/h\ [\rm{Mpc}^{-1}]$", fontsize=18)
plt.ylabel(r"$P(k)\ [(\rm{Mpc}/h)^3]$", fontsize=18)
plt.legend(fontsize=18)
plt.show()
I get the resulting graph as:
https://ibb.co/25Kf5Xt
Image



Is my implementation of the power spectrum correct? The reason I'm asking is twofold. One is that I need this power spectrum to reproduce the collapse fraction of adiabatic halos as a function of redshift, as presented in a graph in a paper that I am reading and I seem to be getting a wrong curve. The second is that if I use the linear growth factor [math] to estimate the power spectrum at an arbitrary redshift [math], I don't get the right answer. For example, if I use: Power spectrum ([math]) [math] Power spectrum([math]), where I calculate " Power spectrum([math])" using CAMB and [math] using Dodelson and Schmidt text book eqn (8.77), the resulting "Power spectrum ([math])" I get is not the same as I get when passing the redshift value [math] directly to CAMB to calculate the power spectrum.

P.S. Please note that the cosmological parameter values that I am using in CAMBparams() function are taken from the "CAMBdemo.ipynb" file that I found online.
Antony Lewis
Posts: 1980
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: CAMB: Calculating the power spectrum of adiabatic perturbations of cold dark matter

Post by Antony Lewis »

You should set var1 and var2 for auto-spectrum, and set kmax and zmax appropriately when getting the interpolator. It doesn't go as low as 1e-8 in k, so probably only valid > 1e-4 or so. The notebook parameters are only test minimal parameters to run something, not neccessarily a good fit to data.
Post Reply