Basic functions
Python CAMB interface (https://camb.info)
- camb.get_age(params)[source]
Get age of universe for given set of parameters
- Parameters:
params –
model.CAMBparams
instance- Returns:
age of universe in Julian gigayears
- camb.get_background(params, no_thermo=False)[source]
Calculate background cosmology for specified parameters and return
CAMBdata
, ready to get derived parameters and use background functions likeangular_diameter_distance()
.- Parameters:
params –
model.CAMBparams
instanceno_thermo – set True if thermal and ionization history not required.
- Returns:
CAMBdata
instance
- camb.get_matter_power_interpolator(params, zmin=0, zmax=10, nz_step=100, zs=None, kmax=10, nonlinear=True, var1=None, var2=None, hubble_units=True, k_hunit=True, return_z_k=False, k_per_logint=None, log_interp=True, extrap_kmax=None)[source]
Return a 2D spline interpolation object to evaluate matter power spectrum as function of z and k/h, e.g.
from camb import get_matter_power_interpolator PK = get_matter_power_interpolator(params); print('Power spectrum at z=0.5, k/h=0.1/Mpc is %s (Mpc/h)^3 '%(PK.P(0.5, 0.1)))
For a description of outputs for different var1, var2 see Matter power spectrum and matter transfer function variables. If you already have a
CAMBdata
result object, you can instead useget_matter_power_interpolator()
.- Parameters:
params –
model.CAMBparams
instancezmin – minimum z (use 0 or smaller than you want for good interpolation)
zmax – maximum z (use larger than you want for good interpolation)
nz_step – number of steps to sample in z (default max allowed is 100)
zs – instead of zmin,zmax, nz_step, can specific explicit array of z values to spline from
kmax – maximum k
nonlinear – include non-linear correction from halo model
var1 – variable i (index, or name of variable; default delta_tot)
var2 – variable j (index, or name of variable; default delta_tot)
hubble_units – if true, output power spectrum in \(({\rm Mpc}/h)^{3}\) units, otherwise \({\rm Mpc}^{3}\)
k_hunit – if true, matter power is a function of k/h, if false, just k (both \({\rm Mpc}^{-1}\) units)
return_z_k – if true, return interpolator, z, k where z, k are the grid used
k_per_logint – specific uniform sampling over log k (if not set, uses optimized irregular sampling)
log_interp – if true, interpolate log of power spectrum (unless any values are negative in which case ignored)
extrap_kmax – if set, use power law extrapolation beyond kmax to extrap_kmax (useful for tails of integrals)
- Returns:
An object PK based on
RectBivariateSpline
, that can be called with PK.P(z,kh) or PK(z,log(kh)) to get log matter power values. If return_z_k=True, instead return interpolator, z, k where z, k are the grid used.
- camb.get_results(params)[source]
Calculate results for specified parameters and return
CAMBdata
instance for getting results.- Parameters:
params –
model.CAMBparams
instance- Returns:
CAMBdata
instance
- camb.get_transfer_functions(params, only_time_sources=False)[source]
Calculate transfer functions for specified parameters and return
CAMBdata
instance for getting results and subsequently calculating power spectra.- Parameters:
params –
model.CAMBparams
instanceonly_time_sources – does not calculate the CMB l,k transfer functions and does not apply any non-linear correction scaling. Results with only_time_sources=True can therefore be used with different initial power spectra to get consistent non-linear lensed spectra.
- Returns:
CAMBdata
instance
- camb.get_valid_numerical_params(transfer_only=False, **class_names)[source]
Get numerical parameter names that are valid input to
set_params()
- Parameters:
transfer_only – if True, exclude parameters that affect only initial power spectrum or non-linear model
class_names – class name parameters that will be used by
model.CAMBparams.set_classes()
- Returns:
set of valid input parameter names for
set_params()
- camb.get_zre_from_tau(params, tau)[source]
Get reionization redshift given optical depth tau
- Parameters:
params –
model.CAMBparams
instancetau – optical depth
- Returns:
reionization redshift (or negative number if error)
- camb.read_ini(ini_filename, no_validate=False)[source]
Get a
model.CAMBparams
instance using parameter specified in a .ini parameter file.- Parameters:
ini_filename – path of the .ini file to read, or a full URL to download from
no_validate – do not pre-validate the ini file (faster, but may crash kernel if error)
- Returns:
model.CAMBparams
instance
- camb.run_ini(ini_filename, no_validate=False)[source]
Run the command line camb from a .ini file (producing text files as with the command line program). This does the same as the command line program, except global config parameters are not read and set (which does not change results in almost all cases).
- Parameters:
ini_filename – .ini file to use
no_validate – do not pre-validate the ini file (faster, but may crash kernel if error)
- camb.set_feedback_level(level=1)[source]
Set the feedback level for internal CAMB calls
- Parameters:
level – zero for nothing, >1 for more
- camb.set_params(cp=None, verbose=False, **params)[source]
Set all CAMB parameters at once, including parameters which are part of the CAMBparams structure, as well as global parameters.
E.g.:
cp = camb.set_params(ns=1, H0=67, ombh2=0.022, omch2=0.1, w=-0.95, Alens=1.2, lmax=2000, WantTransfer=True, dark_energy_model='DarkEnergyPPF')
This is equivalent to:
cp = model.CAMBparams() cp.DarkEnergy = DarkEnergyPPF() cp.DarkEnergy.set_params(w=-0.95) cp.set_cosmology(H0=67, omch2=0.1, ombh2=0.022, Alens=1.2) cp.set_for_lmax(lmax=2000) cp.InitPower.set_params(ns=1) cp.WantTransfer = True
The wrapped functions are (in this order):
dark_energy.DarkEnergyEqnOfState.set_params()
(or equivalent if a different dark energy model class used)initialpower.InitialPowerLaw.set_params()
(or equivalent if a different initial power model class used)
- Parameters:
params – the values of the parameters
cp – use this CAMBparams instead of creating a new one
verbose – print out the equivalent set of commands
- Returns:
model.CAMBparams
instance
- camb.set_params_cosmomc(p, num_massive_neutrinos=1, neutrino_hierarchy='degenerate', halofit_version='mead', dark_energy_model='ppf', lmax=2500, lens_potential_accuracy=1, inpars=None)[source]
get CAMBParams for dictionary of cosmomc-named parameters assuming Planck 2018 defaults
- Parameters:
p – dictionary of cosmomc parameters (e.g. from getdist.types.BestFit’s getParamDict() function)
num_massive_neutrinos – usually 1 if fixed mnu=0.06 eV, three if mnu varying
neutrino_hierarchy – hierarchy
halofit_version – name of the soecific Halofit model to use for non-linear modelling
dark_energy_model – ppf or fluid dark energy model
lmax – lmax for accuracy settings
lens_potential_accuracy – lensing accuracy parameter
inpars – optional input CAMBParams to set
- Returns: