-
Notifications
You must be signed in to change notification settings - Fork 0
/
childressf3.py
executable file
·181 lines (140 loc) · 4.99 KB
/
childressf3.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
#!/usr/bin/env python
import numpy
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib import rc
import pickle
import cPickle
import scipy.stats
import matplotlib as mpl
mpl.rcParams['font.size'] = 18
f = open('MJC_compile_SNdata.pkl','r')
gal= pickle.load(f)
f = open('fix3.pkl','rb')
(fit, _) = pickle.load(f)
f.close()
pkl_file = open('gege_data.pkl', 'r')
data = pickle.load(pkl_file)
pkl_file.close()
dic_phreno=cPickle.load(open("phrenology_2016_12_01_CABALLOv1.pkl"))
dic_meta=cPickle.load(open("META.pkl"))
sivel=[]
sivel_err=[]
for sn in data['snlist']:
if sn in dic_meta.keys() and sn in dic_phreno.keys():
meta = dic_meta[sn]
vSiII_6355_lbd=0.
vSiII_6355_lbd_err=0.
counter = 0
for sp in dic_phreno[sn]["spectra"]:
if sp in meta['spectra'].keys() and numpy.abs(meta['spectra'][sp]['salt2.phase']) < 2.5 and numpy.isfinite(dic_phreno[sn]["spectra"][sp]["phrenology.vSiII_6355_lbd"]):
vSiII_6355_lbd += dic_phreno[sn]["spectra"][sp]["phrenology.vSiII_6355_lbd"]/dic_phreno[sn]['spectra'][sp]["phrenology.vSiII_6355_lbd.err"]**2
vSiII_6355_lbd_err += 1/dic_phreno[sn]['spectra'][sp]["phrenology.vSiII_6355_lbd.err"]**2
counter +=1
if counter !=0:
sivel.append(vSiII_6355_lbd / vSiII_6355_lbd_err)
sivel_err.append(1./numpy.sqrt(vSiII_6355_lbd_err))
else:
sivel.append(float('nan'))
sivel_err.append(float('nan'))
else:
sivel.append(float('nan'))
sivel_err.append(float('nan'))
sivel = numpy.array(sivel)
sivel_err = numpy.array(sivel_err)
use = numpy.isfinite(sivel)
names= numpy.array(data['snlist'])[use]
i = numpy.intersect1d(names, gal.keys(), assume_unique=True)
inda = numpy.zeros(len(i),dtype='int')
mass=[]
emass = []
for j in xrange(len(i)):
inda[j] = numpy.where(names == i[j])[0]
emass.append(gal[i[j]]['eMass'])
mass.append(gal[i[j]]['Mass'])
mass = numpy.array(mass)
emass= numpy.array(emass)
# pick one without mass
# crap = 0
# while crap in inda:
# crap=crap+1
# print crap
# scaled = fit['mag_int_raw'][:,crap]
# # scaled = fit['rho1'][:,0][:,None]*fit['R']
# scaled = scaled[:,inda]
# ksarr=[]
# pvarr=[]
# wlow = numpy.where(mass < 10)[0]
# wbig = numpy.where(mass >= 10)[0]
# for i in xrange(scaled.shape[0]):
# temp1,temp2= scipy.stats.ks_2samp(scaled[i,wlow],scaled[i,wbig])
# ksarr.append(temp1)
# pvarr.append(temp2)
# ksarr=numpy.array(ksarr)
# pvarr=numpy.array(pvarr)
# plt.hist(pvarr)
# plt.xlabel(r'$p$-value')
# pp = PdfPages("output_fix3/childress_pvalue.pdf")
# plt.savefig(pp,format='pdf',bbox_inches='tight')
# pp.close()
# plt.close()
(x, xmin, xmax) = numpy.percentile(fit['ev_sig'][:,None]*fit['mag_int_raw'][:,inda],(50,50-34,50+34),axis=0)
plt.errorbar(mass,x,xerr=[emass, emass], yerr=[x-xmin,xmax-x],fmt='o')
plt.ylabel(r'$p$')
plt.xlabel(r'$\log{(M_{host}/M_{\odot})}$')
pp = PdfPages("output_fix3/childress.pdf")
plt.savefig(pp,format='pdf',bbox_inches='tight')
pp.close()
plt.close()
sdgssg
# done
ux = numpy.array([6,10])
wm = numpy.where(mass < 10)[0]
temp = scaled[:,wm].flatten()
# temp=temp[temp !=0]
(x, xmin, xmax) = numpy.percentile(temp,(50,50-34,50+34))
dx = (xmax-xmin)/2/numpy.sqrt(len(wm))
print r"${:9.4f} \pm {{ {:9.4f} }}$".format(x,dx)
plt.plot(ux, [x,x],color='black')
plt.plot(ux, [x+dx,x+dx],color='red')
plt.plot(ux, [x-dx,x-dx],color='red')
ux = numpy.array([10,13])
wm = numpy.where(mass[1:] > 10)[0]
temp = scaled[:,wm].flatten()
# temp=temp[temp !=0]
(x, xmin, xmax) = numpy.percentile(temp,(50,50-34,50+34))
dx = (xmax-xmin)/2/numpy.sqrt(len(wm))
print r"${:9.4f} \pm {{ {:9.4f} }}$".format(x,dx)
plt.plot(ux, [x,x],color='black')
plt.plot(ux, [x+dx,x+dx],color='red')
plt.plot(ux, [x-dx,x-dx],color='red')
plt.xlim((6,13))
# plt.ylim((-0.1,0.1))
pp = PdfPages("output_fix3/childress.pdf")
plt.savefig(pp,format='pdf',bbox_inches='tight')
pp.close()
plt.close()
wefwe
wm = numpy.where(mass[1:] < 10)[0]
# low = (((fit['rho1'][:,0])[:,None])*fit['R'][:,wm]).flatten()
lowlim = numpy.percentile(scaled,(50,50-34,50+34),axis=0)
lowmn = lowlim[2,:]+lowlim[1,:]/2
lowsig = lowlim[2,:]-lowlim[1,:]/2
print "${:6.1e} \pm {:6.1e}$".format(numpy.sum(lowmn/lowsig**2)/numpy.sum(1/lowsig**2), 1/numpy.sqrt(numpy.sum(1/lowsig**2)))
wm = numpy.where(mass[1:] > 10)[0]
hig = (((fit['rho1'][:,0])[:,None])*fit['R'][:,wm]).flatten()
higlim = numpy.percentile(scaled,(50,50-34,50+34),axis=0)
higmn = higlim[2,:]+higlim[1,:]/2
higsig = higlim[2,:]-higlim[1,:]/2
print "${:6.1e} \pm {:6.1e}$".format(numpy.sum(higmn/higsig**2)/numpy.sum(1/higsig**2), 1/numpy.sqrt(numpy.sum(1/higsig**2)))
# import scipy.stats
# ans= scipy.stats.ks_2samp(hig,low)
# print '{:6.2e} {:6.2e}'.format(low.mean(), low.std())
# print '{:6.2e} {:6.2e}'.format(hig.mean(), hig.std())
plt.hist([lowlim[1],higlim[1]],label=['low mass','high mass'],normed=True,bins=20)
plt.xlabel(r'$A_{\delta U}-A_{\delta U}|_0$')
plt.legend()
pp = PdfPages("output_fix3/childress2.pdf")
plt.savefig(pp,format='pdf')
pp.close()
plt.close()