import math, scipy.integrate
##########################################################################
# Various constants
rhoConst = 1.7885e+9 # 3 / (8 pi G)
secInGy = 3.1536e+16 # s / Gyr
tempNow = 2.725 # CMB temperature now
Hconv = 1 / 978 # Convert km/s/Mpc -> Gyr^-1
infty = float("inf") # Infinity - used as a limit in integrator
##########################################################################
# Inputs (Planck 2015, copied from Jorrie's calculator
H0 = 67.74 # H0 control
OmegaL = 0.691 # OmegaL control
Omega = 1 # Omega control
z_eq = 3370 # z_eq control
zvals = [ 1089.999, # The z values copied from Lightcone7's table
339.0316542,
104.9771906,
32.02928913,
9.293570928,
2.207515378,
0,
-0.6893293728,
-0.8690917659,
-0.9451725312,
-0.9773721629,
-0.991 ]
##########################################################################
# Constants derived from inputs
H0 *= Hconv # H0 in Gyr^-1
rhocritNow = rhoConst * (H0 / secInGy)**2 # Critical density now
s_eq = 1 + z_eq # Stretch when OmegaM=OmegaR
OmegaM = (Omega - OmegaL) * s_eq / (s_eq + 1) # Energy density of matter
OmegaR = OmegaM / s_eq # Energy density of radiation
OmegaK = 1 - OmegaM - OmegaR - OmegaL # Curvature energy density
##########################################################################
# Functions
def H(s):
"""Hubble constant as a function of stretch, s = 1/a, where a is the
usual FLRW scale factor"""
return H0 * math.sqrt(OmegaL
+ OmegaK * s**2
+ OmegaM * s**3
+ OmegaR * s**4)
def TH(s):
return 1 / H(s)
def THs(s):
return TH(s) / s
def formatted(vals):
"""Convenience function to apply standard formatting to a bunch of
numbers"""
return ",".join(("%7.2e" % v) for v in vals)
##########################################################################
# For each specified z, calculate all the things Jorrie's calculator does
# and output them as CSV for easy pasting into a spreadsheet
with open("planck.csv","w") as op:
op.write("z,Scale (a),S,Tnow Gyr,R Gly,Dnow Gly,Dthen Gly," \
+"DHor Gly,Dpar Gly,Vgen/c,Vnow/c,Vthen/c,H(z)," \
+"Temp (K),rho kg/m3,OmegaM,OmegaL,OmegaR,OmegaT\n")
for z in zvals:
s = 1 + z
#s = 1.001 + z # Uncomment to replicate a systematic bug in Lightcone7
a = 1 / s
Tnow = scipy.integrate.quad(THs, s, infty)[0]
R = 1 / H(s)
Dnow = abs(scipy.integrate.quad(TH, 1, s)[0])
Dthen = Dnow / s
Dhor = scipy.integrate.quad(TH, 0, s)[0] / s
Dpar = scipy.integrate.quad(TH, s, infty)[0] / s
Vgen = H(s) / (H0 * s)
Vnow = Dnow * H0
Vthen = Dthen * H(s)
Temp = tempNow * s
rhocrit = rhoConst * (H(s) / secInGy)**2
OmegaMT = (Omega-OmegaL) * s**3 * (H0 / H(s))**2
OmegaLT = (H0 / H(s))**2 * OmegaL
OmegaRT = OmegaMT * s / s_eq
OmegaTT = OmegaMT + OmegaLT + OmegaRT
op.write(formatted([z, a, s, Tnow, R,
Dnow, Dthen, Dhor, Dpar,
Vgen, Vnow, Vthen,
H(s) / Hconv,
Temp, rhocrit,
OmegaMT, OmegaLT, OmegaRT, OmegaTT])+"\n")