27 os.environ[
"MPLCONFIGDIR"] =
"/tmp"
29 matplotlib.rcParams.update({
34 import matplotlib.pyplot
as plt
39 from gstlal
import reference_psd
40 from glue.ligolw
import ligolw
41 from glue.ligolw
import array
as ligolw_array
42 from glue.ligolw
import lsctables
43 from glue.ligolw
import param
as ligolw_param
44 from glue.ligolw
import utils
as ligolw_utils
45 from pylal
import series
as lalseries
46 from gstlal
import far
49 from gstlal
import plotpsd
50 from gstlal
import plotfar
54 ligolw_array.use_in(LIGOLWContentHandler)
55 ligolw_param.use_in(LIGOLWContentHandler)
56 lsctables.use_in(LIGOLWContentHandler)
59 return 10**math.ceil(math.log10(x))
62 return 10**math.floor(math.log10(x))
65 <style type="text/css">
68 font: 12pt arial, sans-serif;
72 font: 18pt arial, sans-serif;
78 box-shadow: 0 0 4px 1px black;
82 font: 18pt arial, sans-serif;
87 font: 18pt arial, sans-serif;
92 font: 14pt arial, sans-serif;
106 font: 14pt arial, sans-serif;
108 border: 2px solid gray;
112 box-shadow: 10px 10px 5px #888888;
117 min-height: 7in; /* This part sucks */
129 border: 1px solid #ccc;
147 border: 1px solid #ccc;
150 [type=radio]:checked ~ label {
152 border-bottom: 1px solid white;
156 [type=radio]:checked ~ label ~ .content {
165 return time.time() - 315964785
168 def __init__(self, form):
171 self.
ifos = form[
"ifos"][0].split(
",")
173 for id
in [
'%04d' % (job,)
for job
in range(int(form[
"id"][0].split(
",")[0]), 1+int(form[
"id"][0].split(
",")[1]))]:
174 url =
'%s/%s%s' % (self.
directory, id,
"_registry.txt")
176 with open(url,
"r") as tmp:
177 self.registry[id] = urlparse.urlparse(tmp.readline()).netloc
183 def __init__(s, *args, **kwargs):
184 dict.__init__(s, *args, **kwargs)
185 def __getitem__(s, k, web = self):
193 def load_data(self, datatype):
194 self.
found[datatype] = {}; self.
missed[datatype] = {}
196 fname =
"%s/%s/%s" % (self.
directory, id, datatype)
197 if datatype ==
"psds":
199 self.
found[datatype][id] = lalseries.read_psd_xmldoc(ligolw_utils.load_url(
"%s.xml" % fname, contenthandler = LIGOLWContentHandler))
201 self.
missed[datatype][id] = {}
202 elif datatype ==
"likelihood":
206 self.
missed[datatype][id] = {}
209 self.
found[datatype][id] = numpy.loadtxt(
"%s.txt" % fname)
210 if len(self.
found[datatype][id].shape) == 1:
211 self.
found[datatype][id] = numpy.array([self.
found[datatype][id],])
213 self.
missed[datatype][id] = numpy.array([])
215 self.
missed[datatype][id] = numpy.array([])
218 if not self.
found[
"latency_history"]:
219 return "<em class=red>NO COINCIDENT EVENTS FOUND!</em>"
222 out = [l[0,1]
for l
in self.
found[
"latency_history"].values()]
223 return "%.2f ± %.2f" % (numpy.mean(out), numpy.std(out))
225 def time_since_last(self):
226 out = [now() - l[0,0]
for l
in self.
found[
"latency_history"].values()]
227 return "%.2f ± %.2f" % (numpy.mean(out), numpy.std(out))
229 def average_up_time(self):
231 for ifo
in self.
ifos:
239 out[ifo] = [sum(l[0,1:4])/fac
for l
in self.
found[
"%s/state_vector_on_off_gap" % ifo].values()]
240 return "<br>".join([
"%s=%.0e s" % (ifo, numpy.mean(v))
for ifo,v
in out.items()])
242 def setup_plot(self):
243 fig = plt.figure(figsize=(15, 4.0),)
244 fig.patch.set_alpha(0.0)
245 h = fig.add_subplot(111, axisbg =
'k')
246 plt.subplots_adjust(top = 0.93, left = .062, right = 0.98, bottom = 0.45)
249 def finish_plot(self, ylim):
250 plt.grid(color=(0.1,0.4,0.5), linewidth=2)
251 ticks = [
"%s : %s " % (id, reg)
for (id, reg)
in sorted(self.registry.items())]
252 plt.xticks(numpy.arange(len(ticks))+.3, ticks, rotation=90, fontsize = 10)
253 plt.xlim([0, len(ticks)])
255 tickpoints = numpy.linspace(ylim[0], ylim[1], 8)
256 ticks = [
"%.1e" % (10.**t,)
for t
in tickpoints]
257 plt.yticks(tickpoints, ticks)
258 f = StringIO.StringIO()
259 plt.savefig(f, format=
"png")
260 out =
'<img src="data:image/png;base64,' + base64.b64encode(f.getvalue()) +
'"></img>'
264 def to_png(self, fig = None):
265 f = StringIO.StringIO()
267 fig.savefig(f, format=
"png")
269 plt.savefig(f, format=
"png")
270 out =
'<img src="data:image/png;base64,' + base64.b64encode(f.getvalue()) +
'"></img>'
274 def plot(self, datatype, ifo = None):
276 found = self.
found[datatype]
277 missed = self.
missed[datatype]
278 if datatype ==
"latency_history":
280 if datatype ==
"snr_history":
281 return self.
plot_snr(fig, h, found, missed)
282 if "state_vector" in datatype:
284 if "bank" in datatype:
285 return self.
plot_single_col(fig, h, found, missed, col = 2, title =
"Chirp Mass")
286 if "ram_history" in datatype:
287 return self.
plot_ram(fig, h, found, missed)
289 def plot_latency(self, fig, h, found, missed):
290 found_x = range(len(found))
291 found_y = numpy.log10(numpy.array([found[k][-1,1]
for k
in sorted(found)]))
292 time_y = numpy.log10(now() - numpy.array([found[k][-1,0]
for k
in sorted(found)]))
294 max_y = max(time_y.max(), found_y.max())
297 missed_x = range(len(missed))
298 missed_y = numpy.ones(len(missed_x)) * max_y
300 h.bar(missed_x, missed_y, color=
'r', alpha=0.9, linewidth=2)
301 h.bar(found_x, found_y, color='w', alpha=0.9, linewidth=2)
302 h.bar(found_x, time_y, color=
'w', alpha=0.7, linewidth=2)
303 plt.title(
"Time (s) since last event (gray) and latency (white)")
306 def plot_snr(self, fig, h, found, missed):
307 found_x = range(len(found))
308 maxsnr_y = numpy.log10(numpy.array([found[k][:,1].max()
for k
in sorted(found)]))
309 mediansnr_y = numpy.log10(numpy.array([numpy.median(found[k][:,1])
for k
in sorted(found)]))
312 max_y = max(maxsnr_y)
315 missed_x = range(len(missed))
316 missed_y = numpy.ones(len(missed_x)) * max_y
318 h.bar(missed_x, missed_y, color=
'r', alpha=0.9, linewidth=2)
319 h.bar(found_x, mediansnr_y, color='w', alpha=0.9, linewidth=2)
320 h.bar(found_x, maxsnr_y, color=
'w', alpha=0.7, linewidth=2)
321 plt.title(
"SNR of last 1000 events: max (gray) and median (white)")
325 def plot_livetime(self, fig, h, found, missed, ifo):
326 found_x = range(len(found))
328 on_y = numpy.log10(numpy.array([max(found[k][0][1],1)
for k
in sorted(found)]))
329 off_y = numpy.log10(numpy.array([max(found[k][0][2],1)
for k
in sorted(found)]))
330 gap_y = numpy.log10(numpy.array([max(found[k][0][3],1)
for k
in sorted(found)]))
333 on_y -= numpy.log10(16)
334 off_y -= numpy.log10(16)
335 gap_y -= numpy.log10(16)
338 max_y = max(on_y.max(), off_y.max(), gap_y.max())
339 min_y = min(on_y.min(), off_y.min(), gap_y.min())
344 missed_x = range(len(missed))
345 missed_y = numpy.ones(len(missed_x)) * max_y
347 h.bar(missed_x, missed_y, color=
'r', alpha=0.9, linewidth=2)
348 h.bar(found_x, off_y, color='w', alpha=0.7, linewidth=2)
349 h.bar(found_x, gap_y, color=
'b', alpha=0.5, linewidth=2)
350 h.bar(found_x, on_y, color=
'w', alpha=0.5, linewidth=2)
351 plt.title(
'%s Up time (gray) Down time (white) Dropped time (blue)' % (ifo,))
354 def plot_single_col(self, fig, h, found, missed, col = 2, title = ''):
355 found_x = range(len(found))
356 found_y = numpy.log10(numpy.array([found[k][0][col]
for k
in sorted(found)]))
359 max_y, min_y = max(found_y), min(found_y)
362 missed_x = range(len(missed))
363 missed_y = numpy.ones(len(missed_x)) * max_y
365 h.bar(missed_x, missed_y, color=
'r', alpha=0.9, linewidth=2)
366 h.bar(found_x, found_y, color='w', alpha=0.9, linewidth=2)
370 def plot_ram(self, fig, h, found, missed):
372 found_x = range(len(found))
373 found_y = numpy.log10(numpy.array([found[k][0,1]
for k
in sorted(found)]))
376 max_y, min_y = max(found_y), min(found_y)
379 missed_x = range(len(missed))
380 missed_y = numpy.ones(len(missed_x)) * max_y
382 h.bar(missed_x, missed_y, color=
'r', alpha=0.9, linewidth=2)
383 h.bar(found_x, found_y, color='w', alpha=0.9, linewidth=2)
384 plt.title(
"max RAM usage (GB)")
391 def livetime_pie(self):
394 for ifo
in self.
ifos:
395 fig = plt.figure(figsize=(5,3),)
396 fig.patch.set_alpha(0.0)
397 h = fig.add_subplot(111, axisbg =
'k', aspect=
'equal')
398 plt.subplots_adjust(bottom = 0, left = .25, top = 1, right = .75)
401 discontdata = self.
found[
"%s/strain_add_drop" % ifo][id]
402 livetimedata = self.
found[
"%s/state_vector_on_off_gap" % ifo][id]
403 dt = livetimedata[0,2]
404 lt = livetimedata[0,1]
405 discont = discontdata[0,1]
411 data = [dt, lt, discont]
412 explode = [0.0, 0, 0.15]
413 labels = [
"OFF : %g (s)" % dt,
"ON : %g (s)" % lt,
"MIA : %g (s)" % discont]
415 h.pie(data, shadow=
True, explode = explode, labels = labels, autopct=
'%1.1f%%', colors = (
'0.5',
'1.0', (0.7, 0.7, 1.)))
421 def psdplot(self, fmin = 10., fmax = 2048.):
424 psds = self.
found[
"psds"][id]
425 fig = plotpsd.plot_psds(psds)
426 out += self.
to_png(fig = fig)
429 def snrchiplot(self, binnedarray_string):
432 likelihood, nu, nu = self.
found[
"likelihood"][id]
433 for ifo
in self.
ifos:
435 out += self.
to_png(fig = fig)
441 likelihood, ranking_data, nu = self.
found[
"likelihood"][id]
443 out += self.
to_png(fig = fig)
447 def plothistory(self, dataurl, xlabel = "", ylabel = "", title = ""):
451 data = self.
found[dataurl][id]
453 out +=
"<em>Data not found</em>"
455 fig = plt.figure(figsize=(5,3.5),)
456 fig.patch.set_alpha(0.0)
457 h = fig.add_subplot(111, axisbg =
'k')
458 plt.subplots_adjust(bottom = 0.2, left = .16)
459 plt.grid(color=(0.1,0.4,0.5), linewidth=2)
461 h.semilogy(data[:,0] - data[-1,0], data[:,1],
'w', alpha=0.75, linewidth=2)
462 plt.ylim([min(data[:,1]), max(data[:,1])])
463 locs = [min(data[:,1]), numpy.median(data[:,1]), max(data[:,1])]
464 labels = [
'%.2g' % lab
for lab
in locs]
465 plt.yticks(locs, labels)
475 likelihood, ranking_data, nu = self.
found[
"likelihood"][id]
476 ranking_data.finish()
479 out += self.
to_png(fig = fig)