Cosmology Calculator

The cosmology calculator can be used to calculate cosmological distances and times given a set of cosmological parameters. A cosmological dataset, ds, will automatically have a cosmology calculator configured with the correct parameters associated with it as ds.cosmology. A standalone Cosmology calculator object can be created in the following way:

from yt.utilities.cosmology import Cosmology

co = Cosmology(hubble_constant=0.7, omega_matter=0.3,
               omega_lambda=0.7, omega_curvature=0.0)

Once created, various distance calculations as well as conversions between redshift and time are available:

In [1]:
from yt.utilities.cosmology import Cosmology

co = Cosmology(hubble_constant=0.7, omega_matter=0.3,
               omega_lambda=0.7, omega_curvature=0.0)

# Hubble distance (c / h)
print("hubble distance", co.hubble_distance())

# distance from z = 0 to 0.5
print("comoving radial distance", co.comoving_radial_distance(0, 0.5).in_units("Mpccm/h"))

# transverse distance
print("transverse distance", co.comoving_transverse_distance(0, 0.5).in_units("Mpccm/h"))

# comoving volume
print("comoving volume", co.comoving_volume(0, 0.5).in_units("Gpccm**3"))

# angular diameter distance
print("angular diameter distance", co.angular_diameter_distance(0, 0.5).in_units("Mpc/h"))

# angular scale
print("angular scale", co.angular_scale(0, 0.5).in_units("Mpc/degree"))

# luminosity distance
print("luminosity distance", co.luminosity_distance(0, 0.5).in_units("Mpc/h"))

# time between two redshifts
print("lookback time", co.lookback_time(0, 0.5).in_units("Gyr"))

# age of the Universe at a given redshift
print("hubble time", co.hubble_time(0).in_units("Gyr"))

# critical density
print("critical density", co.critical_density(0))

# Hubble parameter at a given redshift
print("hubble parameter", co.hubble_parameter(0).in_units("km/s/Mpc"))

# convert time after Big Bang to redshift
my_t = co.quan(8, "Gyr")
print("z from t", co.z_from_t(my_t))

# convert redshift to time after Big Bang (same as Hubble time)
print("t from z", co.t_from_z(0.5).in_units("Gyr"))
hubble distance 1.3215183808459846e+28 cm
comoving radial distance 1321.8984317762809 Mpccm/h
transverse distance 1321.8984317762809 Mpccm/h
comoving volume 28.20906888476638 Gpccm**3
angular diameter distance 881.2656211841872 Mpc/h
angular scale 21.972838106138795 Mpc/degree
luminosity distance 1982.8476476644214 Mpc/h
lookback time 5.04020508019307 Gyr
hubble time 13.466995879287195 Gyr
critical density 9.204508310831514e-30 g/cm**3
hubble parameter 70.0 km/(Mpc*s)
z from t 0.5622761988052263
t from z 8.426346016307079 Gyr


Cosmological distance calculations return values that are either in the comoving or proper frame, depending on the specific quantity. For simplicity, the proper and comoving frames are set equal to each other within the cosmology calculator. This means that for some distance value, x,“Mpc”) and“Mpccm”) will be the same. The user should take care to understand which reference frame is correct for the given calculation.

All of the above functions accept scalar values and arrays. The helper functions, co.quan and co.arr exist to create unitful YTQuantities and YTArray with the unit registry of the cosmology calculator. For more information on the usage and meaning of each calculation, consult the reference documentation at Cosmology Calculator.