3 # Copyright (C) 2011 Chad Hanna
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 os.environ[
"MPLCONFIGDIR"] =
"/tmp"
27 import matplotlib.pyplot as plt
31 from urlparse
import urlparse
33 form = cgi.FieldStorage()
35 from pylal
import rate
40 return float(lal.UTCToGPS(time.gmtime()))
43 f = StringIO.StringIO()
44 plt.savefig(f, format=
"png")
45 sys.stdout.write(
"Content-type: image/png\r\n\r\n" + f.getvalue() )
48 def read_registry(dir, dataurl, ids):
51 url =
'%s/%s%s' % (dir, id, dataurl)
54 nodedict[id] = urlparse(tmp.readline()).netloc
61 fig = plt.figure(figsize=(20,5),)
62 fig.patch.set_alpha(0.0)
63 h = fig.add_subplot(111, axisbg =
'k')
64 plt.subplots_adjust(left = .062, right = 0.98, bottom = 0.3)
67 def finish_plot(ids, registry, ylim, title=
''):
68 plt.grid(color=(0.1,0.4,0.5), linewidth=2)
69 ticks = [
"%s : %s " % (id, registry[id]) for id in ids]
70 plt.xticks(numpy.arange(len(ids))+.3, ticks, rotation=90, fontsize = 10)
71 plt.xlim([0, len(ids)])
73 tickpoints = numpy.linspace(ylim[0], ylim[1], 8)
74 ticks = [
"%.1e" % (10.**t,) for t in tickpoints]
75 plt.yticks(tickpoints, ticks, fontsize = 14)
76 plt.title(title, fontsize = 18)
81 idrange = [int(n) for n in form.getvalue(
"id").split(
",")]
82 #FIXME relies on 4 digit ids
83 ids = [
'%04d' % (job,) for job in range(idrange[0], idrange[1]+1)]
87 raise ValueError(
"must specify dir")
89 raise ValueError(
"must specify id")
92 directory = form.getvalue(
"dir")
93 start = form.getvalue(
"start")
94 stop = form.getvalue(
"stop")
95 reg = read_registry(form.getvalue(
"dir"),
"_registry.txt", ids)
100 for i, id in enumerate(ids):
102 fname =
"%s/%s/%s.txt" % (directory, id,
"snr_history")
103 yaxis.append(float(open(
"%s/%s/%s.txt" % (directory, id,
"bank")).readline().split()[2]))
106 print>>sys.stderr,
"couldn't open ", fname
108 yaxis = numpy.array(sorted(set(yaxis)))
111 if start is not None and stop is not None:
112 ba = rate.BinnedArray(rate.NDBins((rate.LinearBins(float(start) - time_now, float(stop) - time_now, 900), rate.IrregularBins(yaxis))))
114 ba = rate.BinnedArray(rate.NDBins((rate.LinearBins(-4500,-900,900), rate.IrregularBins(yaxis))))
116 print >>sys.stderr, min(yaxis), max(yaxis)
118 window = rate.gaussian_window(10, 1, sigma = 3)
119 print >> sys.stderr, ba.array.shape
122 for i, id in enumerate(ids):
124 fname =
"%s/%s/%s.txt" % (directory, id,
"snr_history")
125 dur = float(open(
"%s/%s/%s.txt" % (directory, id,
"bank")).readline().split()[2])
126 for line in open(fname):
127 thist, thissnr = line.split()
128 t = float(thist)-time_now
130 if ba[t,dur] < thissnr:
136 print>>sys.stderr,
"couldn't open ", fname
138 matplotlib.rcParams.update({
"text.usetex": True})
140 rate.filter_array(ba.array, window)
141 fig = pylab.figure(figsize=(20,4.0))
142 pylab.title(
'max $\\rho_c$ in coincidence')
143 pylab.xlabel(
"time since %d (s)" % (
int(time_now),))
144 pylab.ylabel(
"$\mathcal{M} (M_\odot)$")
145 pylab.xlim([ba.centres()[0][0], ba.centres()[0][-1]])
146 pylab.ylim([ba.centres()[1][0], ba.centres()[1][-1]])
147 pylab.pcolormesh(ba.centres()[0], ba.centres()[1], ba.array.T, norm = matplotlib.colors.LogNorm())