gstlal  1.4.1
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 
20 ### Plot the horizon distance as a function of time from PSDs computed from
21 ### gstlal_reference_psd
22 
23 
24 import sys
25 import matplotlib
26 matplotlib.use('Agg')
27 from matplotlib import pyplot
28 import numpy
29 import lal
30 import lal.series
31 from glue.ligolw import utils as ligolw_utils
32 from gstlal import plotutil
33 from gstlal import reference_psd
34 
35 if len(sys.argv) < 3:
36  print "USAGE gstlal_plot_psd output_name psd_file1 psd_file2 ..."
37  sys.exit()
38 
39 outname = sys.argv[1]
40 horizons = {}
41 times = {}
42 for f in sys.argv[2:]:
43  psds = lal.series.read_psd_xmldoc(ligolw_utils.load_filename(f, verbose = True, contenthandler = lal.series.PSDContentHandler))
44  for ifo, psd in psds.items():
45  if psd is not None:
46  times.setdefault(ifo, []).append(int(psd.epoch))
47  horizons.setdefault(ifo, []).append(reference_psd.HorizonDistance(10., 2048., psd.deltaF, 1.4, 1.4)(psd, 8.)[0])
48 
49 pyplot.figure(figsize=(12,4))
50 pyplot.subplot(121)
51 minh, maxh = (float("inf"), 0)
52 mint = min([min(t) for t in times.values() if t])
53 for ifo in horizons:
54  if len(horizons[ifo]) > 0:
55  pyplot.semilogy((numpy.array(times[ifo]) - mint) / 1000., horizons[ifo], 'x', color = plotutil.colour_from_instruments([ifo]), label = ifo)
56  maxh = max(maxh, max(horizons[ifo]))
57  minh = min(minh, min(horizons[ifo]))
58 #pyplot.legend()
59 pyplot.xlabel('Time (ks) from GPS %d' % mint)
60 pyplot.ylabel('Mpc')
61 pyplot.grid()
62 pyplot.subplot(122)
63 binvec = numpy.linspace(minh, maxh, 25)
64 for ifo in horizons:
65  if len(horizons[ifo]) > 0:
66  pyplot.hist(horizons[ifo], binvec, color = plotutil.colour_from_instruments([ifo]), alpha = 0.5, label = ifo)
67 pyplot.legend()
68 pyplot.xlabel("Mpc")
69 pyplot.ylabel("Count")
70 pyplot.savefig(outname)