def gpstime_inside_segment(gps_seconds, gps_nanoseconds, segment_string): """ Convenience function to be used within sqlite query. It checks if a given gps in is inside the segment or not. Returns boolen. """ # convert segment string into segment segment = segmentsUtils.from_range_strings([segment_string], boundtype=lal.LIGOTimeGPS)[0] return lal.LIGOTimeGPS(gps_seconds, gps_nanoseconds) in segment
def parse_command_line(): parser = OptionParser( version = "Name: %%prog\n%s" % git_version.verbose_msg, usage = "%prog [options] [file ...]", description = "%prog implements the excess power and string cusp coincidence algorithms for use in performing trigger-based multi-instrument searches for gravitational wave events. The LIGO Light Weight XML files listed on the command line are processed one by one in order, and over-written with the results. If no files are named, then input is read from stdin and output written to stdout. Gzipped files will be autodetected on input, if a file's name ends in \".gz\" it will be gzip-compressed on output." ) parser.add_option("-c", "--comment", metavar = "text", help = "Set comment string in process table (default = None).") parser.add_option("-f", "--force", action = "store_true", help = "Process document even if it has already been processed.") parser.add_option("-a", "--coincidence-algorithm", metavar = "[excesspower|stringcusp]", default = None, help = "Select the coincidence test algorithm to use (required).") parser.add_option("-s", "--coincidence-segments", metavar = "start:end[,start:end,...]", help = "Set the GPS segments in which to retain coincidences. Multiple segments can be specified by separating them with commas. If either start or end is absent from a segment then the interval is unbounded on that side, for example \"874000000:\" causes all coincidences starting at 874000000 to be retained. The \"time\" of a coincidence is ambiguous, and is different for different search algorithms, but a deterministic algorithm is used in all cases so the same coincidence of events will always be assigned the same time. This feature is intended to allow large input files to be analyzed; the procedure is to make n copies of the file and run n instances of burca specifying disjoint --coincidence-segments for each.") parser.add_option("-m", "--min-instruments", metavar = "N", type = "int", default = 2, help = "Set the minimum number of instruments required to form a coincidence (default = 2).") parser.add_option("-t", "--threshold", metavar = "threshold", default = None, help = "Set the coincidence algorithm's threshold. For excesspower this parameter is not used. For stringcusp, this parameter sets the maximum peak time difference not including light travel time (which will be added internally).") parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.") options, filenames = parser.parse_args() paramdict = options.__dict__.copy() # # check and convert and bunch of arguments # if options.coincidence_algorithm is None: raise ValueError("missing required argument --coincidence-algorithm") if options.coincidence_algorithm not in ("excesspower", "stringcusp"): raise ValueError("unrecognized --coincidence-algorithm %s" % options.coincidence_algorithm) if options.coincidence_segments is not None: options.coincidence_segments = segmentsUtils.from_range_strings(options.coincidence_segments.split(","), boundtype = lsctables.LIGOTimeGPS).coalesce() if filenames is not None and len(filenames) > 1: raise ValueError("refusing to allow use of --coincidence-segments with more than one input file") if options.min_instruments < 1: raise ValueError("--min-instruments must be >= 1") # # parse the --thresholds arguments # if options.coincidence_algorithm == "stringcusp": if options.threshold is None: raise ValueError("--threshold is required for --coincidence-algorithm stringcusp") options.threshold = Thresholds(float(options.threshold)) # # done # return options, (filenames or [None]), paramdict
def parse_command_line(): parser = OptionParser( version = "Name: %%prog\n%s" % __version__, usage = "%prog [options] [file ...]", description = "%prog implements the inspiral coincidence algorithm for use in performing trigger-based multi-instrument searches for gravitational wave events. The LIGO Light Weight XML files listed on the command line are processed one by one in order, and over-written with the results. If no files are named, then input is read from stdin and output written to stdout. Gzipped files will be autodetected on input, if a file's name ends in \".gz\" it will be gzip-compressed on output." ) parser.add_option("-c", "--comment", metavar = "text", help = "Set comment string in process table (default = None).") parser.add_option("-f", "--force", action = "store_true", help = "Process document even if it has already been processed.") parser.add_option("-m", "--match", metavar = "algorithm", default = "exact", help = "Select the coincidence test. Allowed values are: \"exact\" (require exact template match, the default).") parser.add_option("-t", "--threshold", metavar = "float", type = "float", help = "Set the coincidence threshold (required). The meaning is defined by the match algorithm. For --match=exact this sets the Delta t window in seconds.") parser.add_option("--min-instruments", metavar = "number", default = "2", type = "int", help = "Set the minimum number of instruments that must participate in a coincidence (default = 2). The value must be greater than 0.") parser.add_option("--vetoes-name", metavar = "string", default = "vetoes", help = "From the input document, exatract the segment list having this name to use as the veto segments (default = \"vetoes\"). Warning: if no segments by this name are found in the document then vetoes will not be applied, this is not an error condition.") parser.add_option("--coinc-end-time-segment", metavar = "seg", help = "The segment of time to retain coincident triggers from. Uses segmentUtils.from_range_strings() format \"START:END\" for an interval of the form [START,END), \"START:\" for an interval of the form [START,INF), and \":END\" for an interval of the form (-INF,END).") parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.") options, filenames = parser.parse_args() process_params = options.__dict__.copy() # # check arguments # required_options = ["threshold"] missing_options = [option for option in required_options if getattr(options, option) is None] if missing_options: raise ValueError("missing required option(s) %s" % ", ".join("--%s" % option.replace("_", "-") for option in missing_options)) if options.match not in ("exact",): raise ValueError("unrecognized value for --match: \"%s\"" % options.match) if options.min_instruments < 1: raise ValueError("invalid --min-instruments: \"%s\"" % options.min_instruments) if options.coinc_end_time_segment is not None: if ',' in options.coinc_end_time_segment: raise ValueError("--coinc-end-time-segment may only contain a single segment") options.coinc_end_time_segs = segmentsUtils.from_range_strings([options.coinc_end_time_segment], boundtype = lal.LIGOTimeGPS).coalesce() else: options.coinc_end_time_segs = None # # done # return options, process_params, (filenames or [None])
def parse_command_line(): parser = OptionParser( version = "Name: %%prog\n%s" % git_version.verbose_msg, usage = "%prog [options] [file ...]", description = "%prog implements the excess power and string cusp coincidence algorithms for use in performing trigger-based multi-instrument searches for gravitational wave events. The LIGO Light Weight XML files listed on the command line are processed one by one in order, and over-written with the results. If no files are named, then input is read from stdin and output written to stdout. Gzipped files will be autodetected on input, if a file's name ends in \".gz\" it will be gzip-compressed on output." ) parser.add_option("-c", "--comment", metavar = "text", help = "Set comment string in process table (default = None).") parser.add_option("-f", "--force", action = "store_true", help = "Process document even if it has already been processed.") parser.add_option("-a", "--coincidence-algorithm", metavar = "[excesspower|stringcusp]", default = None, help = "Select the coincidence test algorithm to use (required).") parser.add_option("-s", "--coincidence-segments", metavar = "start:end[,start:end,...]", help = "Set the GPS segments in which to retain coincidences. Multiple segments can be specified by separating them with commas. If either start or end is absent from a segment then the interval is unbounded on that side, for example \"874000000:\" causes all coincidences starting at 874000000 to be retained. The \"time\" of a coincidence is ambiguous, and is different for different search algorithms, but a deterministic algorithm is used in all cases so the same coincidence of events will always be assigned the same time. This feature is intended to allow large input files to be analyzed; the procedure is to make n copies of the file and run n instances of burca specifying disjoint --coincidence-segments for each.") parser.add_option("-m", "--min-instruments", metavar = "N", type = "int", default = 2, help = "Set the minimum number of instruments required to form a coincidence (default = 2).") parser.add_option("-t", "--threshold", metavar = "threshold", type = "float", help = "Set the coincidence algorithm's threshold. For excesspower this parameter is not used and must not be set. For stringcusp, this parameter sets the maximum peak time difference in seconds not including light travel time (which will be added internally).") parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.") options, filenames = parser.parse_args() paramdict = options.__dict__.copy() # # check and convert and bunch of arguments # if options.coincidence_algorithm is None: raise ValueError("missing required argument --coincidence-algorithm") if options.coincidence_algorithm not in ("excesspower", "stringcusp"): raise ValueError("unrecognized --coincidence-algorithm %s" % options.coincidence_algorithm) if options.coincidence_segments is not None: options.coincidence_segments = segmentsUtils.from_range_strings(options.coincidence_segments.split(","), boundtype = lsctables.LIGOTimeGPS).coalesce() if filenames is not None and len(filenames) > 1: raise ValueError("refusing to allow use of --coincidence-segments with more than one input file") if options.min_instruments < 1: raise ValueError("--min-instruments must be >= 1") if options.coincidence_algorithm == "stringcusp" and options.threshold is None: raise ValueError("--threshold is required for --coincidence-algorithm stringcusp") elif options.coincidence_algorithm == "excesspower" and options.threshold is not None: raise ValueError("--threshold is meaningless for --coincidence-algorithm excesspower") # # done # return options, (filenames or [None]), paramdict
def process_file(filename, products, live_time_program, tmp_path = None, veto_segments_name = None, verbose = False): # # connect to database and summarize contents # working_filename = dbtables.get_connection_filename(filename, tmp_path = tmp_path, verbose = verbose) contents = SnglBurstUtils.CoincDatabase(sqlite3.connect(working_filename), live_time_program, search = "StringCusp", veto_segments_name = veto_segments_name) if verbose: SnglBurstUtils.summarize_coinc_database(contents, filename = working_filename) # # augment summary with extra stuff we need. the filename # is recorded for dumping debuggin information related to # missed injections. if burca was run with the # --coincidence-segments option then the value is copied # into a segmentlistdict to facilitate the computation of # livetime # contents.filename = filename contents.coincidence_segments = ligolwprocess.get_process_params(contents.xmldoc, "lalapps_burca", "--coincidence-segments") if contents.coincidence_segments: # as a side-effect, this enforces the rule that # burca has been run on the input file exactly once contents.coincidence_segments, = contents.coincidence_segments contents.coincidence_segments = segments.segmentlistdict.fromkeys(contents.seglists, segmentsUtils.from_range_strings(contents.coincidence_segments.split(","), boundtype = dbtables.lsctables.LIGOTimeGPS).coalesce()) else: contents.coincidence_segments = None # # process contents # for n, product in enumerate(products): if verbose: print >>sys.stderr, "%s: adding to product %d ..." % (working_filename, n) product.add_contents(contents, verbose = verbose) # # close # contents.connection.close() dbtables.discard_connection_filename(filename, working_filename, verbose = verbose)