Exemple #1
0
def background_livetime_ring_by_slide(connection,
                                      live_time_program,
                                      seglists,
                                      veto_segments,
                                      verbose=False):
    background_livetime = {}
    instruments = frozenset(seglists.keys())
    offset_vectors = db_thinca_rings.get_background_offset_vectors(connection)
    # first work out time slide live time
    for on_instruments, livetimes in db_thinca_rings.get_thinca_livetimes(
            db_thinca_rings.get_thinca_rings_by_available_instruments(
                connection, program_name=live_time_program),
            veto_segments,
            offset_vectors,
            verbose=verbose).items():
        on_instruments = frozenset(
            on_instruments
        )  #lsctables.ifos_from_instrument_set(on_instruments)
        for offset, lt in zip(offset_vectors, livetimes):
            background_livetime.setdefault(on_instruments, {})
            key = frozenset(offset.items())
            background_livetime[on_instruments].setdefault(key, 0)
            background_livetime[on_instruments][key] += lt

    return background_livetime
Exemple #2
0
def background_livetime_ring_by_slide(connection, live_time_program, seglists, veto_segments, verbose = False):
	background_livetime = {}
	instruments = frozenset(seglists.keys())
	offset_vectors = db_thinca_rings.get_background_offset_vectors(connection)
	# first work out time slide live time
	for on_instruments, livetimes in db_thinca_rings.get_thinca_livetimes(db_thinca_rings.get_thinca_rings_by_available_instruments(connection, program_name = live_time_program), veto_segments, offset_vectors, verbose = verbose).items():
		on_instruments = frozenset(on_instruments)#lsctables.ifos_from_instrument_set(on_instruments)
		for offset, lt in zip(offset_vectors,livetimes):
			background_livetime.setdefault(on_instruments,{})
			key = frozenset(offset.items())
			background_livetime[on_instruments].setdefault(key, 0)
			background_livetime[on_instruments][key] += lt

	return background_livetime
Exemple #3
0
    JOIN coinc_event AS insp_coinc_event ON (insp_coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id)
    JOIN coinc_definer AS insp_coinc_definer ON (insp_coinc_definer.coinc_def_id == insp_coinc_event.coinc_def_id)
    JOIN coinc_definer AS sim_coinc_definer ON (sim_coinc_definer.coinc_def_id == sim_coinc_event.coinc_def_id)
  WHERE
    insp_coinc_definer.search == 'inspiral'
    AND sim_coinc_definer.search == 'inspiral'
    AND insp_coinc_definer.search_coinc_type == 0
    AND sim_coinc_definer.search_coinc_type == 2
    AND mapC.table_name == 'coinc_event'
    AND mapD.table_name == 'sim_inspiral'
  """):
    injection_likelihood.append(likelihood)
    injection_snr.append(snr)
  #livetimes = db_thinca_rings.get_thinca_livetimes(db_thinca_rings.get_thinca_rings_by_available_instruments(connection,'thinca'), db_thinca_rings.get_veto_segments(connection, 'vetoes'), db_thinca_rings.get_background_offset_vectors(connection), verbose=True)
  # above is the correct calculation of livetimes, but it takes a while. You can comment it out and uncomment the line below for an approximate calculation of livetime.
  livetimes = db_thinca_rings.get_thinca_livetimes(db_thinca_rings.get_thinca_rings_by_available_instruments(connection,'thinca'), segments.segmentlistdict(), db_thinca_rings.get_background_offset_vectors(connection), verbose=True)
  dbtables.put_connection_filename(filename, working_filename, verbose = True)
print "number of timeslides:", len(timeslide_likelihood)
print "number of zerolags:", len(zerolag_likelihood)
print "number of injections:", len(injection_likelihood)

all_likelihoods = numpy.array(timeslide_likelihood + zerolag_likelihood + injection_likelihood, dtype=float)
timeslide_likelihoods = numpy.array(timeslide_likelihood)
zerolag_likelihoods = numpy.array(zerolag_likelihood)
injection_likelihoods = numpy.array(injection_likelihood)
timeslide_snrs = numpy.array(timeslide_snr)
zerolag_snrs = numpy.array(zerolag_snr)
injection_snrs = numpy.array(injection_snr)
# set all zero likelihoods to the next lowest calculated likelihood, and all infinity likelihoods to the next highest, so plotting can work
plottable_likelihoods = all_likelihoods[~numpy.isinf(all_likelihoods) & (all_likelihoods > 0)]
min_likelihood = plottable_likelihoods.min()
Exemple #4
0
    WHERE
      coinc_definer.search == 'inspiral'
      AND coinc_definer.search_coinc_type == 2
      AND mapA.table_name == 'sngl_inspiral'
      AND mapB.table_name == 'sngl_inspiral'
      AND mapC.table_name == 'coinc_event'
      AND mapD.table_name == 'sim_inspiral'
      AND snglA.ifo == ?
      AND snglB.ifo == ?
      """, (tuple(ifos)) ):
        injections.append(values[1:] + (1,))
        injections_info.append([values[0], database])
    dbtables.put_connection_filename(database, working_filename, verbose = True)

  if not is_injections:  
    rings = db_thinca_rings.get_thinca_rings_by_available_instruments(connection)
    offset_vectors = dbtables.lsctables.table.get_table(dbtables.get_xml(connection), dbtables.lsctables.TimeSlideTable.tableName).as_dict()
  
    def calc_delta_t(trigger1_ifo, trigger1_end_time, trigger1_end_time_ns, trigger2_ifo, trigger2_end_time, trigger2_end_time_ns, time_slide_id, rings = rings, offset_vectors = offset_vectors):
      print >>sys.stderr, "calculating delta_t"
      trigger1_true_end_time = dbtables.lsctables.LIGOTimeGPS(trigger1_end_time, trigger1_end_time_ns)
      trigger2_true_end_time = dbtables.lsctables.LIGOTimeGPS(trigger2_end_time, trigger2_end_time_ns)
      # find the instruments that were on at trigger 1's end time and
      # find the ring that contains this trigger
      try:
        [ring] = [segs[segs.find(trigger1_end_time)] for segs in rings.values() if trigger1_end_time in segs]
      except ValueError:
        # FIXME THERE SEEMS TO BE A BUG IN  THINCA!  Occasionally thinca records a trigger on the upper boundary
        # of its ring.  This would make it outside the ring which is very problematic.  It needs to be fixed in thinca
        # for now we'll allow the additional check that the other trigger is in the ring and use it.
          print >>sys.stderr, "trigger1 found not on a ring, trying trigger2"