gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
gstlal_inspiral_plot_svd_bank
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2012 Chad Hanna
4 #
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.
9 #
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.
14 #
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.
18 
19 ## @file
20 # A program to plot the contents of a gstlal_svd_bank file by reconstructing the waveforms
21 
22 import os
23 import sys
24 import copy
25 
26 import pygtk
27 pygtk.require('2.0')
28 import pygst
29 pygst.require('0.10')
30 
31 from gstlal.svd_bank import read_banks
32 import numpy
33 import cgi
34 import cgitb
35 cgitb.enable()
36 form = cgi.FieldStorage()
37 
38 import matplotlib
39 matplotlib.use('Agg')
40 from matplotlib import pyplot
41 
42 from glue.ligolw import lsctables
43 
44 print >>sys.stdout, 'Expires: Mon, 26 Jul 1997 05:00:00 GMT'
45 print >>sys.stdout, 'Content-type: text/html\r\n'
46 
47 print """
48 <html>
49 <head>
50 <meta http-equiv="Pragma" content="no-cache">
51 <meta http-equiv="Expires" content="-1">
52 <meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
53 </head>
54 <body bgcolor=#E0E0E0>
55 """
56 
57 # title
58 print """
59 <font size=10>SVD BANK</font><br>
60 """
61 
62 
63 for bank in read_banks(form.getlist("url")[0]):
64 
65  # get the template number
66  tmps = bank.bank_fragments[0].mix_matrix.shape[1] / 2
67  row = bank.sngl_inspiral_table
68 
69  for n in range(tmps):
70  mc, s1z, s2z = row[n].mchirp, row[n].spin1z, row[n].spin2z
71 
72  pyplot.figure(figsize=(18,6))
73  pyplot.subplot(211)
74  print "<div>"
75  maxrate = 0
76  mint = 0
77  for frag in bank.bank_fragments:
78  m = frag.mix_matrix
79  s = frag.singular_values
80  u = frag.orthogonal_template_bank
81  h = numpy.dot(m.T, u)
82  t = numpy.linspace(-frag.end, -frag.start, h.shape[1])
83  pyplot.plot(t, h[2 * n,:] * frag.rate**.5)
84  pyplot.plot(t, h[2 * n + 1,:] * frag.rate**.5)
85  maxrate = max(maxrate, frag.rate)
86  mint = min(t[0], mint)
87  pyplot.xlabel('time (s) mc:%.2f s1z:%.2f s2z:%.2f' % (mc, s1z, s2z))
88  pyplot.xlim([-.25, 0])
89 
90  pyplot.subplot(212)
91  pyplot.xlabel('samples')
92  l = len(bank.autocorrelation_bank[n,:])
93  ts = l / float(maxrate)
94  t = numpy.linspace(-ts, 0, l)
95  pyplot.plot(numpy.real(bank.autocorrelation_bank[n,:]))
96  pyplot.plot(numpy.imag(bank.autocorrelation_bank[n,:]))
97  pyplot.savefig(sys.stdout, format="svg")
98  print "</div>"
99 
100 
101 print "</body></html>"