Exemple #1
0
2) The second method is using a formula that has been extracted from a Taylor
   expansion approximation for scale factor.

   dp0 = (z*c/H0) * (1-(z*(1+q0)/2))

3) The third method is using astropy's '.lookback_distance()' method.
"""

from astropy.cosmology import Planck13 as cosmo
from astropy.constants import G, c
import numpy as np
import matplotlib.pyplot as plt

Or0 = cosmo.Ogamma(0) + cosmo.Onu(0)
Om0 = cosmo.Om(0)
Ode0 = cosmo.Ode(0)

# deceleration parameter (equation 6.11)
q0 = Or0 + 0.5 * Om0 - Ode0

H0 = cosmo.H(0).to('1 / s')

z = np.linspace(0, 2, 100)

# current proper distance in terms of z (equation 6.12)
dp0_612 = c * z / H0
dp0_612 = dp0_612.to('Mpc')

# current proper distance in terms of z (equation 6.19)
dp0_619 = (z * c / H0) * (1 - (z * (1 + q0) / 2))
dp0_619 = dp0_619.to('Mpc')
sns.set()

t0 = cosmo.age(0)
time_window = np.linspace(0, t0, 100)[1:-1]
z = [z_at_value(cosmo.age, t) for t in time_window]

H = cosmo.H(z)

# critical energy density of universe (all components)
ced = ((3 * c**2) / (8 * np.pi * G)) * H**2

# Plotting Omega (density parameter)
fig, ax = plt.subplots()
ax.scatter(time_window, cosmo.Om(z), s=1, c='b', label='Matter')
ax.scatter(time_window, cosmo.Odm(z), s=1, c='k', label='Dark Matter')
ax.scatter(time_window, cosmo.Ode(z), s=1, c='brown', label='Dark Energy')
plt.xlabel('Time (age of universe in Gyr)')
plt.ylabel('Density Parameter (Omega)')
ax.legend()
plt.show()

# Plotting energy density (ignoring the first 3 Gyrs from Big Bang)
matter = (cosmo.Om(z) * ced).to('MeV / m3')
dark_matter = (cosmo.Odm(z) * ced).to('MeV / m3')
dark_energy = (cosmo.Ode(z) * ced).to('MeV / m3')

fig, ax = plt.subplots()
ax.scatter(time_window[20:], matter[20:], s=1, c='b', label='Matter')
ax.scatter(time_window[20:], dark_matter[20:], s=1, c='k', label='Dark Matter')
ax.scatter(time_window[20:], dark_energy[20:], s=1, c='brown', label='Dark Energy')
plt.xlabel('Time (age of universe in Gyr)')