27from bisect
import bisect_left, bisect_right
33from igwn_ligolw
import lsctables
34from igwn_segments
import PosInfinity
35from .
import snglcoinc
38__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
39from .git_version
import date
as __date__
40from .git_version
import version
as __version__
57ExcessPowerBBCoincDef = lsctables.CoincDef(search =
"excesspower", search_coinc_type = 0, description =
"sngl_burst<-->sngl_burst coincidences")
62 super(ExcessPowerCoincTables, self).
__init__(xmldoc)
68 self.
multibursttable = lsctables.New(lsctables.MultiBurstTable, (
"process_id",
"duration",
"central_freq",
"bandwidth",
"snr",
"confidence",
"amplitude",
"coinc_event_id"))
73 process_id = process_id,
74 coinc_event_id = coinc_event_id,
76 false_alarm_rate =
None
81 multiburst.snr = math.sqrt(sum(event.ms_snr**2.0
for event
in events))
89 t = events[0].peak + offset_vector[events[0].ifo]
90 multiburst.peak = t + sum(event.ms_snr**2.0 * float(event.peak + offset_vector[event.ifo] - t)
for event
in events) / multiburst.snr**2.0
94 multiburst.duration = sum(event.ms_snr**2.0 * event.duration
for event
in events) / multiburst.snr**2.0
99 multiburst.central_freq = sum(event.ms_snr**2.0 * event.peak_frequency
for event
in events) / multiburst.snr**2.0
103 multiburst.bandwidth = sum(event.ms_snr**2.0 * event.bandwidth
for event
in events) / multiburst.snr**2.0
107 multiburst.confidence =
min(event.confidence
for event
in events)
111 multiburst.amplitude =
max(events, key =
lambda event: event.ms_confidence).ms_hrss
117 def coinc_rows(self, process_id, time_slide_id, events, table_name):
118 coinc, coincmaps = super(ExcessPowerCoincTables, self).
coinc_rows(process_id, time_slide_id, events, table_name)
119 coinc.insts = (event.ifo
for event
in events)
123 coinc = super(ExcessPowerCoincTables, self).
append_coinc(coinc, coincmaps)
124 multiburst.coinc_event_id = coinc.coinc_event_id
134StringCuspBBCoincDef = lsctables.CoincDef(search =
"StringCusp", search_coinc_type = 0, description =
"sngl_burst<-->sngl_burst coincidences")
138 def coinc_rows(self, process_id, time_slide_id, events, table_name):
139 coinc, coincmaps = super(StringCuspCoincTables, self).
coinc_rows(process_id, time_slide_id, events, table_name)
140 coinc.insts = (event.ifo
for event
in events)
141 return coinc, coincmaps
172 return max(
max(float(event.peak - event.start), float(event.start + event.duration - event.peak))
for event
in events)
176 if abs(a.central_freq - b.central_freq) > (a.bandwidth + b.bandwidth) / 2:
179 astart = a.start + offseta
181 if astart > bstart + b.duration + coinc_window:
185 if bstart > astart + a.duration + coinc_window:
194 self.
times = tuple(map(ep_coincgen_doubles.singlesqueue.event_time, events))
199 def __call__(self, event_a, offset_a, coinc_window):
204 dt = float(peak - event_a.start)
208 dt =
max(dt, event_a.duration - dt)
226 return [event_b
for event_b
in self.
events[bisect_left(self.
times, peak - dt) : bisect_right(self.
times, peak + dt)]
if not self.
comparefunc(event_a, offset_a, event_b, coinc_window)]
239 self.
times = tuple(map(string_coincgen_doubles.singlesqueue.event_time, events))
241 def __call__(self, event_a, offset_a, coinc_window):
242 peak = event_a.peak + offset_a
243 template_id = event_a.template_id
244 return [event
for event
in self.
events[bisect_left(self.
times, peak - coinc_window) : bisect_right(self.
times, peak + coinc_window)]
if event.template_id == template_id]
263 ntuple_comparefunc = lambda events, offset_vector:
False,
273 print(
"indexing ...", file=sys.stderr)
274 coinc_tables =
CoincTables(xmldoc, coinc_definer_row)
280 time_slide_graph =
snglcoinc.TimeSlideGraph(coincgen_doubles, coinc_tables.time_slide_index, delta_t, min_instruments = min_instruments, verbose = verbose)
286 sngl_burst_table = lsctables.SnglBurstTable.get_table(xmldoc)
291 for instrument, events
in itertools.groupby(sorted(sngl_burst_table, key =
lambda row: row.ifo),
lambda event: event.ifo):
292 time_slide_graph.push(instrument, tuple(events), PosInfinity)
298 for instrument, events
in itertools.groupby(sorted(sngl_burst_table, key =
lambda row: (row.peak, row.ifo)),
lambda event: event.ifo):
299 events = tuple(events)
300 if time_slide_graph.push(instrument, events,
max(event.peak
for event
in events)):
301 for node, events
in time_slide_graph.pull(coinc_sieve = ntuple_comparefunc):
302 coinc_tables.append_coinc(*coinc_tables.coinc_rows(process_id, node.time_slide_id, events,
"sngl_burst"))
308 for node, events
in time_slide_graph.pull(coinc_sieve = ntuple_comparefunc, flush =
True):
309 coinc_tables.append_coinc(*coinc_tables.coinc_rows(process_id, node.time_slide_id, events,
"sngl_burst"))
static double max(double a, double b)
static double min(double a, double b)
def make_multi_burst(self, process_id, coinc_event_id, events, offset_vector)
def __init__(self, xmldoc)
def append_coinc(self, coinc, coincmaps, multiburst)
Appends the coinc_event row object and coinc_event_map row objects to the coinc_event and coinc_event...
def coinc_rows(self, process_id, time_slide_id, events, table_name)
From a process ID, a time slide ID, and a sequence of events (generator expressions are OK),...
def coinc_rows(self, process_id, time_slide_id, events, table_name)
From a process ID, a time slide ID, and a sequence of events (generator expressions are OK),...
def __init__(self, events)
def __call__(self, event_a, offset_a, coinc_window)
def comparefunc(a, offseta, b, coinc_window)
def max_edge_peak_delta(events)
def __init__(self, events)
def __call__(self, event_a, offset_a, coinc_window)
A convenience interface to the XML document's coincidence tables, allowing for easy addition of coinc...
Using a pair of singlesqueue objects, constructs pairs of coincident events from streams of partially...
def burca(xmldoc, process_id, coincgen_doubles, CoincTables, coinc_definer_row, delta_t, ntuple_comparefunc=lambda events, False offset_vector, min_instruments=2, incremental=True, verbose=False)