-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenFLRW.py
343 lines (288 loc) · 11.7 KB
/
genFLRW.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env python
"""
Created on Thu Aug 21 09:40:27 2014
@author: landman
Class to create FLRW universe object
"""
import numpy as np
from numpy import linspace, sqrt, sin, sinh, pi, ones, zeros
from scipy.interpolate import UnivariateSpline as uvs
from scipy.integrate import quad
from Copernicus import Master
import matplotlib.pyplot as plt
from Copernicus.Parset import MyOptParse
class FLRW(object):
def __init__(self,Om0,OL0,H0,zmax,NJ):
self.Om0 = Om0
self.Ok0 = 1- Om0 - OL0
self.OL0 = OL0
self.Lambda = 3*OL0*H0**2
self.H0 = H0
self.NJ = NJ
self.z = linspace(0,zmax,self.NJ)
self.delz = self.z[1]-self.z[0]
self.Hz = self.getHz()
self.Om = self.getOmz()
self.OL = self.Lambda/(3*self.Hz**2)
self.Ok = 1 - self.Om - self.OL
self.Dz = self.getDz()
self.nuz = self.getnuz()
self.nu = linspace(self.nuz[0],self.nuz[-1],self.NJ)
self.rhoz = self.getrho()
# Set function to get t0
self.t0f = lambda x, a, b, c, d: np.sqrt(x) / (d * np.sqrt(a + b * x + c * x ** 3))
def getHz(self, z=None, Om0=None, OL0 = None, H0=None):
if Om0 is None and OL0 is None and H0 is None and z is None:
return self.H0*sqrt(self.Om0*(1+self.z)**3 + self.Ok0*(1+self.z)**2 + self.OL0)
else:
Ok0 = 1.0 - Om0 - OL0
return H0 * sqrt(Om0 * (1 + z) ** 3 + Ok0 * (1 + z) ** 2 + OL0)
def getHo(self):
Ho = uvs(self.z,self.Hz,k=5,s=0.0)
return Ho
def getDz(self, z=None, Om0=None, OL0 = None, H0=None):
if Om0 is None and OL0 is None and H0 is None and z is None:
Om0 = self.Om0
OL0 = self.OL0
Ok0 = self.Ok0
H0 = self.H0
Hz = self.Hz
z = self.z
else:
Ok0 = 1.0 - OL0 - Om0
Hz = self.getHz(z=z, Om0=Om0, OL0=OL0, H0=H0)
K = -Ok0*H0**2
dDc = uvs(z, 1.0/Hz, k=3, s=0.0)
Dc = dDc.antiderivative()(z) #comoving distance
if (K>0.0):
Dz = sin(sqrt(K)*Dc)/sqrt(K)/(1+z)
elif (K<0.0):
Dz = sinh(sqrt(-K)*Dc)/sqrt(-K)/(1+z)
else:
Dz = Dc/(1+z)
return Dz
def getDo(self):
Do = uvs(self.z,self.Dz,k=5,s=0.0)
return Do
def getOmz(self, z=None, Om0=None, H0=None, OL0=None):
if z is None and Om0 is None and H0 is None and OL0 is None:
return self.Om0*(1+self.z)**3*(self.H0/self.Hz)**2
else:
Hz = self.getHz(z, Om0=Om0, OL0=OL0, H0=H0)
return Om0 * (1 + z) ** 3 * (H0 / Hz) ** 2
def getrho(self, z=None, Om0=None, H0=None, OL0=None):
if z is None and Om0 is None and H0 is None and OL0 is None:
return 3.0*self.Om*self.Hz**2.0/(8.0*pi)
else:
Hz = self.getHz(z, Om0=Om0, OL0=OL0, H0=H0)
Om = self.getOmz(z, Om0=Om0, OL0=OL0, H0=H0)
return 3.0*Om*Hz**2.0/(8.0*pi)
def getrhoo(self):
rho = 3.0*self.Om*self.Hz**2.0/(8.0*pi)
rhoo = uvs(self.z,rho,k=5,s=0.0)
return rhoo
def getnuz(self):
dvdzo = uvs(self.z,1/((1+self.z)**2*self.Hz),k=3,s=0.0)
v = dvdzo.antiderivative()(self.z)
return v
def getdzdw(self):
return self.H0*(1+self.z) - self.Hz
def get_sigmasq(self, DelRSq, UV_cut, ac, Hz, Dz, z, Om0, OL0):
"""
Compute the magnitude of sigma^2*D^2/H^2 in perturbed FLRW
DelRSq = amplitude of primordial fluctuations
UV_cut = the UV cut-off
ac = scale factor at central worldline
Hz = the Hubble rate down PLC
Dz = the angular diameter distance down PLC
z = the redshift down PLC
"""
# rescale (1 + z) > (1 + z')/ac
uz_rescaled = (1 + z)/ac
# Get normalisation of growth suppression function
ginf = 2*(Om0**(4.0/7) - OL0 + (1+Om0/2.0)*(1+OL0/70.0))/(5*Om0)
#Hubble scale
h = Hz[0]*299.8/100 #the 299.8 is a unit conversion
kH0 = h/3.0e3
# Normalised densities (remember to check against Julien's result
Omz = Om0*uz_rescaled**3/(OL0 + Om0*uz_rescaled**3)
OLz = OL0/(OL0 + Om0*uz_rescaled**3)
# Growth suppression function and derived evolution function for the shear
#g = 5*ginf*self.Om/(2*(self.Om**(4.0/7) - self.OL + (1+self.Om/2)*(1+self.OL/70)))
g = 5 * ginf * Omz / (2 * (Omz ** (4.0 / 7) - OLz + (1 + Omz / 2) * (1 + OLz / 70)))
go = uvs(z, g, k=3, s=0.0)
dgo = go.derivative()
dg = dgo(z)
G = (dg**2)**uz_rescaled**2 - 2*uz_rescaled*dg + g**2
# Get the UV cut-off
kUV = UV_cut/kH0
# Transfer function
k = linspace(0,kUV,1000)
q = k*kH0/(Om0*h**2)
T = np.zeros_like(k)
T[1::] = np.log(1 + 2.34*q[1::])/(2.34*q[1::]*(1+3.89*q[1::] + (16.1*q[1::])**2 + (5.46*q[1::])**3 + (6.71*q[1::])**4))**0.25
T[0] = 0.0
dSo = uvs(k, k**3*T**2, k=3, s=0.0)
So = dSo.antiderivative() #Maybe do this with quad!!!!
S = So(kUV)
# Expectation value of sigmasq*D**2/H**2
sigmasqDzsqo = 4*DelRSq*G*S*Dz**2*Hz**2/(uz_rescaled**2*75*Om0*ginf**2)
return sigmasqDzsqo
def get_aot(self, Om0, OL0, H0):
"""
Since the Universe is FLRW along the central worldline (viz. C) we have analytic expressions for the input
functions along C. These can be used as boundary data in the CIVP (not currently implemented)
"""
Ok0 = 1.0 - Om0 - OL0
#First get current age of universe
t0 = quad(self.t0f, 0, 1.0, args=(Om0,Ok0,OL0,H0))[0]
#Get t(a) when a_0 = 1 (for some reason spline does not return correct result if we use a = np.linspace(1.0,0.2,1000)?)
a = np.linspace(0, 1.0, 5000)
tmp = self.t0f(a, Om0, Ok0, OL0, H0)
dto = uvs(a, tmp, k=3, s=0)
to = dto.antiderivative()
t = to(a)
#Invert to get a(t)
aoto = uvs(t, a, k=3, s=0.0)
return aoto, t0
def get_C_Sol(self, aoto, Om0, OL0, t0, tstar, Lam):
Ok0 = 1.0 - Om0 - OL0
t = np.linspace(t0, tstar, 300)
aow = aoto(t)
#Now get rho(t)
rho0 = Om0*3*H0**2/(8*np.pi)
rhoow = rho0*aow**(-3.0)
#Get How (this is up_0)
How = H0*np.sqrt(Om0*aow**(-3) + Ok0*aow**(-2) + OL0)
upow = How
#Now get dHz and hence uppow
#First dimensionless densities
Omow = 8*np.pi*rhoow/(3*How**2)
OLow = Lam/(3*How**2)
OKow = 1 - Omow - OLow
dHzow = How*(3*Omow + 2*OKow)/2 #(because the terms in the np.sqrt adds up to 1)
uppow = (dHzow + 2*upow)*upow
return rhoow, upow, uppow
def give_shear_for_plotting(self, Om0, OL0, H0, DelRSq, UV_cut, zmax, Np, tstar, Nret, data_prior, data_lik, fname,
DoPLCF, err):
"""
This gives the FLRW shear on the PLC0 and the PLCF
:param Om0:
:param OL0:
:param H0:
:param DelRSq:
:param UV_cut:
:return:
"""
zi = np.linspace(0, zmax, Np)
Hzi = self.getHz(zi, Om0=Om0, OL0=OL0, H0=H0)
Dzi = self.getDz(zi, Om0=Om0, OL0=OL0, H0=H0)
sigmasqi = self.get_sigmasq(DelRSq, UV_cut, 1.0, Hzi, Dzi, zi, Om0, OL0)
sigmasqio = uvs(zi/zi[-1], sigmasqi, k=3, s=0.0)
LamF = 3 * OL0 * H0 ** 2
rhozi = self.getrho(zi, Om0=Om0, OL0=OL0, H0=H0)
Xrho = np.array([0.5, 2.8])
XH = np.array([0.6, 3.5])
sigmaLam = 0.6 * 3 * 0.7 * (70.0 / 299.79) ** 2
#tstar = 3.9
UF = Master.SSU(zmax, tstar, Np, err, XH, Xrho, sigmaLam, Nret, data_prior, data_lik, fname, DoPLCF, Hz=Hzi, rhoz=rhozi,
Lam=LamF, useInputFuncs=True)
T1iF, T2iF, LLTBConsiF, DiF, SiF, QiF, AiF, ZiF, SpiF, QpiF, ZpiF, uiF, upiF, uppiF, udotiF, rhoiF, rhopiF, rhodotiF, \
DzF, dzdwzF, sigmasqiF, t0F = UF.get_funcsi()
if t0F > UF.tmin and UF.NI > 1 and DoPLCF:
T1fF, T2fF, LLTBConsfF, DfF, SfF, QfF, AfF, ZfF, SpfF, QpfF, ZpfF, ufF, upfF, uppfF, udotfF, rhofF, rhopfF, \
rhodotfF, sigmasqfF = UF.get_funcsf()
# Get background z, Dz, Hz for FLRW at t = tstar
zonuf = ufF - 1.0
zf = np.linspace(0, zonuf[-1], Nret)
DzFf = uvs(zonuf, DfF, k=3, s=0.0)(zf)
DzFf[0] = 0.0
HzFf = uvs(zonuf, upfF / ufF ** 2, k=3, s=0.0)(zf)
# plt.figure()
# plt.plot(zonuf, rhofF)
# plt.show()
Omf = 8*np.pi*rhofF[0]/(3.0*HzFf[0]**2)
OLf = LamF/(3.0*HzFf[0]**2)
#print "Okf = ", 1 - Omf - OLf
# Get aot
aot, t0 = self.get_aot(Om0, OL0, H0)
ac = aot(tstar)
#rhoow, upow, uppow = self.get_C_Sol(aot, Om0, OL0, t0, tstar, LamF)
sigmasqf = self.get_sigmasq(DelRSq, UV_cut, 1.0, HzFf, DzFf, zf, Omf, OLf)
sigmasqfo = uvs(zf / zf[-1], sigmasqf, k=3, s=0.0)
l = np.linspace(0, 1, Nret)
return Dzi, Hzi, rhozi, dzdwzF, sigmasqio(l), sigmasqfo(l)
if __name__=="__main__":
# Get input args
GD = MyOptParse.readargs()
# Print out parset settings
keyslist = GD.keys()
for it in keyslist:
print it, GD[it]
#Determine how many samplers to spawn
NSamplers = GD["nwalkers"]
Nsamp = GD["nsamples"]
Nburn = GD["nburnin"]
tstar = GD["tstar"]
DoPLCF = GD["doplcf"]
DoTransform = GD["dotransform"]
fname = GD["fname"]
data_prior = GD["data_prior"]
data_lik = GD["data_lik"]
zmax = GD["zmax"]
Np = GD["np"]
Nret = GD["nret"]
err = GD["err"]
samps_out_name = GD["samps_out_name"]
OL0 = 0.7
Om0 = 0.3
H0 = 70 / 299.8 #The 299.8 is a conversion factor to keep units consistent
DelRSq = 2.41e-9
UV_cut = 0.005
LamF = 3 * OL0 * H0 ** 2
LCDM = FLRW(Om0, OL0, H0, zmax, Np)
Dzi, Hzi, rhozi, dzdwzF, sigmasqi, sigmasqf = LCDM.give_shear_for_plotting(Om0, OL0, H0, DelRSq, UV_cut, zmax, Np, tstar, Nret, data_prior,
data_lik, fname, DoPLCF, err)
# plot shear on PLC0
l = linspace(0, 1, Nret)
ymax = 1.1*sigmasqi.max()
plt.figure('PLC0')
plt.plot(l, sigmasqi, label='PLC0')
plt.ylim(1e-12, ymax)
#plt.yscale('log')
#plt.savefig(fname+'/Figures/sigmasqiF.png', dpi=250)
# # Do LCDM integration
# Xrho = np.array([0.5,2.8])
# XH = np.array([0.6,3.5])
# sigmaLam = 0.6 * 3 * 0.7 * (70.0 / 299.79) ** 2
# UF = Master.SSU(zmax, tstar, Np, err, XH, Xrho, sigmaLam, Nret, data_prior, data_lik, fname, DoPLCF, Hz=Hzi, rhoz=rhozi,
# Lam=LamF, useInputFuncs=True)
#
# T1iF, T2iF, LLTBConsiF, DiF, SiF, QiF, AiF, ZiF, SpiF, QpiF, ZpiF, uiF, upiF, uppiF, udotiF, rhoiF, rhopiF, rhodotiF, \
# DzF, dzdwzF, sigmasqiF, t0F = UF.get_funcsi()
#
# if t0F > UF.tmin and UF.NI > 1 and DoPLCF:
# T1fF, T2fF, LLTBConsfF, DfF, SfF, QfF, AfF, ZfF, SpfF, QpfF, ZpfF, ufF, upfF, uppfF, udotfF, rhofF, rhopfF, \
# rhodotfF, sigmasqfF = UF.get_funcsf()
#
# # Get background z, Dz, Hz for FLRW at t = tstar
# zonuf = ufF - 1.0
# zf = np.linspace(0, zonuf[-1], Nret)
# DzFf = uvs(zonuf, DfF, k=3, s=0.0)(zf)
# DzFf[0] = 0.0
# HzFf = uvs(zonuf, upfF / ufF ** 2, k=3, s=0.0)(zf)
#
# # Get aot
# aot, t0 = LCDM.get_aot(Om0, OL0, H0)
#
# ac = aot(tstar)
#
# sigmasqf = LCDM.get_sigmasq(2.41e-9, 0.005, ac, HzFf, DzFf, zf)
#plt.figure('PLCF')
plt.plot(l, sigmasqf, label='PLCF')
plt.ylabel(r'$\log\left(\frac{\sigma^2 D^2}{H^2}\right)$')
plt.xlabel(r'$z$')
plt.legend()
#plt.ylim(1.0e-11, 1.0e-6)
plt.yscale('log')
plt.savefig(fname + '/Figures/logsigmasqfF_no_rescale.png', dpi=250)