classylss.binding module

class classylss.binding.Background(ClassEngine engine)

Bases: object

A wrapper of the background module in CLASS.

Parameters:engine (ClassEngine) – the CLASS engine object

Attributes

C The speed of light in units of km/s.
G The gravitational constant in units of \(10^{-10} \ (M_\odot/h)^{-1} (\mathrm{Mpc}/h) \mathrm{km}^2 \mathrm{s}^{-2}\).
H0 Current Hubble parameter in units of \(\mathrm{km/s} (\mathrm{Mpc}/h)^{-1}.\)
N_ncdm The number of distinguishable ncdm (massive neutrino) species.
N_ur The number of ultra-relativistic species.
Neff Effective number of relativistic species, summed over ultra-relativistic and ncdm species.
Omega0_b Current density parameter for photons, \(\Omega_{b,0}\).
Omega0_cdm Current density parameter for cold dark matter, \(\Omega_{cdm,0}\).
Omega0_dcdm Current density parammeter for decaying cold dark matter, \(\Omega_{dcdm,0}\).
Omega0_fld Current density parameter for dark energy (fluid) \(\Omega_{fld, 0}\).
Omega0_g Current density parameter for photons, \(\Omega_{g,0}\).
Omega0_k Current density parameter for curvaturve, \(\Omega_{k,0}\).
Omega0_lambda Current density parameter for cosmological constant, \(\Omega_{\Lambda,0}\).
Omega0_m The sum of density parameters for all non-relativistic components, \(\Omega_{0,m}\).
Omega0_ncdm Current density parameter for distinguishable (massive) neutrinos for each species as an array, \(\Omega_{0, ncdm}\).
Omega0_ncdm_tot Current total density parameter of all distinguishable (massive) neutrinos.
Omega0_pncdm The pressure contribution to the current density parameter for the non-relativatistic part of massive neutrinos (an array holding all species).
Omega0_pncdm_tot The sum of \(\Omega_{0,pncdm}\) for all species.
Omega0_r Current density parameter of radiation, \(\Omega_{0,r}\).
Omega0_ur Current density parameter of ultra-relativistic (massless) neutrinos, \(\Omega_{0,\nu_r}\).
T0_cmb The current CMB temperature in Kelvins.
T0_ncdm An array holding the current ncdm temperature in Kelvins for each species.
a_max The maximum scale factor for which results can be computed; it can be greater than 1.0.
a_today An arbitrary number that sets the reference scaling factor.
age0 The current age of the universe in gigayears.
data
h The dimensionless Hubble parameter.
m_ncdm The masses of the distinguishable ncdm (massive neutrino) species, in units of eV.
w0_fld Current fluid equation of state parameter, \(w_{0,fld}\).
wa_fld Fluid equation of state derivative, \(w_{a,fld}\).

Methods

Omega_b(self, z) Density parameter of baryons.
Omega_cdm(self, z) Density parameter of cold dark matter.
Omega_fld(self, z) Density parameter of dark energy (fluid).
Omega_g(self, z) Density parameter of photons.
Omega_k(self, z) Density parameter of curvature.
Omega_lambda(self, z) Density of dark energy (cosmological constant).
Omega_m(self, z) Density parameter of non-relativistic (matter-like) component, including non-relativistic part of massive neutrino.
Omega_ncdm(self, z[, species]) Density parameter of massive neutrinos.
Omega_pncdm(self, z[, species]) Return \(\Omega_{pncdm}\) as a function redshift.
Omega_r(self, z) Density parameter of relativistic (radiation-like) component, including relativistic part of massive neutrino and massless neutrino.
Omega_ur(self, z) Density parameter of ultra relativistic neutrinos.
T_cmb(self, z) The CMB temperature as a function of redshift.
T_ncdm(self, z) The ncdm temperature (massive neutrinos) as a function of redshift.
angular_diameter_distance(self, z) Angular diameter distance in \(\mathrm{Mpc}/h\) at a given redshift.
comoving_distance(self, z) Comoving line-of-sight distance in \(\mathrm{Mpc}/h\) at a given redshift.
comoving_transverse_distance(self, z) Comoving transverse distance in \(\mathrm{Mpc}/h\) at a given redshift.
compute_for_z(self, z, int column) Internal function to compute the background module at a specific redshift.
efunc(self, z) Function giving \(E(z)\), where the Hubble parameter is defined as \(H(z) = H_0 E(z)\).
efunc_prime(self, z) Function giving \(dE(z) / da\).
hubble_function(self, z) The Hubble function in CLASS units, returning ba.index_bg_H.
hubble_function_prime(self, z) Derivative of Hubble function: \(dH/d\tau\), where \(d\tau/da = 1 / (a^2 H)\) in CLASS units.
luminosity_distance(self, z) Luminosity distance in \(\mathrm{Mpc}/h\) at redshift z.
p_ncdm(self, z[, species]) Pressure of non-relative part of massive neutrino.
rho_b(self, z) Density of baryons \(\rho_b\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_cdm(self, z) Density of cold dark matter \(\rho_{cdm}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_crit(self, z) Critical density excluding curvature \(\rho_c\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_fld(self, z) Density of dark energy fluid \(\rho_{fld}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_g(self, z) Density of photons \(\rho_g\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_k(self, z) Density of curvature \(\rho_k\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_lambda(self, z) Density of cosmological constant \(\rho_\Lambda\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_m(self, z) Density of matter \(\rho_b\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_ncdm(self, z[, species]) Density of non-relativistic part of massive neutrinos \(\rho_{ncdm}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_r(self, z) Density of radiation \(\rho_r\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_tot(self, z) Total density \(\rho_\mathrm{tot}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
rho_ur(self, z) Density of ultra-relativistic radiation (massless neutrinos) \(\rho_{ur}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).
scale_independent_growth_factor(self, z) Return the scale invariant growth factor \(D(a)\) for CDM perturbations.
scale_independent_growth_rate(self, z) The scale invariant growth rate \(d\mathrm{ln}D/d\mathrm{ln}a\) for CDM perturbations.
tau(self, z) Conformal time, equal to comoving distance when K = 0.0 (flat universe).
time(self, z) Proper time (age of universe) in gigayears.
C

The speed of light in units of km/s.

G

The gravitational constant in units of \(10^{-10} \ (M_\odot/h)^{-1} (\mathrm{Mpc}/h) \mathrm{km}^2 \mathrm{s}^{-2}\).

H0

Current Hubble parameter in units of \(\mathrm{km/s} (\mathrm{Mpc}/h)^{-1}.\)

N_ncdm

The number of distinguishable ncdm (massive neutrino) species.

N_ur

The number of ultra-relativistic species.

This is equal to:

\[N_{ur} = \Omega_{0,ur} / (7/8 (4/11)^{4/3} \Omega_{0,g}).\]
Neff

Effective number of relativistic species, summed over ultra-relativistic and ncdm species.

Omega0_b

Current density parameter for photons, \(\Omega_{b,0}\).

Omega0_cdm

Current density parameter for cold dark matter, \(\Omega_{cdm,0}\).

Omega0_dcdm

Current density parammeter for decaying cold dark matter, \(\Omega_{dcdm,0}\).

Omega0_fld

Current density parameter for dark energy (fluid) \(\Omega_{fld, 0}\).

Omega0_g

Current density parameter for photons, \(\Omega_{g,0}\).

Omega0_k

Current density parameter for curvaturve, \(\Omega_{k,0}\).

Omega0_lambda

Current density parameter for cosmological constant, \(\Omega_{\Lambda,0}\).

Omega0_m

The sum of density parameters for all non-relativistic components, \(\Omega_{0,m}\). The value differs from Om0 in astropy.

This is equal to:

\[\Omega_{0,m} = \Omega_{0,b} + \Omega_{0,cdm} + \Omega_{0,ncdm} + \Omega_{0,dcdm} - \Omega_{0,pncdm}.\]
Omega0_ncdm

Current density parameter for distinguishable (massive) neutrinos for each species as an array, \(\Omega_{0, ncdm}\).

Omega0_ncdm_tot

Current total density parameter of all distinguishable (massive) neutrinos.

Omega0_pncdm

The pressure contribution to the current density parameter for the non-relativatistic part of massive neutrinos (an array holding all species).

Omega0_pncdm_tot

The sum of \(\Omega_{0,pncdm}\) for all species.

Omega0_r

Current density parameter of radiation, \(\Omega_{0,r}\). This is equal to:

\[\Omega_{0,r} = \Omega_{0,g} + \Omega_{0,\nu_r} + \Omega_{0,pncdm}.\]
Omega0_ur

Current density parameter of ultra-relativistic (massless) neutrinos, \(\Omega_{0,\nu_r}\).

Omega_b(self, z)

Density parameter of baryons.

Omega_cdm(self, z)

Density parameter of cold dark matter.

Omega_fld(self, z)

Density parameter of dark energy (fluid).

Omega_g(self, z)

Density parameter of photons.

Omega_k(self, z)

Density parameter of curvature.

Omega_lambda(self, z)

Density of dark energy (cosmological constant).

Omega_m(self, z)

Density parameter of non-relativistic (matter-like) component, including non-relativistic part of massive neutrino. Unit

Omega_ncdm(self, z, species=None)

Density parameter of massive neutrinos.

Omega_pncdm(self, z, species=None)

Return \(\Omega_{pncdm}\) as a function redshift.

Omega_r(self, z)

Density parameter of relativistic (radiation-like) component, including relativistic part of massive neutrino and massless neutrino.

Omega_ur(self, z)

Density parameter of ultra relativistic neutrinos.

T0_cmb

The current CMB temperature in Kelvins.

T0_ncdm

An array holding the current ncdm temperature in Kelvins for each species.

T_cmb(self, z)

The CMB temperature as a function of redshift.

T_ncdm(self, z)

The ncdm temperature (massive neutrinos) as a function of redshift.

Return shape is (N_ncdm,) if N_ncdm == 1 else (len(z), N_ncdm)

a_max

The maximum scale factor for which results can be computed; it can be greater than 1.0.

a_today

An arbitrary number that sets the reference scaling factor. It shall be 1 usually.

age0

The current age of the universe in gigayears.

angular_diameter_distance(self, z)

Angular diameter distance in \(\mathrm{Mpc}/h\) at a given redshift.

This gives the proper (sometimes called ‘physical’) transverse distance corresponding to an angle of 1 radian for an object at redshift z.

It is equal to the comoving transverse distance divided by \(1+z\).

See eq. 18 of astro-ph/9905116 for \(D_A(z)\).

comoving_distance(self, z)

Comoving line-of-sight distance in \(\mathrm{Mpc}/h\) at a given redshift.

The comoving distance along the line-of-sight between two objects remains constant with time for objects in the Hubble flow.

See eq. 15 of astro-ph/9905116 for \(D_C(z)\).

comoving_transverse_distance(self, z)

Comoving transverse distance in \(\mathrm{Mpc}/h\) at a given redshift.

This value is the transverse comoving distance at redshift z corresponding to an angular separation of 1 radian. This is the same as the comoving distance in a flat universe.

See eq. 16 of astro-ph/9905116 for \(D_M(z)\).

compute_for_z(self, z, int column)

Internal function to compute the background module at a specific redshift.

data
efunc(self, z)

Function giving \(E(z)\), where the Hubble parameter is defined as \(H(z) = H_0 E(z)\).

efunc_prime(self, z)

Function giving \(dE(z) / da\).

h

The dimensionless Hubble parameter.

hubble_function(self, z)

The Hubble function in CLASS units, returning ba.index_bg_H.

Users should use efunc() instead.

hubble_function_prime(self, z)

Derivative of Hubble function: \(dH/d\tau\), where \(d\tau/da = 1 / (a^2 H)\) in CLASS units.

Users should use efunc_prime() instead.

luminosity_distance(self, z)

Luminosity distance in \(\mathrm{Mpc}/h\) at redshift z.

This is the distance to use when converting between the bolometric flux from an object at redshift z and its bolometric luminosity.

It is equal to the comoving transverse distance times \(1+z\).

See eq. 21 of astro-ph/9905116 for \(D_L(z)\).

m_ncdm

The masses of the distinguishable ncdm (massive neutrino) species, in units of eV.

p_ncdm(self, z, species=None)

Pressure of non-relative part of massive neutrino.

rho_b(self, z)

Density of baryons \(\rho_b\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_cdm(self, z)

Density of cold dark matter \(\rho_{cdm}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_crit(self, z)

Critical density excluding curvature \(\rho_c\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

This is defined as:

\[\rho_c(z) = \frac{3 H(z)^2}{8 \pi G}.\]
rho_fld(self, z)

Density of dark energy fluid \(\rho_{fld}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_g(self, z)

Density of photons \(\rho_g\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_k(self, z)

Density of curvature \(\rho_k\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

Note: this is defined such that

\[\rho_\mathrm{crit} = \rho_\mathrm{tot} + \rho_k\]
rho_lambda(self, z)

Density of cosmological constant \(\rho_\Lambda\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_m(self, z)

Density of matter \(\rho_b\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_ncdm(self, z, species=None)

Density of non-relativistic part of massive neutrinos \(\rho_{ncdm}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_r(self, z)

Density of radiation \(\rho_r\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

rho_tot(self, z)

Total density \(\rho_\mathrm{tot}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\). It is usually close to 27.76.

rho_ur(self, z)

Density of ultra-relativistic radiation (massless neutrinos) \(\rho_{ur}\) as a function of redshift, in units of \(10^{10} (M_\odot/h) (\mathrm{Mpc}/h)^{-3}\).

scale_independent_growth_factor(self, z)

Return the scale invariant growth factor \(D(a)\) for CDM perturbations.

This is the quantity defined by CLASS as index_bg_D in the background module.

scale_independent_growth_rate(self, z)

The scale invariant growth rate \(d\mathrm{ln}D/d\mathrm{ln}a\) for CDM perturbations.

This is the quantity defined by CLASS as index_bg_f in the background module.

tau(self, z)

Conformal time, equal to comoving distance when K = 0.0 (flat universe). In units of \(\mathrm{Mpc}\) as in CLASS.

time(self, z)

Proper time (age of universe) in gigayears.

w0_fld

Current fluid equation of state parameter, \(w_{0,fld}\).

wa_fld

Fluid equation of state derivative, \(w_{a,fld}\).

exception classylss.binding.ClassBadValueError

Bases: ValueError

Raised when Class could not compute the cosmology at this point.

This will be caught by the parameter extraction code to give an extremely unlikely value to this point

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class classylss.binding.ClassEngine(pars={})

Bases: object

The default CLASS engine class, which initializes CLASS from an input set of parameters.

Parameters:pars (dict, optional) – a dictionary of parameters to initialize CLASS with

Attributes

parameter_file A string holding the parameter names and values as loaded by CLASS.
parameter_file

A string holding the parameter names and values as loaded by CLASS.

exception classylss.binding.ClassParserError

Bases: ValueError

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception classylss.binding.ClassRuntimeError

Bases: RuntimeError

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class classylss.binding.Perturbs(ClassEngine engine)

Bases: object

A wrapper of the perturbs module in CLASS.

Parameters:engine (ClassEngine) – the CLASS engine object

Attributes

P_z_max The input parameter specifying the maximum redshift measured for power spectra.
gauge The gauge name as a string, either ‘newtonian’ or ‘synchronous’.
k_max_for_pk The input parameter specifying the maximum k value to compute spectra for; units of \(h \mathrm{Mpc}^{-1}\).
P_z_max

The input parameter specifying the maximum redshift measured for power spectra.

gauge

The gauge name as a string, either ‘newtonian’ or ‘synchronous’.

k_max_for_pk

The input parameter specifying the maximum k value to compute spectra for; units of \(h \mathrm{Mpc}^{-1}\).

class classylss.binding.Primordial(ClassEngine engine)

Bases: object

A wrapper of the primordial module in CLASS.

Parameters:engine (ClassEngine) – the CLASS engine object

Methods

get_pk(self, k) The primoridal spectrum at k.
get_primordial(self) Return the primordial scalar and/or tensor spectrum depending on ‘modes’.
get_pk(self, k)

The primoridal spectrum at k. This is defined as:

\[\mathcal{P_R}(k) = A_s \left (\frac{k}{k_0} \right )^{n_s - 1 + 0.5 \ln(k/k_0) (dn_s / d\ln k)}\]

See also: equation 2 of this reference.

Parameters:k (array_like) – wavenumbers in \(h \mathrm{Mpc}^{-1}\) units.
Returns:the primordial power
Return type:array_like
get_primordial(self)

Return the primordial scalar and/or tensor spectrum depending on ‘modes’.

The ‘output’ parameter must be set to something, e.g. ‘tCl’.

Returns:structured array containing k-vector and primordial scalar and tensor \(P(k)\).
Return type:array_like
class classylss.binding.Spectra(ClassEngine engine)

Bases: object

A wrapper of the spectra module in CLASS.

Parameters:engine (ClassEngine) – the CLASS engine object

Attributes

A_s The scalar amplitude of the primordial power spectrum at \(k_\mathrm{pivot}\).
P_k_max The maximum k value measured for power spectra in \(h \mathrm{Mpc}^{-1}\).
P_k_min The minimum k value for which power spectra have been computed in \(h \mathrm{Mpc}^{-1}\).
data
has_pk_matter Boolean flag specifying whether matter power spectra have been requested as output.
k_pivot The primordial power spectrum pivot scale, where the primordial power is equal to \(A_s\).
ln_1e10_A_s Return \(\log(10^{10}A_s)\).
n_s The tilt of the primordial power spectrum.
nonlinear Boolean flag specifying whether the power spectrum is nonlinear.
sigma8 The amplitude of matter fluctuations at \(z=0\).

Methods

get_pk(self, k, z) The primary power spectrum result (nonlinear if enabled) on k and z array.
get_pklin(self, k, z) Linear power spectrum result (linear even if nonlinear is enabled) on k and z array.
get_transfer(self, z[, output_format]) Return the density and/or velocity transfer functions for all initial conditions today.
sigma8_z(self, z) Return \(\sigma_8(z)\).
A_s

The scalar amplitude of the primordial power spectrum at \(k_\mathrm{pivot}\).

P_k_max

The maximum k value measured for power spectra in \(h \mathrm{Mpc}^{-1}\).

P_k_min

The minimum k value for which power spectra have been computed in \(h \mathrm{Mpc}^{-1}\).

This is computed from the ln_k array of the Spectra module.

data
get_pk(self, k, z)

The primary power spectrum result (nonlinear if enabled) on k and z array.

Parameters:
  • k (float, array_like) – the wavenumber in units of \(h \mathrm{Mpc}^{-1}\)
  • z (float, array_like) – the redshift values
Returns:

the power spectrum in units of \((\mathrm{Mpc}/h)^3\)

Return type:

array like

get_pklin(self, k, z)

Linear power spectrum result (linear even if nonlinear is enabled) on k and z array.

Parameters:
  • k (float, array_like) – the wavenumber in units of \(h \mathrm{Mpc}^{-1}\)
  • z (float, array_like) – the redshift values
Returns:

the power spectrum in units of \((\mathrm{Mpc}/h)^3\)

Return type:

array like

get_transfer(self, z, output_format='class')

Return the density and/or velocity transfer functions for all initial conditions today. You must include ‘dCl’ and ‘vCl’ in the list of ‘output’. The transfer functions can also be computed at higher redshift z provided that ‘z_pk’ has been set and that z is inside the region spanned by ‘z_pk’.

This function is not vectorized because it returns a vector when ‘ic_size’ is greater than 1, and we don’t understand ‘ic_size’.

Parameters:
  • z (float) – redshift (default = 0)
  • output_format (('class' or 'camb')) – Format transfer functions according to CLASS convention (default) or CAMB convention.
Returns:

tk – array containing transfer functions. k here is in units of \(h \mathrm{Mpc}^{-1}\).

Return type:

array_like

has_pk_matter

Boolean flag specifying whether matter power spectra have been requested as output.

k_pivot

The primordial power spectrum pivot scale, where the primordial power is equal to \(A_s\). Units of \(h \mathrm{Mpc}^{-1}\).

ln_1e10_A_s

Return \(\log(10^{10}A_s)\).

n_s

The tilt of the primordial power spectrum.

nonlinear

Boolean flag specifying whether the power spectrum is nonlinear.

sigma8

The amplitude of matter fluctuations at \(z=0\).

sigma8_z(self, z)

Return \(\sigma_8(z)\).

class classylss.binding.Thermo(ClassEngine engine)

Bases: object

A wrapper of the thermo module in CLASS.

Parameters:engine (ClassEngine) – the CLASS engine object

Attributes

rs_drag The comoving sound horizon at baryon drag, in \(\mathrm{Mpc}/h\).
rs_rec The comoving sound horizon at recombination, \(z=z_\mathrm{rec}\).
tau_reio The reionization optical depth.
theta_s The sound horizon angle at recombination, equal to \(r_s(z_\mathrm{rec}) / D_a(z_\mathrm{rec})\).
z_drag The baryon drag redshift.
z_rec The redshift at which the visibility reaches its maximum; equals the recombination redshift.
z_reio The reionization redshift.
rs_drag

The comoving sound horizon at baryon drag, in \(\mathrm{Mpc}/h\).

rs_rec

The comoving sound horizon at recombination, \(z=z_\mathrm{rec}\). Units of \(\mathrm{Mpc}/h\).

tau_reio

The reionization optical depth.

theta_s

The sound horizon angle at recombination, equal to \(r_s(z_\mathrm{rec}) / D_a(z_\mathrm{rec})\).

z_drag

The baryon drag redshift.

z_rec

The redshift at which the visibility reaches its maximum; equals the recombination redshift.

z_reio

The reionization redshift.

classylss.binding.val2str(val)