gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
gstlal_plot_psd_horizon
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 import sys
20 import matplotlib
21 matplotlib.use('Agg')
22 from matplotlib import pyplot
23 import numpy
24 from glue.ligolw import ligolw
25 from glue.ligolw import array
26 from glue.ligolw import param
27 array.use_in(ligolw.LIGOLWContentHandler)
28 param.use_in(ligolw.LIGOLWContentHandler)
29 from glue.ligolw import utils
30 from gstlal import reference_psd
31 from pylal import series as lalseries
32 
33 ## @file
34 # A program to plot the horizon distance as a function of time from various psd estimates; See gstlal_plot_psd_horizon for usage.
35 #
36 # Plot the horizon distance as a function of time from PSDs computed from gstlal_reference_psd
37 #
38 # ### Usage:
39 #
40 # gstlal_plot_psd OUTPUT-NAME PSD1 PSD2 ...
41 #
42 # e.g.,
43 #
44 # gstlal_plot_psd horizon.png psd1.xml.gz psd2.xml.gz
45 #
46 
47 if len(sys.argv) < 3:
48  print "USAGE gstlal_plot_psd output_name psd_file1 psd_file2 ..."
49  sys.exit()
50 
51 outname = sys.argv[1]
52 colors = {"H1":"r", "H2":"b", "L1":"g", "V1":"m", "H1H2":"c", "E1":"b", "E2":"r", "E3":"g"}
53 horizons = dict((k, []) for k in colors)
54 times = dict((k, []) for k in colors)
55 for f in sys.argv[2:]:
56  psds = lalseries.read_psd_xmldoc(utils.load_filename(f, verbose = True, contenthandler = ligolw.LIGOLWContentHandler))
57  for ifo, psd in psds.items():
58  if psd is not None:
59  times[ifo].append(int(psd.epoch))
60  horizons[ifo].append(reference_psd.horizon_distance(psd, 1.4, 1.4, 8, 10, 2048))
61 
62 pyplot.figure(figsize=(12,4))
63 pyplot.subplot(121)
64 minh, maxh = (float("inf"), 0)
65 mint = min([min(t) for t in times.values() if t])
66 for ifo in colors:
67  if len(horizons[ifo]) > 0:
68  pyplot.semilogy((numpy.array(times[ifo]) - mint) / 1000., horizons[ifo], 'x', color = colors[ifo], label = ifo)
69  maxh = max(maxh, max(horizons[ifo]))
70  minh = min(minh, min(horizons[ifo]))
71 #pyplot.legend()
72 pyplot.xlabel('Time (ks) from GPS %d' % mint)
73 pyplot.ylabel('Mpc')
74 pyplot.grid()
75 pyplot.subplot(122)
76 binvec = numpy.linspace(minh, maxh, 25)
77 for ifo in colors:
78  if len(horizons[ifo]) > 0:
79  pyplot.hist(horizons[ifo], binvec, color = colors[ifo], alpha = 0.5, label = ifo)
80 pyplot.legend()
81 pyplot.xlabel("Mpc")
82 pyplot.ylabel("Count")
83 pyplot.savefig(outname)