CAMB: output power spectrum
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
CAMB: output power spectrum
Hello:
I have two simple questions on outputting the power spectrum from CAMB.
1. How to output 2D spectrum galaxy number count from CAMB? I checked all the outputted files, but only found 2D specturm for T, E, B, Phi, both auto and cross-correlations, instead of galaxy count.
2. I tried to output 3D spectrum for P_{d,Weyl} but didn't get the results(basically NAN as output). And is the same when I added a new variable for cross-correlation, say, P_{d,Psi}, with Psi one of the gravitational potentials. However, it works when I outputted P_{Weyl,Weyl} or P_{Psi,Psi}, which is confusing to me. So could you tell me how to do this properly or if I have made any mistakes? As for the outputting script, I simply used the example from: https://camb.readthedocs.io/en/latest/CAMBdemo.html, thus should be fine and it works for all the other variable pairs.
Many thanks!
I have two simple questions on outputting the power spectrum from CAMB.
1. How to output 2D spectrum galaxy number count from CAMB? I checked all the outputted files, but only found 2D specturm for T, E, B, Phi, both auto and cross-correlations, instead of galaxy count.
2. I tried to output 3D spectrum for P_{d,Weyl} but didn't get the results(basically NAN as output). And is the same when I added a new variable for cross-correlation, say, P_{d,Psi}, with Psi one of the gravitational potentials. However, it works when I outputted P_{Weyl,Weyl} or P_{Psi,Psi}, which is confusing to me. So could you tell me how to do this properly or if I have made any mistakes? As for the outputting script, I simply used the example from: https://camb.readthedocs.io/en/latest/CAMBdemo.html, thus should be fine and it works for all the other variable pairs.
Many thanks!
-
- Posts: 1973
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
Re: CAMB: output power spectrum
By "d" you mean delta_tot?
Box 36 in the example notebook shows how to get C_L cross-spectra from counts.
Box 36 in the example notebook shows how to get C_L cross-spectra from counts.
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
Re: CAMB: output power spectrum
Thanks a lot.
Yes, d means delta_tot.
Yes, d means delta_tot.
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
Re: CAMB: output power spectrum
Hello, I am still having trouble with question 2 above. It would be nice if you could give some directions. Thanks.
-
- Posts: 1973
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
Re: CAMB: output power spectrum
It's not very clear what you are doing, "added new variable"? Please give complete code that reproduces any issue.
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
Re: CAMB: output power spectrum
Hi Antony. Sorry for not making clear the question here. Basically, I was trying to output the cross-power spectrum P_{delta_tot, Weyl}. I made a simple script as below to run it, but I only got NAN outputted. The same script outputs normally for other pairs like P_{delta_tot, delta_tot} or P_{Weyl, Weyl}, so I am confused about it. Thanks.
===
from camb import model
from camb.camb import get_matter_power_interpolator
from camb import camb
import numpy as np
#parameter settings
pars =model.CAMBparams()
pars.set_cosmology(H0=70, ombh2=0.0226, omch2=0.112, mnu=0.06, omk=0)
pars.set_dark_energy()
pars.InitPower.set_params(ns=0.96)
pars.WantTransfer = True
zbins = 15
kpoints = 200
zrange=np.linspace(0,1,zbins, endpoint=False)
pars.set_matter_power(redshifts=zrange,kmax=2.0)
pars.NonLinear = model.NonLinear_none
results = camb.get_results(pars)
kh, z, pk_dd = results.get_matter_power_spectrum(minkh=1e-4, maxkh=1, npoints = 200,
var1 = model.Transfer_tot, var2 = model.Transfer_Weyl)
print(pk_dd)
===
===
from camb import model
from camb.camb import get_matter_power_interpolator
from camb import camb
import numpy as np
#parameter settings
pars =model.CAMBparams()
pars.set_cosmology(H0=70, ombh2=0.0226, omch2=0.112, mnu=0.06, omk=0)
pars.set_dark_energy()
pars.InitPower.set_params(ns=0.96)
pars.WantTransfer = True
zbins = 15
kpoints = 200
zrange=np.linspace(0,1,zbins, endpoint=False)
pars.set_matter_power(redshifts=zrange,kmax=2.0)
pars.NonLinear = model.NonLinear_none
results = camb.get_results(pars)
kh, z, pk_dd = results.get_matter_power_spectrum(minkh=1e-4, maxkh=1, npoints = 200,
var1 = model.Transfer_tot, var2 = model.Transfer_Weyl)
print(pk_dd)
===
-
- Posts: 1973
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
Re: CAMB: output power spectrum
That code runs fine for me, outputting
Code: Select all
Note: redshifts have been re-sorted (earliest first)
[[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]
[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]
[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]
...
[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]
[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]
[2.43416726e-22 2.42966500e-22 2.42517106e-22 ... 1.69027924e-22
1.68715288e-22 1.68403230e-22]]
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
Re: CAMB: output power spectrum
Thanks, Antony. Although the code using "get_matter_power_spectrum" could output values for {matter, Weyl}, the order e-22 is too low and doesn't make sense to me. For example, if using the code of box 32 at: https://camb.readthedocs.io/en/latest/CAMBdemo.html, with "get_matter_power_interpolator", but changing the var pairs into {matter, Weyl}, I can get the output of PK as:
where the order of magnitude makes more sense. So I was wondering whether we could only use "get_matter_power_interpolator" to calculate PK regarding Weyl potentials, but not "get_matter_power_spectrum"? If so, what makes that difference?
Besides, I also tried outputting the matter power spectrum(delta_tot, delta_tot) with both methods of "get_matter_power_interpolator" and "get_matter_power_spectrum" using the code below, and found that there is a big difference on the outputted PK(pk1 vs pk2) at redshift z =0. So which one should be standard result?
Thanks a lot!
Code: Select all
[-4.55433315e-05 -4.86949737e-05 -5.20640957e-05 -5.56655683e-05
-5.95152092e-05 -6.36299160e-05 -6.80277085e-05 -7.27277540e-05
-7.77505092e-05 -8.31176830e-05 -8.88522737e-05 -9.49788558e-05
-1.01523506e-04 -1.08513838e-04 -1.15979127e-04 -1.23950442e-04
-1.32460637e-04 -1.41544315e-04 -1.51238090e-04 -1.61580627e-04
-1.72612632e-04 -1.84376759e-04 -1.96917827e-04 -2.10282790e-04
-2.24520461e-04 -2.39681642e-04 -2.55818990e-04 -2.72986735e-04
-2.91240300e-04 -3.10636319e-04 -3.31232395e-04 -3.53086318e-04
-3.76256433e-04 -4.00800800e-04 -4.26775398e-04 -4.54235582e-04
-4.83234070e-04 -5.13818232e-04 -5.46031128e-04 -5.79910412e-04
-6.15486699e-04 -6.52781451e-04 -6.91806431e-04 -7.32562063e-04
-7.75034878e-04 -8.19196689e-04 -8.65001993e-04 -9.12384825e-04
-9.61256928e-04 -1.01150533e-03 -1.06298990e-03 -1.11554087e-03
-1.16895067e-03 -1.22298193e-03 -1.27737961e-03 -1.33179034e-03
-1.38580438e-03 -1.43901208e-03 -1.49097862e-03 -1.54120437e-03
-1.58911050e-03 -1.63406245e-03 -1.67537843e-03 -1.71233747e-03
-1.74418495e-03 -1.77012320e-03 -1.78933743e-03 -1.80102449e-03
-1.80441160e-03 -1.79879660e-03 -1.78359176e-03 -1.75837734e-03
-1.72296437e-03 -1.67745421e-03 -1.62230518e-03 -1.55839759e-03
-1.48704961e-03 -1.41001782e-03 -1.32950038e-03 -1.24794890e-03
-1.16796556e-03 -1.09226368e-03 -1.02263443e-03 -9.60643929e-04
-9.08129034e-04 -8.63538713e-04 -8.24311579e-04 -7.87753863e-04
-7.50391131e-04 -7.07732636e-04 -6.56141574e-04 -5.96192231e-04
-5.32863453e-04 -4.72921312e-04 -4.22749357e-04 -3.86606649e-04
-3.63194648e-04 -3.44775638e-04 -3.22031132e-04 -2.90895149e-04
-2.55801955e-04 -2.26274557e-04 -2.07913655e-04 -1.95303074e-04
-1.79429445e-04 -1.59177825e-04 -1.42310287e-04 -1.31632804e-04
-1.21137993e-04 -1.08810557e-04 -9.92737473e-05 -9.17077245e-05
-8.35773739e-05 -7.69351913e-05 -7.10834663e-05 -6.55730039e-05
-6.09026271e-05 -5.65506655e-05 -5.27287025e-05 -4.92297166e-05
-4.60692272e-05 -4.31768722e-05 -4.05162243e-05 -3.80438890e-05
-3.57313092e-05 -3.35536588e-05 -3.14880174e-05 -2.95153065e-05
-2.76210029e-05 -2.57960239e-05 -2.40339889e-05 -2.23311224e-05
-2.06875058e-05 -1.91043104e-05 -1.75835282e-05 -1.61292268e-05
-1.47451869e-05 -1.34344542e-05 -1.22000997e-05 -1.10441486e-05
-9.96734615e-06 -8.96941380e-06 -8.04908728e-06 -7.20423146e-06
-6.43197804e-06 -5.72893058e-06 -5.09132326e-06 -4.51512811e-06
-3.99618080e-06 -3.53026874e-06 -3.11313115e-06 -2.74060820e-06
-2.40873184e-06 -2.11371434e-06 -1.85199699e-06 -1.62028057e-06
-1.41552306e-06 -1.23492886e-06 -1.07593580e-06 -9.36195024e-07
-8.13568536e-07 -7.06125689e-07 -6.12128095e-07 -5.30014293e-07
-4.58384955e-07 -3.95989045e-07 -3.41710693e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07
-3.15603748e-07 -3.15603748e-07 -3.15603748e-07 -3.15603748e-07]
Besides, I also tried outputting the matter power spectrum(delta_tot, delta_tot) with both methods of "get_matter_power_interpolator" and "get_matter_power_spectrum" using the code below, and found that there is a big difference on the outputted PK(pk1 vs pk2) at redshift z =0. So which one should be standard result?
Code: Select all
from camb import model
from camb.camb import get_matter_power_interpolator
from camb import camb
import numpy as np
import matplotlib.pyplot as plt
nz = 100 #number of steps to use for the radial/redshift integration
kmax=2 #kmax to use
h=0.7
pars = camb.CAMBparams()
pars.set_cosmology(H0=70, ombh2=0.0226, omch2=0.112, mnu=0.06, omk=0)
pars.set_dark_energy()
pars.InitPower.set_params(ns=0.96)
pars.WantTransfer = True
#get_matter_power_interpolator
results= camb.get_background(pars)
chistar = results.conformal_time(0)- results.tau_maxvis
chis = np.linspace(0,chistar,nz)
zs=results.redshift_at_comoving_radial_distance(chis)
chis = chis[1:-1]
zs = zs[1:-1]
PK = camb.get_matter_power_interpolator(pars, nonlinear=False,
hubble_units=False, k_hunit=False, kmax=kmax,
var1=model.Transfer_tot,var2=model.Transfer_tot, zmin=0.,zmax=zs[-1])
k=np.exp(np.log(10)*np.linspace(-4,0,200))*h
pk1 = PK.P(0,k)
#get_matter_power_spectrum
pars.set_matter_power(redshifts=[0.],kmax=2.0)
pars.NonLinear = model.NonLinear_none
results = camb.get_results(pars)
kh, z, pk2 = results.get_matter_power_spectrum(minkh=1e-4, maxkh=1, npoints = 200,
var1 = model.Transfer_tot, var2 = model.Transfer_tot)
-
- Posts: 1973
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
Re: CAMB: output power spectrum
If you set hubble_units=True, k_hunit=True, and remove the *h, then the results agree.
For the Weyl-cross, I think there is a bug in get_matter_power_spectrum for spectra that are negative.
To get a grid you can use results.get_[non]linear_matter_power_spectrum.
For the Weyl-cross, I think there is a bug in get_matter_power_spectrum for spectra that are negative.
To get a grid you can use results.get_[non]linear_matter_power_spectrum.
-
- Posts: 1973
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
-
- Posts: 31
- Joined: October 09 2021
- Affiliation: Simon Fraser University
Re: CAMB: output power spectrum
OK that makes sense now. Thanks a lot.