Code: Select all
import numpy as np
import camb
from camb import model, initialpower
import matplotlib.pyplot as plt
# Set up the CAMB parameters
pars = camb.CAMBparams()
# Set cosmological parameters
pars.set_cosmology(H0=67.7, ombh2=0.022447, omch2=0.11928, mnu=0.06, omk=0, tau=0.0568)
# Indicate we want scalar perturbations
pars.WantScalars = True
pars.WantTensors = False
pars.WantVectors = False
pars.DoLensing = True
# Set the initial power spectrum parameters
pars.InitPower.set_params(As=2e-9, ns=0.9682)
# Adjust the InitialCondition and InitialConditionVector
pars.InitialCondition = 2
pars.InitialConditionVector = [0, 1]
# Set the desired redshift
redshifts = np.array([1])
pars.set_matter_power(redshifts=redshifts, kmax=5)
# Calculate results for these parameters
results = camb.get_results(pars)
# Get the matter power spectrum at the desired redshift: P(k,z)
kmin = 1e-4
kmax = 5
nk = 1000
k = np.logspace(np.log10(kmin), np.log10(kmax), nk)
ks_isocurvature, zs_isocurvature, pk_isocurvature = results.get_matter_power_spectrum(minkh=kmin, maxkh=kmax, npoints=nk)
pk_isocurvature = pk_isocurvature.T
plt.rcParams["mathtext.fontset"] = "cm"
# Plot
for i , z in enumerate(zs_isocurvature):
plt.loglog(ks_isocurvature, pk_isocurvature[:,i], label=f"Isocurvature mode")