gstlal-inspiral  1.9.3
 All Classes Namespaces Files Functions
gstlal_inspiral_plot_kernels
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2017 Kipp Cannon
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 #
21 # =============================================================================
22 #
23 # Preamble
24 #
25 # =============================================================================
26 #
27 
28 
29 import math
30 import matplotlib
31 matplotlib.rcParams.update({
32  "font.size": 10.0,
33  "axes.titlesize": 10.0,
34  "axes.labelsize": 10.0,
35  "xtick.labelsize": 8.0,
36  "ytick.labelsize": 8.0,
37  "legend.fontsize": 8.0,
38  "figure.dpi": 600,
39  "savefig.dpi": 600,
40  "text.usetex": True
41 })
42 import numpy
43 from optparse import OptionParser
44 import sys
45 
46 
47 from ligo import segments
48 from gstlal import far
49 from gstlal.plots import far as plotfar
50 
51 
52 #
53 # =============================================================================
54 #
55 # Command Line
56 #
57 # =============================================================================
58 #
59 
60 
61 def parse_command_line():
62  parser = OptionParser()
63  parser.add_option("--max-snr", metavar = "snr", type = "float", default = 200.0, help = "Set the maximum SNR for (chi^2, snr) plots (default = 200.0).")
64  parser.add_option("--output-format", metavar = "extension", default = ".png", help = "Select output format by choosen the filename extension (default = \".png\").")
65  parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
66  options, filenames = parser.parse_args()
67 
68  if options.output_format not in (".png", ".pdf", ".svg"):
69  raise ValueError("invalid --output-format \"%s\"" % options.output_format)
70 
71  return options, filenames
72 
73 
74 #
75 # =============================================================================
76 #
77 # Main
78 #
79 # =============================================================================
80 #
81 
82 
83 #
84 # command line
85 #
86 
87 
88 options, filenames = parse_command_line()
89 
90 
91 #
92 # load input
93 #
94 
95 
96 rankingstat = far.RankingStat(instruments = frozenset(("H1",)), min_instruments = 1)
97 
98 
99 #
100 # place a grid of impulses into the arrays and smooth
101 #
102 
103 
104 for x in 1.5**numpy.arange(4, 13):
105  for y in 3.**numpy.arange(-8, 0):
106  rankingstat.background_rates["H1_snr_chi"][x, y] = 1e8
107 rankingstat.finish()
108 
109 
110 #
111 # plots
112 #
113 
114 
115 if rankingstat is not None:
116  fig = plotfar.plot_snr_chi_pdf(rankingstat, "H1", "background_pdf", options.max_snr)
117  plotname = "coinc_params_binning%s" % options.output_format
118  if options.verbose:
119  print >>sys.stderr, "writing %s" % plotname
120  fig.savefig(plotname)
121 
122 
123 # ranking statistic PDFs and CCDFs
124 #fig = plotfar.plot_likelihood_ratio_pdf(rankingstatpdf, (options.min_log_lambda, options.max_log_lambda), "Noise", which = "noise")
125 #plotname = "coinc_params_binning%s" % options.output_format
126 #if options.verbose:
127 # print >>sys.stderr, "writing %s" % plotname
128 #fig.savefig(plotname)