-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigault15.py
executable file
·144 lines (111 loc) · 4.01 KB
/
rigault15.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
#!/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 sivel
f = open('forAlex_tmp16sept2016_localhost_parameters.dat', 'r')
for i in xrange(1):
f.readline()
data = [x.split() for x in f.readlines()]
f.close()
data=numpy.array(data)
rnames= data[:,0]
data=numpy.delete(data,0,axis=1)
rdata=data.astype('float')
f = open('temp15.pkl','rb')
(fit, _) = pickle.load(f)
f.close()
pkl_file = open('gege_data.pkl', 'r')
data = pickle.load(pkl_file)
pkl_file.close()
sivel, sivel_err, _, _ = sivel.sivel(data)
head = ['lmass','lsfr','lssfr','gmass']
use = numpy.isfinite(sivel)
names= numpy.array(data['snlist'])[use]
# Figure out intersection between the two lists
i = numpy.intersect1d(names, rnames, assume_unique=True)
inda = numpy.zeros(len(i),dtype='int')
indr = numpy.zeros(len(i),dtype='int')
for j in xrange(len(i)):
inda[j] = numpy.where(names == i[j])[0]
indr[j] = numpy.where(rnames == i[j])[0]
# the intrinsic parameter is A_I
(x, xmin, xmax) = numpy.percentile(fit['rho1'][:,4][:,None]*fit['R'],(50,50-34,50+34),axis=0)
# print the table of intrinsic parameters
# for x1,x2,x3,x4 in zip(names,x,xmin,xmax):
# print x1,x2,x3,x4
# wefwe
fig, axes = plt.subplots(nrows=4)
for i in xrange(4):
axes[i].errorbar(rdata[indr,3*i],x[inda],xerr=[rdata[indr,3*i+2], rdata[indr,3*i+1]], yerr=[x[inda]-xmin[inda],xmax[inda]-x[inda]],fmt='o')
axes[i].set_ylabel(r'$A_{\delta I}$')
axes[i].set_xlabel(head[i])
axes[i].set_ylim((-0.1,0.03))
fig.subplots_adjust(hspace=.3)
fig.set_size_inches(8,11)
pp = PdfPages("output15/rigault.pdf")
plt.savefig(pp,format='pdf')
pp.close()
plt.close()
# wefwe
# i=2
# plt.errorbar(rdata[indr,3*i],x[inda],xerr=[rdata[indr,3*i+2], rdata[indr,3*i+1]], yerr=[x[inda]-xmin[inda],xmax[inda]-x[inda]],fmt='o')
# plt.ylabel(r'$E_\delta(B-V)$')
# plt.xlabel(r'local sSFR')
# pp = PdfPages("output15/rigaultssfr.pdf")
# plt.savefig(pp,format='pdf')
# pp.close()
# plt.close()
# Calculate the weighted mean of low and high mass hosts
wm = numpy.where(rdata[indr,9] < 10)[0]
x_=x[inda[wm]]
dx = (xmax[inda[wm]]-xmin[inda[wm]])/2.
dx2 = numpy.sum(1/dx**2)
low1 = numpy.sum(x_/dx**2)/dx2
dlow1= 1/numpy.sqrt(dx2)
print r"${:9.4f} \pm {:9.4f}$".format(low1, dlow1)
wm = numpy.where(rdata[indr,9] > 10)[0]
x_=x[inda[wm]]
dx = (xmax[inda[wm]]-xmin[inda[wm]])/2.
dx2 = numpy.sum(1/dx**2)
high1 = numpy.sum(x_/dx**2)/dx2
dhigh1= 1/numpy.sqrt(dx2)
print r"${:9.4f} \pm {:9.4f}$".format(high1, dhigh1)
i=3
# (x, xmin, xmax) = numpy.percentile(fit['rho1'][:,4][:,None]*fit['R'],(50,50-34,50+34),axis=0)
plt.errorbar(rdata[indr,3*i],x[inda],xerr=[rdata[indr,3*i+2], rdata[indr,3*i+1]], yerr=[x[inda]-xmin[inda],xmax[inda]-x[inda]],fmt='o')
plt.plot([5,10],[low1,low1],color='black')
plt.plot([5,10],[low1+dlow1,low1+dlow1],linestyle='--',color='black')
plt.plot([5,10],[low1-dlow1,low1-dlow1],linestyle='--',color='black')
plt.plot([10,12],[high1,high1],color='black')
plt.plot([10,12],[high1+dhigh1,high1+dhigh1],linestyle='--',color='black')
plt.plot([10,12],[high1-dhigh1,high1-dhigh1],linestyle='--',color='black')
plt.ylabel(r'$A_{\delta I}$')
plt.xlabel(r'Host Mass ($\log(M_\odot)$)')
plt.ylim((-0.1,0.03))
pp = PdfPages("output15/rigault3.pdf")
plt.savefig(pp,format='pdf')
pp.close()
plt.close()
wm = numpy.where(rdata[indr,9] < 10)[0]
low = (fit['rho1'][:,4][:,None]*fit['R'][:,wm]).flatten()
wm = numpy.where(rdata[indr,9] > 10)[0]
hig = (fit['rho1'][:,4][:,None]*fit['R'][:,wm]).flatten()
plt.hist([low,hig],20,label=['low mass','high mass'],normed=True,range=(-0.05,0.05))
plt.xlabel(r'$A_{\delta I}$')
plt.xlim((-0.05,0.05))
plt.legend()
pp = PdfPages("output15/rigault2.pdf")
plt.savefig(pp,format='pdf')
pp.close()
plt.close()
import scipy.stats
wm = numpy.where(rdata[:,9] < 10)[0]
low = numpy.median(fit['rho1'][:,4][:,None]*fit['R'][:,wm],axis=0)
wm = numpy.where(rdata[:,9] > 10)[0]
hig = numpy.median(fit['rho1'][:,4][:,None]*fit['R'][:,wm],axis=0)
ans= scipy.stats.ks_2samp(hig,low)
print ans