-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmic_density.py
71 lines (51 loc) · 1.49 KB
/
cosmic_density.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
density calculations
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
from astropy import units as u
from astropy import constants as const
import scipy.integrate as integrate
from default_cosmo import default_cosmo # define a default cosology for utilities
__all__=('mean_density', 'critical_density',)
__author__=('Duncan Campbell')
def mean_density(z, cosmo=None):
"""
Return the mean density of the Universe.
Paramaters
----------
z : array_like
arry of redshifts
cosmo : astropy.cosmology object
cosmology object
Returns
-------
rho_b : numpy.array
mean density of the universe at redshift z in units Msol/Mpc^3
"""
if cosmo is None:
cosmo = default_cosmo
z = np.atleast_1d(z)
a = 1.0/(1.0+z) # scale factor
rho = (3.0/(8.0*np.pi*const.G))*(cosmo.H(z)**2)*(cosmo.Om(z)*a**(-3.0))
rho = rho.to(u.M_sun / u.parsec**3.0)*((10**6)**3.0)
return rho.value
def critical_density(z, cosmo='default'):
"""
critical density of the universe
Paramaters
----------
z : array_like
redshift
cosmo : astropy.cosmology object
cosmology object
Returns
-------
rho_c : numpy.array
critical density of the universe at redshift z in g/cm^3
"""
if cosmo=='default':
cosmo = default_cosmo
rho = (3.0*cosmo.H(z)**2)/(8.0*np.pi*const.G)
rho = rho.to(u.g / u.cm**3)
return rho