gstlal  1.4.1
gstlal_plot_psd
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 ### A program to plot a psd such as one generated by gstlal_reference_psd
21 
22 
23 from optparse import OptionParser
24 import os
25 
26 
27 import lal
28 from glue.ligolw import utils as ligolw_utils
29 from gstlal import plotpsd
30 
31 
32 plotpsd.matplotlib.rcParams.update({
33  "font.size": 10.0,
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,
39  "figure.dpi": 300,
40  "savefig.dpi": 300,
41  "text.usetex": True,
42  "path.simplify": True
43 })
44 
45 
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()
51 
52  if not filenames:
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")
56 
57  return options, filenames
58 
59 
60 options, filenames = parse_command_line()
61 
62 
63 for fname in filenames:
64  if options.output:
65  outname = options.output
66  else:
67  outname = os.path.join(os.path.splitext(fname)[0], ".png")
68 
69  fig = plotpsd.plot_psds(
70  lal.series.read_psd_xmldoc(
71  ligolw_utils.load_filename(
72  fname,
73  verbose = options.verbose,
74  contenthandler = lal.series.PSDContentHandler
75  )
76  ),
77  plot_width = 2400
78  )
79 
80  fig.savefig(outname)