/
MMSS_cosmology.py
159 lines (116 loc) · 5.65 KB
/
MMSS_cosmology.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
#Load all required packages
import numpy as np #The holy grail of scientific computing!
import matplotlib.pyplot as plt #The only reason I can call myself an "artist"
#Set plotting params
import matplotlib as mpl
mpl.rcParams['xtick.direction'], mpl.rcParams['ytick.direction'] = 'in', 'in'
mpl.rcParams['xtick.major.size'], mpl.rcParams['xtick.minor.size'] = 14, 8
mpl.rcParams['xtick.major.width'], mpl.rcParams['xtick.minor.width'] = 1.2, 0.8
mpl.rcParams['xtick.major.pad'], mpl.rcParams['xtick.minor.pad'] = 10, 10
mpl.rcParams['ytick.major.size'], mpl.rcParams['ytick.minor.size'] = 14, 8
mpl.rcParams['ytick.major.width'], mpl.rcParams['ytick.minor.width'] = 1.2, 0.8
#Command to compute Omega
def Omega_X(a, Omega_0, w_func):
'''
Computes the fraction of energy in the Universe due to a component X.
Input
--------
a: numpy array
All the values of the scale factor, a, at which we compute Omega_X
Omega_0: float
The value of Omega_X at present (a = 1)
w_func: float, int, or function of a
The equation of state w = pressure/energy of the component X.
In this project, we make it a function of scale factor a
Output
--------
numpy array:
The value of Omega_X at all values in the array a
'''
#Initialize numpy array to store our output
factor = np.zeros(a.size)
#If given an int/float, rewrite it as a function
try:
w_func(0)
w = w_func
except:
w = lambda x: w_func
#Iterate/loop over all input values of a
for i, a_now in enumerate(a):
#For each a_now, create an array of values from a = a_now to a = 1
present_epoch_to_a_now = np.geomspace(a_now, 1, 1000, endpoint=True)
#Integrate
factor[i] = np.exp(3*np.trapz(1/present_epoch_to_a_now*(1 + w(present_epoch_to_a_now)), present_epoch_to_a_now))
return Omega_0*factor
#Compute Hubble constant given list of Omegas
def Hubble(list_of_Omegas):
H0 = 70 #Fiducial value of hubble constant in km/s/Mpc
return H0*np.sqrt(np.sum(list_of_Omegas, axis = 0))
def Our_Universe(a_start = 1e-7, a_end = 1e2, Omega_m = 0.3, Omega_r = 2e-5, Omega_l = 0.7, w_m = 0, w_r = 0.33, w_Lambda = -1):
a = np.geomspace(a_start, a_end, 500, endpoint=True)
Omega_M = Omega_X(a, Omega_m, w_m)
Omega_R = Omega_X(a, Omega_r, w_r)
Omega_L = Omega_X(a, Omega_l, w_Lambda)
Normalize = (Omega_M + Omega_R + Omega_L)
Sum = Omega_m + Omega_r + Omega_l
print("-----------------------")
print("Our Initial Conditions")
print("-----------------------")
print("Omega_m : %0.2f"%(Omega_m/Sum))
print("Omega_r : %0.2f"%(Omega_r/Sum))
print("Omega_L : %0.2f"%(Omega_l/Sum))
plt.rc('xtick',labelsize=22)
plt.rc('ytick',labelsize=22)
fig, axes = plt.subplots(2, 1, figsize = (12,14), sharex=True)
plt.subplots_adjust(hspace = 0.05)
axes[1].set_yscale('log')
[ax.set_xscale('log') for ax in axes]
axes[0].plot(a, Omega_M/Normalize, lw = 2, label = r'$\Omega_m$')
axes[0].plot(a, Omega_R/Normalize, lw = 2, label = r'$\Omega_r$')
axes[0].plot(a, Omega_L/Normalize, lw = 2, label = r'$\Omega_\Lambda$')
axes[0].legend(fontsize = 24)
axes[0].set_ylabel(r'$\Omega_i(a)$', size = 30)
axes[0].grid()
axes[0].axvline(1, alpha = 0.3, lw = 2, ls = '--', c = 'k')
list_of_Omegas = np.array([Omega_M, Omega_R, Omega_L])
axes[1].plot(a, Hubble(list_of_Omegas), lw = 3, alpha = 1, color = 'C6')
axes[1].set_ylabel(r'$H(a)$', size = 30)
axes[1].set_xlabel(r'$a$', size = 30)
axes[1].grid()
axes[1].axvline(1, alpha = 0.3, lw = 2, ls = '--', c = 'k')
def New_Universe(w_new, Omega_new, name = 'new', a_start = 1e-7, a_end = 1e2, Omega_m = 0.3, Omega_r = 2e-5, Omega_l = 0.7, w_m = 0, w_r = 0.33, w_Lambda = -1):
a = np.geomspace(a_start, a_end, 500, endpoint=True)
Omega_M = Omega_X(a, Omega_m, w_m)
Omega_R = Omega_X(a, Omega_r, w_r)
Omega_L = Omega_X(a, Omega_l, w_Lambda)
Omega_New = Omega_X(a, Omega_new, w_new)
Normalize = (Omega_M + Omega_R + Omega_L + Omega_New)
Sum = Omega_m + Omega_r + Omega_l + Omega_new
print("-----------------------")
print("Our Initial Conditions")
print("-----------------------")
print("Omega_m : %0.2f"%(Omega_m/Sum))
print("Omega_r : %0.2f"%(Omega_r/Sum))
print("Omega_L : %0.2f"%(Omega_l/Sum))
print("Omega_" + name + ": %0.2f"%(Omega_new/Sum))
plt.rc('xtick',labelsize=22)
plt.rc('ytick',labelsize=22)
fig, axes = plt.subplots(2, 1, figsize = (12,14), sharex=True)
plt.subplots_adjust(hspace = 0.05)
axes[1].set_yscale('log')
[ax.set_xscale('log') for ax in axes]
axes[0].plot(a, Omega_M/Normalize, lw = 2, label = r'$\Omega_m$')
axes[0].plot(a, Omega_R/Normalize, lw = 2, label = r'$\Omega_r$')
axes[0].plot(a, Omega_L/Normalize, lw = 2, label = r'$\Omega_\Lambda$')
axes[0].plot(a, Omega_New/Normalize, lw = 2, label = r'$\Omega_{\rm ' + name + '}$')
axes[0].legend(fontsize = 24)
axes[0].set_ylabel(r'$\Omega_i(a)$', size = 30)
axes[0].grid()
list_of_Omegas = np.array([Omega_M, Omega_R, Omega_L])
axes[1].plot(a, Hubble(list_of_Omegas), lw = 3, label = r'Normal Universe', alpha = 0.3, color = 'C4')
list_of_Omegas = np.array([Omega_M, Omega_R, Omega_L, Omega_New])
axes[1].plot(a, Hubble(list_of_Omegas), lw = 3, label = r'The ' + name + ' Universe!', color = 'C6')
axes[1].legend(fontsize = 24)
axes[1].set_ylabel(r'$H(a)$', size = 30)
axes[1].set_xlabel(r'$a$', size = 30)
axes[1].grid()