Esempio n. 1
0
def ligolw_burca(
	xmldoc,
	process_id,
	EventListType,
	CoincTables,
	coinc_definer_row,
	event_comparefunc,
	thresholds,
	ntuple_comparefunc = lambda events, offset_vector: False,
	min_instruments = 2,
	verbose = False
):
	#
	# validate input
	#

	if min_instruments < 1:
		raise ValueError("min_instruments (=%d) must be >= 1" % min_instruments)

	#
	# prepare the coincidence table interface.
	#

	if verbose:
		print >>sys.stderr, "indexing ..."
	coinc_tables = CoincTables(xmldoc)
	coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, coinc_definer_row.search, coinc_definer_row.search_coinc_type, create_new = True, description = coinc_definer_row.description)
	sngl_burst_table = lsctables.SnglBurstTable.get_table(xmldoc)
	sngl_index = dict((row.event_id, row) for row in sngl_burst_table)

	#
	# build the event list accessors, populated with events from those
	# processes that can participate in a coincidence
	#

	eventlists = snglcoinc.EventListDict(EventListType, sngl_burst_table, instruments = set(coinc_tables.time_slide_table.getColumnByName("instrument")))

	#
	# construct offset vector assembly graph
	#

	time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index, verbose = verbose)

	#
	# retrieve all coincidences, apply the final n-tuple compare func
	# and record the survivors
	#

	for node, coinc in time_slide_graph.get_coincs(eventlists, event_comparefunc, thresholds, verbose = verbose):
		if len(coinc) < min_instruments:
			continue
		ntuple = tuple(sngl_index[id] for id in coinc)
		if not ntuple_comparefunc(ntuple, node.offset_vector):
			coinc_tables.append_coinc(*coinc_tables.coinc_rows(process_id, node.time_slide_id, coinc_def_id, ntuple))

	#
	# done
	#

	return xmldoc
Esempio n. 2
0
def ligolw_burca(
	xmldoc,
	process_id,
	EventListType,
	CoincTables,
	coinc_definer_row,
	event_comparefunc,
	thresholds,
	ntuple_comparefunc = lambda events, offset_vector: False,
	verbose = False
):
	#
	# prepare the coincidence table interface.
	#

	if verbose:
		print >>sys.stderr, "indexing ..."
	coinc_tables = CoincTables(xmldoc)
	coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, coinc_definer_row.search, coinc_definer_row.search_coinc_type, create_new = True, description = coinc_definer_row.description)
	sngl_index = dict((row.event_id, row) for row in lsctables.SnglBurstTable.get_table(xmldoc))

	#
	# build the event list accessors, populated with events from those
	# processes that can participate in a coincidence
	#

	eventlists = snglcoinc.make_eventlists(xmldoc, EventListType, lsctables.SnglBurstTable.tableName)

	#
	# construct offset vector assembly graph
	#

	time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index, verbose = verbose)

	#
	# retrieve all coincidences, apply the final n-tuple compare func
	# and record the survivors
	#

	for node, coinc in time_slide_graph.get_coincs(eventlists, event_comparefunc, thresholds, verbose = verbose):
		ntuple = tuple(sngl_index[id] for id in coinc)
		if not ntuple_comparefunc(ntuple, node.offset_vector):
			coinc_tables.append_coinc(process_id, node.time_slide_id, coinc_def_id, ntuple)

	#
	# remove time offsets from events
	#

	del eventlists.offsetvector

	#
	# done
	#

	return xmldoc
def burca(xmldoc,
          process_id,
          EventListType,
          CoincTables,
          coinc_definer_row,
          thresholds,
          ntuple_comparefunc=lambda events, offset_vector: False,
          min_instruments=2,
          verbose=False):
    #
    # validate input
    #

    if min_instruments < 1:
        raise ValueError("min_instruments (=%d) must be >= 1" %
                         min_instruments)

    #
    # prepare the coincidence table interface.
    #

    if verbose:
        print >> sys.stderr, "indexing ..."
    coinc_tables = CoincTables(xmldoc)
    coinc_def_id = ligolw_coincs.get_coinc_def_id(
        xmldoc,
        coinc_definer_row.search,
        coinc_definer_row.search_coinc_type,
        create_new=True,
        description=coinc_definer_row.description)

    #
    # build the event list accessors, populated with events from those
    # processes that can participate in a coincidence
    #

    eventlists = snglcoinc.EventListDict(
        EventListType,
        lsctables.SnglBurstTable.get_table(xmldoc),
        instruments=set(
            coinc_tables.time_slide_table.getColumnByName("instrument")))

    #
    # construct offset vector assembly graph
    #

    time_slide_graph = snglcoinc.TimeSlideGraph(
        coinc_tables.time_slide_index,
        min_instruments=min_instruments,
        verbose=verbose)

    #
    # retrieve all coincidences, apply the final n-tuple compare func
    # and record the survivors
    #

    for node, coinc in time_slide_graph.get_coincs(eventlists,
                                                   thresholds,
                                                   verbose=verbose):
        if not ntuple_comparefunc(coinc, node.offset_vector):
            coinc_tables.append_coinc(*coinc_tables.coinc_rows(
                process_id, node.time_slide_id, coinc_def_id, coinc))

    #
    # done
    #

    return xmldoc
Esempio n. 4
0
def ligolw_thinca(xmldoc,
                  process_id,
                  coinc_definer_row,
                  event_comparefunc,
                  thresholds,
                  ntuple_comparefunc=default_ntuple_comparefunc,
                  effective_snr_factor=250.0,
                  veto_segments=None,
                  trigger_program=u"inspiral",
                  likelihood_func=None,
                  likelihood_params_func=None,
                  verbose=False,
                  max_dt=None):
    #
    # prepare the coincidence table interface.
    #

    if verbose:
        print >> sys.stderr, "indexing ..."
    coinc_tables = InspiralCoincTables(
        xmldoc,
        vetoes=veto_segments,
        program=trigger_program,
        likelihood_func=likelihood_func,
        likelihood_params_func=likelihood_params_func)
    coinc_def_id = ligolw_coincs.get_coinc_def_id(
        xmldoc,
        coinc_definer_row.search,
        coinc_definer_row.search_coinc_type,
        create_new=True,
        description=coinc_definer_row.description)
    sngl_index = dict((row.event_id, row)
                      for row in lsctables.SnglInspiralTable.get_table(xmldoc))

    #
    # build the event list accessors, populated with events from those
    # processes that can participate in a coincidence.  apply vetoes by
    # removing events from the lists that fall in vetoed segments
    #

    eventlists = snglcoinc.make_eventlists(
        xmldoc, InspiralEventList, lsctables.SnglInspiralTable.tableName)
    if veto_segments is not None:
        for eventlist in eventlists.values():
            iterutils.inplace_filter(
                (lambda event: event.ifo not in veto_segments or event.end
                 not in veto_segments[event.ifo]), eventlist)

    #
    # set the \Delta t parameter on all the event lists
    #

    if max_dt is None:
        max_dt = inspiral_max_dt(lsctables.SnglInspiralTable.get_table(xmldoc),
                                 thresholds)
    if verbose:
        print >> sys.stderr, "event bisection search window will be %.16g s" % max_dt
    for eventlist in eventlists.values():
        eventlist.set_dt(max_dt)

    #
    # replicate the ethinca parameter for every possible instrument
    # pair
    #

    thresholds = replicate_threshold(thresholds, set(eventlists))

    #
    # construct offset vector assembly graph
    #

    time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index,
                                                verbose=verbose)

    #
    # retrieve all coincidences, apply the final n-tuple compare func
    # and record the survivors
    #

    for node, coinc in time_slide_graph.get_coincs(eventlists,
                                                   event_comparefunc,
                                                   thresholds,
                                                   verbose=verbose):
        coinc = tuple(sngl_index[event_id] for event_id in coinc)
        if not ntuple_comparefunc(coinc, node.offset_vector):
            coinc_tables.append_coinc(process_id, node.time_slide_id,
                                      coinc_def_id, coinc,
                                      effective_snr_factor)

    #
    # remove time offsets from events
    #

    del eventlists.offsetvector

    #
    # done
    #

    return xmldoc
Esempio n. 5
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, scndef, process, sngl_type,
                 sim_type, get_sngl_time):
        #
        # store the process row
        #

        self.process = process

        #
        # locate the sngl_inspiral and sim_inspiral tables
        #

        self.sngltable = sngl_type.get_table(xmldoc)
        try:
            self.simtable = sim_type.get_table(xmldoc)
        except ValueError:
            self.simtable = lsctables.SimInspiralTable.get_table(xmldoc)
            print >> sys.stderr, "No SimRingdownTable, use SimInspiralTable instead!"

        #
        # 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_tisi.get_time_slide_id(xmldoc, {}.fromkeys(
            self.sngltable.getColumnByName("ifo"), 0.0),
                                                     create_new=process)

        #
        # get coinc_definer row for sim_type <--> sngl_type
        # 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_type <--> sngl_type, and
        # the sim_type <--> coinc_event coincs.  set all
        # to None if this document does not contain any sngl_type
        # <--> sngl_type coincs.
        #

        try:
            bb_coinc_def_id = ligolw_coincs.get_coinc_def_id(
                xmldoc,
                bbdef.search,
                bbdef.search_coinc_type,
                create_new=False)
        except KeyError:
            bb_coinc_def_id = None
            self.scn_coinc_def_id = None
        else:
            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:  type<-->type coincs should be organized by time
        # slide ID, but since injections are only done at zero lag
        # for now this is ignored.
        #

        # index sngl_type table
        index = {}
        for row in self.sngltable:
            index[row.event_id] = row
        # find IDs of type<-->type coincs
        self.coincs = {}
        for coinc in self.coinctable:
            if coinc.coinc_def_id == bb_coinc_def_id:
                self.coincs[coinc.coinc_event_id] = []
        # construct event list for each type<-->type coinc
        for row in self.coincmaptable:
            if row.coinc_event_id in self.coincs:
                self.coincs[row.coinc_event_id].append(index[row.event_id])
        del index
        # sort each event list by end/start time and convert to tuples
        # for speed

        for coinc_event_id, events in self.coincs.iteritems():
            events.sort(key=get_sngl_time)
            self.coincs[coinc_event_id] = tuple(events)
        # convert dictionary to a list

        self.coincs = self.coincs.items()

        #
        # FIXME Is this true for inspirals too?
        # sort sngl_type table by end/start time, and sort the coincs
        # list by the end/start time of the first (earliest) event in
        # each coinc (recall that the event tuple for each coinc
        # has been time-ordered)
        #

        self.sngltable.sort(key=get_sngl_time)
        self.coincs.sort(key=lambda (id, a): get_sngl_time(a[0]))

        #
        # set the window for type_near_time().  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.
        #

        # FIXME I'll just make the windows 1.0 s

        self.search_time_window = 1.0
        self.coinc_time_window = 1.0
Esempio n. 7
0
	def __init__(self, xmldoc, bbdef, sbdef, scndef, process, sngl_type, sim_type, get_sngl_time):
		#
		# store the process row
		#

		self.process = process

		#
		# locate the sngl_inspiral and sim_inspiral tables
		#

		self.sngltable = sngl_type.get_table(xmldoc)
		try:
			self.simtable = sim_type.get_table(xmldoc)
		except ValueError:
			self.simtable = lsctables.SimInspiralTable.get_table(xmldoc)
			print >>sys.stderr,"No SimRingdownTable, use SimInspiralTable instead!"

		#
		# 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_tisi.get_time_slide_id(xmldoc, {}.fromkeys(self.sngltable.getColumnByName("ifo"), 0.0), create_new = process)

		#
		# get coinc_definer row for sim_type <--> sngl_type
		# 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_type <--> sngl_type, and
		# the sim_type <--> coinc_event coincs.  set all
		# to None if this document does not contain any sngl_type
		# <--> sngl_type coincs.
		#

		try:
			bb_coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, bbdef.search, bbdef.search_coinc_type, create_new = False)
		except KeyError:
			bb_coinc_def_id = None
			self.scn_coinc_def_id = None
		else:
			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:  type<-->type coincs should be organized by time
		# slide ID, but since injections are only done at zero lag
		# for now this is ignored.
		#

		# index sngl_type table
		index = {}
		for row in self.sngltable:
			index[row.event_id] = row
		# find IDs of type<-->type coincs
		self.coincs = {}
		for coinc in self.coinctable:
			if coinc.coinc_def_id == bb_coinc_def_id:
				self.coincs[coinc.coinc_event_id] = []
		# construct event list for each type<-->type coinc
		for row in self.coincmaptable:
			if row.coinc_event_id in self.coincs:
				self.coincs[row.coinc_event_id].append(index[row.event_id])
		del index
		# sort each event list by end/start time and convert to tuples
		# for speed

		for coinc_event_id, events in self.coincs.iteritems():
			events.sort(key=get_sngl_time)
			self.coincs[coinc_event_id]=tuple(events)
		# convert dictionary to a list

		self.coincs = self.coincs.items()

		#
		# FIXME Is this true for inspirals too?
		# sort sngl_type table by end/start time, and sort the coincs
		# list by the end/start time of the first (earliest) event in
		# each coinc (recall that the event tuple for each coinc
		# has been time-ordered)
		#

		self.sngltable.sort(key=get_sngl_time)
		self.coincs.sort(key=lambda(id,a): get_sngl_time(a[0]))

		#
		# set the window for type_near_time().  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.
		#

 		# FIXME I'll just make the windows 1.0 s

                self.search_time_window = 1.0
                self.coinc_time_window = 1.0
Esempio n. 8
0
def ligolw_thinca(
	xmldoc,
	process_id,
	coinc_definer_row,
	event_comparefunc,
	thresholds,
	ntuple_comparefunc = default_ntuple_comparefunc,
	effective_snr_factor = 250.0,
	veto_segments = None,
	trigger_program = u"inspiral",
	likelihood_func = None,
	likelihood_params_func = None,
	verbose = False,
	max_dt = None
):
	#
	# prepare the coincidence table interface.
	#

	if verbose:
		print >>sys.stderr, "indexing ..."
	coinc_tables = InspiralCoincTables(xmldoc, vetoes = veto_segments, program = trigger_program, likelihood_func = likelihood_func, likelihood_params_func = likelihood_params_func)
	coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, coinc_definer_row.search, coinc_definer_row.search_coinc_type, create_new = True, description = coinc_definer_row.description)
	sngl_index = dict((row.event_id, row) for row in lsctables.SnglInspiralTable.get_table(xmldoc))

	#
	# build the event list accessors, populated with events from those
	# processes that can participate in a coincidence.  apply vetoes by
	# removing events from the lists that fall in vetoed segments
	#

	eventlists = snglcoinc.make_eventlists(xmldoc, InspiralEventList, lsctables.SnglInspiralTable.tableName)
	if veto_segments is not None:
		for eventlist in eventlists.values():
			iterutils.inplace_filter((lambda event: event.ifo not in veto_segments or event.get_end() not in veto_segments[event.ifo]), eventlist)

	#
	# set the \Delta t parameter on all the event lists
	#

	if max_dt is None:
		max_dt = inspiral_max_dt(lsctables.SnglInspiralTable.get_table(xmldoc), thresholds)
	if verbose:
		print >>sys.stderr, "event bisection search window will be %.16g s" % max_dt
	for eventlist in eventlists.values():
		eventlist.set_dt(max_dt)

	#
	# replicate the ethinca parameter for every possible instrument
	# pair
	#

	thresholds = replicate_threshold(thresholds, set(eventlists))

	#
	# construct offset vector assembly graph
	#

	time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index, verbose = verbose)

	#
	# retrieve all coincidences, apply the final n-tuple compare func
	# and record the survivors
	#

	for node, coinc in time_slide_graph.get_coincs(eventlists, event_comparefunc, thresholds, verbose = verbose):
		coinc = tuple(sngl_index[event_id] for event_id in coinc)
		if not ntuple_comparefunc(coinc, node.offset_vector):
			coinc_tables.append_coinc(process_id, node.time_slide_id, coinc_def_id, coinc, effective_snr_factor)

	#
	# remove time offsets from events
	#

	del eventlists.offsetvector

	#
	# done
	#

	return xmldoc
    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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
def ligolw_thinca(xmldoc,
                  process_id,
                  coinc_definer_row,
                  thresholds,
                  ntuple_comparefunc=InspiralCoincTables.ntuple_comparefunc,
                  veto_segments=None,
                  trigger_program=u"inspiral",
                  likelihood_func=None,
                  likelihood_params_func=None,
                  min_instruments=2,
                  min_log_L=None,
                  verbose=False):
    #
    # validate input
    #

    if min_instruments < 1:
        raise ValueError("min_instruments (=%d) must be >= 1" %
                         min_instruments)
    if min_log_L is not None and likelihood_func is None:
        raise ValueError("must supply likelihood_func to impose min_log_L cut")

    #
    # prepare the coincidence table interface.
    #

    if verbose:
        print("indexing ...", file=sys.stderr)
    coinc_tables = InspiralCoincTables(
        xmldoc,
        vetoes=veto_segments,
        program=trigger_program,
        likelihood_func=likelihood_func,
        likelihood_params_func=likelihood_params_func)
    coinc_def_id = ligolw_coincs.get_coinc_def_id(
        xmldoc,
        coinc_definer_row.search,
        coinc_definer_row.search_coinc_type,
        create_new=True,
        description=coinc_definer_row.description)
    instruments = set(
        coinc_tables.time_slide_table.getColumnByName("instrument"))

    #
    # replicate the coincidence window parameter for every possible
    # instrument pair
    #

    thresholds = replicate_threshold(thresholds, instruments)

    #
    # build the event list accessors.  apply vetoes by excluding events
    # from the lists that fall in vetoed segments
    #

    sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc)
    if veto_segments is not None:
        sngl_inspiral_table = (event for event in sngl_inspiral_table
                               if event.ifo not in veto_segments
                               or event.end not in veto_segments[event.ifo])
    eventlists = snglcoinc.EventListDict(InspiralEventList,
                                         sngl_inspiral_table,
                                         instruments=instruments)

    #
    # construct offset vector assembly graph
    #

    time_slide_graph = snglcoinc.TimeSlideGraph(
        coinc_tables.time_slide_index,
        min_instruments=min_instruments,
        verbose=verbose)

    #
    # retrieve all coincidences, apply the final n-tuple compare func
    # and record the survivors
    #

    for node, coinc in time_slide_graph.get_coincs(eventlists,
                                                   thresholds,
                                                   verbose=verbose):
        if not ntuple_comparefunc(coinc, node.offset_vector):
            coinc, coincmaps, coinc_inspiral = coinc_tables.coinc_rows(
                process_id, node.time_slide_id, coinc_def_id, coinc)
            if min_log_L is None or coinc.likelihood >= min_log_L:
                coinc_tables.append_coinc(coinc, coincmaps, coinc_inspiral)

    #
    # done
    #

    return xmldoc
Esempio n. 13
0
def ligolw_burca(xmldoc,
                 process_id,
                 EventListType,
                 CoincTables,
                 coinc_definer_row,
                 event_comparefunc,
                 thresholds,
                 ntuple_comparefunc=lambda events, offset_vector: False,
                 verbose=False):
    #
    # prepare the coincidence table interface.
    #

    if verbose:
        print >> sys.stderr, "indexing ..."
    coinc_tables = CoincTables(xmldoc)
    coinc_def_id = ligolw_coincs.get_coinc_def_id(
        xmldoc,
        coinc_definer_row.search,
        coinc_definer_row.search_coinc_type,
        create_new=True,
        description=coinc_definer_row.description)
    sngl_index = dict((row.event_id, row)
                      for row in lsctables.SnglBurstTable.get_table(xmldoc))

    #
    # build the event list accessors, populated with events from those
    # processes that can participate in a coincidence
    #

    eventlists = snglcoinc.make_eventlists(xmldoc, EventListType,
                                           lsctables.SnglBurstTable.tableName)

    #
    # construct offset vector assembly graph
    #

    time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index,
                                                verbose=verbose)

    #
    # retrieve all coincidences, apply the final n-tuple compare func
    # and record the survivors
    #

    for node, coinc in time_slide_graph.get_coincs(eventlists,
                                                   event_comparefunc,
                                                   thresholds,
                                                   verbose=verbose):
        ntuple = tuple(sngl_index[id] for id in coinc)
        if not ntuple_comparefunc(ntuple, node.offset_vector):
            coinc_tables.append_coinc(process_id, node.time_slide_id,
                                      coinc_def_id, ntuple)

    #
    # remove time offsets from events
    #

    del eventlists.offsetvector

    #
    # done
    #

    return xmldoc
Esempio n. 14
0
def ligolw_thinca(xmldoc,
                  process_id,
                  coinc_definer_row,
                  event_comparefunc,
                  thresholds,
                  max_dt,
                  ntuple_comparefunc=default_ntuple_comparefunc,
                  veto_segments=None,
                  trigger_program=u"inspiral",
                  likelihood_func=None,
                  likelihood_params_func=None,
                  min_instruments=2,
                  min_log_L=None,
                  verbose=False):
    #
    # validate input
    #

    if min_instruments < 1:
        raise ValueError("min_instruments (=%d) must be >= 1" %
                         min_instruments)
    if min_log_L is not None and likelihood_func is None:
        raise ValueError("must supply likelihood_func to impose min_log_L cut")

    #
    # prepare the coincidence table interface.
    #

    if verbose:
        print >> sys.stderr, "indexing ..."
    coinc_tables = InspiralCoincTables(
        xmldoc,
        vetoes=veto_segments,
        program=trigger_program,
        likelihood_func=likelihood_func,
        likelihood_params_func=likelihood_params_func)
    coinc_def_id = ligolw_coincs.get_coinc_def_id(
        xmldoc,
        coinc_definer_row.search,
        coinc_definer_row.search_coinc_type,
        create_new=True,
        description=coinc_definer_row.description)
    sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc)
    sngl_index = dict((row.event_id, row) for row in sngl_inspiral_table)

    #
    # build the event list accessors, populated with events from those
    # processes that can participate in a coincidence.  apply vetoes by
    # removing events from the lists that fall in vetoed segments
    #

    eventlists = snglcoinc.EventListDict(
        InspiralEventList,
        sngl_inspiral_table,
        instruments=set(
            coinc_tables.time_slide_table.getColumnByName("instrument")))
    if veto_segments is not None:
        for eventlist in eventlists.values():
            iterutils.inplace_filter(
                (lambda event: event.ifo not in veto_segments or event.end
                 not in veto_segments[event.ifo]), eventlist)

    #
    # set the \Delta t parameter on all the event lists
    #

    if verbose:
        print >> sys.stderr, "event bisection search window will be %.16g s" % max_dt
    for eventlist in eventlists.values():
        eventlist.set_dt(max_dt)

    #
    # replicate the ethinca parameter for every possible instrument
    # pair
    #

    thresholds = replicate_threshold(thresholds, eventlists)

    #
    # construct offset vector assembly graph
    #

    time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index,
                                                verbose=verbose)

    #
    # retrieve all coincidences, apply the final n-tuple compare func
    # and record the survivors
    #

    for node, coinc in time_slide_graph.get_coincs(eventlists,
                                                   event_comparefunc,
                                                   thresholds,
                                                   verbose=verbose):
        if len(coinc) < min_instruments:
            continue
        coinc = tuple(sngl_index[event_id] for event_id in coinc)
        if not ntuple_comparefunc(coinc, node.offset_vector):
            coinc, coincmaps, coinc_inspiral = coinc_tables.coinc_rows(
                process_id, node.time_slide_id, coinc_def_id, coinc)
            if min_log_L is None or coinc.likelihood >= min_log_L:
                coinc_tables.append_coinc(coinc, coincmaps, coinc_inspiral)

    #
    # done
    #

    return xmldoc
Esempio n. 15
0
def ligolw_thinca(
	xmldoc,
	process_id,
	coinc_definer_row,
	thresholds,
	ntuple_comparefunc = InspiralCoincTables.ntuple_comparefunc,
	seglists = None,
	veto_segments = None,
	likelihood_func = None,
	min_instruments = 2,
	min_log_L = None,
	verbose = False
):
	#
	# validate input
	#

	if min_instruments < 1:
		raise ValueError("min_instruments (=%d) must be >= 1" % min_instruments)
	if min_log_L is not None and likelihood_func is None:
		raise ValueError("must supply likelihood_func to impose min_log_L cut")

	#
	# prepare the coincidence table interface.
	#

	if verbose:
		print("indexing ...", file=sys.stderr)
	coinc_tables = InspiralCoincTables(xmldoc, likelihood_func = likelihood_func)
	coinc_def_id = ligolw_coincs.get_coinc_def_id(xmldoc, coinc_definer_row.search, coinc_definer_row.search_coinc_type, create_new = True, description = coinc_definer_row.description)
	instruments = set(coinc_tables.time_slide_table.getColumnByName("instrument"))

	#
	# replicate the coincidence window parameter for every possible
	# instrument pair
	#

	thresholds = replicate_threshold(thresholds, instruments)

	#
	# build the event list accessors.  apply vetoes by excluding events
	# from the lists that fall in vetoed segments
	#

	sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc)
	if veto_segments is not None:
		sngl_inspiral_table = (event for event in sngl_inspiral_table if event.ifo not in veto_segments or event.end not in veto_segments[event.ifo])
		if seglists is not None:
			# don't do in-place
			seglists = seglists - veto_segments
	eventlists = snglcoinc.EventListDict(InspiralEventList, sngl_inspiral_table, instruments = instruments)

	#
	# construct offset vector assembly graph
	#

	time_slide_graph = snglcoinc.TimeSlideGraph(coinc_tables.time_slide_index, min_instruments = min_instruments, verbose = verbose)

	#
	# retrieve all coincidences, apply the final n-tuple compare func
	# and record the survivors
	#

	for node, coinc in time_slide_graph.get_coincs(eventlists, thresholds, verbose = verbose):
		if not ntuple_comparefunc(coinc, node.offset_vector):
			coinc, coincmaps, coinc_inspiral = coinc_tables.coinc_rows(process_id, node.time_slide_id, coinc_def_id, coinc, seglists = seglists)
			if min_log_L is None or coinc.likelihood >= min_log_L:
				coinc_tables.append_coinc(coinc, coincmaps, coinc_inspiral)

	#
	# done
	#

	return xmldoc