Basic usage of cosmological functions

In this section some basic examples of how to use the class colibri.cosmology.cosmo() is shown. If desired, there is a file in the folder tests named test_cosmology.py and a notebook test_cosmology.ipynb in the notebooks folder. They can be run as they are and provide similar results to here.

Evolution of cosmological parameters and distances

If one wants to compute the evolution of density parameters in redshift, the following code may be helpful

# Redshifts
zz = np.geomspace(1., 1e7, 101)-1

Omega_de    = C.Omega_lambda_z(zz)
Omega_cdm   = C.Omega_cdm_z(zz)
Omega_b     = C.Omega_b_z(zz)
Omega_gamma = C.Omega_gamma_z(zz)
Omega_K     = C.Omega_K_z(zz)
Omega_wdm   = C.Omega_wdm_z(zz)
Omega_nu    = C.Omega_nu_z(zz)
Omega_ur    = C.Omega_ur_z(zz)

Also distances can be easily computed:

# Distances and Hubble parameter as function of redshift
# `massive_nu_approx = True` is a flag that approximate neutrinos as matter
# (it is faster, but less accurate; anyway the error is much smaller than 0.1% at z < 10.
Hz          = C.H(zz)
DC          = C.comoving_distance(zz)
DL          = C.luminosity_distance(zz)
DA          = C.angular_diameter_distance(zz)

Plotting these quantities would generate

../../_images/density_parameter_evolution.png

Power spectra

Generating power spectra requires the installation of the Python wrapper of CAMB or Class , unless the Eisenstein-Hu formula is used (for which the function colibri.cosmology.cosmo.EisensteinHu_Pk() is provided).

Generating linear matter power spectra is as easy as typing

# Generate power spectra at scales and redshifts at default value
# (z=0 and k = np.logspace(-4., 2., 1001))
k_camb,  pk_camb  = C.camb_Pk()
k_class, pk_class = C.class_Pk()
k_eh,    pk_eh    = C.EisensteinHu_Pk()

In this case, each line returns two things:

  • an array of scales (the same as the input)

  • a 2D array of shape (len(z), len(k)) containing the total matter power spectrum at the required redshifts and scales

It may happen that, instead of the total matter, the linear cold dark matter only power spectrum is required. In this case, the routines colibri.cosmology.cosmo.camb_XPk() and colibri.cosmology.cosmo.class_XPk() will do:

# Generate CDM linear power spectra at scales and redshifts at default value
# (z=0 and k = np.logspace(-4., 2., 1001))
k_camb,  pk_camb  = C.camb_XPk(var_1 = ['cdm'], var_2 = ['cdm'])
k_class, pk_class = C.class_XPk(var_1 = ['cdm'], var_2 = ['cdm'])

Each pk is a dictionary with keys ['`var_1`-`var_2`']: each key is in turn a 2D array of shape (len(z), len(k)). The latter functions can also be used to compute cross-spectra: for example, with the line

k_camb,  pk_camb  = C.camb_XPk(var_1 = ['cb', 'nu'], var_2 = ['cb', 'nu'])

the quantity pk_camb is a dictionary with keys ['cb-cb'], ['nu-nu'], ['cb-nu'], ['nu-cb'] containing the cold dark matter plus baryons autospectrum, the neutrino autospectrum and the cross-spectrum between the two (notice that 'cb-nu' and 'nu-cb' give the same result).

The file named test_pk.py in the tests folder or the notebook test_pk.ipynb in the notebooks folder contains different well-documented examples of how this can be done. This is an example of computing the linear total matter power spectrum at \(z=0\) with 3 different methods

../../_images/linear_spectra.png