def __init__(self, xmldoc, b_b_def, sb_b_def, si_b_def, sb_c_e_def, sb_c_n_def, si_c_e_def, si_c_n_def, process, livetime_program): # # store the process row # self.process = process # # locate the sngl_burst, time_slide and injection tables # self.snglbursttable = lsctables.SnglBurstTable.get_table(xmldoc) try: self.simbursttable = lsctables.SimBurstTable.get_table(xmldoc) except ValueError: self.simbursttable = None try: self.siminspiraltable = lsctables.SimInspiralTable.get_table( xmldoc) except ValueError: self.siminspiraltable = None try: timeslidetable = lsctables.TimeSlideTable.get_table(xmldoc) except ValueError: timeslidetable = None if timeslidetable is not None: self.offsetvectors = timeslidetable.as_dict() else: self.offsetvectors = {} # # store the longest duration of a burst event # if self.snglbursttable: self.longestduration = max( self.snglbursttable.getColumnByName("duration")) else: self.longestduration = 0.0 # # get a segmentlistdict indicating the times when the jobs # that produced burst events could have produced output # self.seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary( xmldoc, livetime_program).coalesce() # # FIXME: in the future, the sim_inspiral table should # indicate time slide at which the injection was done, like # the sim_burst table does. for now, fake it by giving # each one a time_slide_id attribute. this is the only # reason why a place-holder class is required for the # SimInspiral row type; that class can be deleted when # this is no longer needed # if self.siminspiraltable is not None: time_slide_id = ligolw_time_slide.get_time_slide_id( xmldoc, {}.fromkeys(self.seglists, 0.0), create_new=process, superset_ok=True, nonunique_ok=False) for sim in self.siminspiraltable: sim.time_slide_id = time_slide_id # # get coinc_definer rows for sim_* <--> sngl_burst coincs # for whichever sim_* tables are present; this creates a # coinc_definer table if the document doesn't have one # if self.simbursttable is not None: self.sb_b_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, sb_b_def.search, sb_b_def.search_coinc_type, create_new=True, description=sb_b_def.description) else: self.sb_b_coinc_def_id = None if self.siminspiraltable is not None: self.si_b_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, si_b_def.search, si_b_def.search_coinc_type, create_new=True, description=si_b_def.description) else: self.si_b_coinc_def_id = None # # get coinc_def_id's for sngl_burst <--> sngl_burst, and # both kinds of sim_* <--> coinc_event coincs. set all to # None if this document does not contain any sngl_burst # <--> sngl_burst coincs. # try: b_b_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, b_b_def.search, b_b_def.search_coinc_type, create_new=False) except KeyError: b_b_coinc_def_id = None self.sb_c_e_coinc_def_id = None self.sb_c_n_coinc_def_id = None self.si_c_e_coinc_def_id = None self.si_c_n_coinc_def_id = None else: if self.simbursttable is not None: self.sb_c_e_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, sb_c_e_def.search, sb_c_e_def.search_coinc_type, create_new=True, description=sb_c_e_def.description) self.sb_c_n_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, sb_c_n_def.search, sb_c_n_def.search_coinc_type, create_new=True, description=sb_c_n_def.description) else: self.sb_c_e_coinc_def_id = None self.sb_c_n_coinc_def_id = None if self.siminspiraltable is not None: self.si_c_e_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, si_c_e_def.search, si_c_e_def.search_coinc_type, create_new=True, description=si_c_e_def.description) self.si_c_n_coinc_def_id = ligolw_coincs.get_coinc_def_id( xmldoc, si_c_n_def.search, si_c_n_def.search_coinc_type, create_new=True, description=si_c_n_def.description) else: self.si_c_e_coinc_def_id = None self.si_c_n_coinc_def_id = None # # get coinc table, create one if needed # try: self.coinctable = lsctables.CoincTable.get_table(xmldoc) except ValueError: self.coinctable = lsctables.New(lsctables.CoincTable) xmldoc.childNodes[0].appendChild(self.coinctable) self.coinctable.sync_next_id() # # get coinc_map table, create one if needed # try: self.coincmaptable = lsctables.CoincMapTable.get_table(xmldoc) except ValueError: self.coincmaptable = lsctables.New(lsctables.CoincMapTable) xmldoc.childNodes[0].appendChild(self.coincmaptable) # # index the document # # index sngl_burst table index = dict((row.event_id, row) for row in self.snglbursttable) # find IDs of burst<-->burst coincs self.coincs = dict((row.coinc_event_id, []) for row in self.coinctable if row.coinc_def_id == b_b_coinc_def_id) # construct event list for each burst<-->burst coinc for row in self.coincmaptable: try: self.coincs[row.coinc_event_id].append(index[row.event_id]) except KeyError: pass del index # sort the event list for each coin by peak time and # convert to tuples for speed for coinc_event_id, events in self.coincs.items(): events.sort(key=lambda event: event.peak) self.coincs[coinc_event_id] = tuple(events) # convert dictionary to a list of (coinc_event_id, events) # tuples and create a coinc_event_id to offset vector # look-up table self.coincs = self.coincs.items() self.coincoffsets = dict( (row.coinc_event_id, self.offsetvectors[row.time_slide_id]) for row in self.coinctable if row.coinc_def_id == b_b_coinc_def_id) # # represent the sngl_burst table as a dictionary indexed by # instrument whose values are the event lists for those # instruments sorted by peak time. sort the coincs list by # the peak time of the first (earliest) event in each coinc # (recall that the event tuple for each coinc has been # time-ordered) # self.snglbursttable = dict( (instrument, sorted((event for event in self.snglbursttable if event.ifo == instrument), key=lambda event: event.peak)) for instrument in set(self.snglbursttable.getColumnByName("ifo"))) self.coincs.sort( key=lambda coinc_id_events: coinc_id_events[1][0].peak)
def __init__(self, xmldoc, bbdef, sbdef, scedef, scndef, process, end_time_bisect_window): # # store the process row # self.process = process # # locate the sngl_inspiral and sim_inspiral tables # self.snglinspiraltable = lsctables.SnglInspiralTable.get_table(xmldoc) self.siminspiraltable = lsctables.SimInspiralTable.get_table(xmldoc) # # get the offset vectors from the document # self.offsetvectors = lsctables.TimeSlideTable.get_table(xmldoc).as_dict() # # construct the zero-lag time slide needed to cover the # instruments listed in all the triggers, then determine # its ID (or create it if needed) # # FIXME: in the future, the sim_inspiral table should # indicate time slide at which the injection was done # 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) # # get coinc_definer row for sim_inspiral <--> sngl_inspiral # coincs; this creates a coinc_definer table if the # document doesn't have one # self.sb_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, sbdef.search, sbdef.search_coinc_type, create_new = True, description = sbdef.description) # # get coinc_def_id's for sngl_inspiral <--> sngl_inspiral, and # both kinds of sim_inspiral <--> coinc_event coincs. set all # to None if this document does not contain any sngl_inspiral # <--> sngl_inspiral coincs. # try: ii_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, bbdef.search, bbdef.search_coinc_type, create_new = False) except KeyError: ii_coinc_def_id = None self.sce_coinc_def_id = None self.scn_coinc_def_id = None else: self.sce_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, scedef.search, scedef.search_coinc_type, create_new = True, description = scedef.description) self.scn_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, scndef.search, scndef.search_coinc_type, create_new = True, description = scndef.description) # # get coinc table, create one if needed # try: self.coinctable = lsctables.CoincTable.get_table(xmldoc) except ValueError: self.coinctable = lsctables.New(lsctables.CoincTable) xmldoc.childNodes[0].appendChild(self.coinctable) self.coinctable.sync_next_id() # # get coinc_map table, create one if needed # try: self.coincmaptable = lsctables.CoincMapTable.get_table(xmldoc) except ValueError: self.coincmaptable = lsctables.New(lsctables.CoincMapTable) xmldoc.childNodes[0].appendChild(self.coincmaptable) # # index the document # # FIXME: inspiral<-->inspiral coincs should be organized by time # slide ID, but since injections are only done at zero lag # for now this is ignored. # # index the sngl_inspiral table index = dict((row.event_id, row) for row in self.snglinspiraltable) # find IDs of inspiral<-->inspiral coincs self.sngls = dict((row.coinc_event_id, []) for row in self.coinctable if row.coinc_def_id == ii_coinc_def_id) # construct event list for each inspiral<-->inspiral coinc for row in self.coincmaptable: try: self.sngls[row.coinc_event_id].append(index[row.event_id]) except KeyError: pass del index # construct a sngl-->coincs look-up table self.coincs = dict((event.event_id, set()) for events in self.sngls.values() for event in events) for row in self.coincmaptable: if row.event_id in self.coincs and row.coinc_event_id in self.sngls: self.coincs[row.event_id].add(row.coinc_event_id) # create a coinc_event_id to offset vector look-up table self.coincoffsets = dict((row.coinc_event_id, self.offsetvectors[row.time_slide_id]) for row in self.coinctable if row.coinc_def_id == ii_coinc_def_id) # # sort sngl_inspiral table by end time # self.snglinspiraltable.sort(key = lambda row: row.end) # # set the window for inspirals_near_endtime(). this window # is the amount of time such that if an injection's end # time and a inspiral event's end time differ by more than # this it is *impossible* for them to match one another. # self.end_time_bisect_window = lsctables.LIGOTimeGPS(end_time_bisect_window)
def __init__(self, xmldoc, b_b_def, sb_b_def, si_b_def, sb_c_e_def, sb_c_n_def, si_c_e_def, si_c_n_def, process, livetime_program): # # store the process row # self.process = process # # locate the sngl_burst, time_slide and injection tables # self.snglbursttable = lsctables.SnglBurstTable.get_table(xmldoc) try: self.simbursttable = lsctables.SimBurstTable.get_table(xmldoc) except ValueError: self.simbursttable = None try: self.siminspiraltable = lsctables.SimInspiralTable.get_table(xmldoc) except ValueError: self.siminspiraltable = None try: timeslidetable = lsctables.TimeSlideTable.get_table(xmldoc) except ValueError: timeslidetable = None if timeslidetable is not None: self.offsetvectors = timeslidetable.as_dict() else: self.offsetvectors = {} # # store the longest duration of a burst event # if self.snglbursttable: self.longestduration = max(self.snglbursttable.getColumnByName("duration")) else: self.longestduration = 0.0 # # get a segmentlistdict indicating the times when the jobs # that produced burst events could have produced output # self.seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, livetime_program).coalesce() # # FIXME: in the future, the sim_inspiral table should # indicate time slide at which the injection was done, like # the sim_burst table does. for now, fake it by giving # each one a time_slide_id attribute. this is the only # reason why a place-holder class is required for the # SimInspiral row type; that class can be deleted when # this is no longer needed # if self.siminspiraltable is not None: time_slide_id = ligolw_time_slide.get_time_slide_id(xmldoc, {}.fromkeys(self.seglists, 0.0), create_new = process, superset_ok = True, nonunique_ok = False) for sim in self.siminspiraltable: sim.time_slide_id = time_slide_id # # get coinc_definer rows for sim_* <--> sngl_burst coincs # for whichever sim_* tables are present; this creates a # coinc_definer table if the document doesn't have one # if self.simbursttable is not None: self.sb_b_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, sb_b_def.search, sb_b_def.search_coinc_type, create_new = True, description = sb_b_def.description) else: self.sb_b_coinc_def_id = None if self.siminspiraltable is not None: self.si_b_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, si_b_def.search, si_b_def.search_coinc_type, create_new = True, description = si_b_def.description) else: self.si_b_coinc_def_id = None # # get coinc_def_id's for sngl_burst <--> sngl_burst, and # both kinds of sim_* <--> coinc_event coincs. set all to # None if this document does not contain any sngl_burst # <--> sngl_burst coincs. # try: b_b_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, b_b_def.search, b_b_def.search_coinc_type, create_new = False) except KeyError: b_b_coinc_def_id = None self.sb_c_e_coinc_def_id = None self.sb_c_n_coinc_def_id = None self.si_c_e_coinc_def_id = None self.si_c_n_coinc_def_id = None else: if self.simbursttable is not None: self.sb_c_e_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, sb_c_e_def.search, sb_c_e_def.search_coinc_type, create_new = True, description = sb_c_e_def.description) self.sb_c_n_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, sb_c_n_def.search, sb_c_n_def.search_coinc_type, create_new = True, description = sb_c_n_def.description) else: self.sb_c_e_coinc_def_id = None self.sb_c_n_coinc_def_id = None if self.siminspiraltable is not None: self.si_c_e_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, si_c_e_def.search, si_c_e_def.search_coinc_type, create_new = True, description = si_c_e_def.description) self.si_c_n_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, si_c_n_def.search, si_c_n_def.search_coinc_type, create_new = True, description = si_c_n_def.description) else: self.si_c_e_coinc_def_id = None self.si_c_n_coinc_def_id = None # # get coinc table, create one if needed # try: self.coinctable = lsctables.CoincTable.get_table(xmldoc) except ValueError: self.coinctable = lsctables.New(lsctables.CoincTable) xmldoc.childNodes[0].appendChild(self.coinctable) self.coinctable.sync_next_id() # # get coinc_map table, create one if needed # try: self.coincmaptable = lsctables.CoincMapTable.get_table(xmldoc) except ValueError: self.coincmaptable = lsctables.New(lsctables.CoincMapTable) xmldoc.childNodes[0].appendChild(self.coincmaptable) # # index the document # # index sngl_burst table index = dict((row.event_id, row) for row in self.snglbursttable) # find IDs of burst<-->burst coincs self.coincs = dict((row.coinc_event_id, []) for row in self.coinctable if row.coinc_def_id == b_b_coinc_def_id) # construct event list for each burst<-->burst coinc for row in self.coincmaptable: try: self.coincs[row.coinc_event_id].append(index[row.event_id]) except KeyError: pass del index # sort the event list for each coin by peak time and # convert to tuples for speed for coinc_event_id, events in self.coincs.items(): events.sort(key = lambda event: event.peak) self.coincs[coinc_event_id] = tuple(events) # convert dictionary to a list of (coinc_event_id, events) # tuples and create a coinc_event_id to offset vector # look-up table self.coincs = self.coincs.items() self.coincoffsets = dict((row.coinc_event_id, self.offsetvectors[row.time_slide_id]) for row in self.coinctable if row.coinc_def_id == b_b_coinc_def_id) # # represent the sngl_burst table as a dictionary indexed by # instrument whose values are the event lists for those # instruments sorted by peak time. sort the coincs list by # the peak time of the first (earliest) event in each coinc # (recall that the event tuple for each coinc has been # time-ordered) # self.snglbursttable = dict((instrument, sorted((event for event in self.snglbursttable if event.ifo == instrument), key = lambda event: event.peak)) for instrument in set(self.snglbursttable.getColumnByName("ifo"))) self.coincs.sort(key = lambda coinc_id_events: coinc_id_events[1][0].peak)