-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvar_plot.py
More file actions
282 lines (206 loc) · 10.2 KB
/
Copy pathvar_plot.py
File metadata and controls
282 lines (206 loc) · 10.2 KB
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
from pylab import *
from matplotlib.widgets import Slider, Button, RadioButtons
import constants as cc
import var_def as var
import plot as plt
from numpy import save
from decimal import Decimal, ROUND_DOWN
#-----: Discrete Slider !!
class DiscreteSlider(Slider):
"""A matplotlib slider widget with discrete steps."""
def __init__(self, *args, **kwargs):
"""
Identical to Slider.__init__, except for the new keyword 'allowed_vals'.
This keyword specifies the allowed positions of the slider
"""
self.allowed_vals = kwargs.pop('allowed_vals',None)
self.previous_val = kwargs['valinit']
Slider.__init__(self, *args, **kwargs)
if self.allowed_vals==None:
self.allowed_vals = [self.valmin,self.valmax]
def set_val(self, val):
discrete_val = self.allowed_vals[abs(val-self.allowed_vals).argmin()]
xy = self.poly.xy
xy[2] = discrete_val, 1
xy[3] = discrete_val, 0
self.poly.xy = xy
self.valtext.set_text(self.valfmt % discrete_val)
if self.drawon:
self.ax.figure.canvas.draw()
self.val = val
if self.previous_val!=discrete_val:
self.previous_val = discrete_val
if not self.eventson:
return
for cid, func in self.observers.iteritems():
func(discrete_val)
#---: Interacting-Non-Gaussianity matching Galaxy Power Spectrum !!
def IN_Pg_var_plot():
#---------- Cosmo parameters -----------------
cosmo = {'omega_M_0': 0.315, 'omega_b_0': 0.045, 'omega_lambda_0': 1 - 0.315}
ax = subplot(111)
subplots_adjust(left=0.25, bottom=0.25)
f_NL0 = cc.f_NL[0]
f_NL1 = cc.f_NL[1]
#galaxy_power(model, lcdm_model, f_NL, **cosmo)
ref_l_model = "lcdm_%s" %cc.z[0]
ref_w_model = "wcdm_%s_%s_%s" %(cc.z[0], cc.w_x[0], cc.c2_s[0])
ref_g_model = "gwcdm_%s_%s_%s_%s_%s" %(cc.z[0], cc.w_x[0], cc.c2_s[0], cc.gamma[2], cc.Inrct)
Pg_Delta_m0 = var.galaxy_power(ref_w_model, ref_l_model, f_NL0, **cosmo)
Pg_Delta_m1 = var.galaxy_power(ref_w_model, ref_l_model, f_NL1, **cosmo)
Pg_Delta_m01 = var.galaxy_power(ref_g_model, ref_l_model, f_NL0, **cosmo)
PPg_Delta_m01 = var.galaxy_power(ref_g_model, ref_l_model, f_NL0, **cosmo)[0]
f_NL = linspace(f_NL0, f_NL1, 1000)
for i in range(len(f_NL)):
PPg_Delta_m1 = var.galaxy_power(ref_w_model, ref_l_model, f_NL[i], **cosmo)[0]
if PPg_Delta_m01 >= PPg_Delta_m1:
f_NL01 = f_NL[i]
else:
exit
print "Effective f_NL: ", f_NL01
text(0.05, 0.9,'$f^{eff}_{NL}$ = %s' %round(f_NL01, 3) , ha ='left', va ='top', transform = ax.transAxes)
l, = loglog(cc.k, Pg_Delta_m0, '-', linewidth = 2)
l1, = loglog(cc.k, Pg_Delta_m1, '--', linewidth = 2, label = "wcdm - $f_{NL}$")
l2, = loglog(cc.k, Pg_Delta_m01, '-.', linewidth = 2, label = "$\Gamma$-wcdm")
l3, = loglog(cc.k, Pg_Delta_m01, ':', linewidth = 2, label = "$\Gamma$-wcdm + $f_{NL}$" )
axvline(x = 0.17 * 10**-2, color='r', ls = '--') # vertical line at k_eq
axvline(x = 0.14 * 10**-1, color='b', ls = '-.') # vertical line at k_eq
xlim((cc.k_min, cc.k_max))
#xlim((10**-3, cc.k_max))
axvline(x = 10**-3, color='g', ls = '--') # vertical line at k_eq
legend(loc = 'best')
xlabel('k')
ylabel('$Pg_m$(k, a = 1)')
axcolor = 'lightgoldenrodyellow'
axf_NL = axes([0.25, 0.05, 0.65, 0.03], axisbg=axcolor)
axgamma = axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axw_x = axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
axz = axes([0.025, 0.2, 0.1, 0.04], axisbg=axcolor)
sf_NL = Slider(axf_NL, '$f_{NL}$', f_NL0, f_NL1, valfmt='%1.3f', valinit = f_NL01)
sgamma = DiscreteSlider(axgamma, '$\Gamma$', 0.0, 1.0, allowed_vals = cc.gamma, valfmt='%1.1f', valinit = cc.gamma[2])
sz = DiscreteSlider(axz,'z', cc.z[0], cc.z[-1], valfmt='%1.1f' , allowed_vals = cc.z, valinit = cc.z[0])
sw_x = DiscreteSlider(axw_x, '$w_x$', cc.w_x[0], cc.w_x[-1], allowed_vals = cc.w_x , valfmt='%1.1f', valinit = cc.w_x[0])
def update(val):
f_NL = sf_NL.val
gamma = Decimal(sgamma.val).quantize(Decimal('0.1'),rounding=ROUND_DOWN)
z = Decimal(int(sz.val)).quantize(Decimal('0.0'),rounding=ROUND_DOWN)
w_x = Decimal(sw_x.val).quantize(Decimal('0.1'),rounding=ROUND_DOWN)
ref_l_model1 = "lcdm_%s" %z
ref_w_model1 = "wcdm_%s_%s_%s" %(z, w_x, cc.c2_s[0])
ref_g_model1 = "gwcdm_%s_%s_%s_%s_%s" %(z, w_x, cc.c2_s[0], gamma, cc.Inrct)
Pg_Delta_m = var.galaxy_power(ref_w_model1, ref_l_model1, f_NL, **cosmo)
Pg_Delta_m11 = var.galaxy_power(ref_g_model1, ref_l_model1, f_NL0, **cosmo)
Pg_Delta_mt = var.galaxy_power(ref_g_model1, ref_l_model1, f_NL, **cosmo)
l.set_ydata(Pg_Delta_m0)
l1.set_ydata(Pg_Delta_m)
l2.set_ydata(Pg_Delta_m11)
l3.set_ydata(Pg_Delta_mt)
draw()
sf_NL.on_changed(update)
sgamma.on_changed(update)
sz.on_changed(update)
sw_x.on_changed(update)
resetax = axes([0.8, 0.0, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sf_NL.reset()
sgamma.reset()
sz.reset()
sw_x.reset()
button.on_clicked(reset)
show()
return
#--: Interacting-Non-Gaussianity matching Angular Power Spectrum !!
def IN_APg_var_plot():
#---------- Cosmo parameters -----------------
cosmo = {'omega_M_0': 0.315, 'omega_b_0': 0.045, 'omega_lambda_0': 1 - 0.315}
ax = subplot(111)
subplots_adjust(left=0.25, bottom=0.25)
f_NL0 = cc.f_NL[0]
f_NL1 = cc.f_NL[1]
APg_Delta_m0 = var.galaxy_angular_power("wcdm_%s-%s-%s" %(cc.w_x, cc.c2_s, cc.z), 1, f_NL0, **cosmo)
APg_Delta_m1 = var.galaxy_angular_power("wcdm_%s-%s-%s" %(cc.w_x, cc.c2_s, cc.z), 1, f_NL1, **cosmo)
APg_Delta_m01 = var.galaxy_angular_power("gwcdm_%s-%s-%s-%s-%s" %(cc.w_x, cc.c2_s, cc.gamma, cc.Inrct, cc.z), 1, f_NL0, **cosmo)
PPg_Delta_m01 = var.galaxy_angular_power("gwcdm_%s-%s-%s-%s-%s" %(cc.w_x, cc.c2_s, cc.gamma, cc.Inrct, cc.z), 1, f_NL0, **cosmo)[0]
# f_NL = linspace(f_NL0, f_NL1, 1000)
# for i in range(len(f_NL)):
# PPg_Delta_m1 = var.galaxy_angular_power("wcdm_%s-%s-%s" %(cc.w_x, cc.c2_s, cc.z), 1, f_NL[i], **cosmo)[0]
# if PPg_Delta_m01 >= PPg_Delta_m1:
# f_NL01 = f_NL[i]
# else:
# exit
# print "Effective f_NL: ", f_NL01
l, = semilogy(cc.l, APg_Delta_m0, '-', linewidth = 2)#, label = "wcdm - $f_{NL}$: %s" % cc.f_NL[0] )
l1, = semilogy(cc.l, APg_Delta_m1, '--', linewidth = 2, label = "wcdm - $f_{NL}$")
l2, = semilogy(cc.l, APg_Delta_m01, '-.', linewidth = 2, label = "$\Gamma$-wcdm")
l3, = semilogy(cc.l, APg_Delta_m01, ':', linewidth = 2, label = "$\Gamma$-wcdm + $f_{NL}$" )
#axvline(x = 0.17 * 10**-2, color='r', ls = '--') # vertical line at k_eq
#axvline(x = 0.14 * 10**-1, color='b', ls = '-.') # vertical line at k_eq
#xlim((cc.k_min, cc.k_max))
#xlim((10**-3, cc.k_max))
#axvline(x = 10**-3, color='g', ls = '--') # vertical line at k_eq
legend(loc = 'best')
xlabel('l')
ylabel('$l(l+1)/(2\pi) C_l$(a=1)')
axcolor = 'lightgoldenrodyellow'
axf_NL = axes([0.25, 0.05, 0.65, 0.03], axisbg=axcolor)
axgamma = axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axz = axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
sf_NL = Slider(axf_NL, '$f_{NL}$', f_NL0, 10.0, valfmt='%1.3f', valinit = f_NL1)
sgamma = Slider(axgamma, '$\Gamma$', 0.0, 1.0, valfmt='%1.1f', valinit = cc.gamma)
sz = Slider(axz, '$z$', 0.0, 3.0, valfmt='%1.0f', valinit = cc.z)
def update(val):
f_NL = sf_NL.val
gamma = Decimal(sgamma.val).quantize(Decimal('0.1'),rounding=ROUND_DOWN)
z = Decimal(int(sz.val)).quantize(Decimal('0.0'),rounding=ROUND_DOWN)
APg_Delta_m = var.galaxy_angular_power("wcdm_%s-%s-%s" %(cc.w_x, cc.c2_s, z), 1, f_NL, **cosmo)
APg_Delta_m11 = var.galaxy_angular_power("gwcdm_%s-%s-%s-%s-%s" %(cc.w_x, cc.c2_s, gamma, cc.Inrct, z), 1, f_NL0, **cosmo)
APg_Delta_mt = var.galaxy_angular_power("gwcdm_%s-%s-%s-%s-%s" %(cc.w_x, cc.c2_s, gamma, cc.Inrct, z), 1, f_NL, **cosmo)
l.set_ydata(APg_Delta_m0)
l1.set_ydata(APg_Delta_m)
l2.set_ydata(APg_Delta_m11)
l3.set_ydata(APg_Delta_mt)
draw()
sf_NL.on_changed(update)
sgamma.on_changed(update)
sz.on_changed(update)
resetax = axes([0.8, 0.0, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sf_NL.reset()
sgamma.reset()
sz.reset()
button.on_clicked(reset)
show()
return
#--: Effective Non-Gaussainity !!
def IN_gfnl_var_plot():
#---------- Cosmo parameters -----------------
cosmo = {'omega_M_0': 0.315, 'omega_b_0': 0.045, 'omega_lambda_0': 1 - 0.315}
ax = subplot(111)
subplots_adjust(left=0.25, bottom=0.25)
eff_f_NL0 = var.f_NL_eff(cc.z[0], cc.w_x[0])
l, = plot(eff_f_NL0, cc.gamma, '-.o', linewidth = 2)
xlabel('$f^{eff}_{NL}$')
ylabel('$\Gamma$/$H_0$')
axcolor = 'lightgoldenrodyellow'
axz = axes([0.25, 0.05, 0.65, 0.03], axisbg=axcolor)
axw_x = axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
sz = DiscreteSlider(axz,'z', cc.z[0], cc.z[-1], valfmt='%1.1f' , allowed_vals = cc.z, valinit = cc.z[0])
sw_x = DiscreteSlider(axw_x, '$w_x$', cc.w_x[0], cc.w_x[-1], allowed_vals = cc.w_x , valfmt='%1.1f', valinit = cc.w_x[0])
def update(val):
w_x = Decimal(sw_x.val).quantize(Decimal('0.1'),rounding=ROUND_DOWN)
z = Decimal(int(sz.val)).quantize(Decimal('0.0'),rounding=ROUND_DOWN)
eff_f_NL1 = var.f_NL_eff(z, w_x)
l.set_xdata(eff_f_NL1)
draw()
sw_x.on_changed(update)
sz.on_changed(update)
resetax = axes([0.8, 0.0, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sw_x.reset()
sz.reset()
button.on_clicked(reset)
show()
return