-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmo.py
164 lines (109 loc) · 3.5 KB
/
cosmo.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
__author__ = 'drjfunk'
import theano.tensor as T
from theano.ifelse import ifelse
from astropy.constants import c as sol
from astropy import cosmology
from integration_routines import gauss_kronrod
# this sets up the radiation content of the universe.
# It is probably a valid assumption that Planck gets this right
cosmo = cosmology.FlatLambdaCDM(H0=67.3, Om0=.3)
Or = cosmo.Onu0 + cosmo.Ogamma0
sol = sol.value
# Flat universe with cosmological constant
def integrand_constant_flat(z, Om):
"""
:param z: redshift
:param Om: matter content
:return: theano array of 1/H(z)
"""
zp = (1 + z)
Ode = 1 - Om - Or # Adjust cosmological constant
return T.power(T.pow(zp, 3) * Om + Ode, -0.5)
def distmod_constant_flat(Om, h0, z):
"""
Distance modulus for a flat universe with a
cosmological constant
:param Om: matter content
:param h0: hubble constant
:param z: redshift
:return: theano array of dist. mods.
"""
# Hubble distance
dh = sol * 1.e-3 / h0
# comoving distance
dc = dh * gauss_kronrod(integrand_constant_flat, z, parameters=[Om])
# luminosity distance
dl = (1 + z) * dc
return 5. * T.log10(dl) + 25. # dist mod.
# Flat universe with dark energy equation of state: w != -1
def integrand_w_flat(z, Om, w):
"""
:param z: redshift
:param Om: matter content
:param w: DE EOS
:return: theano array of 1/H(z)
"""
zp = (1 + z)
Ode = 1 - Om - Or # Adjust cosmological constant
return T.power((T.pow(zp, 3) * (Or * zp + Om)
+ Ode * T.pow(zp, 3. * (1 + w))),-0.5)
def distmod_w_flat(Om, h0, w, z):
"""
Distance modulus for a flat universe with a
dark energy EOS
:param Om: matter content
:param h0: hubble constant
:param w: DE EOS
:param z: redshift
:return: theano array of dist. mods.
"""
# Hubble distance
dh = sol * 1.e-3 / h0
# Comoving distance
dc = dh * gauss_kronrod(integrand_w_flat, z, parameters=[Om, w])
# luminosity distance
dl = (1+z) * dc
return 5. * T.log10(dl) + 25. #dist mod
# Curved universe with cosmolgical constant
def integrand_constant_curve(z, Om, Ok):
"""
:param z: redshift
:param Om: matter content
:param Ok: curvature
:return: theano array of 1/H(z)
"""
zp = (1 + z)
Ode = 1 - Om - Or - Ok
return T.power(zp * zp * ((Or * zp + Om) * zp + Ok) + Ode,-0.5)
def distmod_constant_curve(Om, Ok, h0, z):
"""
Distance modulus for a curved universe with a
cosmological constant
:param Om: matter content
:param Ok: curvature
:param h0: hubble constant
:param z: redshift
:return: theano array of dist. mods.
"""
# Hubble distance
dh = sol * 1.e-3 / h0
# Comoving distance
dc = dh * gauss_kronrod(integrand_constant_curve, z, parameters=[Om, Ok])
# Pre-compute the sqrt
sqrtOk = T.sqrt(T.abs_(Ok))
# Theno does not have exhaustive
# control flow, so we have to compute them all
# Start here
dl = ifelse(T.eq(Ok,0.),
(1+z) * dc,
0. * (1+z) * dc)
# The above statement is zero if the
# condition fails, so we add on to it
dl += ifelse(T.gt(Ok,0),
(1+z) * dh / sqrtOk * T.sinh(sqrtOk * dc / dh),
0. * (1+z) * dc)
# same idea as above
dl += ifelse(T.lt(Ok,0),
(1+z) * dh / sqrtOk * T.sin(sqrtOk * dc / dh),
0. * (1+z) * dc)
return 5. * T.log10(dl) + 25. # dist mod