28Inspiral injection identification library. Contains code providing the
29capacity to search a list of sngl_inspiral candidates for events
30matching entries
in a sim_inspiral list of software injections, recording the
31matches
as inspiral <--> injection coincidences using the standard coincidence
32infrastructure. Also, any pre-recorded inspiral <--> inspiral coincidences are
33checked
for cases where all the inspiral events
in a coincidence match an
34injection,
and these are recorded
as coinc <--> injection coincidences,
35again using the standard coincidence infrastructure.
45from lal import iterutils
46from igwn_ligolw import ligolw
47from igwn_ligolw import lsctables
48from igwn_ligolw.utils import coincs as ligolw_coincs
49from igwn_ligolw.utils import time_slide as ligolw_time_slide
53__author__ = "Kipp Cannon <kipp.cannon@ligo.org>"
54from .git_version import date as __date__
55from .git_version import version as __version__
59# =============================================================================
67@functools.total_ordering
70 Version of lsctables.SnglInspiral who's .__cmp__() method compares
71 this object's .end value directly to the value of other. Allows a
72 list of instances of this class sorted by .end to be bisection
73 searched
for a LIGOTimeGPS end time.
77 def __lt__(self, other):
78 return self.
end < other
81 return self.
end == other
93InspiralSICoincDef = lsctables.CoincDef(search =
u"inspiral", search_coinc_type = 1, description =
u"sim_inspiral<-->sngl_inspiral coincidences")
94InspiralSCNearCoincDef = lsctables.CoincDef(search =
u"inspiral", search_coinc_type = 2, description =
u"sim_inspiral<-->coinc_event coincidences (nearby)")
95InspiralSCExactCoincDef = lsctables.CoincDef(search =
u"inspiral", search_coinc_type = 3, description =
u"sim_inspiral<-->coinc_event coincidences (exact)")
96InspiralSTCoincDef = lsctables.CoincDef(search =
u"inspiral", search_coinc_type = 4, description =
u"sim_inspiral<-->sngl_inspiral template coincidences")
101 A wrapper interface to the XML document.
103 def __init__(self, xmldoc, bbdef, sbdef, scedef, scndef, process, end_time_bisect_window):
132 self.
tisi_id = ligolw_time_slide.get_time_slide_id(xmldoc, {}.fromkeys(self.
snglinspiraltable.getColumnByName(
"ifo"), 0.0), create_new = process, superset_ok =
True, nonunique_ok =
True)
140 self.
sb_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, sbdef.search, sbdef.search_coinc_type, create_new =
True, description = sbdef.description)
150 ii_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, bbdef.search, bbdef.search_coinc_type, create_new =
False)
152 ii_coinc_def_id =
None
156 self.
sce_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, scedef.search, scedef.search_coinc_type, create_new =
True, description = scedef.description)
157 self.
scn_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, scndef.search, scndef.search_coinc_type, create_new =
True, description = scndef.description)
167 xmldoc.childNodes[0].appendChild(self.
coinctable)
191 self.
sngls = dict((row.coinc_event_id, [])
for row
in self.
coinctable if row.coinc_def_id == ii_coinc_def_id)
195 self.
sngls[row.coinc_event_id].append(index[row.event_id])
200 self.
coincs = dict((event.event_id, set())
for events
in self.
sngls.values()
for event
in events)
202 if row.event_id
in self.
coincs and row.coinc_event_id
in self.
sngls:
203 self.
coincs[row.event_id].add(row.coinc_event_id)
225 Return a list of the inspiral events whose end times are
232 Return a list of the (coinc_event_id, event list) tuples in
233 which at least one inspiral event
's end time is within
240 coinc_event_ids = set()
243 coinc_event_ids |= self.
coincs[event.event_id]
247 return [(coinc_event_id, self.
sngls[coinc_event_id])
for coinc_event_id
in coinc_event_ids]
251 Sort the sngl_inspiral table's rows by ID (tidy-up document
258 Construct a new coinc_event row attached to the given
259 process, and belonging to the set of coincidences defined
260 by the given coinc_def_id.
262 coinc = lsctables.Coinc()
263 coinc.process_id = self.process.process_id
264 coinc.coinc_def_id = coinc_def_id
265 coinc.coinc_event_id = self.coinctable.get_next_id()
266 coinc.time_slide_id = self.tisi_id
269 coinc.likelihood =
None
285 Scan the inspiral table for triggers matching sim.
287 return [inspiral
for inspiral
in contents.inspirals_near_endtime(sim.time_geocent)
if not comparefunc(sim, inspiral)]
292 Create a coinc_event in the coinc table, and add arcs in the
293 coinc_event_map table linking the sim_inspiral row and the list of
294 sngl_inspiral rows to the new coinc_event row.
296 coinc = contents.new_coinc(contents.sb_coinc_def_id)
297 coinc.insts = (event.ifo
for event
in inspirals)
298 coinc.nevents = len(inspirals)
300 contents.coincmaptable.append(lsctables.CoincMap(
301 coinc_event_id = coinc.coinc_event_id,
302 table_name =
u"sim_inspiral",
303 event_id = sim.simulation_id
306 for event
in inspirals:
307 contents.coincmaptable.append(lsctables.CoincMap(
308 coinc_event_id = coinc.coinc_event_id,
309 table_name =
u"sngl_inspiral",
310 event_id = event.event_id
325 Return a set of the coinc_event_ids of the inspiral<-->inspiral
326 coincs in which all inspiral events match sim.
335 return set(coinc_event_id
for coinc_event_id, inspirals
in coincs
if not any(comparefunc(sim, inspiral)
for inspiral
in inspirals))
340 Return a set of the coinc_event_ids of the inspiral<-->inspiral
341 coincs in which at least one inspiral event matches sim.
350 return set(coinc_event_id
for coinc_event_id, inspirals
in coincs
if not all(comparefunc(sim, inspiral)
for inspiral
in inspirals))
355 Create a coinc_event in the coinc table, and add arcs in the
356 coinc_event_map table linking the sim_inspiral row and the list of
357 coinc_event rows to the new coinc_event row.
359 coinc = contents.new_coinc(coinc_def_id)
360 coinc.nevents = len(coinc_event_ids)
362 contents.coincmaptable.append(lsctables.CoincMap(
363 coinc_event_id = coinc.coinc_event_id,
364 table_name =
u"sim_inspiral",
365 event_id = sim.simulation_id
368 for coinc_event_id
in coinc_event_ids:
369 contents.coincmaptable.append(lsctables.CoincMap(
370 coinc_event_id = coinc.coinc_event_id,
371 table_name =
u"coinc_event",
372 event_id = coinc_event_id
385def ligolw_inspinjfind(xmldoc, process, search, snglcomparefunc, nearcoinccomparefunc, end_time_bisect_window = 1.0, verbose = False):
391 print(
"indexing ...", file=sys.stderr)
393 bbdef = {
"inspiral": thinca.InspiralCoincDef}[search]
394 sbdef = {
"inspiral": InspiralSICoincDef}[search]
395 scedef = {
"inspiral": InspiralSCExactCoincDef}[search]
396 scndef = {
"inspiral": InspiralSCNearCoincDef}[search]
398 contents =
DocContents(xmldoc = xmldoc, bbdef = bbdef, sbdef = sbdef, scedef = scedef, scndef = scndef, process = process, end_time_bisect_window = end_time_bisect_window)
404 for sim
in tqdm.tqdm(contents.siminspiraltable, desc = sbdef.description, disable =
not verbose):
413 if contents.scn_coinc_def_id:
414 for sim
in tqdm.tqdm(contents.siminspiraltable, desc = scndef.description, disable =
not verbose):
415 coincs = contents.coincs_near_endtime(sim.time_geocent)
418 assert exact_coinc_event_ids.issubset(near_coinc_event_ids)
419 if exact_coinc_event_ids:
421 if near_coinc_event_ids:
429 print(
"finishing ...", file=sys.stderr)
430 contents.sort_triggers_by_id()
448def revert(xmldoc, program, verbose = False):
454 print(
"removing process metadata ...", file=sys.stderr)
455 process_table = lsctables.ProcessTable.get_table(xmldoc)
457 process_ids = process_table.get_ids_by_program(program)
458 iterutils.inplace_filter((
lambda row: row.process_id
not in process_ids), process_table)
459 iterutils.inplace_filter((
lambda row: row.process_id
not in process_ids), lsctables.ProcessParamsTable.get_table(xmldoc))
466 print(
"removing coincs ...", file=sys.stderr)
467 coinc_event_table = lsctables.CoincTable.get_table(xmldoc)
469 coinc_ids = frozenset(row.coinc_event_id
for row
in coinc_event_table
if row.process_id
in process_ids)
470 iterutils.inplace_filter((
lambda row: row.coinc_event_id
not in coinc_ids), coinc_event_table)
471 iterutils.inplace_filter((
lambda row: row.coinc_event_id
not in coinc_ids), lsctables.CoincMapTable.get_table(xmldoc))
473 time_slide_ids = frozenset(row.time_slide_id
for row
in coinc_event_table)
474 coinc_def_ids = frozenset(row.coinc_def_id
for row
in coinc_event_table)
481 print(
"removing coinc metadata ...", file=sys.stderr)
483 coinc_defs = frozenset((row.search, row.search_coinc_type)
for row
in (InspiralSICoincDef, InspiralSCNearCoincDef, InspiralSCExactCoincDef))
484 iterutils.inplace_filter((
lambda row: row.process_id
not in process_ids
or row.time_slide_id
in time_slide_ids), lsctables.TimeSlideTable.get_table(xmldoc))
485 iterutils.inplace_filter((
lambda row: (row.search, row.search_coinc_type)
not in coinc_defs
or row.coinc_def_id
in coinc_def_ids), lsctables.CoincDefTable.get_table(xmldoc))
A wrapper interface to the XML document.
def coincs_near_endtime(self, t)
Return a list of the (coinc_event_id, event list) tuples in which at least one inspiral event's end t...
def inspirals_near_endtime(self, t)
Return a list of the inspiral events whose end times are within self.end_time_bisect_window of t.
def new_coinc(self, coinc_def_id)
Construct a new coinc_event row attached to the given process, and belonging to the set of coincidenc...
def sort_triggers_by_id(self)
Sort the sngl_inspiral table's rows by ID (tidy-up document for output).
def __init__(self, xmldoc, bbdef, sbdef, scedef, scndef, process, end_time_bisect_window)
Version of lsctables.SnglInspiral who's .__cmp__() method compares this object's ....
def ligolw_inspinjfind(xmldoc, process, search, snglcomparefunc, nearcoinccomparefunc, end_time_bisect_window=1.0, verbose=False)
def find_near_coinc_matches(coincs, sim, comparefunc)
Return a set of the coinc_event_ids of the inspiral<-->inspiral coincs in which at least one inspiral...
def add_sim_inspiral_coinc(contents, sim, inspirals)
Create a coinc_event in the coinc table, and add arcs in the coinc_event_map table linking the sim_in...
def find_sngl_inspiral_matches(contents, sim, comparefunc)
Scan the inspiral table for triggers matching sim.
def find_exact_coinc_matches(coincs, sim, comparefunc)
Return a set of the coinc_event_ids of the inspiral<-->inspiral coincs in which all inspiral events m...
def add_sim_coinc_coinc(contents, sim, coinc_event_ids, coinc_def_id)
Create a coinc_event in the coinc table, and add arcs in the coinc_event_map table linking the sim_in...
def revert(xmldoc, program, verbose=False)