-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob_trigger.py
204 lines (174 loc) · 6.51 KB
/
prob_trigger.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
#!/usr/bin/env python
# 2019
# L. Strolger, STScI
# a simple routine to help decide to execute a UDToO
# for KNe possibly associated with neutron star GW event.
#
"""
prob_trigger.py [--options]
returns the likelihood that we should execute a trigger
options are:
--verbose (shows all output, by default)
--quiet (shows only the likelihood)
--help
--plotit (generates plots)
--area = [float] (in deg2)
--distance = [float] (in Mpc)
--bprob = [float] (BNS probablity)
--velocity = [float] (spectral expansion velocity, if known)
--hours = [float] (time since burst, in hours)
Options can be combined. There are some default values for testing
"""
import os,sys,pdb,scipy,glob
from pylab import *
from strolger_util import util as u
d0 = 150 #Mpc
q0 = 1000 #deg2
b0 = 1 #BNS prob
verbose=True
hours=12 ##from burst
velocity = 0
plotit=False
def sigmoid_sn(x,*p):
x0, T, k, b = p
b = sqrt(b**2)
T = sqrt(T**2)
y = (T / (1 + exp(-k*(x-x0))))-b
return y
def prob_confusion(d0, q0, verbose=True, plotit=True):
p0 = (1460, 1, -0.003, 0.) #defines the sigmoid probablity function
p1 = (1460, 1, 0.003, 0.) #defines the sigmoid probablity function
local_grp_density = 2./14 #galaxies per Mpc^-3
ave_lum = 10**12 #in sol. lum
snu = 5 ## on average, SNe per Century per 10**12 L_sol
Ngal = q0 *pi**2/180**2*d0**2*local_grp_density
Prob = sigmoid_sn(Ngal, *p0)
Nsn=Ngal*ave_lum*snu*1e-10*1e-2*5/365.
## Nsn = Ngal/100*5/365*5
Nlo=Nsn-Nsn/5*2
Nhi=Nsn/5*10.-Nsn
if verbose:print('Ngal=%.1f, Nsn=%.1f+%.1f-%.1f, Nprob=%.2f' %(Ngal, Nsn, Nhi, Nlo, Prob))
if plotit:
clf()
xx = arange(0,5000,10) ## number of potential hosts
ax1 = subplot(221)
ax2 = subplot(222)
ax3 = subplot(223)
ax4 = subplot(224)
## limit of confusion with other SNe
ax1.plot(xx, sigmoid_sn(xx, *p0), 'b-', label=r'P$_{\rm good}$')
ax5 = ax1.twinx()
ax5.plot(xx, sigmoid_sn(xx, *p1), 'b--', label=r'P$_{\rm bad}$')
## by volume
volume = xx / 0.14 ## local grp has 2/14 Mpc^-3
ax2.plot(volume/1e6, sigmoid_sn(xx, *p0), 'b-', label=r'P$_{\rm good}$')
ax6 = ax2.twinx()
ax6.plot(volume/1e6, sigmoid_sn(xx, *p1), 'b--', label=r'P$_{\rm bad}$')
## by distance
omegas = linspace(2000, 20000, 5) #deg^2
my_map = plt.get_cmap('RdBu_r')
colors = r_[linspace(0.1,1,len(omegas)),linspace(0.1,1,len(omegas))]
my_colors = my_map(colors)
for i,omega in enumerate(omegas):
distance = sqrt(volume/omega*(180/pi)**2)
if i==0:
ax3.plot(distance, sigmoid_sn(xx, *p0), '-', color=my_colors[i], label=r'%2d $\times10^3$deg$^2$'%(omega/1e3))
else:
ax3.plot(distance, sigmoid_sn(xx, *p0), '-', color=my_colors[i], label=r'%2d'%(omega/1e3))
## by angular size
distances = [30, 40, 80, 100, 150]#, 200]
colors = r_[linspace(0.1,1,len(distances)),linspace(0.1,1,len(distances))]
my_colors = my_map(colors)
for i,distance in enumerate(distances):
omega = (180/pi)**2*volume/(distance**2)
ax4.plot(omega/1e3, sigmoid_sn(xx, *p0),'-', color=my_colors[i], label='%2d Mpc'%distance)
ax3.set_xlim(0,200)
ax4.set_xlim(0,20)
ax1.set_xlabel('Number of Normal Galaxies')
ax2.set_xlabel(r'Volume (Gpc$^3$)')
ax3.set_xlabel('Distance (Mpc)')
ax4.set_xlabel(r'Sky localization (10$^3$ deg$^2$)')
tight_layout()
lg1=ax1.legend(frameon=False, loc=4)
lg2=ax2.legend(frameon=False, loc=4)
lg5=ax5.legend(frameon=False, loc=1)
lg6=ax6.legend(frameon=False, loc=1)
lg3=ax3.legend(frameon=False)
lg4=ax4.legend(frameon=False)
ax5.set_yticks([])
ax6.set_yticks([])
u.allblack2(ax1, lg1)
u.allblack2(ax2, lg2)
u.allblack2(ax3, lg3)
u.allblack2(ax4, lg4)
u.allblack2(ax5, lg5)
u.allblack2(ax6, lg6)
savefig('prob_ccsne.png', transparent=True)
return(Prob)
def prob_spec(velocity, verbose=True, plotit=True):
p0=(10000, 1., 1./2000, 0.)
Prob = sigmoid_sn(velocity, *p0)
if verbose: print('Prob_velocity = %.2f' %Prob)
if plotit:
clf()
velocities = arange(0, 30000, 500)
ax=subplot(111)
ax.plot(velocities, sigmoid_sn(velocities, *p0), 'r-')
ax.set_xlabel('Expansion Velocity')
savefig('prob_spec.png')
return(Prob)
def prob_time(hours_since_burst, verbose=True, plotit=True):
Prob=exp(-hours/24/7.)
if verbose: print('Prob_hours=%.2f' %Prob)
if plotit:
xx=arange(0,14,1/24.)
ax=subplot(111)
ax.plot(xx,exp(-xx/7.), 'r-')
ax.set_xlabel('Trigger Submitted (Days)')
savefig('prob_time.png')
return(Prob)
if __name__=='__main__':
import getopt
try:
opt, arg = getopt.getopt(
sys.argv[1:],"v,h",
longopts=["verbose", "quiet","help","plotit",
"distance=", "area=", "bprob=",
"velocity=","hours="])
except getopt.GetoptError:
print ("Error : incorrect option or missing argument.")
print (__doc__)
sys.exit(1)
for o, a in opt:
if o in ["-h", "--help"]:
print (__doc__)
sys.exit(0)
elif o == "-v":
verbose=True
elif o == "--verbose":
verbose=True
elif o == "--quiet":
verbose=False
elif o =="--plotit":
plotit=True
elif o =="--distance":
d0 = float(a)
elif o =="--area":
q0 = float(a)
elif o =="--bprob":
b0 = float(a)
elif o =="--velocity":
velocity = float(a)
elif o =="--hours":
hours = float(a)
if verbose:
print('Assuming distance = %.1f Mpc, area = %.1f deg2, BNS_prob=%.1f, OT_prob = 1.0' %(d0,q0,b0),)
print('hours since burst= %.1f hours, spec_velocity = %.1f km/s (if zero, no spectral confirmation)' %(hours, velocity))
P_ccsne=prob_confusion(d0, q0, verbose=verbose, plotit=plotit)
if verbose: print('BNS_prob=%.1f' %b0)
P_time=prob_time(hours, verbose=verbose, plotit=plotit)
if velocity != 0.:
P_spec=prob_spec(velocity, verbose=verbose,plotit=plotit)
else:
P_spec=1.0
print (" Likelihood that we should trigger = %.1f" %(P_ccsne*b0*P_time*P_spec))