67 from fpconst
import PosInf, NegInf
71 PosInf = float(
"+inf")
72 NegInf = float(
"-inf")
76from matplotlib
import patches
78from scipy
import interpolate
79from scipy
import optimize
80from optparse
import OptionParser
85from igwn_ligolw
import dbtables
86from lal
import iterutils
88from lalburst
import git_version
89from lalburst
import SimBurstUtils
90from lalburst
import SnglBurstUtils
93__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
94__version__ =
"git id %s" % git_version.id
95__date__ = git_version.date
108 parser = OptionParser(
109 version =
"Name: %%prog\n%s" % git_version.verbose_msg,
110 usage =
"%prog [options] -i|--injections-glob pattern -b|--background-glob pattern",
111 description =
"%prog performs the final, summary, stages of an upper-limit excess power search for burst-like gravitational waves."
113 parser.add_option(
"-b",
"--background-glob", metavar =
"pattern", default = [], action =
"append", help =
"Shell filename pattern for non-injection files (required).")
114 parser.add_option(
"-i",
"--injections-glob", metavar =
"pattern", default = [], action =
"append", help =
"Shell filename pattern for injection files (required).")
115 parser.add_option(
"-l",
"--live-time-program", metavar =
"program", default =
"lalapps_power", help =
"Set the name, as it appears in the process table, of the program whose search summary \"out\" segments define the search live time (default = \"lalapps_power\")")
116 parser.add_option(
"--open-box", action =
"store_true", help =
"Open the box. If this is not set, then instead of setting a threshold based on the loudest zero-lag coincidence, the threshold is set at the predicted loudest-event amplitude as derived from the background.")
117 parser.add_option(
"--confidence-contour-slope", metavar =
"slope", type =
"float", default = -12.0, help =
"Set the slope of the confidence-likelihood joint threshold contours (default = -12.0).")
118 parser.add_option(
"--dump-scatter-data", action =
"store_true", help =
"Instead of computing upper limit, dump data files for confidence-likelihood scatter diagnostic scatter plot.")
119 parser.add_option(
"--plot-scatter-data", action =
"store_true", help =
"Instead of computing upper limit, load data files for confidence-likelihood scatter diagnostic scatter plot and generate scatter plot.")
120 parser.add_option(
"-t",
"--tmp-space", metavar =
"path", help =
"Path to a directory suitable for use as a work area while manipulating the database file. The database file will be worked on in this directory, and then moved to the final location when complete. This option is intended to improve performance when running in a networked environment, where there might be a local disk with higher bandwidth than is available to the filesystem on which the final output will reside.")
121 parser.add_option(
"--upper-limit-confidence", metavar =
"percent", type =
"float", default = 90, help =
"Set the confidence in percent of the upper limit to derive (default = 90.0).")
122 parser.add_option(
"--upper-limit-scale", metavar =
"E|hrss", default =
"E", help =
"Select the scale on which to measure the upper limit. Allowed values are 'E' for an upper limit on rate of bursts by energy, and 'hrss' for an upper limit on rate of bursts by h_{rss}. (default = 'E')")
123 parser.add_option(
"--zero-lag-survivors", metavar =
"number", type =
"int", default = 0, help =
"Set the final confidence-likelihood joint threshold so that this many events survive at zero lag. If n survivors are requested, then the threshold is set at exactly the amplitude of the n+1 loudest event, and events are discarded if their amplitudes are <= the threshold. A \"loudest-event\" upper limit is obtained by setting this to 0. The default is 0.")
124 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"be verbose")
125 options, filenames = parser.parse_args()
127 if not options.plot_scatter_data:
128 if not options.background_glob:
129 raise ValueError(
"missing required --background-glob argument")
130 if not options.injections_glob:
131 raise ValueError(
"missing required --injections-glob argument")
133 options.upper_limit_confidence /= 100.0
135 if options.upper_limit_scale
not in (
"E",
"hrss"):
136 raise ValueError(
"invalid value '%s' for --upper-limit-scale" % options.upper_limit_scale)
138 return options, (filenames
or [
None])
157 return database.connection.cursor().execute(
"""
159 coinc_event.coinc_event_id,
160 coinc_event.likelihood,
161 multi_burst.confidence,
168 time_slide.time_slide_id == coinc_event.time_slide_id
169 AND time_slide.offset != 0
173 JOIN multi_burst ON (
174 multi_burst.coinc_event_id == coinc_event.coinc_event_id
177 coinc_event.coinc_def_id == ?
178 """, (database.bb_definer_id,))
182# Construct the temporary sim_coinc_map view that allows for quick mapping
183# from sim_burst to sngl_burst<-->sngl_burst coincs
187def create_sim_coinc_map_view(connection):
188 connection.cursor().execute("""
193 sim_burst.simulation_id AS simulation_id,
194 sim_coinc_event.coinc_def_id AS sim_coinc_def_id,
195 burst_coinc_event.coinc_event_id AS burst_coinc_event_id,
196 burst_coinc_event.likelihood AS burst_coinc_likelihood,
197 multi_burst.confidence AS burst_coinc_confidence,
201 JOIN coinc_event_map AS a ON (
202 a.table_name ==
'sim_burst'
203 AND a.event_id == sim_burst.simulation_id
205 JOIN coinc_event AS sim_coinc_event ON (
206 sim_coinc_event.coinc_event_id == a.coinc_event_id
208 JOIN coinc_event_map AS b ON (
209 b.coinc_event_id == a.coinc_event_id
211 JOIN coinc_event AS burst_coinc_event ON (
212 b.table_name ==
'coinc_event'
213 AND b.event_id == burst_coinc_event.coinc_event_id
215 JOIN multi_burst ON (
216 multi_burst.coinc_event_id == burst_coinc_event.coinc_event_id
222# =============================================================================
224# Measuring Confidence-Likelihood Density Contour Slope
241 print(
"building file list ...", file=sys.stderr)
242 filenames = sorted(filename
for g
in globs
for filename
in glob.glob(g))
256 for n, filename
in enumerate(filenames):
262 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
263 working_filename = dbtables.get_connection_filename(filename, tmp_path = tmp_path, verbose = verbose)
264 connection = sqlite3.connect(working_filename)
265 connection.create_function(
"coinc_detection_statistic", 2, coinc_detection_statistic)
266 database = SnglBurstUtils.CoincDatabase(connection, live_time_program)
268 SnglBurstUtils.summarize_coinc_database(database)
276 if database.sim_burst_table
is None:
281 if len(background) < 1e6:
282 heapq.heappush(background, record)
284 heapq.heappushpop(background, record)
286 if len(zero_lag) < 1e6:
287 heapq.heappush(zero_lag, record)
289 heapq.heappushpop(zero_ag, record)
293 for a, l, c
in database.connection.cursor().execute(
"""
295 burst_coinc_amplitude,
296 burst_coinc_likelihood,
297 burst_coinc_confidence
301 sim_coinc_def_id == ?
302 """, (database.sce_definer_id,)):
304 if len(injections) < 1e6:
305 heapq.heappush(injections, record)
307 heapq.heappushpop(injections, record)
313 database.connection.close()
314 dbtables.discard_connection_filename(filename, working_filename, verbose = verbose)
321 print(
"writing scatter plot data ...", file=sys.stderr)
323 f =
file(
"lalburst_power_final_background_scatter.dat",
"w")
324 for a, l, c
in background:
325 print(
"%.16g %.16g" % (l, c), file=f)
327 f =
file(
"lalburst_power_final_zero_lag_scatter.dat",
"w")
328 for a, l, c
in zero_lag:
329 print(
"%.16g %.16g" % (l, c), file=f)
331 f =
file(
"lalburst_power_final_injections_scatter.dat",
"w")
332 for a, l, c
in injections:
333 print(
"%.16g %.16g" % (l, c), file=f)
336 print(
"done.", file=sys.stderr)
349 fig = SnglBurstUtils.figure.Figure()
350 SnglBurstUtils.FigureCanvas(fig)
351 fig.set_size_inches(6.5, 6.5 / ((1 + math.sqrt(5)) / 2))
355 axes.set_xlabel(
r"Confidence")
356 axes.set_ylabel(
r"Likelihood Ratio")
357 axes.set_title(
r"Likelihood Ratio vs.\ Confidence Scatter Plot")
363 def read_and_plot(filename, colour, verbose = False):
365 print(
"reading '%s' ..." % filename, file=sys.stderr)
368 for line
in file(filename):
371 y, x = map(float, line.strip().split())
375 print(
"plotting ...", file=sys.stderr)
376 return axes.plot(X, Y, colour)
378 set1 = read_and_plot(
"lalburst_power_final_injections_scatter.dat",
"r+", verbose = verbose)
379 set2 = read_and_plot(
"lalburst_power_final_background_scatter.dat",
"k+", verbose = verbose)
383 axes.legend((set1, set2), (
r"Injections",
r"Background (time slides)"), loc =
"lower right")
390 return numpy.exp(slope * numpy.log(x) + lnb)
393 print(
"plotting contours ...", file=sys.stderr)
394 ymin, ymax = axes.get_ylim()
395 for lnb
in range(10, 110, 10):
396 x = 10**numpy.arange(0.85, 3.0, 0.01)
398 x = numpy.compress((ymin <= y) & (y <= ymax), x)
399 y = numpy.compress((ymin <= y) & (y <= ymax), y)
400 axes.plot(x, y,
"g-")
406 axes.plot(axes.get_xlim(), (1, 1),
"k-")
407 axes.set_xlim(10**0.85, 10**3)
414 print(
"writing 'lalburst_power_final_scatter.png' ...", file=sys.stderr)
415 fig.savefig(
"lalburst_power_final_scatter.png")
422 print(
"done.", file=sys.stderr)
454 print(
"measuring live time ...", file=sys.stderr)
455 zero_lag_time_slides, background_time_slides = SnglBurstUtils.get_time_slides(contents.connection)
456 self.
zero_lag_live_time += SnglBurstUtils.time_slides_livetime(contents.seglists, zero_lag_time_slides.values(), verbose = verbose)
457 self.
background_live_time += SnglBurstUtils.time_slides_livetime(contents.seglists, background_time_slides.values(), verbose = verbose)
465 print(
"retrieving sngl_burst<-->sngl_burst coincs ...", file=sys.stderr)
479 print(
"done", file=sys.stderr)
482 def finish(self, zero_lag_survivors, open_box = False, verbose = False):
589def measure_threshold(filenames, n_survivors, live_time_program = "lalapps_power", tmp_path = None, open_box = False, verbose = False):
600 for n, filename
in enumerate(filenames):
606 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
607 working_filename = dbtables.get_connection_filename(filename, tmp_path = tmp_path, verbose = verbose)
608 database = SnglBurstUtils.CoincDatabase(sqlite3.connect(str(working_filename)), live_time_program)
610 SnglBurstUtils.summarize_coinc_database(database)
616 rate_vs_threshold_data.update_from(database, filename = filename, verbose = verbose)
622 database.connection.close()
623 dbtables.discard_connection_filename(filename, working_filename, verbose = verbose)
630 print(
"finishing rate vs. threshold measurement ...", file=sys.stderr)
631 rate_vs_threshold_data.finish(n_survivors, open_box = open_box, verbose = verbose)
637 return rate_vs_threshold_data
646 print(file=sys.stderr)
647 print(
"=== Threshold Summary ===", file=sys.stderr)
648 print(file=sys.stderr)
649 print(
"threshold definition: ln likelihood > %.16g ln confidence + %.16g" % (confidence_contour_slope, rate_vs_threshold_data.amplitude_threshold), file=sys.stderr)
650 print(
"total live time in background = %.16g s" % rate_vs_threshold_data.background_live_time, file=sys.stderr)
651 print(
"total live time at zero lag = %.16g s" % rate_vs_threshold_data.zero_lag_live_time, file=sys.stderr)
652 print(
"number of coincs in background = %d" % rate_vs_threshold_data.n_background_amplitudes, file=sys.stderr)
653 print(
"average number of background coincs per zero lag live time = %.16g" % (rate_vs_threshold_data.n_background_amplitudes / rate_vs_threshold_data.background_live_time * rate_vs_threshold_data.zero_lag_live_time), file=sys.stderr)
654 print(
"number of coincs at zero lag = %d" % len(rate_vs_threshold_data.zero_lag_amplitudes), file=sys.stderr)
655 print(
"at threshold, \\mu_{0} = %.16g Hz +/- %.16g Hz" % (rate_vs_threshold_data.mu_0, rate_vs_threshold_data.dmu_0), file=sys.stderr)
656 print(
"at threshold, \\mu_{0}' = %.16g Hz / unit of amplitude" % rate_vs_threshold_data.mu_0primed, file=sys.stderr)
657 print(file=sys.stderr)
658 print(
"100 Highest-Ranked Zero Lag Events", file=sys.stderr)
659 print(
"----------------------------------", file=sys.stderr)
660 print(file=sys.stderr)
661 print(
"Detection Statistic\tFilename\tID", file=sys.stderr)
662 for amplitude, filename, id
in rate_vs_threshold_data.zero_lag_amplitudes[:100]:
663 print(
"%.16g\t%s\t%s" % (amplitude, filename, id), file=sys.stderr)
664 print(file=sys.stderr)
674 Input is a RateVsThresholdData instance. Output is a matplotlib
677 # start the rate vs. threshold plot
680 print(file=sys.stderr)
681 print("plotting event rate ...", file=sys.stderr)
683 fig, axes = SnglBurstUtils.make_burst_plot(r"Detection Statistic Threshold", r"Mean Event Rate (Hz)")
686 # draw the background rate 1-sigma error bars as a shaded polygon
687 # clipped to the plot. warning: the error bar polygon is not
693 poly_x = numpy.concatenate((data.background_rate_x, data.background_rate_x[::-1]))
694 poly_y = numpy.concatenate((data.background_rate_y + 1 * data.background_rate_dy, (data.background_rate_y - 1 * data.background_rate_dy)[::-1]))
695 axes.add_patch(patches.Polygon(numpy.column_stack((poly_x, numpy.clip(poly_y, ymin, ymax))), edgecolor =
"k", facecolor =
"k", alpha = 0.3))
699 line1 = axes.plot(data.background_rate_x, data.background_rate_y,
"k-")
712 line3 = axes.plot(data.zero_lag_rate_x, data.zero_lag_rate_y,
"r-")
716 axes.axvline(data.amplitude_threshold, color =
"k")
724 axes.legend((line1, line3), (
r"Background (time slides)",
r"Zero lag"))
725 axes.set_title(
r"Mean Event Rate vs.\ Detection Statistic Threshold")
731 print(
"writing lalburst_power_final_rate_vs_threshold.png ...", file=sys.stderr)
732 fig.savefig(
"lalburst_power_final_rate_vs_threshold.png")
736 fig, axes = SnglBurstUtils.make_burst_plot(
r"Detection Statistic Threshold",
r"Mean Event Rate Residual (standard deviations)")
742 interp_y = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_y, kind =
"linear", bounds_error =
False)
743 interp_dy = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_dy, kind =
"linear", bounds_error =
False)
747 axes.plot(data.zero_lag_rate_x, (data.zero_lag_rate_y - interp_y(data.zero_lag_rate_x)) / interp_dy(data.zero_lag_rate_x),
"k-")
751 axes.set_title(
r"Mean Event Rate Residual vs.\ Detection Statistic Threshold")
757 print(
"writing lalburst_power_final_rate_vs_threshold_residual.png ...", file=sys.stderr)
758 fig.savefig(
"lalburst_power_final_rate_vs_threshold_residual.png")
778 print(
"generating %s ..." % filename, file=sys.stderr)
779 fig, axes = SnglBurstUtils.make_burst_plot(
"Centre Frequency (Hz)", ylabel)
781 xcoords, ycoords = bins.centres()
782 cset = axes.contour(xcoords, ycoords, numpy.transpose(z), 9)
783 cset.clabel(inline =
True, fontsize = 5, fmt =
r"$%g$", colors =
"k")
784 axes.set_title(title)
785 fig.savefig(filename)
795 SimBurstUtils.Efficiency_hrss_vs_freq.__init__(self, *args)
800 if self.instruments != contents.instruments:
801 raise ValueError(
"this document contains instruments %s, but we want %s" % (
"+".join(contents.instruments),
"+".join(self.instruments)))
805 offsetvectors = contents.time_slide_table.as_dict()
807 for values
in contents.connection.cursor().execute(
"""
812 MAX(sim_coinc_map.burst_coinc_amplitude)
816 sim_coinc_map.simulation_id == sim_burst.simulation_id
817 AND sim_coinc_map.sim_coinc_def_id == ?
821 """, (contents.scn_definer_id,)):
822 sim = contents.sim_burst_table.row_from_cols(values)
823 detection_statistic = values[-1]
824 amplitude = self.amplitude_func(sim, None)
825 if SimBurstUtils.on_instruments(sim, contents.seglists, offsetvectors[sim.time_slide_id]) == self.instruments:
827 self.injected_x.
append(sim.frequency)
828 self.injected_y.
append(amplitude)
829 if detection_statistic
is not None:
833 if detection_statistic > threshold:
836 self.found_x.
append(sim.frequency)
837 self.found_y.
append(amplitude)
838 elif (detection_statistic
is not None)
and (detection_statistic > threshold):
846 print(
"odd, injection %s was found but not injected ..." % sim.simulation_id, file=sys.stderr)
861 amplitude_weight = rate.BinnedArray(rate.NDBins((rate.LinearBins(threshold - 100, threshold + 100, 10001),)))
869 index, = amplitude_weight.bins[threshold,]
870 window = rate.gaussian_window(10.0 / amplitude_weight.bins.volumes()[index])
871 window /= 10 * window[(len(window) - 1) / 2]
877 lo = index - (len(window) - 1) / 2
878 hi = lo + len(window)
879 if lo < 0
or hi > len(amplitude_weight.array):
880 raise ValueError(
"amplitude weighting window too large")
881 amplitude_weight.array[lo:hi] = window
888 weight = amplitude_weight[z,]
918 n = self.efficiency.numerator.array
919 d = self.efficiency.denominator.array
922 for x, y
in enumerate(numpy.max(numpy.where((d > 0) & (numpy.roll(d, -1, axis = 1) <= 0), numpy.indices(d.shape)[1], bady), axis = 1)):
924 n[x, y + 1:] = n[x, y]
925 d[x, y + 1:] = d[x, y]
926 f[x, y + 1:] = f[x, y]
932 for x, y
in enumerate(numpy.min(numpy.where((d > 0) & (numpy.roll(d, 1, axis = 1) <= 0), numpy.indices(d.shape)[1], bady), axis = 1)):
938 diagnostic_plot(self.efficiency.numerator.array, self.efficiency.denominator.bins,
r"Efficiency Numerator (Before Averaging)", self.amplitude_lbl,
"lalburst_power_final_efficiency_numerator_before.png")
939 diagnostic_plot(self.efficiency.denominator.array, self.efficiency.denominator.bins,
r"Efficiency Denominator (Before Averaging)", self.amplitude_lbl,
"lalburst_power_final_efficiency_denominator_before.png")
940 diagnostic_plot(self.
found_density.array, self.efficiency.denominator.bins,
r"Injections Lost / Unit of Threshold (Before Averaging)", self.amplitude_lbl,
"lalburst_power_final_found_density_before.png")
945 window = rate.gaussian_window(self.window_size_x, self.window_size_y)
946 window /= window[tuple((numpy.array(window.shape, dtype =
"double") - 1) / 2)]
947 rate.filter_binned_ratios(self.efficiency, window)
950 diagnostic_plot(self.efficiency.numerator.array, self.efficiency.denominator.bins,
r"Efficiency Numerator (After Averaging)", self.amplitude_lbl,
"lalburst_power_final_efficiency_numerator_after.png")
951 diagnostic_plot(self.efficiency.denominator.array, self.efficiency.denominator.bins,
r"Efficiency Denominator (After Averaging)", self.amplitude_lbl,
"lalburst_power_final_efficiency_denominator_after.png")
952 diagnostic_plot(self.
found_density.array, self.efficiency.denominator.bins,
r"Injections Lost / Unit of Threshold (After Averaging)", self.amplitude_lbl,
"lalburst_power_final_found_density_after.png")
958 p = self.efficiency.ratio()
959 self.
defficiency = numpy.sqrt(p * (1 - p) / self.efficiency.denominator.array)
960 p = self.
found_density.array / self.efficiency.denominator.array
961 self.
dfound_density = numpy.sqrt(p * (1 - p) / self.efficiency.denominator.array)
969def measure_efficiency(filenames, threshold, live_time_program = "lalapps_power", upper_limit_scale = "E", tmp_path = None, verbose = False):
971 if upper_limit_scale ==
"E":
972 efficiency =
EfficiencyData((
"H1",
"H2",
"L1"), (
lambda sim, instrument: sim.egw_over_rsquared),
r"Equivalent Isotropic Energy ($M_{\odot} / \mathrm{pc}^{2}$)", 0.1)
973 elif upper_limit_scale ==
"hrss":
974 efficiency =
EfficiencyData((
"H1",
"H2",
"L1"), (
lambda sim, instrument: sim.hrss),
r"$h_{\mathrm{rss}}$", 0.1)
976 raise ValueError(
"bad upper_limit_scale %s" % repr(upper_limit_scale))
982 for n, filename
in enumerate(filenames):
988 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
989 working_filename = dbtables.get_connection_filename(filename, tmp_path = tmp_path, verbose = verbose)
990 connection = sqlite3.connect(str(working_filename))
991 connection.create_function(
"coinc_detection_statistic", 2, coinc_detection_statistic)
992 database = SnglBurstUtils.CoincDatabase(connection, live_time_program)
994 SnglBurstUtils.summarize_coinc_database(database)
1000 efficiency.add_contents(database, threshold)
1006 database.connection.close()
1007 dbtables.discard_connection_filename(filename, working_filename, verbose = verbose)
1014 print(
"binning and smoothnig efficiency data ...", file=sys.stderr)
1015 efficiency.finish(threshold)
1030 print(
"plotting efficiency curves ...", file=sys.stderr)
1035 fig = SimBurstUtils.plot_Efficiency_hrss_vs_freq(efficiency_data)
1042 print(
"writing lalburst_power_final_efficiency.png ...", file=sys.stderr)
1043 fig.savefig(
"lalburst_power_final_efficiency.png")
1062 Given the background correction factor $\\xi$, and the upper limit
1065 $p = 1 - \\ee^{-\\mu_{p} \\epsilon} (1 + \\xi \\mu_{p} \\epsilon)$
1067 for ($\\mu_{p} \\epsilon$), the product of the foreground rate
1068 upper limit times the efficiency. Note that this product is always
1069 well defined by this relation (i.e., even when the efficiency
is
1073 return math.exp(-mue) * (1 + xi * mue) - (1 - p)
1075 return -math.exp(-mue) * (1 + xi * mue - xi)
1076 return optimize.newton(f, 1, fprime = fprime, tol = 1e-8)
1086 self.
rate_array = rate.BinnedArray(efficiency_data.efficiency.denominator.bins)
1092 print(
"computing rate upper limit ...", file=sys.stderr)
1097 rate_data =
RateData(efficiency_data, p)
1101 e = efficiency_data.efficiency.ratio()
1126 e_over_eprimed = efficiency_data.efficiency.numerator.array / -efficiency_data.found_density.array
1131 xi = 1.0 / (1.0 - e_over_eprimed * abs(mu_0primed * zero_lag_live_time))
1132 xi = numpy.where(numpy.isnan(e_over_eprimed), 1.0, xi)
1134 diagnostic_plot(xi, rate_data.rate_array.bins,
r"Background Correction Factor $\xi$", rate_data.amplitude_lbl,
"lalburst_power_final_xi.png")
1138 for xy
in iterutils.MultiIter(*map(xrange, rate_data.rate_array.array.shape)):
1139 rate_data.rate_array.array[xy] =
mu_p_epsilon(xi[xy], p)
1140 diagnostic_plot(rate_data.rate_array.array, rate_data.rate_array.bins,
r"$\mu_{%.2g} \epsilon$" % p, rate_data.amplitude_lbl,
"lalburst_power_final_mu_p_epsilon.png")
1141 rate_data.rate_array.array /= zero_lag_live_time * e
1154 print(
"plotting rate upper limit ...", file=sys.stderr)
1160 fig, axes = SnglBurstUtils.make_burst_plot(
"Centre Frequency (Hz)", rate_data.amplitude_lbl)
1163 xcoords, ycoords = rate_data.rate_array.centres()
1165 zvals = numpy.log10(numpy.clip(rate_data.rate_array.array, 0, 1) / 1.0)
1166 cset = axes.contour(xcoords, ycoords, numpy.transpose(zvals), 19)
1167 cset.clabel(inline =
True, fontsize = 5, fmt =
r"$%g$", colors =
"k")
1171 axes.set_title(
r"%g\%% Confidence Rate Upper Limit ($\log_{10} R_{%g} / 1\,\mathrm{Hz}$)" % (100 * rate_data.confidence, rate_data.confidence))
1175 print(
"writing lalburst_power_final_upper_limit_1.png ...", file=sys.stderr)
1176 fig.savefig(
"lalburst_power_final_upper_limit_1.png")
1182 fig, axes = SnglBurstUtils.make_burst_plot(rate_data.amplitude_lbl,
r"Rate Upper Limit (Hz)")
1185 zvals = rate_data.rate_array[110, :]
1186 max =
min(zvals) * 1e4
1187 ycoords = numpy.compress(zvals <= max, ycoords)
1188 zvals = numpy.compress(zvals <= max, zvals)
1189 max =
min(ycoords) * 1e6
1190 zvals = numpy.compress(ycoords <= max, zvals)
1191 ycoords = numpy.compress(ycoords <= max, ycoords)
1192 axes.plot(ycoords, zvals,
"k-")
1194 axes.set_title(
r"%g\%% Confidence Rate Upper Limit at $110\,\mathrm{Hz}$" % (100 * rate_data.confidence))
1198 print(
"writing lalburst_power_final_upper_limit_2.png ...", file=sys.stderr)
1199 fig.savefig(
"lalburst_power_final_upper_limit_2.png")
1254 if 1.0 / likelihood <= 0:
1260 return math.log(likelihood) - m * math.log(confidence)
1268if options.dump_scatter_data:
1269 print(
"=== Confidence-Likelihood Scatter Dump ===", file=sys.stderr)
1270 print(file=sys.stderr)
1272 print(file=sys.stderr)
1273 print(
"=== Done ===", file=sys.stderr)
1277if options.plot_scatter_data:
1278 print(
"=== Confidence-Likelihood Scatter Plot ===", file=sys.stderr)
1279 print(file=sys.stderr)
1281 print(file=sys.stderr)
1282 print(
"=== Done ===", file=sys.stderr)
1293print(
"=== Threshold ===", file=sys.stderr)
1294print(file=sys.stderr)
1295print(
"\t\tBOX IS %s" % (options.open_box
and "OPEN!!" or "CLOSED!!"), file=sys.stderr)
1296print(file=sys.stderr)
1299 print(
"building file list ...", file=sys.stderr)
1300filenames = sorted(filename
for g
in options.background_glob
for filename
in glob.glob(g))
1302 raise ValueError(
"no background/zero lag files found")
1305 rate_vs_threshold_data =
measure_threshold(filenames, options.zero_lag_survivors, live_time_program = options.live_time_program, tmp_path = options.tmp_space, open_box = options.open_box, verbose = options.verbose)
1311 rate_vs_threshold_data.zero_lag_live_time = 1163382.623777472
1312 rate_vs_threshold_data.amplitude_threshold = 49.3975937091782
1313 rate_vs_threshold_data.mu_0primed = -2.000347702238217e-07
1315print(
"done.", file=sys.stderr)
1316print(file=sys.stderr)
1324print(file=sys.stderr)
1325print(
"=== Efficiency ==", file=sys.stderr)
1326print(file=sys.stderr)
1329 print(
"building file list ...", file=sys.stderr)
1330filenames = sorted(filename
for g
in options.injections_glob
for filename
in glob.glob(g))
1332 raise ValueError(
"no injection files found")
1334efficiency_data =
measure_efficiency(filenames, rate_vs_threshold_data.amplitude_threshold, live_time_program = options.live_time_program, upper_limit_scale = options.upper_limit_scale, tmp_path = options.tmp_space, verbose = options.verbose)
1336print(file=sys.stderr)
1337print(
"=== Efficiency Summary ===", file=sys.stderr)
1338print(file=sys.stderr)
1342print(
"done.", file=sys.stderr)
1343print(file=sys.stderr)
1351print(file=sys.stderr)
1352print(
"=== Rate Upper Limit ===", file=sys.stderr)
1353print(file=sys.stderr)
1355rate_data =
rate_upper_limit(efficiency_data, rate_vs_threshold_data.mu_0primed, rate_vs_threshold_data.zero_lag_live_time, options.upper_limit_confidence)
1358print(
"done.", file=sys.stderr)
1359print(file=sys.stderr)
1367print(file=sys.stderr)
1368print(
"=== Done ===", file=sys.stderr)
1369print(file=sys.stderr)
static double min(double a, double b)
def __init__(self, *args)
def finish(self, threshold)
def add_contents(self, contents, threshold)
def __init__(self, efficiency_data, confidence)
def finish(self, zero_lag_survivors, open_box=False, verbose=False)
def update_from(self, contents, filename="", verbose=False)
background_rate_approximant
def dump_confidence_likelihood_scatter_data(globs, live_time_program="lalapps_power", tmp_path=None, verbose=False)
def coinc_detection_statistic(likelihood, confidence, m=options.confidence_contour_slope)
def bb_id_likelihood_confidence_background(database)
def measure_threshold(filenames, n_survivors, live_time_program="lalapps_power", tmp_path=None, open_box=False, verbose=False)
def diagnostic_plot(z, bins, title, ylabel, filename)
def plot_rate_vs_threshold(data)
Input is a RateVsThresholdData instance.
def measure_efficiency(filenames, threshold, live_time_program="lalapps_power", upper_limit_scale="E", tmp_path=None, verbose=False)
def print_rate_vs_threshold_data(rate_vs_threshold_data, confidence_contour_slope)
def plot_rate_upper_limit(rate_data)
def create_sim_coinc_map_view(connection)
def mu_p_epsilon(xi, p)
Given the background correction factor $\xi$, and the upper limit confidence p, solve.
def plot_confidence_likelihood_scatter_data(slope, verbose=False)
def rate_upper_limit(efficiency_data, mu_0primed, zero_lag_live_time, p)
def plot_efficiency_data(efficiency_data)