-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinf_dyn_plot.py
373 lines (266 loc) · 13.2 KB
/
inf_dyn_plot.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#########################################################################################################
#########################################################################################################
#
# This script is for generating high-quality plots of various quantities generated by the other scripts
# Please refer to <arXiv link> for explaination of variables and instructions for using the code
#
#########################################################################################################
#########################################################################################################
import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
import matplotlib.patches as pch
from matplotlib import rcParams
from matplotlib import rc
from matplotlib.ticker import AutoMinorLocator
#########################################################################################################
# The plot settings are defined in this section
#
# It is recommended that you don't alter this section unless you're familiar with MatPlotLib and LaTeX
#########################################################################################################
# activate LaTeX text rendering
plt.rc('text', usetex=True)
#LaTex settings
plt.rcParams['text.latex.preamble']=r'\usepackage{amsmath}'
plt.rcParams['text.latex.preamble'] = r'\boldmath'
###Plot settings:
# dimensions of figure
plt.rcParams['figure.figsize'] = (10, 7)
# font
#plt.rcParams['font.size'] = 10
#plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['axes.labelsize'] = plt.rcParams['font.size']
plt.rcParams['axes.titlesize'] = 1.4*plt.rcParams['font.size']
plt.rcParams['legend.fontsize'] = 1.4*plt.rcParams['font.size']
plt.rcParams['xtick.labelsize'] = 1.4*plt.rcParams['font.size']
plt.rcParams['ytick.labelsize'] = 1.4*plt.rcParams['font.size']
# dots per inch: dpi
#plt.rcParams['savefig.dpi'] = 2*plt.rcParams['savefig.dpi']
# tick sizes
plt.rcParams['xtick.major.size'] = 3
plt.rcParams['xtick.minor.size'] = 3
plt.rcParams['xtick.major.width'] = 1
plt.rcParams['xtick.minor.width'] = 1
plt.rcParams['ytick.major.size'] = 3
plt.rcParams['ytick.minor.size'] = 3
plt.rcParams['ytick.major.width'] = 1
plt.rcParams['ytick.minor.width'] = 1
fig = plt.figure()
ax = fig.add_subplot(111)
#ticks position setting
#plt.gca().xaxis.set_ticks_position('bottom')
#plt.gca().yaxis.set_ticks_position('left')
#ax.tick_params(labeltop=False, labelright=True)
#legends
plt.rcParams['legend.frameon'] = True
#plt.rcParams['legend.loc'] = 'center left'
# width of axes
plt.rcParams['axes.linewidth'] = 1
#border setting
#plt.gca().spines['right'].set_color('none')
#plt.gca().spines['top'].set_color('none')
# gridlines
plt.grid(which='major', color='lightgrey', linestyle='-', linewidth=1, zorder=0)
#########################################################################################################
# The model of inflation is defined in this section
#########################################################################################################
S = 5e-5 # for scaling time
# parameters used in the potential function
M = 5.9e-6
v0 = 0.5*M**2
# dimensionless potential function and its derivatives
def f(x):
return x**2
def dfdx(x):
return 2*x
def d2fdx2(x):
return 2
#########################################################################################################
# This is the main section of the code and follows a menu-driven format
#
# The section is divided into segments, each concerning different parts of inflationary dynamics
# Each segment is further divided into subsegments that contain different plots
# Select the segment corresponding to the dynamics you want to study (see the menu below) and uncomment
# the subsegment corresponding to the required plot
# In each subsegment, there are labels, lines, arrows and other markers to accompany the main plots.
# It is recommended that you comment those out and include them at suitable locations in your plots.
#########################################################################################################
# Select the segment to execute:
switch = 3
# background 0
# scalar modes 1
# tensor modes 2
# power spectrum 3
if switch == 0: # background
data = np.loadtxt('data/inf_bg_data.txt') # T,N,Ne,x,y,z,aH,epsH,etaH,meff,Ps,Pt. 12 columns
x = data[:,3]
y = data[:,4]
z = np.sqrt(y**2/6 + (v0*f(x)/(3*S**2)))
meff = data[:,9]
aH = data[:,6]
def i(Ne):
return np.max(np.where(data[:,2]>=Ne))
''' # to calculate n_s and r
ns = 1 + 2*data[:,5] - 4*data[:,6]
r = 16*data[:,6]
print('%.4f \t %.4f'%(1 + 2*data[i(50),5] - 4*data[i(50),6], 1 + 2*data[i(60),5] - 4*data[i(60),6]))
print('%.4f \t %.4f'%(16*data[i(50),6], 16*data[i(60),6]))
'''
#''' # for T vs N
plot1 = plt.plot(data[:,0],data[:,1])
plt.setp(plot1, color='g', linewidth=4, linestyle='-')
#plt.text(100,20, r'$\textbf{accelerated expansion}$', fontsize=20, color='purple', rotation=38)
plt.text(420,75, r'$\textbf{end of inflation}$', fontsize=20, color='purple')
plt.axhline(y=79.4135, ls='--', lw=1.5, color='k')
#plt.axvline(x=730, ls=':', color='k')
plt.text(350,25, r'$a\simeq a_0\mathrm{e}^{HT}$', fontsize=20, bbox=dict(facecolor='none', edgecolor='black', pad=10))
#plt.text(750,30, r'$\textbf{decelerated expansion}$', fontsize=20, color='purple', rotation=90)
plt.xlim(0,800)
plt.ylim(0,85)
plt.xlabel(r'$T$', fontsize = 22)
plt.ylabel(r'$N$', fontsize = 24)
#'''
''' # for phase plot
plot1 = plt.plot(x,y*S)
plt.setp(plot1, color='g', linewidth=4, linestyle='-')
plt.axvline(x=0.615, ls='--', lw=2, color='k')
plt.text(0.7, -3e-6, r'$\textbf{end of inflation}$', fontsize=20, color='purple', rotation=90)
plt.xlabel(r'$\phi/m_p$', fontsize = 22)
plt.ylabel(r'$\dot\phi/m_p^2$', fontsize = 24)
'''
''' # for slow-roll parameters
plot1 = plt.plot(data[:,2],np.abs(data[:,8]))
plt.setp(plot1, color='r', linewidth=3.5, linestyle='-')
plot1 = plt.plot(data[:,2],data[:,7])
plt.setp(plot1, color='g', linewidth=3.5, linestyle='-')
ax.add_patch(pch.Rectangle((0,1), 70,10, fc='brown', alpha=0.5))
plt.text(5,2, r'$\epsilon_H,\,\eta_H > 1$', fontsize=20)
plt.axhline(y=1, ls='--', color='k', lw=2)
plt.text(0.5,5e-4, r'$\textbf{end of inflation}$', fontsize=20, color='purple', verticalalignment='center', rotation=90)
plt.text(30,2e-4, r'$|\eta_H|$', color='r', fontsize=18, bbox=dict(fc='grey', ec='r', alpha=0.5, boxstyle='round'))
ax.annotate("", xy=(25, 1.33e-4), xytext=(23, 1.55e-4), arrowprops=dict(arrowstyle="<-", lw=4, color='r'))
plt.text(20,5e-2, r'$\epsilon_H$', color='g', fontsize=18, bbox=dict(fc='grey', ec='g', alpha=0.5, boxstyle='round'))
ax.annotate("", xy=(30, 1.69e-2), xytext=(28, 1.8e-2), arrowprops=dict(arrowstyle="<-", lw=4, color='g'))
plt.text(45,5e-4, r'$\textbf{slow-roll: }$', fontsize=20, color='purple')
plt.text(56,5e-4, r'$\epsilon_H \ll 1$', fontsize=20)
plt.yscale('log')
plt.xlim(0.0,70.0)
plt.ylim(1e-5,10)
plt.xlabel(r"$N_e$", fontsize = 22)
'''
''' # for z''/z
plot1 = plt.plot(data[:,2], z**(-2) *meff, label=r'$(aH)^{^{-2}}\frac{z^{\prime\prime}}{z}$')
plt.setp(plot1, color='g', linewidth=4, linestyle='-')
plot1 = plt.plot(data[:,2], data[:,8], label=r'$\eta_H$')
plt.setp(plot1, color='b', linewidth=4, linestyle='--')
plot1 = plt.plot(data[:,2], 2 - data[:,6], label=r'$(aH)^{^{-2}}\frac{a^{\prime\prime}}{a}$')
plt.setp(plot1, color='r', linewidth=4, linestyle='--')
plt.xlim(0,70)
plt.ylim(0,3)
plt.xlabel(r'$N_e$', fontsize = 22)
plt.ylabel(r'$(aH)^{-2} z^{\prime\prime}/z$', fontsize = 24)
plt.legend(frameon=True, fontsize = 16, borderpad = 1)
'''
''' # for x,y,z vs Ne
plot1 = plt.plot(data[:,2], S*np.sqrt(data[:,4]**2/6 + (v0*f(data[:,3])/(3*S**2))), label=r'$H/m_p$')
plt.setp(plot1, color='g', linewidth=4, linestyle='-')
#plot1 = plt.plot(data[:,2], data[:,3], label=r'$\phi/m_p$')
#plt.setp(plot1, color='g', linewidth=4, linestyle='-')
#plot1 = plt.plot(data[:,2], S*data[:,4], label=r'$\dot\phi/m_p^2$')
#plt.setp(plot1, color='r', linewidth=4, linestyle='-')
plt.axvline(x=60, ls='--', lw=2, color='b')
ax.add_patch(pch.Rectangle((55,-5), 10,20, fc='grey', alpha=0.5))
#plt.plot([60,60], [data[i(60),3],S*data[i(60),3]], 'b*', ms=14)
#plt.text(56,3, r'$\textbf{pivot scale}$', fontsize=24, color='purple', rotation=90, verticalalignment='center', bbox=dict(fc='w', ec='k'))
#plt.text(60,1, r'$\textbf{CMB window}$', fontsize=20, color='purple', horizontalalignment='center', bbox=dict(fc='w', ec='k'))
plt.plot(60, S*np.sqrt(data[i(60),4]**2/6 + (v0*f(data[i(60),3])/(3*S**2))), 'b*', ms=14)
plt.text(56,3e-6, r'$\textbf{pivot scale}$', fontsize=24, color='purple', rotation=90, verticalalignment='center', bbox=dict(fc='w', ec='k'))
plt.text(60,0.5e-6, r'$\textbf{CMB window}$', fontsize=20, color='purple', horizontalalignment='center', bbox=dict(fc='w', ec='k'))
ax.add_patch(pch.Rectangle((3,2e-6), 47,1.8e-6, fill=True, alpha=1, fc='w', ec='k', lw=2, zorder=10))
plt.text(4,2e-6, r'$$H^2 = \frac{1}{3m_p^2} \left[\frac{\dot\phi^2}{2}+V(\phi)\right]$$', fontsize=32, zorder=20)#, bbox=dict(fc='w', ec='k'))
plt.xlim(0,75)
#plt.ylim(-1,6)
plt.ylim(0,7e-6)
plt.xlabel(r'$N_e$', fontsize=32)
plt.ylabel(r'$H/m_p$', fontsize=34)
#plt.legend(frameon=True, fontsize = 24, borderpad = 1, loc='best') #legend format
'''
''' # for n_S and n_T under slow-roll approximation
epsH = data[:,7]
etaH = data[:,8]
ns = 2*etaH - 4*epsH
nt = 2*epsH
plot1 = plt.plot(data[:,2], ns)
plt.setp(plot1, color='g', linewidth=4, linestyle='-')
#plot1 = plt.plot(data[:,2], nt)
#plt.setp(plot1, color='g', linewidth=4, linestyle='-')
plt.axvline(60, color='b', linewidth=2, linestyle='--')
plt.plot(60.01,0.9674-1, 'b*', ms=17) # ns
#plt.plot(60.01,0.0004, 'b*', ms=16) # nt
ax.add_patch(pch.Rectangle((55,-0.3), 10,0.7, fc='grey', alpha=0.5))
#plt.text(55,4.11, r'$\times 10^{-3}$', fontsize=22, horizontalalignment='left', verticalalignment='top')
#plt.yscale('log')
#plt.grid(which='both', color='lightgrey', linestyle='-', linewidth=1)
plt.xlim(0,70)
plt.ylim(-0.3,0)
#plt.ylim(1e-5,1)
plt.xlabel(r'$N_e$', fontsize=34)
plt.ylabel(r'$n_{_S}-1$', fontsize=34)
#plt.ylabel(r'$|n_{_T}|$', fontsize=36)
'''
if switch == 1: # to calculate P_S at k
Nk = 60 # Select the mode to be plotted
file_name = 'data/modes/inf_MS_data_%.1f.txt'%Nk
data = np.loadtxt(file_name) # Ne,aHk,zeta2,P_S,h2,P_T. 6 columns
def i(Ne):
return np.max(np.where(data[:,0]>=Ne))
def j(aHk):
return np.max(np.where(data[:,1]<=aHk))
Nt = 77.4859
plot1 = plt.plot(data[:,0] - Nt + Nk+5, data[:,3], label='Ne = %.1f'%Nk)
plt.setp(plot1, color='g', linewidth=2, linestyle='-')
plt.plot(data[j(1.0),0]- Nt + Nk+5, data[j(1.0),3], marker='o', markersize=5, color='g')
#plt.xscale('log') # for plotting aHk on the x-axis
plt.yscale('log')
#plt.xlim(0,75)
#plt.ylim(2e-12,2e-9)
plt.xlabel(r'$N_e$', fontsize = 22)
plt.ylabel(r'$4k^3\left|h_k\right|^2/\pi^2$', fontsize = 24)
if switch == 2: # to calculate P_T at k
Nk = 60 # Select the mode to be plotted
file_name = 'data/modes/inf_MS_data_%.1f.txt'%Nk
data = np.loadtxt(file_name) # Ne,aHk,zeta2,P_S,h2,P_T. 6 columns
def i(Ne):
return np.max(np.where(data[:,0]>=Ne))
def j(aHk):
return np.max(np.where(data[:,1]<=aHk))
Nt = 77.4859
plot1 = plt.plot(data[:,0] - Nt + Nk+5, data[:,5], label='Ne = %.1f'%Nk)
plt.setp(plot1, color='g', linewidth=2, linestyle='-')
plt.plot(data[j(1.0),0]- Nt + Nk+5, data[j(1.0),5], marker='o', markersize=5, color='g') # horizon exit marker
#plt.xscale('log') # for plotting aHk on the x-axis
plt.yscale('log')
#plt.xlim(0,75)
#plt.ylim(2e-12,2e-9)
plt.xlabel(r'$N_e$', fontsize = 22)
plt.ylabel(r'$4k^3\left|h_k\right|^2/\pi^2$', fontsize = 24)
if switch == 3: # to plot power spectrum
#data = np.loadtxt('data/inf_MS_power.txt') # Ne,P_S,P_T. 3 columns
data1 = np.loadtxt('data/inf_bg_data.txt') # T,N,Ne,x,y,z,aH,epsH,etaH,meff,Ps,Pt. 12 columns
def i(Ne):
return np.max(np.where(data1[:,0]<=Ne))
#In order to plot power spectrum wrt k instead of Ne
def k(Ne):
return 0.05 * np.exp(60 - Ne)
#plt.plot(data[:,0], data[:,1], 'go', label='Scalar (numerical)')
plt.plot(data1[:,2], data1[:,10], 'g-', lw=4 , label='Scalar (slow-roll)')
#plt.plot(data[:,0], data[:,2], 'ro', label='Tensor (numerical)')
plt.plot(data1[:,2], data1[:,11], 'r-', lw=4 , label='Tensor (slow-roll)')
plt.yscale('log')
plt.xlim(5,70)
plt.ylim(1e-12,1e-8)
plt.xlabel(r"$N_e$", fontsize = 22)
plt.ylabel(r"$\textbf{Power}$", fontsize = 24)
plt.title(r"$\textbf{Scalar \& Tensor Power Spectra for Quadratic Model}$", fontsize = 22)
plt.legend(frameon=True, fontsize = 14, borderpad = 1.2) #legend format
plt.show()