In this example, we will calculate various cosmological distances for an example cosmology.
import numpy as np
import pylab as plt
import pyccl as ccl
%matplotlib inline
Cosmology
objects contain the parameters and metadata needed as inputs to most functions. Each Cosmology
object has a set of cosmological parameters attached to it. In this example, we will only use the parameters of a vanilla LCDM model, but simple extensions (like curvature, neutrino mass, and w0/wa) are also supported.
Cosmology
objects also contain precomputed data (e.g. splines) to help speed-up certain calculations. As such, Cosmology
objects are supposed to be immutable; you should create a new Cosmology
object when you want to change the values of any cosmological parameters.
cosmo = ccl.Cosmology(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=2.1e-9, n_s=0.96)
print(cosmo)
<pyccl.cosmology.Cosmology> A_s = 2.1e-09 Neff = 3.044 Omega_b = 0.045 Omega_c = 0.27 h = 0.67 n_s = 0.96 extra_parameters = emu = {'neutrinos': 'strict'} HASH_ACCURACY_PARAMS = 0xa0af9c5b75d6de86
Parameter values can be accessed from the Cosmology
object contains, like so:
print(cosmo['Omega_c'])
0.27
print(cosmo['sigma8'])
nan
Notice $\sigma_8$ is nan here because it has not yet been computed. Instead, the normalization of the power spectrum was defined via $A_s$ above.
With a cosmology in hand, we can begin performing some calculations. We can start with the most basic measure, the comoving radial distance.
z = 0.5
ccl.comoving_radial_distance(cosmo, 1/(1+z)) # Mpc
1962.9390685778556
Note that all distance function calls require scale factors, not redshifts. This function can take a numpy
array of values as well.
zs = np.arange(0, 1, 0.1)
ccl.comoving_radial_distance(cosmo, 1/(1+zs))
array([ 0. , 436.6985067 , 851.3944111 , 1243.78925379, 1614.09910482, 1962.93906858, 2291.20721282, 2599.98198852, 2890.43959663, 3163.79072723])
CCL also supports calculation of the comoving angular distance. In flat spacetime (like the cosmology we have here) it is the same as the radial distance.
ccl.comoving_angular_distance(cosmo, 1/(1+z))
1962.9390685778556
If we create a cosmology with curvature, we'll get a different result.
curved_cosmo = ccl.Cosmology(Omega_k = 0.1, Omega_c=0.17, Omega_b=0.045, h=0.67, A_s=2.1e-9, n_s=0.96)
chi_rad = ccl.comoving_radial_distance(curved_cosmo, 1/(1+z))
chi_curved = ccl.comoving_angular_distance(curved_cosmo, 1/(1+z))
print ('Radial Dist. = %.2f Mpc \t Angular Dist. = %.2f Mpc'%(chi_rad, chi_curved))
Radial Dist. = 1992.53 Mpc Angular Dist. = 1999.12 Mpc
CCL explictly supports the calculation of the luminosity distance and the distance modulus too:
chi_lum = ccl.luminosity_distance(cosmo, 1/(1+z))
DM = ccl.distance_modulus(cosmo, 1/(1+z))
print('Luminosity Dist = %.2f Mpc \t Distance Modulus = %.2f ' % (chi_lum, DM))
Luminosity Dist = 2944.41 Mpc Distance Modulus = 42.34
Finally, CCL supports an inverse operation, which calculates the scale factor for a given comoving distance:
ccl.scale_factor_of_chi(cosmo, 1962.96)
0.6666639215879805