def get_segments(connection, xmldoc, table_name, live_time_program, veto_segments_name=None, data_segments_name="datasegments"): segs = segments.segmentlistdict() if table_name == dbtables.lsctables.CoincInspiralTable.tableName: if live_time_program == "gstlal_inspiral": segs = ligolw_segments.segmenttable_get_by_name( xmldoc, data_segments_name).coalesce() segs &= ligolw_search_summary.segmentlistdict_fromsearchsummary( xmldoc, live_time_program).coalesce() elif live_time_program == "thinca": segs = db_thinca_rings.get_thinca_zero_lag_segments( connection, program_name=live_time_program).coalesce() else: raise ValueError( "for burst tables livetime program must be one of gstlal_inspiral, thinca" ) if veto_segments_name is not None: veto_segs = db_thinca_rings.get_veto_segments( connection, veto_segments_name) segs -= veto_segs return segs elif table_name == dbtables.lsctables.CoincRingdownTable.tableName: segs = ligolw_search_summary.segmentlistdict_fromsearchsummary( xmldoc, live_time_program).coalesce() if veto_segments_name is not None: veto_segs = ligolw_segments.segmenttable_get_by_name( xmldoc, veto_segments_name).coalesce() segs -= veto_segs return segs elif table_name == dbtables.lsctables.MultiBurstTable.tableName: if live_time_program == "omega_to_coinc": segs = ligolw_search_summary.segmentlistdict_fromsearchsummary( xmldoc, live_time_program).coalesce() if veto_segments_name is not None: veto_segs = ligolw_segments.segmenttable_get_by_name( xmldoc, veto_segments_name).coalesce() segs -= veto_segs elif live_time_program == "waveburst": segs = db_thinca_rings.get_thinca_zero_lag_segments( connection, program_name=live_time_program).coalesce() if veto_segments_name is not None: veto_segs = db_thinca_rings.get_veto_segments( connection, veto_segments_name) segs -= veto_segs else: raise ValueError( "for burst tables livetime program must be one of omega_to_coinc, waveburst" ) return segs else: raise ValueError("table must be in " + " ".join(allowed_analysis_table_names()))
def get_segments(connection, xmldoc, program_name): seglists = segments.segmentlistdict() if program_name == "thinca": seglists = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name) if program_name == "gstlal_inspiral" or program_name == "lalapps_ring": seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name).coalesce() return seglists
def get_far_threshold_and_segments(zerofname, instruments, live_time_program, veto_seg_name="vetoes", verbose=True): """ return the false alarm rate of the most rare zero-lag coinc, and a dictionary of the thinca segments indexed by instrument. """ # open database working_filename = dbtables.get_connection_filename(zerofname, verbose=verbose) connection = sqlite3.connect(working_filename) dbtables.DBTable_set_connection(connection) # extract false alarm rate threshold query = 'SELECT MIN(coinc_inspiral.false_alarm_rate) FROM coinc_inspiral JOIN coinc_event ON (coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id) WHERE ( coinc_event.instruments = "' + instruments + '" AND NOT EXISTS(SELECT * FROM time_slide WHERE time_slide.time_slide_id == coinc_event.time_slide_id AND time_slide.offset != 0) );' print("\n", query) far, = connection.cursor().execute(query).fetchone() # extract segments. seglists = db_thinca_rings.get_thinca_zero_lag_segments( connection, program_name=live_time_program) # done connection.close() dbtables.discard_connection_filename(zerofname, working_filename, verbose=verbose) dbtables.DBTable_set_connection(None) return far, seglists
def get_segments(self, connection,xmldoc): if self.coinc_inspiral_table: segments = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = self.opts.live_time_program) if self.multi_burst_table: #FIXME CWB case of rings not handled segments = llwapp.segmentlistdict_fromsearchsummary(xmldoc, self.opts.live_time_program).coalesce() return segments
def get_far_threshold_and_segments(zerofname, live_time_program, instruments, verbose = False): """ return the false alarm rate of the most rare zero-lag coinc, and a dictionary of the thinca segments indexed by instrument. """ # open database working_filename = dbtables.get_connection_filename(zerofname, verbose = verbose) connection = sqlite3.connect(working_filename) dbtables.DBTable_set_connection(connection) # extract false alarm rate threshold query = 'SELECT MIN(coinc_inspiral.combined_far) FROM coinc_inspiral JOIN coinc_event ON (coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id) WHERE (coinc_event.instruments == "' + str(instruments) + '") AND NOT EXISTS(SELECT * FROM time_slide WHERE time_slide.time_slide_id == coinc_event.time_slide_id AND time_slide.offset != 0);' print(query) far, = connection.cursor().execute(query).fetchone() # extract segments. seglists = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program) # done connection.close() dbtables.discard_connection_filename(zerofname, working_filename, verbose = verbose) dbtables.DBTable_set_connection(None) print("WARNING replacing far with 10^-7", file=sys.stderr) far = 1.0e-7 return far, seglists
def get_far_threshold_and_segments(zerofname, live_time_program, instruments, verbose=False): """ return the false alarm rate of the most rare zero-lag coinc, and a dictionary of the thinca segments indexed by instrument. """ # open database working_filename = dbtables.get_connection_filename(zerofname, verbose=verbose) connection = sqlite3.connect(working_filename) dbtables.DBTable_set_connection(connection) # extract false alarm rate threshold query = 'SELECT MIN(coinc_inspiral.combined_far) FROM coinc_inspiral JOIN coinc_event ON (coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id) WHERE (coinc_event.instruments == "' + str( instruments ) + '") AND NOT EXISTS(SELECT * FROM time_slide WHERE time_slide.time_slide_id == coinc_event.time_slide_id AND time_slide.offset != 0);' print(query) far, = connection.cursor().execute(query).fetchone() # extract segments. seglists = db_thinca_rings.get_thinca_zero_lag_segments( connection, program_name=live_time_program) # done connection.close() dbtables.discard_connection_filename(zerofname, working_filename, verbose=verbose) dbtables.DBTable_set_connection(None) print("WARNING replacing far with 10^-7", file=sys.stderr) far = 1.0e-7 return far, seglists
def get_segments(connection, xmldoc, table_name, live_time_program, veto_segments_name = None, data_segments_name = "datasegments"): from pylal import db_thinca_rings segs = segments.segmentlistdict() if table_name == dbtables.lsctables.CoincInspiralTable.tableName: if live_time_program == "gstlal_inspiral": segs = ligolw_segments.segmenttable_get_by_name(xmldoc, data_segments_name).coalesce() segs &= ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce() elif live_time_program == "thinca": segs = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program).coalesce() else: raise ValueError("for burst tables livetime program must be one of gstlal_inspiral, thinca") if veto_segments_name is not None: veto_segs = db_thinca_rings.get_veto_segments(connection, veto_segments_name) segs -= veto_segs return segs elif table_name == dbtables.lsctables.CoincRingdownTable.tableName: segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce() if veto_segments_name is not None: veto_segs = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce() segs -= veto_segs return segs elif table_name == dbtables.lsctables.MultiBurstTable.tableName: if live_time_program == "omega_to_coinc": segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce() if veto_segments_name is not None: veto_segs = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce() segs -= veto_segs elif live_time_program == "waveburst": segs = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program).coalesce() if veto_segments_name is not None: veto_segs = db_thinca_rings.get_veto_segments(connection, veto_segments_name) segs -= veto_segs else: raise ValueError("for burst tables livetime program must be one of omega_to_coinc, waveburst") return segs else: raise ValueError("table must be in " + " ".join(allowed_analysis_table_names()))
def get_far_threshold_and_segments(zerofname, instruments, live_time_program, veto_seg_name="vetoes", verbose = True): """ return the false alarm rate of the most rare zero-lag coinc, and a dictionary of the thinca segments indexed by instrument. """ # open database working_filename = dbtables.get_connection_filename(zerofname, verbose = verbose) connection = sqlite3.connect(working_filename) dbtables.DBTable_set_connection(connection) # extract false alarm rate threshold query = 'SELECT MIN(coinc_inspiral.false_alarm_rate) FROM coinc_inspiral JOIN coinc_event ON (coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id) WHERE ( coinc_event.instruments = "' + instruments + '" AND NOT EXISTS(SELECT * FROM time_slide WHERE time_slide.time_slide_id == coinc_event.time_slide_id AND time_slide.offset != 0) );' print "\n", query far, = connection.cursor().execute(query).fetchone() # extract segments. seglists = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program) # done connection.close() dbtables.discard_connection_filename(zerofname, working_filename, verbose = verbose) dbtables.DBTable_set_connection(None) return far, seglists
def __init__(self, flist, opts): self.far = {} self.segments = segments.segmentlistdict() self.non_inj_fnames = [] self.inj_fnames = [] #self.der_fit = None self.twoDMassBins = None #self.dBin = {} self.gw = None self.found = {} self.missed = {} self.wnfunc = None self.opts = opts if opts.bootstrap_iterations: self.bootnum = int(opts.bootstrap_iterations) else: self.bootnum = 100 self.veto_segments = segments.segmentlistdict() self.zero_lag_segments = {} self.instruments = [] self.livetime = {} self.minmass = None self.maxmass = None self.mintotal = None self.maxtotal = None for f in flist: if opts.verbose: print >> sys.stderr, "Gathering stats from: %s...." % (f,) working_filename = dbtables.get_connection_filename(f, verbose = opts.verbose) connection = sqlite3.connect(working_filename) dbtables.DBTable_set_connection(connection) xmldoc = dbtables.get_xml(connection) # look for a sim table try: sim_inspiral_table = table.get_table(xmldoc, dbtables.lsctables.SimInspiralTable.tableName) self.inj_fnames.append(f) sim = True except ValueError: self.non_inj_fnames.append(f) sim = False if not sim: if opts.veto_segments_name is not None: self.veto_segments = db_thinca_rings.get_veto_segments(connection, opts.veto_segments_name) self.get_instruments(connection) self.segments += db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = opts.live_time_program) self.get_far_thresholds(connection) else: self.get_mass_ranges(connection) #connection.close() dbtables.discard_connection_filename(f, working_filename, verbose = opts.verbose) dbtables.DBTable_set_connection(None) # FIXME Do these have to be done by instruments? self.segments -= self.veto_segments # compute far, segments and livetime by instruments for i in self.instruments: self.far[i] = min(self.far[i]) # FIXME this bombs if any of the FARS are zero. maybe it should continue # and just remove that instrument combo from the calculation if self.far[i] == 0: print >> sys.stderr, "Encountered 0 FAR in %s, ABORTING" % (i,) sys.exit(1) self.zero_lag_segments[i] = self.segments.intersection(i) - self.segments.union(set(self.segments.keys()) - i) # Livetime must have playground removed self.livetime[i] = float(abs(self.zero_lag_segments[i] - segmentsUtils.S2playground(self.segments.extent_all()))) if opts.verbose: print >> sys.stderr, "%s FAR %e, livetime %f" % (",".join(sorted(list(i))), self.far[i], self.livetime[i]) # get a 2D mass binning self.twoDMassBins = self.get_2d_mass_bins(self.minmass, self.maxmass, opts.mass_bins)