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)
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
Esempio n. 3
0
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])
Esempio n. 4
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()

		#
		# 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(self.snglinspiraltable.getColumnByName("ifo"), 0.0), create_new = process, superset_ok = True, nonunique_ok = True)

		#
		# 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)
Esempio n. 5
0
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 in Hertz (default = 64).")
    parser.add_option(
        "-d",
        "--delta-f",
        metavar="Hz",
        type="float",
        default=16.0,
        help=
        "Set the bandwidth of the pixels in Hertz (default = 16).  Must be > 0.  The product of --delta-f and --delta-t must be at least 2/pi."
    )
    parser.add_option(
        "-t",
        "--delta-t",
        metavar="s",
        type="float",
        default=1.0 / 16,
        help=
        "Set the duration of the pixels in seconds (default = 1/16).  Must be > 0.  The product of --delta-f and --delta-t must be at least 2/pi."
    )
    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 pixels centres are spaced (1 - --overlap-fraction) * --delta-f apart in the frequency domain.  The value must be in the range [0, 1)."
    )
    parser.add_option(
        "-H",
        "--height",
        metavar="pixels",
        type="int",
        default=64,
        help=
        "Set the number of pixles in the frequency domain (default = 64).  The image will be scaled to this vertical size, and the number of pixels in the time domain (horizontal size) will be fixed by the image aspect ratio."
    )
    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(
        "--sample-rate",
        metavar="Hz",
        type="int",
        default=16384,
        help=
        "Set the sample rate in Hertz 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.  The highest frequency pixel must have a centre frequency < 1/2 this frequency."
    )
    parser.add_option(
        "-n",
        "--hrss-scale",
        metavar="hrss",
        type="float",
        default=1e-20,
        help=
        "Set the single-pixel hrss (root-sum-square strain) 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()

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

    if options.gps_start_time is None:
        raise ValueError("missing required option --gps-start-time")
    if not 0. < options.delta_f:
        raise ValueError("--delta-f must be > 0")
    if not 0. < options.delta_t:
        raise ValueError("--delta-t must be > 0")
    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 not (0. <= options.overlap_fraction < 1.):
        raise ValueError("--overlap-fraction must be in [0, 1)")
    if options.f_low + options.height * (
            1. - options.overlap_fraction
    ) * options.delta_f >= options.sample_rate / 2.:
        raise ValueError("total waveform bandwidth exceeds Nyquist frequency")
    if options.time_slide_xml is None:
        raise ValueError("missing required option time-slide-xml")

    # type-cast
    options.gps_start_time = lsctables.LIGOTimeGPS(options.gps_start_time)

    return options, filenames
Esempio n. 6
0
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