29from optparse
import OptionParser
33from igwn_ligolw
import lsctables
34from igwn_ligolw
import utils
as ligolw_utils
35from igwn_ligolw.utils
import process
as ligolw_process
36from igwn_ligolw.utils
import segments
as ligolw_segments
38from lalinspiral
import thinca
39from igwn_segments
import utils
as segmentsUtils
42__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
57 parser = OptionParser(
58 version =
"Name: %%prog\n%s" % __version__,
59 usage =
"%prog [options] [file ...]",
60 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."
62 parser.add_option(
"-c",
"--comment", metavar =
"text", help =
"Set comment string in process table (default = None).")
63 parser.add_option(
"-f",
"--force", action =
"store_true", help =
"Process document even if it has already been processed.")
64 parser.add_option(
"-t",
"--threshold", metavar =
"float", type =
"float", help =
"Set the coincidence window in seconds, not including light travel time (required). The value entered here will be dilated by the light travel time between detectors to define the coincidence window for each detector pair.")
65 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.")
68 parser.add_option(
"--snr-segments-name", metavar =
"string", default =
"whitehtsegments", help =
"From the input document, use the segment list with this name to define when each detector was operating (default = \"whitehtsegments\").")
69 parser.add_option(
"--vetoes-segments-name", metavar =
"string", help =
"From the input document, use the segment list with this name to veto single-detector triggers before considering them for coincidence (default = do not apply vetoes.")
70 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) (default = retain all coincidences)")
71 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
72 options, filenames = parser.parse_args()
74 process_params = options.__dict__.copy()
80 required_options = [
"threshold"]
81 missing_options = [option
for option
in required_options
if getattr(options, option)
is None]
83 raise ValueError(
"missing required option(s) %s" %
", ".join(
"--%s" % option.replace(
"_",
"-")
for option
in missing_options))
84 if options.min_instruments < 1:
85 raise ValueError(
"invalid --min-instruments: \"%s\"" % options.min_instruments)
87 if options.coinc_end_time_segment
is not None:
88 if ',' in options.coinc_end_time_segment:
89 raise ValueError(
"--coinc-end-time-segment may only contain a single segment")
90 options.coinc_end_time_segs = segmentsUtils.from_range_strings([options.coinc_end_time_segment], boundtype = lal.LIGOTimeGPS).coalesce()
92 options.coinc_end_time_segs =
None
98 return options, process_params, (filenames
or [
None])
110process_program_name =
"lalapps_thinca"
135if options.coinc_end_time_segs
is not None:
139 Return False (ntuple should be retained)
if the end time of
140 the coinc
is in the segmentlist segs.
142 return thinca.coinc_inspiral_end_time(events, offset_vector)
not in seg
144 ntuple_comparefunc =
None
152for n, filename
in enumerate(filenames, start = 1):
158 print(
"%d/%d:" % (n, len(filenames)), end=
' ', file=sys.stderr)
159 xmldoc = ligolw_utils.load_filename(filename, verbose = options.verbose)
165 if ligolw_process.doc_includes_process(xmldoc, process_program_name):
167 print(
"warning: %s already processed," % (filename
or "stdin"), end=
' ', file=sys.stderr)
168 if not options.force:
170 print(
"skipping", file=sys.stderr)
173 print(
"continuing by --force", file=sys.stderr)
179 process = ligolw_process.register_to_xmldoc(
181 process_program_name,
183 comment = options.comment,
184 version = __version__,
185 cvs_repository =
"lscsoft",
186 cvs_entry_time = __date__
194 tbl = lsctables.SnglInspiralTable.get_table(xmldoc)
195 assert len(set(tbl.getColumnByName(
"event_id"))) == len(tbl),
"degenerate sngl_inspiral event_id detected"
207 seglists = ligolw_segments.segmenttable_get_by_name(xmldoc, options.snr_segments_name).coalesce()
208 if options.vetoes_segments_name
is not None:
209 vetoes = ligolw_segments.segmenttable_get_by_name(xmldoc, options.vetoes_segments_name).coalesce()
217 thinca.ligolw_thinca(
219 process_id = process.process_id,
220 delta_t = options.threshold,
221 ntuple_comparefunc = ntuple_comparefunc,
223 veto_segments = vetoes,
224 min_instruments = options.min_instruments,
225 verbose = options.verbose
232 process.set_end_time_now()
238 ligolw_utils.write_filename(xmldoc, filename, verbose = options.verbose)
240 lsctables.reset_next_ids(lsctables.TableByName.values())