3 # Copyright (C) 2012 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.
22 from matplotlib
import pyplot
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
34 # A program to plot the horizon distance as a function of time from various psd estimates; See gstlal_plot_psd_horizon for usage.
36 # Plot the horizon distance as a function of time from PSDs computed from gstlal_reference_psd
40 # gstlal_plot_psd OUTPUT-NAME PSD1 PSD2 ...
44 # gstlal_plot_psd horizon.png psd1.xml.gz psd2.xml.gz
48 print
"USAGE gstlal_plot_psd output_name psd_file1 psd_file2 ..."
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():
59 times[ifo].append(
int(psd.epoch))
60 horizons[ifo].append(reference_psd.horizon_distance(psd, 1.4, 1.4, 8, 10, 2048))
62 pyplot.figure(figsize=(12,4))
64 minh, maxh = (float(
"inf"), 0)
65 mint = min([min(t)
for t in times.values()
if t])
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]))
72 pyplot.xlabel(
'Time (ks) from GPS %d' % mint)
76 binvec = numpy.linspace(minh, maxh, 25)
78 if len(horizons[ifo]) > 0:
79 pyplot.hist(horizons[ifo], binvec, color = colors[ifo], alpha = 0.5, label = ifo)
82 pyplot.ylabel(
"Count")
83 pyplot.savefig(outname)