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,
               omega_radiation=0.0)

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

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

co = Cosmology()

# 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"))

# 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
print("t from z", co.t_from_z(0.5).in_units("Gyr"))
hubble distance 1.302905445904492e+28 cm
comoving radial distance 1335.9380778448963 Mpccm/h
transverse distance 1335.9380778448963 Mpccm/h
comoving volume 27.904391015363775 Gpccm**3
angular diameter distance 890.6253852299309 Mpc/h
angular scale 21.893444188880515 Mpc/degree
luminosity distance 2003.9071167673444 Mpc/h
lookback time 5.018375176367299 Gyr
critical density 9.469372733653403e-30 g/cm**3
hubble parameter 71.0 km/(Mpc*s)
z from t 0.5964291915253255
t from z 8.652221844930681 Gyr

Warning

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, x.to(“Mpc”) and x.to(“Mpccm”) will be the same. The user should take care to understand which reference frame is correct for the given calculation.

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.