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