示例#1
0
	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(lambda a, b: cmp(a.peak_time, b.peak_time) or cmp(a.peak_time_ns, b.peak_time_ns))
			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), lambda a, b: cmp(a.peak_time, b.peak_time) or cmp(a.peak_time_ns, b.peak_time_ns))) for instrument in set(self.snglbursttable.getColumnByName("ifo")))
		self.coincs.sort(lambda (id_a, events_a), (id_b, events_b): cmp(events_a[0].peak_time, events_b[0].peak_time) or cmp(events_a[0].peak_time_ns, events_b[0].peak_time_ns))
    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()

        #
        # get out segment lists for programs that generated
        # triggers (currently only used for time_slide vector
        # construction)
        #

        seglists = lsctables.SearchSummaryTable.get_table(
            xmldoc).get_out_segmentlistdict(
                set(self.snglinspiraltable.getColumnByName(
                    "process_id"))).coalesce()

        #
        # 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(
            seglists, 0.0),
                                                           create_new=process)

        #
        # 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, and sort the coincs
        # list by the end time of the first (earliest) event in
        # each coinc (recall that the event tuple for each coinc
        # has been time-ordered)
        #

        self.snglinspiraltable.sort(lambda a, b: cmp(a.end_time, b.end_time) or
                                    cmp(a.end_time_ns, b.end_time_ns))

        #
        # 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 = LIGOTimeGPS(end_time_bisect_window)
示例#3
0
    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 create_tables(self, xmldoc, rootfiles):
    """
    Sets up table structures and calls populating methods.
    """

    if os.path.splitext(rootfiles[0])[1] == ".root":
      sim_tree = TChain("waveburst")
    else: # If the file is (for example) text, use a proxy class
      sim_tree = CWBTextConverter()

    for rootfile in rootfiles:
	  sim_tree.Add(rootfile)

    # Define tables
    sngl_burst_table = lsctables.New(lsctables.SnglBurstTable,
	  ["peak_time_ns", "start_time_ns", "stop_time_ns",
	  "process_id", "ifo", "peak_time", "start_time", "stop_time", 
	  "duration", "time_lag", "peak_frequency", "search",
	  "flow", "fhigh", "bandwidth", "tfvolume", "hrss", "event_id", "snr"])
    xmldoc.childNodes[0].appendChild(sngl_burst_table)
    sngl_burst_table.sync_next_id()
  
    coinc_event_table = lsctables.New(lsctables.CoincTable,
	  [ "process_id", "coinc_event_id", "nevents", "instruments", "time_slide_id",
	  "coinc_def_id", "likelihood"])
    xmldoc.childNodes[0].appendChild(coinc_event_table)
    coinc_event_table.sync_next_id()
  
    # TODO: Reimplement this when the cwb_table module is included
    #if self.cwbtable:
      #cohwb_table = lsctables.New(cwb_table.CoherentWaveburstTable,
	    #["ellipticity", "correlated_energy", "eff_correlated_energy", 
      #"coherent_network_amp", "penalty", "network_correlation", 
      #"energy_disbalance", "ellip_energy_disbalance", "process_id", 
      #"coinc_event_id", "cwb_id"])
      #xmldoc.childNodes[0].appendChild(cohwb_table)
      #cohwb_table.sync_next_id()
  
    multi_burst_table = lsctables.New(lsctables.MultiBurstTable,
	  ["process_id", "peak_time", "peak_time_ns", "coinc_event_id", "snr", "ifos",
    # NOTE: Added to the table definition
    "false_alarm_rate", "ligo_axis_ra", "ligo_axis_dec"])
    xmldoc.childNodes[0].appendChild(multi_burst_table)
  
    coinc_event_map_table = lsctables.New(lsctables.CoincMapTable)
    xmldoc.childNodes[0].appendChild(coinc_event_map_table)
  
    jobsegment = None
    if self.start and self.end :
      jobsegment = segments.segment(LIGOTimeGPS(self.start), LIGOTimeGPS(self.end))
  
    if self.verbose:
      print "Creating Process Table...",
  
    if self.job_list:
      self.do_process_table(xmldoc, sim_tree)
    else :
      self.do_process_table_from_segment(xmldoc, sim_tree, jobsegment)
  
    process_index = dict((int(row.process_id), row) for row in lsctables.ProcessTable.get_table(xmldoc))
  
    if self.verbose:
      print " done."
  
    if self.verbose:
      print "Creating Summary Table...",
    # If we are provided a joblist, use it to generate the list
    if self.job_list :
      self.do_summary_table_from_joblist(xmldoc, sim_tree)
    elif self.job_list == None and self.start and self.end :
      self.do_summary_table_from_segment(xmldoc, jobsegment, sim_tree)
    else :
      self.do_summary_table(xmldoc, sim_tree)
    if self.verbose:
      print " done."
  
    # create coinc_definer row
    row = self.get_coinc_def_row(sim_tree)
    coinc_def_id = llwapp.get_coinc_def_id(xmldoc, row.search, row.search_coinc_type, description = row.description)
  
    entries = sim_tree.GetEntries()
    for i in range(0, entries):
      sim_tree.GetEntry(i)
      if self.start != None :
        if float(self.start) > sim_tree.start[0] : continue
      if self.end != None :
        if float(self.end) < sim_tree.stop[0] : continue
        
  
      offset_vector = dict((get_ifos_from_index(instrument_index), offset) for instrument_index, offset in zip(sim_tree.ifo, sim_tree.lag))
  
      coinc_event = coinc_event_table.RowType()
      coinc_event.process_id = process_index[sim_tree.run].process_id
      coinc_event.coinc_event_id = coinc_event_table.get_next_id()
      coinc_event.coinc_def_id = coinc_def_id
      coinc_event.nevents = sim_tree.ndim
      coinc_event.instruments = lsctables.ifos_from_instrument_set( get_ifos_from_index( branch_array_to_list ( sim_tree.ifo, sim_tree.ndim ) ) )
      coinc_event.time_slide_id = time_slide.get_time_slide_id(xmldoc, offset_vector, process_index[sim_tree.run])
      coinc_event.likelihood = sim_tree.likelihood
      coinc_event_table.append(coinc_event)
  
      for d in range(0, sim_tree.ndim):
        sngl_burst = self.get_sngl_burst_row(sngl_burst_table, sim_tree, d)
        sngl_burst.process_id = coinc_event.process_id
        sngl_burst.event_id = sngl_burst_table.get_next_id()
        sngl_burst_table.append(sngl_burst)
  
        coinc_event_map = coinc_event_map_table.RowType()
        coinc_event_map.event_id = sngl_burst.event_id
        coinc_event_map.table_name = sngl_burst.event_id.table_name
        coinc_event_map.coinc_event_id = coinc_event.coinc_event_id
        coinc_event_map_table.append(coinc_event_map)
  
      # TODO: Reimplement when cwb_table module is included
      #if self.cwbtable:
        #cwb = get_cwb_row(cohwb_table, sim_tree)
        #cwb.process_id = coinc_event.process_id
        #cwb.coinc_event_id = coinc_event.coinc_event_id
        #cwb.cwb_id = cohwb_table.get_next_id()
        #cohwb_table.append(cwb)
  
      multi_burst = self.get_multi_burst_row(multi_burst_table, sim_tree)
      multi_burst.process_id = coinc_event.process_id
      multi_burst.coinc_event_id = coinc_event.coinc_event_id
      # NOTE: Until we have an embedded cwb table definition, this will be
      # copied here so official tools have a ranking statistic to use
      try:
        multi_burst.snr = sim_tree.rho[1]
      except TypeError: # difference in definition between ROOT and text
        multi_burst.snr = sim_tree.rho
      # NOTE: To be filled in later by farburst
      multi_burst.false_alarm_rate = -1.0 
      # Reconstructed right ascension and declination
      multi_burst.ligo_axis_ra = sim_tree.phi[2]
      multi_burst.ligo_axis_dec = sim_tree.theta[2]
      multi_burst.ifos = lsctables.ifos_from_instrument_set( get_ifos_from_index( branch_array_to_list ( sim_tree.ifo, sim_tree.ndim ) ) )
  
      multi_burst_table.append(multi_burst)
示例#5
0
	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()

		#
		# get out segment lists for programs that generated
		# triggers (currently only used for time_slide vector
		# construction)
		#

		seglists = lsctables.SearchSummaryTable.get_table(xmldoc).get_out_segmentlistdict(set(self.snglinspiraltable.getColumnByName("process_id"))).coalesce()

		#
		# 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(seglists, 0.0), create_new = process)

		#
		# 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, and sort the coincs
		# list by the end time of the first (earliest) event in
		# each coinc (recall that the event tuple for each coinc
		# has been time-ordered)
		#

		self.snglinspiraltable.sort(lambda a, b: cmp(a.end_time, b.end_time) or cmp(a.end_time_ns, b.end_time_ns))

		#
		# 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 = LIGOTimeGPS(end_time_bisect_window)
示例#6
0
    def create_tables(self, xmldoc, rootfiles):
        """
    Sets up table structures and calls populating methods.
    """

        if os.path.splitext(rootfiles[0])[1] == ".root":
            sim_tree = TChain("waveburst")
        else:  # If the file is (for example) text, use a proxy class
            sim_tree = CWBTextConverter()

        for rootfile in rootfiles:
            sim_tree.Add(rootfile)

        # Define tables
        sngl_burst_table = lsctables.New(lsctables.SnglBurstTable, [
            "peak_time_ns", "start_time_ns", "stop_time_ns", "process_id",
            "ifo", "peak_time", "start_time", "stop_time", "duration",
            "time_lag", "peak_frequency", "search", "flow", "fhigh",
            "bandwidth", "tfvolume", "hrss", "event_id", "snr"
        ])
        xmldoc.childNodes[0].appendChild(sngl_burst_table)
        sngl_burst_table.sync_next_id()

        coinc_event_table = lsctables.New(lsctables.CoincTable, [
            "process_id", "coinc_event_id", "nevents", "instruments",
            "time_slide_id", "coinc_def_id", "likelihood"
        ])
        xmldoc.childNodes[0].appendChild(coinc_event_table)
        coinc_event_table.sync_next_id()

        # TODO: Reimplement this when the cwb_table module is included
        #if self.cwbtable:
        #cohwb_table = lsctables.New(cwb_table.CoherentWaveburstTable,
        #["ellipticity", "correlated_energy", "eff_correlated_energy",
        #"coherent_network_amp", "penalty", "network_correlation",
        #"energy_disbalance", "ellip_energy_disbalance", "process_id",
        #"coinc_event_id", "cwb_id"])
        #xmldoc.childNodes[0].appendChild(cohwb_table)
        #cohwb_table.sync_next_id()

        multi_burst_table = lsctables.New(
            lsctables.MultiBurstTable,
            [
                "process_id",
                "peak_time",
                "peak_time_ns",
                "coinc_event_id",
                "snr",
                "ifos",
                # NOTE: Added to the table definition
                "false_alarm_rate",
                "ligo_axis_ra",
                "ligo_axis_dec"
            ])
        xmldoc.childNodes[0].appendChild(multi_burst_table)

        coinc_event_map_table = lsctables.New(lsctables.CoincMapTable)
        xmldoc.childNodes[0].appendChild(coinc_event_map_table)

        jobsegment = None
        if self.start and self.end:
            jobsegment = segments.segment(LIGOTimeGPS(self.start),
                                          LIGOTimeGPS(self.end))

        if self.verbose:
            print "Creating Process Table...",

        if self.job_list:
            self.do_process_table(xmldoc, sim_tree)
        else:
            self.do_process_table_from_segment(xmldoc, sim_tree, jobsegment)

        process_index = dict(
            (int(row.process_id), row)
            for row in lsctables.ProcessTable.get_table(xmldoc))

        if self.verbose:
            print " done."

        if self.verbose:
            print "Creating Summary Table...",
        # If we are provided a joblist, use it to generate the list
        if self.job_list:
            self.do_summary_table_from_joblist(xmldoc, sim_tree)
        elif self.job_list == None and self.start and self.end:
            self.do_summary_table_from_segment(xmldoc, jobsegment, sim_tree)
        else:
            self.do_summary_table(xmldoc, sim_tree)
        if self.verbose:
            print " done."

        # create coinc_definer row
        row = self.get_coinc_def_row(sim_tree)
        coinc_def_id = llwapp.get_coinc_def_id(xmldoc,
                                               row.search,
                                               row.search_coinc_type,
                                               description=row.description)

        entries = sim_tree.GetEntries()
        for i in range(0, entries):
            sim_tree.GetEntry(i)
            if self.start != None:
                if float(self.start) > sim_tree.start[0]: continue
            if self.end != None:
                if float(self.end) < sim_tree.stop[0]: continue

            offset_vector = dict(
                (get_ifos_from_index(instrument_index), offset)
                for instrument_index, offset in zip(sim_tree.ifo,
                                                    sim_tree.lag))

            coinc_event = coinc_event_table.RowType()
            coinc_event.process_id = process_index[sim_tree.run].process_id
            coinc_event.coinc_event_id = coinc_event_table.get_next_id()
            coinc_event.coinc_def_id = coinc_def_id
            coinc_event.nevents = sim_tree.ndim
            coinc_event.instruments = lsctables.ifos_from_instrument_set(
                get_ifos_from_index(
                    branch_array_to_list(sim_tree.ifo, sim_tree.ndim)))
            coinc_event.time_slide_id = time_slide.get_time_slide_id(
                xmldoc, offset_vector, process_index[sim_tree.run])
            coinc_event.likelihood = sim_tree.likelihood
            coinc_event_table.append(coinc_event)

            for d in range(0, sim_tree.ndim):
                sngl_burst = self.get_sngl_burst_row(sngl_burst_table,
                                                     sim_tree, d)
                sngl_burst.process_id = coinc_event.process_id
                sngl_burst.event_id = sngl_burst_table.get_next_id()
                sngl_burst_table.append(sngl_burst)

                coinc_event_map = coinc_event_map_table.RowType()
                coinc_event_map.event_id = sngl_burst.event_id
                coinc_event_map.table_name = sngl_burst.event_id.table_name
                coinc_event_map.coinc_event_id = coinc_event.coinc_event_id
                coinc_event_map_table.append(coinc_event_map)

            # TODO: Reimplement when cwb_table module is included
            #if self.cwbtable:
            #cwb = get_cwb_row(cohwb_table, sim_tree)
            #cwb.process_id = coinc_event.process_id
            #cwb.coinc_event_id = coinc_event.coinc_event_id
            #cwb.cwb_id = cohwb_table.get_next_id()
            #cohwb_table.append(cwb)

            multi_burst = self.get_multi_burst_row(multi_burst_table, sim_tree)
            multi_burst.process_id = coinc_event.process_id
            multi_burst.coinc_event_id = coinc_event.coinc_event_id
            # NOTE: Until we have an embedded cwb table definition, this will be
            # copied here so official tools have a ranking statistic to use
            try:
                multi_burst.snr = sim_tree.rho[1]
            except TypeError:  # difference in definition between ROOT and text
                multi_burst.snr = sim_tree.rho
            # NOTE: To be filled in later by farburst
            multi_burst.false_alarm_rate = -1.0
            # Reconstructed right ascension and declination
            multi_burst.ligo_axis_ra = sim_tree.phi[2]
            multi_burst.ligo_axis_dec = sim_tree.theta[2]
            multi_burst.ifos = lsctables.ifos_from_instrument_set(
                get_ifos_from_index(
                    branch_array_to_list(sim_tree.ifo, sim_tree.ndim)))

            multi_burst_table.append(multi_burst)