예제 #1
0
	def add_contents(self, contents, verbose = False):
		#
		# update segment information
		#

		self.seglists |= contents.seglists
		self.vetoseglists |= contents.vetoseglists
		seglists = contents.seglists - contents.vetoseglists
		if set(("H1", "H2")).issubset(set(seglists)):
			# we have segments for both H1 and H2, remove time
			# when exactly that pair are on
			seglists -= segments.segmentlistdict.fromkeys(seglists, seglists.intersection(("H1", "H2")) - seglists.union(set(seglists) - set(("H1", "H2"))))

		# for each injection, retrieve the highest likelihood ratio
		# of the burst coincs that were found to match the
		# injection or null if no burst coincs matched the
		# injection
		offsetvectors = contents.time_slide_table.as_dict()
		stringutils.create_recovered_ln_likelihood_ratio_table(contents.connection, contents.bb_definer_id)
		for values in contents.connection.cursor().execute("""
SELECT
	sim_burst.*,
	recovered_ln_likelihood_ratio.ln_likelihood_ratio
FROM
	sim_burst
	LEFT JOIN recovered_ln_likelihood_ratio ON (
		recovered_ln_likelihood_ratio.simulation_id == sim_burst.simulation_id
	)
		"""):
			sim = contents.sim_burst_table.row_from_cols(values[:-1])
			ln_likelihood_ratio = values[-1]
			found = ln_likelihood_ratio is not None
			# were at least 2 instruments on when the injection
			# was made?
			if len(SimBurstUtils.on_instruments(sim, seglists, offsetvectors[sim.time_slide_id])) >= 2:
				# yes
				self.all.append(sim)
				if found and ln_likelihood_ratio > self.detection_threshold:
					self.found.append(sim)
					# 1/amplitude needs to be first so
					# that it acts as the sort key
					record = (1.0 / sim.amplitude, sim, offsetvectors[sim.time_slide_id], contents.filename, ln_likelihood_ratio)
					if len(self.quietest_found) < self.n_diagnostics:
						heapq.heappush(self.quietest_found, record)
					else:
						heapq.heappushpop(self.quietest_found, record)
				else:
					# amplitude needs to be first so
					# that it acts as the sort key
					record = (sim.amplitude, sim, offsetvectors[sim.time_slide_id], contents.filename, ln_likelihood_ratio)
					if len(self.loudest_missed) < self.n_diagnostics:
						heapq.heappush(self.loudest_missed, record)
					else:
						heapq.heappushpop(self.loudest_missed, record)
			elif found:
				# no, but it was found anyway
				print("%s: odd, injection %s was found but not injected ..." % (contents.filename, sim.simulation_id), file=sys.stderr)
예제 #2
0
	def add_contents(self, contents, verbose = False):
		#
		# update segment information
		#

		self.seglists |= contents.seglists
		self.vetoseglists |= contents.vetoseglists
		seglists = contents.seglists - contents.vetoseglists
		if set(("H1", "H2")).issubset(set(seglists)):
			# we have segments for both H1 and H2, remove time
			# when exactly that pair are on
			seglists -= segments.segmentlistdict.fromkeys(seglists, seglists.intersection(("H1", "H2")) - seglists.union(set(seglists) - set(("H1", "H2"))))

		# for each injection, retrieve the highest likelihood ratio
		# of the burst coincs that were found to match the
		# injection or null if no burst coincs matched the
		# injection
		offsetvectors = contents.time_slide_table.as_dict()
		stringutils.create_recovered_likelihood_table(contents.connection, contents.bb_definer_id)
		for values in contents.connection.cursor().execute("""
SELECT
	sim_burst.*,
	recovered_likelihood.likelihood
FROM
	sim_burst
	LEFT JOIN recovered_likelihood ON (
		recovered_likelihood.simulation_id == sim_burst.simulation_id
	)
		"""):
			sim = contents.sim_burst_table.row_from_cols(values[:-1])
			likelihood_ratio = values[-1]
			found = likelihood_ratio is not None
			# were at least 2 instruments on when the injection
			# was made?
			if len(SimBurstUtils.on_instruments(sim, seglists, offsetvectors[sim.time_slide_id])) >= 2:
				# yes
				self.all.append(sim)
				if found and likelihood_ratio > self.detection_threshold:
					self.found.append(sim)
					# 1/amplitude needs to be first so
					# that it acts as the sort key
					record = (1.0 / sim.amplitude, sim, offsetvectors[sim.time_slide_id], contents.filename, likelihood_ratio)
					if len(self.quietest_found) < self.n_diagnostics:
						heapq.heappush(self.quietest_found, record)
					else:
						heapq.heappushpop(self.quietest_found, record)
				else:
					# amplitude needs to be first so
					# that it acts as the sort key
					record = (sim.amplitude, sim, offsetvectors[sim.time_slide_id], contents.filename, likelihood_ratio)
					if len(self.loudest_missed) < self.n_diagnostics:
						heapq.heappush(self.loudest_missed, record)
					else:
						heapq.heappushpop(self.loudest_missed, record)
			elif found:
				# no, but it was found anyway
				print >>sys.stderr, "%s: odd, injection %s was found but not injected ..." % (contents.filename, sim.simulation_id)
예제 #3
0
	def add_contents(self, contents, threshold):
		if self.instruments != contents.instruments:
			raise ValueError("this document contains instruments %s, but we want %s" % ("+".join(contents.instruments), "+".join(self.instruments)))

		# iterate over all sims

		offsetvectors = contents.time_slide_table.as_dict()
		create_sim_coinc_map_view(contents.connection)
		for values in contents.connection.cursor().execute("""
SELECT
	sim_burst.*,
	(
		SELECT
			MAX(sim_coinc_map.burst_coinc_amplitude)
		FROM
			sim_coinc_map
		WHERE
			sim_coinc_map.simulation_id == sim_burst.simulation_id
			AND sim_coinc_map.sim_coinc_def_id == ?
	)
FROM
	sim_burst
		""", (contents.scn_definer_id,)):
			sim = contents.sim_burst_table.row_from_cols(values)
			detection_statistic = values[-1]
			amplitude = self.amplitude_func(sim, None)
			if SimBurstUtils.on_instruments(sim, contents.seglists, offsetvectors[sim.time_slide_id]) == self.instruments:
				# injection was made
				self.injected_x.append(sim.frequency)
				self.injected_y.append(amplitude)
				if detection_statistic is not None:
					# injection was recovered (found at
					# all)
					self.recovered_xyz.append((sim.frequency, amplitude, detection_statistic))
					if detection_statistic > threshold:
						# injection was found above
						# threshold
						self.found_x.append(sim.frequency)
						self.found_y.append(amplitude)
			elif (detection_statistic is not None) and (detection_statistic > threshold):
				# injection was found, and found above
				# threshold, but not "injected" because it
				# lies outside of the output segments.
				# this is not unusual, in particular
				# because we are only looking for coincs
				# that are "nearby" an injection which can
				# mean several seconds.
				print("odd, injection %s was found but not injected ..." % sim.simulation_id, file=sys.stderr)
	def add_contents(self, contents, threshold):
		if self.instruments != contents.instruments:
			raise ValueError("this document contains instruments %s, but we want %s" % ("+".join(contents.instruments), "+".join(self.instruments)))

		# iterate over all sims

		offsetvectors = contents.time_slide_table.as_dict()
		create_sim_coinc_map_view(contents.connection)
		for values in contents.connection.cursor().execute("""
SELECT
	sim_burst.*,
	(
		SELECT
			MAX(sim_coinc_map.burst_coinc_amplitude)
		FROM
			sim_coinc_map
		WHERE
			sim_coinc_map.simulation_id == sim_burst.simulation_id
			AND sim_coinc_map.sim_coinc_def_id == ?
	)
FROM
	sim_burst
		""", (contents.scn_definer_id,)):
			sim = contents.sim_burst_table.row_from_cols(values)
			detection_statistic = values[-1]
			amplitude = self.amplitude_func(sim, None)
			if SimBurstUtils.on_instruments(sim, contents.seglists, offsetvectors[sim.time_slide_id]) == self.instruments:
				# injection was made
				self.injected_x.append(sim.frequency)
				self.injected_y.append(amplitude)
				if detection_statistic is not None:
					# injection was recovered (found at
					# all)
					self.recovered_xyz.append((sim.frequency, amplitude, detection_statistic))
					if detection_statistic > threshold:
						# injection was found above
						# threshold
						self.found_x.append(sim.frequency)
						self.found_y.append(amplitude)
			elif (detection_statistic is not None) and (detection_statistic > threshold):
				# injection was found, and found above
				# threshold, but not "injected" because it
				# lies outside of the output segments.
				# this is not unusual, in particular
				# because we are only looking for coincs
				# that are "nearby" an injection which can
				# mean several seconds.
				print >>sys.stderr, "odd, injection %s was found but not injected ..." % sim.simulation_id