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.
20 ### A program to plot a psd such as one generated by gstlal_reference_psd
23 from optparse import OptionParser
28 from glue.ligolw import utils as ligolw_utils
29 from gstlal import plotpsd
32 plotpsd.matplotlib.rcParams.update({
34 "axes.titlesize": 10.0,
35 "axes.labelsize": 10.0,
36 "xtick.labelsize": 8.0,
37 "ytick.labelsize": 8.0,
38 "legend.fontsize": 8.0,
46 def parse_command_line():
47 parser = OptionParser()
48 parser.add_option("-o", "--output", help = "Set plot filename (default = replace input file's extension with .png).")
49 parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
50 options, filenames = parser.parse_args()
53 raise ValueError("must supply at least one input filename")
54 if options.output and len(filenames) > 1:
55 raise ValueError("must supply only one input file when setting --output")
57 return options, filenames
60 options, filenames = parse_command_line()
63 for fname in filenames:
65 outname = options.output
67 outname = os.path.join(os.path.splitext(fname)[0], ".png")
69 fig = plotpsd.plot_psds(
70 lal.series.read_psd_xmldoc(
71 ligolw_utils.load_filename(
73 verbose = options.verbose,
74 contenthandler = lal.series.PSDContentHandler