Help with CAMB's Spline interpolation module [Python]

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Ayan MitraAM
Posts: 6
Joined: March 07 2019
Affiliation: Energetic Cosmos Laboratory

Help with CAMB's Spline interpolation module [Python]

Post by Ayan MitraAM » March 07 2019

I have recently started with the python version of CAMB. Currently I am stuck with the module :

Code: Select all

camb.initialpower.SplinedInitialPower(**kwargs) 
I have a custom data set of

Code: Select all

k, P(K)
which I would like to feed in to this module.
I am unable to locate the proper function call to extract the Splined output. I have tried :

Code: Select all

np.random.seed(0)
k = np.logspace(np.log10(1), np.log10(1000.0), num=10) 
ran = np.random.randint(5,16,size=np.shape(k)[0])
pk2 = np.power(k,0.2)*(ran/10.)
inflation_params2 = initialpower.SplinedInitialPower()
#inflation_params2.set_scalar_log_regular(1.0,1000.0,pk2)
inflation_params2.set_scalar_table(k,pk2)
my question is how to extract the splined results from here ? If I try (after implementing the cosmology params)

Code: Select all

camb.get_transfer_functions(pars).power_spectra_from_transfer(inflation_params2)
My kernel dies .


Also is there a provision, to implement the boundary conditions on the spline at the two ends of the spectrum with this module(or other) ?

thanks

Antony Lewis
Posts: 1941
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Help with CAMB's Spline interpolation module [Python]

Post by Antony Lewis » March 08 2019

There are some examples in the sample notebook (cell 40 etc).

If setting the initial power spectrum from a table, you need to define a wide range of k starting at about 1e-5 Mpc^{-1} when setting up the table.

Ayan MitraAM
Posts: 6
Joined: March 07 2019
Affiliation: Energetic Cosmos Laboratory

Re: Help with CAMB's Spline interpolation module [Python]

Post by Ayan MitraAM » March 12 2019

Thanks for the reply Antony. However is it possible to post a small simple example of the Splinedinitialpower module.

Antony Lewis
Posts: 1941
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Help with CAMB's Spline interpolation module [Python]

Post by Antony Lewis » March 12 2019

Code: Select all

ks = np.logspace(-5.5, 2, 1000)
ns = 0.97
pk = (ks / 0.05) ** (ns - 1) * 2e-9

pars = camb.CAMBparams()
pars.set_cosmology(H0=67)
pars.InitPower= camb.SplinedInitialPower(ks=ks, PK=pk)
test_result = camb.get_results(pars)

Post Reply