def finish(self):
		for instrument, data in sorted(self.dataA.items()):
			fig, axes = SnglBurstUtils.make_burst_plot(r"SNR in %s" % instrument, r"$(f_{\mathrm{recovered}} - f_{\mathrm{injected}})/ f_{\mathrm{injected}}$")

			axes.set_title("Cut-off Frequency Residual vs.\ SNR in %s\n(%d Found Injections)" % (instrument, data.found))
			axes.loglog()
			axes.plot(data.x, data.y, "k+")

			yield fig

		for instrument, data in sorted(self.dataB.items()):
			fig, axes = SnglBurstUtils.make_burst_plot(r"$f_{\mathrm{injected}}$ (Hz)", r"$f_{\mathrm{recovered}}$ (Hz)")
			axes.loglog()
			fig.set_size_inches(8, 8)
			axes.scatter(data.x, data.y, c = data.c, s = 16)
			xmin, xmax = min(data.x), max(data.x)
			ymin, ymax = min(data.y), max(data.y)
			xmin = ymin = min(xmin, ymin)
			xmax = ymax = max(xmax, ymax)
			axes.plot([xmin, xmax], [ymin, ymax], "k-")
			axes.set_xlim([xmin, xmax])
			axes.set_ylim([ymin, ymax])
			axes.set_title(r"Recovered Cut-off Frequency vs.\ Injected Cut-off Frequency in %s\\(%d Injections; red = high recovered SNR, blue = low recovered SNR)" % (instrument, data.found))

			yield fig
Exemple #2
0
    def finish(self):
        for instrument, data in sorted(self.dataA.items()):
            fig, axes = SnglBurstUtils.make_burst_plot(
                r"SNR in %s" % instrument,
                r"$(f_{\mathrm{recovered}} - f_{\mathrm{injected}})/ f_{\mathrm{injected}}$"
            )

            axes.set_title(
                "Cut-off Frequency Residual vs.\ SNR in %s\n(%d Found Injections)"
                % (instrument, data.found))
            axes.loglog()
            axes.plot(data.x, data.y, "k+")

            yield fig

        for instrument, data in sorted(self.dataB.items()):
            fig, axes = SnglBurstUtils.make_burst_plot(
                r"$f_{\mathrm{injected}}$ (Hz)",
                r"$f_{\mathrm{recovered}}$ (Hz)")
            axes.loglog()
            fig.set_size_inches(8, 8)
            axes.scatter(data.x, data.y, c=data.c, s=16)
            xmin, xmax = min(data.x), max(data.x)
            ymin, ymax = min(data.y), max(data.y)
            xmin = ymin = min(xmin, ymin)
            xmax = ymax = max(xmax, ymax)
            axes.plot([xmin, xmax], [ymin, ymax], "k-")
            axes.set_xlim([xmin, xmax])
            axes.set_ylim([ymin, ymax])
            axes.set_title(
                r"Recovered Cut-off Frequency vs.\ Injected Cut-off Frequency in %s\\(%d Injections; red = high recovered SNR, blue = low recovered SNR)"
                % (instrument, data.found))

            yield fig
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Peak Frequency (Hz)", "Confidence")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.y = []
		self.axes.semilogy()
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Confidence", "Trigger Rate (Hz)")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.seglist = segments.segmentlist()
		self.axes.loglog()
Exemple #5
0
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Peak Frequency (Hz)", "Confidence")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.y = []
		self.axes.semilogy()
Exemple #6
0
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Confidence", "Trigger Rate (Hz)")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.seglist = segments.segmentlist()
		self.axes.loglog()
 def __init__(self, instrument):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "Number of Triggers Coincident with Injection", "Count")
     self.axes.semilogy()
     self.instrument = instrument
     self.found = 0
     self.bins = []
Exemple #8
0
 def __init__(self, x_instrument, y_instrument, magnitude, desc,
              min_magnitude, max_magnitude):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "%s %s" % (x_instrument, desc), "%s %s" % (y_instrument, desc))
     self.fig.set_size_inches(6, 6)
     self.axes.loglog()
     self.x_instrument = x_instrument
     self.y_instrument = y_instrument
     self.magnitude = magnitude
     self.foreground_x = []
     self.foreground_y = []
     self.n_foreground = 0
     self.n_background = 0
     self.n_injections = 0
     self.foreground_bins = rate.BinnedArray(
         rate.NDBins(
             (rate.LogarithmicBins(min_magnitude, max_magnitude, 1024),
              rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
     self.background_bins = rate.BinnedArray(
         rate.NDBins(
             (rate.LogarithmicBins(min_magnitude, max_magnitude, 1024),
              rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
     self.coinc_injection_bins = rate.BinnedArray(
         rate.NDBins(
             (rate.LogarithmicBins(min_magnitude, max_magnitude, 1024),
              rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
     self.incomplete_coinc_injection_bins = rate.BinnedArray(
         rate.NDBins(
             (rate.LogarithmicBins(min_magnitude, max_magnitude, 1024),
              rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
Exemple #9
0
 def __init__(self, x, y, magnitude, max_magnitude):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot("X", "Y")
     self.fig.set_size_inches(6, 6)
     self.x = x
     self.y = y
     self.magnitude = magnitude
     self.n_foreground = 0
     self.n_background = 0
     self.n_injections = 0
     max_magnitude = math.log10(max_magnitude)
     self.foreground_bins = rate.BinnedArray(
         rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024),
                      rate.LinearBins(-max_magnitude, max_magnitude,
                                      1024))))
     self.background_bins = rate.BinnedArray(
         rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024),
                      rate.LinearBins(-max_magnitude, max_magnitude,
                                      1024))))
     self.coinc_injection_bins = rate.BinnedArray(
         rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024),
                      rate.LinearBins(-max_magnitude, max_magnitude,
                                      1024))))
     self.incomplete_coinc_injection_bins = rate.BinnedArray(
         rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024),
                      rate.LinearBins(-max_magnitude, max_magnitude,
                                      1024))))
Exemple #10
0
	def finish(self):
		fig, axes = SnglBurstUtils.make_burst_plot("Number of Triggers Coincident with Injection", "Count")
		axes.semilogy()
		axes.plot(range(len(self.bins)), self.bins, "ko-")
		axes.set_title("Triggers per Found Injection\n(%d Found Injections)" % self.found)

		return fig,
def plot_rate_upper_limit(rate_data):
	print >>sys.stderr, "plotting rate upper limit ..."

	#
	# contour plot in frequency-energy plane
	#

	fig, axes = SnglBurstUtils.make_burst_plot("Centre Frequency (Hz)", rate_data.amplitude_lbl)
	axes.loglog()

	xcoords, ycoords = rate_data.rate_array.centres()
	# zvals = log_{10}(R_{0.9} / 1 Hz)
	zvals = numpy.log10(numpy.clip(rate_data.rate_array.array, 0, 1) / 1.0)
	cset = axes.contour(xcoords, ycoords, numpy.transpose(zvals), 19)
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%g$", colors = "k")

	#axes.set_ylim((3e-17, 3e-10))

	axes.set_title(r"%g\%% Confidence Rate Upper Limit ($\log_{10} R_{%g} / 1\,\mathrm{Hz}$)" % (100 * rate_data.confidence, rate_data.confidence))

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_1.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_upper_limit_1.pdf")
	print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_1.png ..."
	fig.savefig("lalapps_excesspowerfinal_upper_limit_1.png")

	#
	# rate vs. energy curve at a sample frequency
	#

	fig, axes = SnglBurstUtils.make_burst_plot(rate_data.amplitude_lbl, r"Rate Upper Limit (Hz)")
	axes.loglog()

	zvals = rate_data.rate_array[110, :]
	max = min(zvals) * 1e4
	ycoords = numpy.compress(zvals <= max, ycoords)
	zvals = numpy.compress(zvals <= max, zvals)
	max = min(ycoords) * 1e6
	zvals = numpy.compress(ycoords <= max, zvals)
	ycoords = numpy.compress(ycoords <= max, ycoords)
	axes.plot(ycoords, zvals, "k-")

	axes.set_title(r"%g\%% Confidence Rate Upper Limit at $110\,\mathrm{Hz}$" % (100 * rate_data.confidence))

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_2.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_upper_limit_2.pdf")
	print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_2.png ..."
	fig.savefig("lalapps_excesspowerfinal_upper_limit_2.png")
Exemple #12
0
def plot_rate_upper_limit(rate_data):
	print("plotting rate upper limit ...", file=sys.stderr)

	#
	# contour plot in frequency-energy plane
	#

	fig, axes = SnglBurstUtils.make_burst_plot("Centre Frequency (Hz)", rate_data.amplitude_lbl)
	axes.loglog()

	xcoords, ycoords = rate_data.rate_array.centres()
	# zvals = log_{10}(R_{0.9} / 1 Hz)
	zvals = numpy.log10(numpy.clip(rate_data.rate_array.array, 0, 1) / 1.0)
	cset = axes.contour(xcoords, ycoords, numpy.transpose(zvals), 19)
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%g$", colors = "k")

	#axes.set_ylim((3e-17, 3e-10))

	axes.set_title(r"%g\%% Confidence Rate Upper Limit ($\log_{10} R_{%g} / 1\,\mathrm{Hz}$)" % (100 * rate_data.confidence, rate_data.confidence))

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_1.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_upper_limit_1.pdf")
	print("writing lalapps_excesspowerfinal_upper_limit_1.png ...", file=sys.stderr)
	fig.savefig("lalapps_excesspowerfinal_upper_limit_1.png")

	#
	# rate vs. energy curve at a sample frequency
	#

	fig, axes = SnglBurstUtils.make_burst_plot(rate_data.amplitude_lbl, r"Rate Upper Limit (Hz)")
	axes.loglog()

	zvals = rate_data.rate_array[110, :]
	max = min(zvals) * 1e4
	ycoords = numpy.compress(zvals <= max, ycoords)
	zvals = numpy.compress(zvals <= max, zvals)
	max = min(ycoords) * 1e6
	zvals = numpy.compress(ycoords <= max, zvals)
	ycoords = numpy.compress(ycoords <= max, ycoords)
	axes.plot(ycoords, zvals, "k-")

	axes.set_title(r"%g\%% Confidence Rate Upper Limit at $110\,\mathrm{Hz}$" % (100 * rate_data.confidence))

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_upper_limit_2.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_upper_limit_2.pdf")
	print("writing lalapps_excesspowerfinal_upper_limit_2.png ...", file=sys.stderr)
	fig.savefig("lalapps_excesspowerfinal_upper_limit_2.png")
	def __init__(self, x_instrument, y_instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("%s Offset (s)" % x_instrument, "%s Offset (s)" % y_instrument)
		self.fig.set_size_inches(6,6)
		self.x_instrument = x_instrument
		self.y_instrument = y_instrument
		self.tisi_rows = None
		self.seglists = segments.segmentlistdict()
		self.counts = None
	def __init__(self, instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("%s Confidence" % instrument, "Coincident Event Rate (Hz)")
		self.instrument = instrument
		self.foreground = []
		self.background = []
		self.foreground_segs = segments.segmentlist()
		self.background_segs = segments.segmentlist()
		self.axes.loglog()
Exemple #15
0
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("GPS Time (s)", "Confidence")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.y = []
		self.seglist = segments.segmentlist()
		self.axes.semilogy()
Exemple #16
0
	def __init__(self, ifo, width, max):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Delay (s)", "Count / Delay")
		self.ifo = ifo
		self.nevents = 0
		# 21 bins per filter width
		interval = segments.segment(0, max + 2)
		self.bins = rate.BinnedDensity(rate.NDBins((rate.LinearBins(interval[0], interval[1], int(float(abs(interval)) / width) * 21),)))
		self.axes.semilogy()
	def __init__(self, ifo, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Peak Frequency (Hz)", "Trigger Rate Spectral Density (triggers / s / Hz)")
		self.ifo = ifo
		self.nevents = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.rate = rate.BinnedDensity(binning)
Exemple #18
0
	def __init__(self, ifo, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Peak Frequency (Hz)", "Trigger Rate Spectral Density (triggers / s / Hz)")
		self.ifo = ifo
		self.nevents = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.rate = rate.BinnedDensity(binning)
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("GPS Time (s)", "Confidence")
		self.ifo = ifo
		self.nevents = 0
		self.x = []
		self.y = []
		self.seglist = segments.segmentlist()
		self.axes.semilogy()
	def __init__(self, ifo, width, max):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Delay (s)", "Count / Delay")
		self.ifo = ifo
		self.nevents = 0
		# 21 bins per filter width
		interval = segments.segment(0, max + 2)
		self.bins = rate.BinnedDensity(rate.NDBins((rate.LinearBins(interval[0], interval[1], int(float(abs(interval)) / width) * 21),)))
		self.axes.semilogy()
Exemple #21
0
 def __init__(self, x_instrument, y_instrument):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "%s Offset (s)" % x_instrument, "%s Offset (s)" % y_instrument)
     self.fig.set_size_inches(6, 6)
     self.x_instrument = x_instrument
     self.y_instrument = y_instrument
     self.tisi_rows = None
     self.seglists = segments.segmentlistdict()
     self.counts = None
def diagnostic_plot(z, bins, title, ylabel, filename):
	print >>sys.stderr, "generating %s ..." % filename
	fig, axes = SnglBurstUtils.make_burst_plot("Centre Frequency (Hz)", ylabel)
	axes.loglog()
	xcoords, ycoords = bins.centres()
	cset = axes.contour(xcoords, ycoords, numpy.transpose(z), 9)
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%g$", colors = "k")
	axes.set_title(title)
	fig.savefig(filename)
Exemple #23
0
def diagnostic_plot(z, bins, title, ylabel, filename):
	print("generating %s ..." % filename, file=sys.stderr)
	fig, axes = SnglBurstUtils.make_burst_plot("Centre Frequency (Hz)", ylabel)
	axes.loglog()
	xcoords, ycoords = bins.centres()
	cset = axes.contour(xcoords, ycoords, numpy.transpose(z), 9)
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%g$", colors = "k")
	axes.set_title(title)
	fig.savefig(filename)
	def __init__(self, instruments):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$f_{\mathrm{injected}}$ (Hz)", r"$f_{\mathrm{recovered}}$ (Hz)")
		self.axes.loglog()
		self.fig.set_size_inches(8, 8)
		self.instruments = set(instruments)
		self.matches = 0
		self.x = []
		self.y = []
		self.c = []
Exemple #25
0
 def __init__(self, instrument):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "%s Confidence" % instrument, "Coincident Event Rate (Hz)")
     self.instrument = instrument
     self.foreground = []
     self.background = []
     self.foreground_segs = segments.segmentlist()
     self.background_segs = segments.segmentlist()
     self.axes.loglog()
Exemple #26
0
	def __init__(self, instruments):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$f_{\mathrm{injected}}$ (Hz)", r"$f_{\mathrm{recovered}}$ (Hz)")
		self.axes.loglog()
		self.fig.set_size_inches(8, 8)
		self.instruments = set(instruments)
		self.matches = 0
		self.x = []
		self.y = []
		self.c = []
	def __init__(self, instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("GPS Time (s)", "Frequency (Hz)")
		self.axes.semilogy()
		self.instrument = instrument
		self.num_injections = 0
		self.injected_x = []
		self.injected_y = []
		self.missed_x = []
		self.missed_y = []
		self.seglist = segments.segmentlist()
	def __init__(self, instrument, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$t_{\mathrm{recovered}} - t_{\mathrm{injected}}$ (s)", "Triggers per Unit Offset")
		self.axes.semilogy()
		self.instrument = instrument
		self.found = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.offsets = rate.BinnedDensity(binning)
		self.coinc_offsets = rate.BinnedDensity(binning)
Exemple #29
0
	def finish(self):
		for instrument, data in sorted(self.data.items()):
			fig, axes = SnglBurstUtils.make_burst_plot(r"SNR", r"$\chi^{2} / \mathrm{DOF}$")

			axes.set_title("$\chi^{2} / \mathrm{DOF}$ vs.\ SNR in %s" % instrument)
			axes.loglog()
			axes.plot(data.injections_x, data.injections_y, "r+")
			axes.plot(data.noninjections_x, data.noninjections_y, "k+")

			yield fig
Exemple #30
0
	def __init__(self, instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("GPS Time (s)", "Frequency (Hz)")
		self.axes.semilogy()
		self.instrument = instrument
		self.num_injections = 0
		self.injected_x = []
		self.injected_y = []
		self.missed_x = []
		self.missed_y = []
		self.seglist = segments.segmentlist()
Exemple #31
0
	def finish(self):
		for instrument, data in sorted(self.data.items()):
			fig, axes = SnglBurstUtils.make_burst_plot(r"$t_{\mathrm{recovered}} - t_{\mathrm{injected}}$ (s)", "Triggers per Unit Offset")
			axes.semilogy()
			axes.set_title("Trigger Peak Time - Injection Peak Time in %s\n(%d Found Injections)" % (instrument, data.found))
			# 21 bins per filter width
			rate.filter_array(data.offsets.array, rate.gaussian_window(21))
			axes.plot(data.offsets.centres()[0], data.offsets.at_centres(), "k")
			#axes.legend(["%s residuals" % instrument, "SNR-weighted mean of residuals in all instruments"], loc = "lower right")
			yield fig
Exemple #32
0
	def __init__(self, instrument, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$f_{\mathrm{recovered}} / f_{\mathrm{injected}}$", "Event Number Density")
		self.axes.loglog()
		self.instrument = instrument
		self.found = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.offsets = rate.BinnedArray(binning)
		self.coinc_offsets = rate.BinnedArray(binning)
	def __init__(self, instrument, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$f_{\mathrm{recovered}} / f_{\mathrm{injected}}$", "Event Number Density")
		self.axes.loglog()
		self.instrument = instrument
		self.found = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.offsets = rate.BinnedDensity(binning)
		self.coinc_offsets = rate.BinnedDensity(binning)
Exemple #34
0
	def __init__(self, instrument, interval, width):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$t_{\mathrm{recovered}} - t_{\mathrm{injected}}$ (s)", "Triggers per Unit Offset")
		self.axes.semilogy()
		self.instrument = instrument
		self.found = 0
		# 21 bins per filter width
		bins = int(float(abs(interval)) / width) * 21
		binning = rate.NDBins((rate.LinearBins(interval[0], interval[1], bins),))
		self.offsets = rate.BinnedArray(binning)
		self.coinc_offsets = rate.BinnedArray(binning)
	def __init__(self, instrument, amplitude_func, amplitude_lbl):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$\Delta f_{\mathrm{recovered}}$ (Hz)", r"Recovered $h_{\mathrm{rss}}$ / Injected " + amplitude_lbl)
		self.axes.loglog()
		self.fig.set_size_inches(8, 8)
		self.instrument = instrument
		self.amplitude_func = amplitude_func
		self.amplitude_lbl = amplitude_lbl
		self.matches = 0
		self.x = []
		self.y = []
		self.c = []
	def __init__(self, instrument, amplitude_func, amplitude_lbl):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Frequency (Hz)", amplitude_lbl)
		self.axes.loglog()
		self.instrument = instrument
		self.amplitude_func = amplitude_func
		self.amplitude_lbl = amplitude_lbl
		self.num_injections = 0
		self.injected_x = []
		self.injected_y = []
		self.missed_x = []
		self.missed_y = []
Exemple #37
0
	def __init__(self, instrument, amplitude_func, amplitude_lbl):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot(r"$\Delta f_{\mathrm{recovered}}$ (Hz)", r"Recovered $h_{\mathrm{rss}}$ / Injected " + amplitude_lbl)
		self.axes.loglog()
		self.fig.set_size_inches(8, 8)
		self.instrument = instrument
		self.amplitude_func = amplitude_func
		self.amplitude_lbl = amplitude_lbl
		self.matches = 0
		self.x = []
		self.y = []
		self.c = []
Exemple #38
0
	def __init__(self, instrument, amplitude_func, amplitude_lbl):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Frequency (Hz)", amplitude_lbl)
		self.axes.loglog()
		self.instrument = instrument
		self.amplitude_func = amplitude_func
		self.amplitude_lbl = amplitude_lbl
		self.num_injections = 0
		self.injected_x = []
		self.injected_y = []
		self.missed_x = []
		self.missed_y = []
Exemple #39
0
def plot_multi_Efficiency_hrss_vs_freq(efficiencies):
	fig, axes = SnglBurstUtils.make_burst_plot("Frequency (Hz)", r"$h_{\mathrm{rss}}$")
	axes.loglog()

	e = efficiencies[0]
	xcoords, ycoords = e.efficiency.centres()
	zvals = e.efficiency.ratio()
	error = e.error
	for n, e in enumerate(efficiencies[1:]):
		error += e.error
		other_xcoords, other_ycoords = e.efficiency.centres()
		if (xcoords != other_xcoords).any() or (ycoords != other_ycoords).any():
			# binnings don't match, can't compute product of
			# efficiencies
			raise ValueError("binning mismatch")
		zvals *= e.efficiency.ratio()
	error /= len(efficiencies)

	nfound = numpy.array([len(e.found_x) for e in efficiencies], dtype = "double")
	ninjected = numpy.array([len(e.injected_x) for e in efficiencies], dtype = "double")

	# the model for guessing the ninjected in the coincidence case is
	# to assume that the injections done in the instrument with the
	# most injections were done into all three with a probability given
	# by the ratio of the number actually injected into each instrument
	# to the number injected into the instrument with the most
	# injected, and then to assume that these are independent random
	# occurances and that to be done in coincidence an injection must
	# be done in all three instruments.

	ninjected_guess = (ninjected / ninjected.max()).prod() * ninjected.min()

	# the model for guessing the nfound in the coincidence case is to
	# assume that each injection is found or missed in each instrument
	# at random, and to be found in the coincidence case it must be
	# found in all three.

	nfound_guess = (nfound / ninjected).prod() * ninjected_guess

	ninjected_guess = int(round(ninjected_guess))
	nfound_guess = int(round(nfound_guess))

	instruments = r" \& ".join(sorted("+".join(sorted(e.instruments)) for e in efficiencies))

	cset = axes.contour(xcoords, ycoords, numpy.transpose(zvals), (.1, .2, .3, .4, .5, .6, .7, .8, .9))
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%%g \pm %g$" % error, colors = "k")

	axes.set_title(r"%s Estimated Injection Detection Efficiency ($\sim$%d of $\sim$%d Found)" % (instruments, nfound_guess, ninjected_guess))

	return fig
def plot_multi_Efficiency_hrss_vs_freq(efficiencies):
	fig, axes = SnglBurstUtils.make_burst_plot("Frequency (Hz)", r"$h_{\mathrm{rss}}$")
	axes.loglog()

	e = efficiencies[0]
	xcoords, ycoords = e.efficiency.centres()
	zvals = e.efficiency.ratio()
	error = e.error
	for n, e in enumerate(efficiencies[1:]):
		error += e.error
		other_xcoords, other_ycoords = e.efficiency.centres()
		if (xcoords != other_xcoords).any() or (ycoords != other_ycoords).any():
			# binnings don't match, can't compute product of
			# efficiencies
			raise ValueError("binning mismatch")
		zvals *= e.efficiency.ratio()
	error /= len(efficiencies)

	nfound = numpy.array([len(e.found_x) for e in efficiencies], dtype = "double")
	ninjected = numpy.array([len(e.injected_x) for e in efficiencies], dtype = "double")

	# the model for guessing the ninjected in the coincidence case is
	# to assume that the injections done in the instrument with the
	# most injections were done into all three with a probability given
	# by the ratio of the number actually injected into each instrument
	# to the number injected into the instrument with the most
	# injected, and then to assume that these are independent random
	# occurances and that to be done in coincidence an injection must
	# be done in all three instruments.

	ninjected_guess = (ninjected / ninjected.max()).prod() * ninjected.min()

	# the model for guessing the nfound in the coincidence case is to
	# assume that each injection is found or missed in each instrument
	# at random, and to be found in the coincidence case it must be
	# found in all three.

	nfound_guess = (nfound / ninjected).prod() * ninjected_guess

	ninjected_guess = int(round(ninjected_guess))
	nfound_guess = int(round(nfound_guess))

	instruments = r" \& ".join(sorted("+".join(sorted(e.instruments)) for e in efficiencies))

	cset = axes.contour(xcoords, ycoords, numpy.transpose(zvals), (.1, .2, .3, .4, .5, .6, .7, .8, .9))
	cset.clabel(inline = True, fontsize = 5, fmt = r"$%%g \pm %g$" % error, colors = "k")

	axes.set_title(r"%s Estimated Injection Detection Efficiency ($\sim$%d of $\sim$%d Found)" % (instruments, nfound_guess, ninjected_guess))

	return fig
	def __init__(self, x, y, magnitude, max_magnitude):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("X", "Y")
		self.fig.set_size_inches(6,6)
		self.x = x
		self.y = y
		self.magnitude = magnitude
		self.n_foreground = 0
		self.n_background = 0
		self.n_injections = 0
		max_magnitude = math.log10(max_magnitude)
		self.foreground_bins = rate.BinnedArray(rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024), rate.LinearBins(-max_magnitude, max_magnitude, 1024))))
		self.background_bins = rate.BinnedArray(rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024), rate.LinearBins(-max_magnitude, max_magnitude, 1024))))
		self.coinc_injection_bins = rate.BinnedArray(rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024), rate.LinearBins(-max_magnitude, max_magnitude, 1024))))
		self.incomplete_coinc_injection_bins = rate.BinnedArray(rate.NDBins((rate.LinearBins(-max_magnitude, max_magnitude, 1024), rate.LinearBins(-max_magnitude, max_magnitude, 1024))))
	def __init__(self, x_instrument, y_instrument, magnitude, desc, min_magnitude, max_magnitude):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("%s %s" % (x_instrument, desc), "%s %s" % (y_instrument, desc))
		self.fig.set_size_inches(6,6)
		self.axes.loglog()
		self.x_instrument = x_instrument
		self.y_instrument = y_instrument
		self.magnitude = magnitude
		self.foreground_x = []
		self.foreground_y = []
		self.n_foreground = 0
		self.n_background = 0
		self.n_injections = 0
		self.foreground_bins = rate.BinnedArray(rate.NDBins((rate.LogarithmicBins(min_magnitude, max_magnitude, 1024), rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
		self.background_bins = rate.BinnedArray(rate.NDBins((rate.LogarithmicBins(min_magnitude, max_magnitude, 1024), rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
		self.coinc_injection_bins = rate.BinnedArray(rate.NDBins((rate.LogarithmicBins(min_magnitude, max_magnitude, 1024), rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
		self.incomplete_coinc_injection_bins = rate.BinnedArray(rate.NDBins((rate.LogarithmicBins(min_magnitude, max_magnitude, 1024), rate.LogarithmicBins(min_magnitude, max_magnitude, 1024))))
Exemple #43
0
	def finish(self):
		for instrument, data in sorted(self.data.items()):
			fig, axes = SnglBurstUtils.make_burst_plot("Injected %s" % self.amplitude_lbl, r"Recovered $A$")
			axes.loglog()
			fig.set_size_inches(8, 8)
			axes.scatter(data.x, data.y, c = data.c, s = 16)
			#xmin, xmax = axes.get_xlim()
			#ymin, ymax = axes.get_ylim()
			xmin, xmax = min(data.x), max(data.x)
			ymin, ymax = min(data.y), max(data.y)
			xmin = ymin = min(xmin, ymin)
			xmax = ymax = max(xmax, ymax)
			axes.plot([xmin, xmax], [ymin, ymax], "k-")
			axes.set_xlim([xmin, xmax])
			axes.set_ylim([ymin, ymax])
			axes.set_title(r"Recovered $A$ vs.\ Injected %s in %s (%d Recovered Injections)" % (self.amplitude_lbl, instrument, data.found))
			yield fig
Exemple #44
0
def plot_rate_vs_threshold(data):
	"""
	Input is a RateVsThresholdData instance.  Output is a matplotlib
	Figure instance.
	"""
	# start the rate vs. threshold plot


	print(file=sys.stderr)
	print("plotting event rate ...", file=sys.stderr)

	fig, axes = SnglBurstUtils.make_burst_plot(r"Detection Statistic Threshold", r"Mean Event Rate (Hz)")
	axes.semilogy()

	# draw the background rate 1-sigma error bars as a shaded polygon
	# clipped to the plot.  warning:  the error bar polygon is not
	# *really* clipped to the axes' bounding box, the result will be
	# incorrect if the number of sample points is small.

	ymin = 1e-9
	ymax = 1e0
	poly_x = numpy.concatenate((data.background_rate_x, data.background_rate_x[::-1]))
	poly_y = numpy.concatenate((data.background_rate_y + 1 * data.background_rate_dy, (data.background_rate_y - 1 * data.background_rate_dy)[::-1]))
	axes.add_patch(patches.Polygon(numpy.column_stack((poly_x, numpy.clip(poly_y, ymin, ymax))), edgecolor = "k", facecolor = "k", alpha = 0.3))

	# draw the mean background event rate

	line1 = axes.plot(data.background_rate_x, data.background_rate_y, "k-")

	# draw the smoothed approximation to the mean background event rate

	#index = bisect.bisect(data.background_rate_x, data.amplitude_threshold)
	#lo = len(data.background_rate_x) - (len(data.background_rate_x) - index) * 10
	#hi = len(data.background_rate_x) - (len(data.background_rate_x) - index) / 10
	#x = data.background_rate_x[lo:hi]
	#line2 = axes.plot(x, data.background_rate_approximant(x), "b-")

	# draw the mean zero-lag event rate.  if the box is closed, these
	# arrays will be empty.

	line3 = axes.plot(data.zero_lag_rate_x, data.zero_lag_rate_y, "r-")

	# draw a vertical marker indicating the threshold

	axes.axvline(data.amplitude_threshold, color = "k")

	#axes.set_ylim((ymin, ymax))
	#axes.xaxis.grid(True, which="minor")
	#axes.yaxis.grid(True, which="minor")

	# add a legend and a title

	axes.legend((line1, line3), (r"Background (time slides)", r"Zero lag"))
	axes.set_title(r"Mean Event Rate vs.\ Detection Statistic Threshold")

	# done rate vs. threshold plot

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold.pdf")
	print("writing lalapps_excesspowerfinal_rate_vs_threshold.png ...", file=sys.stderr)
	fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold.png")

	# start rate vs. threshold residual plot

	fig, axes = SnglBurstUtils.make_burst_plot(r"Detection Statistic Threshold", r"Mean Event Rate Residual (standard deviations)")

	# construct a linear interpolator for the backround rate data so
	# that we can evaluate it at the x co-ordinates of the zero-lag
	# curve samples

	interp_y = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_y, kind = "linear", bounds_error = False)
	interp_dy = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_dy, kind = "linear", bounds_error = False)

	# plot the residual

	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-")

	# add a title

	axes.set_title(r"Mean Event Rate Residual vs.\ Detection Statistic Threshold")

	# done rate vs. threshold residual plot

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold_residual.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold_residual.pdf")
	print("writing lalapps_excesspowerfinal_rate_vs_threshold_residual.png ...", file=sys.stderr)
	fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold_residual.png")
	def finish(self):
		#
		# dump info about highest-ranked zero-lag and background
		# events
		#

		self.most_significant_background.sort()
		self.candidates.sort()

		f = file("string_most_significant_background.txt", "w")
		print("Highest-Ranked Background Events", file=f)
		print("================================", file=f)
		for ln_likelihood_ratio, filename, coinc_event_id, instruments, peak_time in self.most_significant_background:
			print(file=f)
			print("%s in %s:" % (str(coinc_event_id), filename), file=f)
			print("Recovered in: %s" % ", ".join(sorted(instruments or [])), file=f)
			print("Mean peak time:  %.16g s GPS" % peak_time, file=f)
			print("\\log \\Lambda:  %.16g" % ln_likelihood_ratio, file=f)

		f = file("string_candidates.txt", "w")
		print("Highest-Ranked Zero-Lag Events", file=f)
		print("==============================", file=f)
		if self.open_box:
			for ln_likelihood_ratio, filename, coinc_event_id, instruments, peak_time in self.candidates:
				print(file=f)
				print("%s in %s:" % (str(coinc_event_id), filename), file=f)
				print("Recovered in: %s" % ", ".join(sorted(instruments or [])), file=f)
				print("Mean peak time:  %.16g s GPS" % peak_time, file=f)
				print("\\log \\Lambda:  %.16g" % ln_likelihood_ratio, file=f)
		else:
			print(file=f)
			print("List suppressed:  box is closed", file=f)

		#
		# sort the ranking statistics and convert to arrays.
		#

		self.background.sort()
		self.zero_lag.sort()
		self.zero_lag = numpy.array(self.zero_lag, dtype = "double")
		background_x = numpy.array(self.background, dtype = "double")

		#
		# convert counts to rates and their uncertainties
		#

		# background count expected in zero-lag and \sqrt{N}
		# standard deviation
		background_y = numpy.arange(len(background_x), 0.0, -1.0, dtype = "double") / self.background_time * self.zero_lag_time
		background_yerr = numpy.sqrt(background_y)

		# count observed in zero-lag
		zero_lag_y = numpy.arange(len(self.zero_lag), 0.0, -1.0, dtype = "double")

		# compute zero-lag - expected residual in units of \sqrt{N}
		zero_lag_residual = numpy.zeros((len(self.zero_lag),), dtype = "double")
		for i in xrange(len(self.zero_lag)):
			n = expected_count(self.zero_lag[i], background_x, background_y)
			zero_lag_residual[i] = (zero_lag_y[i] - n) / math.sqrt(n)

		# convert counts to rates
		background_y /= self.zero_lag_time
		background_yerr /= self.zero_lag_time
		zero_lag_y /= self.zero_lag_time

		#
		# determine the horizontal and vertical extent of the plot
		#

		if self.open_box:
			minX, maxX, minY, maxY = ratevsthresh_bounds(background_x, background_y, self.zero_lag, zero_lag_y)
		else:
			minX, maxX, minY, maxY = ratevsthresh_bounds(background_x, background_y, [], [])

		#
		# compress the background data
		#

		background_x, background_y, background_yerr = compress_ratevsthresh_curve(background_x, background_y, background_yerr)

		#
		# save data points in a text file
		#

		numpy.savetxt('string_rate_background.txt',numpy.transpose((background_x,background_y,background_yerr)))

		#
		# start the rate vs. threshold plot
		#

		ratefig, axes = SnglBurstUtils.make_burst_plot(r"Ranking Statistic Threshold, $\log \Lambda$", "Event Rate (Hz)", width = 108.0)
		axes.semilogy()
		axes.set_position([0.125, 0.15, 0.83, 0.75])
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")
		if self.open_box:
			axes.set_title(r"Event Rate vs.\ Ranking Statistic Threshold")
		else:
			axes.set_title(r"Event Rate vs.\ Ranking Statistic Threshold (Closed Box)")

		# warning:  the error bar polygon is not *really* clipped
		# to the axes' bounding box, the result will be incorrect
		# if the density of data points is small where the polygon
		# encounters the axes' bounding box.

		poly_x = numpy.concatenate((background_x, background_x[::-1]))
		poly_y = numpy.concatenate((background_y + 1 * background_yerr, (background_y - 1 * background_yerr)[::-1]))
		axes.add_patch(patches.Polygon(zip(poly_x, numpy.clip(poly_y, minY, maxY)), edgecolor = "k", facecolor = "k", alpha = 0.3))
		line1, = axes.semilogy(background_x.repeat(2)[:-1], background_y.repeat(2)[1:], color = "k", linestyle = "--")
		if self.open_box:
			line2, = axes.semilogy(self.zero_lag.repeat(2)[:-1], zero_lag_y.repeat(2)[1:], color = "k", linestyle = "-", linewidth = 2)
			axes.legend((line1, line2), (r"Expected background", r"Zero-lag"), loc = "lower left")
		else:
			axes.legend((line1,), (r"Expected background",), loc = "lower left")

		axes.set_xlim((minX, maxX))
		axes.set_ylim((minY, maxY))

		#
		# start the count residual vs. threshold plot
		#

		residualfig, axes = SnglBurstUtils.make_burst_plot(r"Ranking Statistic Threshold, $\log \Lambda$", r"Event Count Residual / $\sqrt{N}$", width = 108.0)
		axes.set_position([0.125, 0.15, 0.83, 0.75])
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")
		if self.open_box:
			axes.set_title(r"Event Count Residual vs.\ Ranking Statistic Threshold")
		else:
			axes.set_title(r"Event Count Residual vs.\ Ranking Statistic Threshold (Closed Box)")

		axes.add_patch(patches.Polygon(((minX, -1), (maxX, -1), (maxX, +1), (minX, +1)), edgecolor = "k", facecolor = "k", alpha = 0.3))
		if self.open_box:
			line1, = axes.plot(self.zero_lag, zero_lag_residual, color = "k", linestyle = "-", linewidth = 2)

		axes.set_xlim((minX, maxX))

		#
		# done
		#

		return ratefig, residualfig
Exemple #46
0
	def finish(self):
		fig, axes = SnglBurstUtils.make_burst_plot(r"Injection Amplitude (\(\mathrm{s}^{-\frac{1}{3}}\))", "Detection Efficiency", width = 108.0)
		axes.set_title(r"Detection Efficiency vs.\ Amplitude")
		axes.semilogx()
		axes.set_position([0.10, 0.150, 0.86, 0.77])

		# set desired yticks
		axes.set_yticks((0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0))
		axes.set_yticklabels((r"\(0\)", r"\(0.1\)", r"\(0.2\)", r"\(0.3\)", r"\(0.4\)", r"\(0.5\)", r"\(0.6\)", r"\(0.7\)", r"\(0.8\)", r"\(0.9\)", r"\(1.0\)"))
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")

		# put made and found injections in the denominators and
		# numerators of the efficiency bins
		bins = rate.NDBins((rate.LogarithmicBins(min(sim.amplitude for sim in self.all), max(sim.amplitude for sim in self.all), 400),))
		efficiency_num = rate.BinnedArray(bins)
		efficiency_den = rate.BinnedArray(bins)
		for sim in self.found:
			efficiency_num[sim.amplitude,] += 1
		for sim in self.all:
			efficiency_den[sim.amplitude,] += 1

		# generate and plot trend curves.  adjust window function
		# normalization so that denominator array correctly
		# represents the number of injections contributing to each
		# bin:  make w(0) = 1.0.  note that this factor has no
		# effect on the efficiency because it is common to the
		# numerator and denominator arrays.  we do this for the
		# purpose of computing the Poisson error bars, which
		# requires us to know the counts for the bins
		windowfunc = rate.gaussian_window(self.filter_width)
		windowfunc /= windowfunc[len(windowfunc) / 2 + 1]
		rate.filter_binned_array(efficiency_num, windowfunc)
		rate.filter_binned_array(efficiency_den, windowfunc)

		# regularize:  adjust unused bins so that the efficiency is
		# 0, not NaN
		assert (efficiency_num <= efficiency_den).all()
		efficiency_den[efficiency_num == 0 & efficiency_den == 0] = 1

		line1, A50, A50_err = render_data_from_bins(file("string_efficiency.dat", "w"), axes, efficiency_num, efficiency_den, self.cal_uncertainty, self.filter_width, colour = "k", linestyle = "-", erroralpha = 0.2)
		print >>sys.stderr, "Pipeline's 50%% efficiency point for all detections = %g +/- %g%%\n" % (A50, A50_err * 100)

		# add a legend to the axes
		axes.legend((line1,), (r"\noindent Injections recovered with $\Lambda > %s$" % SnglBurstUtils.latexnumber("%.2e" % self.detection_threshold),), loc = "lower right")

		# adjust limits
		axes.set_xlim([1e-21, 2e-18])
		axes.set_ylim([0.0, 1.0])

		#
		# dump some information about the highest-amplitude missed
		# and quietest-amplitude found injections
		#

		self.loudest_missed.sort(reverse = True)
		self.quietest_found.sort(reverse = True)

		f = file("string_loud_missed_injections.txt", "w")
		print >>f, "Highest Amplitude Missed Injections"
		print >>f, "==================================="
		for amplitude, sim, offsetvector, filename, likelihood_ratio in self.loudest_missed:
			print >>f
			print >>f, "%s in %s:" % (str(sim.simulation_id), filename)
			if likelihood_ratio is None:
				print >>f, "Not recovered"
			else:
				print >>f, "Recovered with \\Lambda = %.16g, detection threshold was %.16g" % (likelihood_ratio, self.detection_threshold)
			for instrument in self.seglists:
				print >>f, "In %s:" % instrument
				print >>f, "\tInjected amplitude:\t%.16g" % SimBurstUtils.string_amplitude_in_instrument(sim, instrument, offsetvector)
				print >>f, "\tTime of injection:\t%s s" % sim.time_at_instrument(instrument, offsetvector)
			print >>f, "Amplitude in waveframe:\t%.16g" % sim.amplitude
			t = sim.get_time_geocent()
			print >>f, "Time at geocentre:\t%s s" % t
			print >>f, "Segments within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.seglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.seglists))
			print >>f, "Vetoes within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.vetoseglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.vetoseglists))

		f = file("string_quiet_found_injections.txt", "w")
		print >>f, "Lowest Amplitude Found Injections"
		print >>f, "================================="
		for inv_amplitude, sim, offsetvector, filename, likelihood_ratio in self.quietest_found:
			print >>f
			print >>f, "%s in %s:" % (str(sim.simulation_id), filename)
			if likelihood_ratio is None:
				print >>f, "Not recovered"
			else:
				print >>f, "Recovered with \\Lambda = %.16g, detection threshold was %.16g" % (likelihood_ratio, self.detection_threshold)
			for instrument in self.seglists:
				print >>f, "In %s:" % instrument
				print >>f, "\tInjected amplitude:\t%.16g" % SimBurstUtils.string_amplitude_in_instrument(sim, instrument, offsetvector)
				print >>f, "\tTime of injection:\t%s s" % sim.time_at_instrument(instrument, offsetvector)
			print >>f, "Amplitude in waveframe:\t%.16g" % sim.amplitude
			t = sim.get_time_geocent()
			print >>f, "Time at geocentre:\t%s s" % t
			print >>f, "Segments within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.seglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.seglists))
			print >>f, "Vetoes within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.vetoseglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.vetoseglists))

		#
		# done
		#

		return fig,
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Duration (s)", "Trigger Count")
		self.ifo = ifo
		self.nevents = 0
		self.bins = {}
Exemple #48
0
	def finish(self):
		#
		# dump info about highest-ranked zero-lag and background
		# events
		#

		self.most_significant_background.sort()
		self.candidates.sort()

		f = file("string_most_significant_background.txt", "w")
		print >>f, "Highest-Ranked Background Events"
		print >>f, "================================"
		for likelihood_ratio, filename, coinc_event_id, instruments, peak_time in self.most_significant_background:
			print >>f
			print >>f, "%s in %s:" % (str(coinc_event_id), filename)
			print >>f, "Recovered in: %s" % ", ".join(sorted(instruments or []))
			print >>f, "Mean peak time:  %.16g s GPS" % peak_time
			print >>f, "\\Lambda:  %.16g" % likelihood_ratio

		f = file("string_candidates.txt", "w")
		print >>f, "Highest-Ranked Zero-Lag Events"
		print >>f, "=============================="
		if self.open_box:
			for likelihood_ratio, filename, coinc_event_id, instruments, peak_time in self.candidates:
				print >>f
				print >>f, "%s in %s:" % (str(coinc_event_id), filename)
				print >>f, "Recovered in: %s" % ", ".join(sorted(instruments or []))
				print >>f, "Mean peak time:  %.16g s GPS" % peak_time
				print >>f, "\\Lambda:  %.16g" % likelihood_ratio
		else:
			print >>f
			print >>f, "List suppressed:  box is closed"

		#
		# sort the ranking statistics and convert to arrays.
		#

		self.background.sort()
		self.zero_lag.sort()
		self.zero_lag = numpy.array(self.zero_lag, dtype = "double")
		background_x = numpy.array(self.background, dtype = "double")

		#
		# convert counts to rates and their uncertainties
		#

		# background count expected in zero-lag and \sqrt{N}
		# standard deviation
		background_y = numpy.arange(len(background_x), 0.0, -1.0, dtype = "double") / self.background_time * self.zero_lag_time
		background_yerr = numpy.sqrt(background_y)

		# count observed in zero-lag
		zero_lag_y = numpy.arange(len(self.zero_lag), 0.0, -1.0, dtype = "double")

		# compute zero-lag - expected residual in units of \sqrt{N}
		zero_lag_residual = numpy.zeros((len(self.zero_lag),), dtype = "double")
		for i in xrange(len(self.zero_lag)):
			n = expected_count(self.zero_lag[i], background_x, background_y)
			zero_lag_residual[i] = (zero_lag_y[i] - n) / math.sqrt(n)

		# convert counts to rates
		background_y /= self.zero_lag_time
		background_yerr /= self.zero_lag_time
		zero_lag_y /= self.zero_lag_time

		#
		# determine the horizontal and vertical extent of the plot
		#

		if self.open_box:
			minX, maxX, minY, maxY = ratevsthresh_bounds(background_x, background_y, self.zero_lag, zero_lag_y)
		else:
			minX, maxX, minY, maxY = ratevsthresh_bounds(background_x, background_y, [], [])

		#
		# compress the background data
		#

		background_x, background_y, background_yerr = compress_ratevsthresh_curve(background_x, background_y, background_yerr)

		#
		# start the rate vs. threshold plot
		#

		ratefig, axes = SnglBurstUtils.make_burst_plot(r"Likelihood Ratio Threshold $\Lambda$", "Event Rate (Hz)", width = 108.0)
		axes.loglog()
		axes.set_position([0.125, 0.15, 0.83, 0.75])
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")
		if self.open_box:
			axes.set_title(r"Event Rate vs.\ Likelihood Ratio Threshold")
		else:
			axes.set_title(r"Event Rate vs.\ Likelihood Ratio Threshold (Closed Box)")

		# warning:  the error bar polygon is not *really* clipped
		# to the axes' bounding box, the result will be incorrect
		# if the density of data points is small where the polygon
		# encounters the axes' bounding box.

		poly_x = numpy.concatenate((background_x, background_x[::-1]))
		poly_y = numpy.concatenate((background_y + 1 * background_yerr, (background_y - 1 * background_yerr)[::-1]))
		axes.add_patch(patches.Polygon(zip(poly_x, numpy.clip(poly_y, minY, maxY)), edgecolor = "k", facecolor = "k", alpha = 0.3))
		line1, = axes.loglog(background_x.repeat(2)[:-1], background_y.repeat(2)[1:], color = "k", linestyle = "--")
		if self.open_box:
			line2, = axes.loglog(self.zero_lag.repeat(2)[:-1], zero_lag_y.repeat(2)[1:], color = "k", linestyle = "-", linewidth = 2)
			axes.legend((line1, line2), (r"Expected background", r"Zero-lag"), loc = "lower left")
		else:
			axes.legend((line1,), (r"Expected background",), loc = "lower left")

		axes.set_xlim((minX, maxX))
		axes.set_ylim((minY, maxY))

		#
		# start the count residual vs. threshold plot
		#

		residualfig, axes = SnglBurstUtils.make_burst_plot(r"Likelihood Ratio Threshold $\Lambda$", r"Event Count Residual / $\sqrt{N}$", width = 108.0)
		axes.semilogx()
		axes.set_position([0.125, 0.15, 0.83, 0.75])
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")
		if self.open_box:
			axes.set_title(r"Event Count Residual vs.\ Likelihood Ratio Threshold")
		else:
			axes.set_title(r"Event Count Residual vs.\ Likelihood Ratio Threshold (Closed Box)")

		axes.add_patch(patches.Polygon(((minX, -1), (maxX, -1), (maxX, +1), (minX, +1)), edgecolor = "k", facecolor = "k", alpha = 0.3))
		if self.open_box:
			line1, = axes.semilogx(self.zero_lag, zero_lag_residual, color = "k", linestyle = "-", linewidth = 2)

		axes.set_xlim((minX, maxX))

		#
		# done
		#

		return ratefig, residualfig
	def __init__(self, ifo):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("GPS Time (s)", "Frequency (Hz)")
		self.ifo = ifo
		self.nevents = 0
		self.seglist = segments.segmentlist()
	def __init__(self, instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("Number of Triggers Coincident with Injection", "Count")
		self.axes.semilogy()
		self.instrument = instrument
		self.found = 0
		self.bins = []
 def __init__(self, ifo):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "Duration (s)", "Trigger Count")
     self.ifo = ifo
     self.nevents = 0
     self.bins = {}
 def __init__(self, ifo):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "GPS Time (s)", "Frequency (Hz)")
     self.ifo = ifo
     self.nevents = 0
     self.seglist = segments.segmentlist()
def plot_rate_vs_threshold(data):
	"""
	Input is a RateVsThresholdData instance.  Output is a matplotlib
	Figure instance.
	"""
	# start the rate vs. threshold plot


	print >>sys.stderr
	print >>sys.stderr, "plotting event rate ..."

	fig, axes = SnglBurstUtils.make_burst_plot(r"Detection Statistic Threshold", r"Mean Event Rate (Hz)")
	axes.semilogy()

	# draw the background rate 1-sigma error bars as a shaded polygon
	# clipped to the plot.  warning:  the error bar polygon is not
	# *really* clipped to the axes' bounding box, the result will be
	# incorrect if the number of sample points is small.

	ymin = 1e-9
	ymax = 1e0
	poly_x = numpy.concatenate((data.background_rate_x, data.background_rate_x[::-1]))
	poly_y = numpy.concatenate((data.background_rate_y + 1 * data.background_rate_dy, (data.background_rate_y - 1 * data.background_rate_dy)[::-1]))
	axes.add_patch(patches.Polygon(numpy.column_stack((poly_x, numpy.clip(poly_y, ymin, ymax))), edgecolor = "k", facecolor = "k", alpha = 0.3))

	# draw the mean background event rate

	line1 = axes.plot(data.background_rate_x, data.background_rate_y, "k-")

	# draw the smoothed approximation to the mean background event rate

	#index = bisect.bisect(data.background_rate_x, data.amplitude_threshold)
	#lo = len(data.background_rate_x) - (len(data.background_rate_x) - index) * 10
	#hi = len(data.background_rate_x) - (len(data.background_rate_x) - index) / 10
	#x = data.background_rate_x[lo:hi]
	#line2 = axes.plot(x, data.background_rate_approximant(x), "b-")

	# draw the mean zero-lag event rate.  if the box is closed, these
	# arrays will be empty.

	line3 = axes.plot(data.zero_lag_rate_x, data.zero_lag_rate_y, "r-")

	# draw a vertical marker indicating the threshold

	axes.axvline(data.amplitude_threshold, color = "k")

	#axes.set_ylim((ymin, ymax))
	#axes.xaxis.grid(True, which="minor")
	#axes.yaxis.grid(True, which="minor")

	# add a legend and a title

	axes.legend((line1, line3), (r"Background (time slides)", r"Zero lag"))
	axes.set_title(r"Mean Event Rate vs.\ Detection Statistic Threshold")

	# done rate vs. threshold plot

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold.pdf")
	print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold.png ..."
	fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold.png")

	# start rate vs. threshold residual plot

	fig, axes = SnglBurstUtils.make_burst_plot(r"Detection Statistic Threshold", r"Mean Event Rate Residual (standard deviations)")

	# construct a linear interpolator for the backround rate data so
	# that we can evaluate it at the x co-ordinates of the zero-lag
	# curve samples

	interp_y = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_y, kind = "linear", bounds_error = False)
	interp_dy = interpolate.interpolate.interp1d(data.background_rate_x, data.background_rate_dy, kind = "linear", bounds_error = False)

	# plot the residual

	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-")

	# add a title

	axes.set_title(r"Mean Event Rate Residual vs.\ Detection Statistic Threshold")

	# done rate vs. threshold residual plot

	#print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold_residual.pdf ..."
	#fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold_residual.pdf")
	print >>sys.stderr, "writing lalapps_excesspowerfinal_rate_vs_threshold_residual.png ..."
	fig.savefig("lalapps_excesspowerfinal_rate_vs_threshold_residual.png")
	def finish(self):
		fig, axes = SnglBurstUtils.make_burst_plot(r"Injection Amplitude (\(\mathrm{s}^{-\frac{1}{3}}\))", "Detection Efficiency", width = 108.0)
		axes.set_title(r"Detection Efficiency vs.\ Amplitude")
		axes.semilogx()
		axes.set_position([0.10, 0.150, 0.86, 0.77])

		# set desired yticks
		axes.set_yticks((0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0))
		axes.set_yticklabels((r"\(0\)", r"\(0.1\)", r"\(0.2\)", r"\(0.3\)", r"\(0.4\)", r"\(0.5\)", r"\(0.6\)", r"\(0.7\)", r"\(0.8\)", r"\(0.9\)", r"\(1.0\)"))
		axes.xaxis.grid(True, which = "major,minor")
		axes.yaxis.grid(True, which = "major,minor")

		# put made and found injections in the denominators and
		# numerators of the efficiency bins
		bins = rate.NDBins((rate.LogarithmicBins(min(sim.amplitude for sim in self.all), max(sim.amplitude for sim in self.all), 400),))
		efficiency_num = rate.BinnedArray(bins)
		efficiency_den = rate.BinnedArray(bins)
		for sim in self.found:
			efficiency_num[sim.amplitude,] += 1
		for sim in self.all:
			efficiency_den[sim.amplitude,] += 1

		# generate and plot trend curves.  adjust window function
		# normalization so that denominator array correctly
		# represents the number of injections contributing to each
		# bin:  make w(0) = 1.0.  note that this factor has no
		# effect on the efficiency because it is common to the
		# numerator and denominator arrays.  we do this for the
		# purpose of computing the Poisson error bars, which
		# requires us to know the counts for the bins
		windowfunc = rate.gaussian_window(self.filter_width)
		windowfunc /= windowfunc[len(windowfunc) / 2 + 1]
		rate.filter_array(efficiency_num.array, windowfunc)
		rate.filter_array(efficiency_den.array, windowfunc)

		# regularize:  adjust unused bins so that the efficiency is
		# 0, not NaN
		assert (efficiency_num.array <= efficiency_den.array).all()
		efficiency_den.array[(efficiency_num.array == 0) & (efficiency_den.array == 0)] = 1

		line1, A50, A50_err = render_data_from_bins(file("string_efficiency.dat", "w"), axes, efficiency_num, efficiency_den, self.cal_uncertainty, self.filter_width, colour = "k", linestyle = "-", erroralpha = 0.2)
		print("Pipeline's 50%% efficiency point for all detections = %g +/- %g%%\n" % (A50, A50_err * 100), file=sys.stderr)

		# add a legend to the axes
		axes.legend((line1,), (r"\noindent Injections recovered with $\log \Lambda > %.2f$" % self.detection_threshold,), loc = "lower right")

		# adjust limits
		axes.set_xlim([3e-22, 3e-19])
		axes.set_ylim([0.0, 1.0])

		#
		# dump some information about the highest-amplitude missed
		# and quietest-amplitude found injections
		#

		self.loudest_missed.sort(reverse = True)
		self.quietest_found.sort(reverse = True)

		f = file("string_loud_missed_injections.txt", "w")
		print("Highest Amplitude Missed Injections", file=f)
		print("===================================", file=f)
		for amplitude, sim, offsetvector, filename, ln_likelihood_ratio in self.loudest_missed:
			print(file=f)
			print("%s in %s:" % (str(sim.simulation_id), filename), file=f)
			if ln_likelihood_ratio is None:
				print("Not recovered", file=f)
			else:
				print("Recovered with \\log \\Lambda = %.16g, detection threshold was %.16g" % (ln_likelihood_ratio, self.detection_threshold), file=f)
			for instrument in self.seglists:
				print("In %s:" % instrument, file=f)
				print("\tInjected amplitude:\t%.16g" % SimBurstUtils.string_amplitude_in_instrument(sim, instrument, offsetvector), file=f)
				print("\tTime of injection:\t%s s" % sim.time_at_instrument(instrument, offsetvector), file=f)
			print("Amplitude in waveframe:\t%.16g" % sim.amplitude, file=f)
			t = sim.get_time_geocent()
			print("Time at geocentre:\t%s s" % t, file=f)
			print("Segments within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.seglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.seglists)), file=f)
			print("Vetoes within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.vetoseglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.vetoseglists)), file=f)

		f = file("string_quiet_found_injections.txt", "w")
		print("Lowest Amplitude Found Injections", file=f)
		print("=================================", file=f)
		for inv_amplitude, sim, offsetvector, filename, ln_likelihood_ratio in self.quietest_found:
			print(file=f)
			print("%s in %s:" % (str(sim.simulation_id), filename), file=f)
			if ln_likelihood_ratio is None:
				print("Not recovered", file=f)
			else:
				print("Recovered with \\log \\Lambda = %.16g, detection threshold was %.16g" % (ln_likelihood_ratio, self.detection_threshold), file=f)
			for instrument in self.seglists:
				print("In %s:" % instrument, file=f)
				print("\tInjected amplitude:\t%.16g" % SimBurstUtils.string_amplitude_in_instrument(sim, instrument, offsetvector), file=f)
				print("\tTime of injection:\t%s s" % sim.time_at_instrument(instrument, offsetvector), file=f)
			print("Amplitude in waveframe:\t%.16g" % sim.amplitude, file=f)
			t = sim.get_time_geocent()
			print("Time at geocentre:\t%s s" % t, file=f)
			print("Segments within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.seglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.seglists)), file=f)
			print("Vetoes within 60 seconds:\t%s" % segmentsUtils.segmentlistdict_to_short_string(self.vetoseglists & segments.segmentlistdict((instrument, segments.segmentlist([segments.segment(t-offsetvector[instrument]-60, t-offsetvector[instrument]+60)])) for instrument in self.vetoseglists)), file=f)

		#
		# done
		#

		return fig,