Exemplo n.º 1
0
def snglburst_append(self, row):
	global summary
	if row.ifo not in summary:
		summary[row.ifo] = Summary()
	summary[row.ifo].nevents += 1
	summary[row.ifo].start_time.append(lsctables.LIGOTimeGPS(row.start_time, row.start_time_ns))
	summary[row.ifo].duration.append(row.duration)
	summary[row.ifo].peak_time.append(lsctables.LIGOTimeGPS(row.peak_time, row.peak_time_ns))
	summary[row.ifo].peak_freq.append(row.peak_frequency)
	summary[row.ifo].bandwidth.append(row.bandwidth)
	summary[row.ifo].lo_freq.append(row.central_freq - row.bandwidth / 2.0)
	summary[row.ifo].snr.append(row.snr)
	summary[row.ifo].confidence.append(row.confidence)
Exemplo n.º 2
0
            def injection_was_made(geocent_end_time,
                                   geocent_end_time_ns,
                                   zero_lag_segments=zero_lag_segments):
                """
				return True if injection was made in the given segmentlist
				"""
                return lsctables.LIGOTimeGPS(
                    geocent_end_time, geocent_end_time_ns) in zero_lag_segments
Exemplo n.º 3
0
def InspiralSnglCompare(sim,
                        sngl,
                        twindow=lsctables.LIGOTimeGPS(options.time_window)):
    """
	Returns 0 if sim and sngl are less than twindow apart.
	"""
    dt = sim.time_geocent - sngl.end
    return 0 if abs(dt) < twindow else dt
Exemplo n.º 4
0
    def set_dt(self, dt):
        """
		If an event's start time differs by more than this many
		seconds from the start time of another event then it is
		*impossible* for them to be coincident.
		"""
        # add 1% for safety, and pre-convert to LIGOTimeGPS to
        # avoid doing type conversion in loops
        self.dt = lsctables.LIGOTimeGPS(dt * 1.01)
Exemplo n.º 5
0
def CompareSnglInspiral(a, b, twindow=lsctables.LIGOTimeGPS(0)):
    """
  Returns 0 if a and b are less than twindow appart.
  """
    tdiff = abs(a.get_end() - b.get_end())
    if tdiff < twindow:
        return 0
    else:
        return cmp(a.get_end(), b.get_end())
Exemplo n.º 6
0
def time_within_segments(geocent_end_time, geocent_end_time_ns, zero_lag_segments = None):
	"""
	Return True if injection was made in the given segmentlist, if no
	segments just return True
	"""
	if zero_lag_segments is None:
		return True
	else:
		return lsctables.LIGOTimeGPS(geocent_end_time, geocent_end_time_ns) in zero_lag_segments
def cmp_sngl_sim(sim,
                 sngl,
                 get_sim_time,
                 get_sngl_time,
                 twindow=lsctables.LIGOTimeGPS(9)):
    tdiff = abs(get_sngl_time(sngl) - get_sim_time(sim))
    if tdiff < twindow:
        return 0
    else:
        return cmp(get_sngl_time(sngl), get_sim_time(sim))
Exemplo n.º 8
0
   def create_is_playground_func(
       connection,
       playground_segs=segmentsUtils.S2playground(
           self.segments.extent_all())):
       """
 Construct the is_playground() SQL function.
 """
       connection.create_function(
           "is_playground", 2,
           lambda seconds, nanoseconds: lsctables.LIGOTimeGPS(
               seconds, nanoseconds) in playground_segs)
def parse_command_line():
	parser = OptionParser(
		version = "Name: %%prog\n%s" % git_version.verbose_msg,
		usage = "%prog [options] [file ...]",
		description = "Removes sngl_burst events from XML files according to a variety of criteria.  Files named on the command line are read one-by-one, and over-written with the new files.  If no files are named on the command line, input is read from stdin and written to stdout.  Note that, for the most part, this program does not understand coincidence information, and so if an injection or burst event is removed that participates in a coincidence, this program simply deletes the entire coincidence as well (before applying the --coinc-only cut)."
	)
	parser.add_option("--coinc-only", action = "store_true", help = "Discard events that are not participating in a coincident event.")
	parser.add_option("--comment", metavar = "text", help = "Set the comment string to be recorded in the process table for this job (default = None).")
	parser.add_option("--inj-made-only", action = "store_true", help = "Discard injections outside the search summary out segments.")
	parser.add_option("--min-amplitude", metavar = "value", type = "float", help = "Discard events below the given amplitude.")
	parser.add_option("--max-amplitude", metavar = "value", type = "float", help = "Discard events above the given amplitude.")
	parser.add_option("--min-bandwidth", metavar = "Hz", type = "float", help = "Discard events narrower than the given bandwidth.")
	parser.add_option("--max-bandwidth", metavar = "Hz", type = "float", help = "Discard events wider than the given bandwidth.")
	parser.add_option("--min-central-freq", metavar = "Hz", type = "float", help = "Discard events with central frequency lower than that given.")
	parser.add_option("--max-central-freq", metavar = "Hz", type = "float", help = "Discard events with central frequency higher than that given.")
	parser.add_option("--min-confidence", metavar = "value", type = "float", help = "Discard events below the given confidence.")
	parser.add_option("--max-confidence", metavar = "value", type = "float", help = "Discard events above the given confidence.")
	parser.add_option("--min-duration", metavar = "seconds", type = "float", help = "Discard events shorter than the given duration.")
	parser.add_option("--max-duration", metavar = "seconds", type = "float", help = "Discard events longer than the given duration.")
	parser.add_option("--min-fhigh", metavar = "Hz", type = "float", help = "Discard events with highest frequency below the given frequency.")
	parser.add_option("--max-fhigh", metavar = "Hz", type = "float", help = "Discard events with highest frequency above the given frequency.")
	parser.add_option("--min-flow", metavar = "Hz", type = "float", help = "Discard events with lowest frequency below the given frequency.")
	parser.add_option("--max-flow", metavar = "Hz", type = "float", help = "Discard events with loest frequency above the given frequency.")
	parser.add_option("--min-hrss", metavar = "value", type = "float", help = "Discard events with h_rss below the given value.")
	parser.add_option("--max-hrss", metavar = "value", type = "float", help = "Discard events with h_rss above the given value.")
	parser.add_option("--cut-instrument", metavar = "name", action = "append", default = [], help = "Discard events from given instrument.")
	parser.add_option("--min-peak-time", metavar = "seconds", help = "Discard events with peak time before the given GPS time.")
	parser.add_option("--max-peak-time", metavar = "seconds", help = "Discard events with peak time after the given GPS time.")
	parser.add_option("--min-start-time", metavar = "seconds", help = "Discard events starting before the given GPS time.")
	parser.add_option("--max-start-time", metavar = "seconds", help = "Discard events starting after the given GPS time.")
	parser.add_option("--min-stop-time", metavar = "seconds", help = "Discard events ending before the given GPS time.")
	parser.add_option("--max-stop-time", metavar = "seconds", help = "Discard events ending after the given GPS time.")
	parser.add_option("--min-snr", metavar = "value", type = "float", help = "Discard events below the given SNR.")
	parser.add_option("--max-snr", metavar = "value", type = "float", help = "Discard events above the given SNR.")
	parser.add_option("--program", metavar = "name", help = "Process events generated by the given program.")
	parser.add_option("--veto-file", metavar = "filename", help = "Veto events using the veto segment list extracted from this XML file.  The file must contain segment tables, and the veto list will be constructed from the segments named \"sngl_burst_veto\".")
	parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
	options, filenames = parser.parse_args()

	if options.inj_made_only and not options.program:
		raise ValueError("must set --program when --inj-made-only is set")
	options.cut_instrument = set(options.cut_instrument)

	if options.min_peak_time is not None:
		options.min_peak_time = lsctables.LIGOTimeGPS(options.min_peak_time)
	if options.max_peak_time is not None:
		options.max_peak_time = lsctables.LIGOTimeGPS(options.max_peak_time)
	if options.min_start_time is not None:
		options.min_start_time = lsctables.LIGOTimeGPS(options.min_start_time)
	if options.max_start_time is not None:
		options.max_start_time = lsctables.LIGOTimeGPS(options.max_start_time)
	if options.min_stop_time is not None:
		options.min_stop_time = lsctables.LIGOTimeGPS(options.min_stop_time)
	if options.max_stop_time is not None:
		options.max_stop_time = lsctables.LIGOTimeGPS(options.max_stop_time)

	return options, (filenames or [None])
def InspiralNearCoincCompare(sim, inspiral):
    """
	Return False if the peak time of the sim is within 9 seconds of the inspiral event.
	"""
    return SnglInspiralUtils.CompareSnglInspiral(
        sim, inspiral, twindow=lsctables.LIGOTimeGPS(9))
Exemplo 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
        #

        self.snglinspiraltable.sort(key=lambda row: row.end)

        #
        # set the window for inspirals_near_endtime().  this window
        # is the amount of time such that if an injection's end
        # time and a inspiral event's end time differ by more than
        # this it is *impossible* for them to match one another.
        #

        self.end_time_bisect_window = lsctables.LIGOTimeGPS(
            end_time_bisect_window)
Exemplo n.º 12
0
 def get_start(self):
     return lsctables.LIGOTimeGPS(self.start_time, self.start_time_ns)
def parse_command_line():
    parser = OptionParser(
        version="Name: %%prog\n%s" % git_version.verbose_msg,
        usage="%prog [options] filename",
        description=
        "Convert an image into a LIGO Light-Weight XML file containing a list of sine-Gaussian burst injections.  When injected into data, the injections will cause a waterfall plot to display the image."
    )
    parser.add_option(
        "-l",
        "--f-low",
        metavar="Hz",
        type="float",
        default=64.0,
        help="Set the low-frequency limit of the tiling (default = 64).")
    parser.add_option(
        "-d",
        "--delta-f",
        metavar="Hz",
        type="float",
        default=16.0,
        help="Set the frequency spacing of the tiling (default = 16).")
    parser.add_option(
        "-t",
        "--delta-t",
        metavar="s",
        type="float",
        default=1.0 / 16,
        help="Set the time spacing of the tiling (default = 1/16).")
    parser.add_option(
        "-H",
        "--height",
        metavar="pixels",
        type="int",
        default=64,
        help="Set the number of tiles in the frequency domain (default = 64).")
    parser.add_option(
        "-o",
        "--output",
        metavar="filename",
        help="Set the name of the output file (default = stdout).")
    parser.add_option(
        "-s",
        "--gps-start-time",
        metavar="seconds",
        help="Set the start time of the tiling in GPS seconds (required).")
    parser.add_option(
        "-f",
        "--overlap-fraction",
        metavar="fraction",
        type="float",
        default=0.25,
        help=
        "Set the fraction by which adjacent tiles overlap (default = 0.25).  The value must be in the range [0, 1)."
    )
    parser.add_option(
        "--sample-rate",
        metavar="Hz",
        type="int",
        default=16384,
        help=
        "Set the sample rate of the data into which the injections will be placed (default = 16384).  This information is required in order to normalize each pixel accurately.  If the wrong value is used, the result will be the addition of noise to the image."
    )
    parser.add_option(
        "-n",
        "--hrss-scale",
        metavar="hrss",
        type="float",
        default=1e-20,
        help="Set the hrss corresponding to \"white\" (default = 1e-20).")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      help="Be verbose.")
    parser.add_option(
        "-T",
        "--time-slide-xml",
        metavar="filename",
        help=
        "Associate injections with the first time slide ID in this XML file (required)."
    )
    options, filenames = parser.parse_args()

    if options.gps_start_time is None:
        raise ValueError("missing required option --gps-start-time")
    if not (0 <= options.overlap_fraction < 1.0):
        raise ValueError("--overlap-fraction must be in [0, 1)")
    if options.delta_f * options.delta_t < 2 / math.pi:
        raise ValueError(
            "the product of --delta-t and --delta-f must be >= 2/pi")
    if options.time_slide_xml is None:
        raise ValueError("missing required option time-slide-xml")

    # for the process_params table
    options.options_dict = dict(options.__dict__)

    options.gps_start_time = lsctables.LIGOTimeGPS(options.gps_start_time)

    return options, filenames