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(Omega_c=0.27, Omega_b=0.045, h=0.67, n_s=0.96, sigma8=None, A_s=2.1e-09, Omega_k=0.0, Omega_g=None, Neff=3.046, w0=-1.0, wa=0.0, T_CMB=None, bcm_log10Mc=14.079181246047625, bcm_etab=0.5, bcm_ks=55.0, mu_0=0.0, sigma_0=0.0, m_nu=0.0, m_nu_type=None, z_mg=None, df_mg=None, transfer_function='boltzmann_camb', matter_power_spectrum='halofit', baryons_power_spectrum='nobaryons', mass_function='tinker10', halo_concentration='duffy2008', emulator_neutrinos='strict')
As you can see, a number of cosmological parameters have been set to default values, or derived from the input parameters. Some, like sigma8
, have been left undefined; this is because calculating them from the input parameters is non-trivial, so this will only be done if needed (or if the user explicitly requests it).
Parameter values can be accessed from the Cosmology
object contains, like so:
print(cosmo['Omega_c'])
0.27
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.939114147973
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.69850865, 851.39441882, 1243.78927092, 1614.09913469, 1962.93911415, 2291.20727664, 2599.98207275, 2890.43970306, 3163.79085733])
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.939114147973
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.6666639275736294