30Command-line interface to CBC injection identification code.
34from optparse
import OptionParser
38from igwn_ligolw
import lsctables
39from igwn_ligolw
import utils
as ligolw_utils
40from igwn_ligolw.utils
import process
as ligolw_process
41from lalinspiral
import inspinjfind
44__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
49process_program_name =
"lalapps_inspinjfind"
57lsctables.SnglInspiralTable.RowType = lsctables.SnglInspiral = inspinjfind.SnglInspiral
70 parser = OptionParser(
71 version =
"Name: %%prog\n%s" % __version__,
72 usage =
"%prog [options] [file ...]",
73 description =
"Accepts as input one or more LIGO Light Weight XML files, each containing CBC candidates and a list of injections, and adds entries to the coincidence tables indicating which events match which injections."
75 parser.add_option(
"-f",
"--force", action =
"store_true", help =
"Process even if file has already been processed.")
76 parser.add_option(
"--comment", metavar =
"text", help =
"Set the comment string to be written to the process table (default = None).")
77 parser.add_option(
"-c",
"--match-algorithm", metavar =
"[inspiral]", default =
"inspiral", help =
"Set the algorithm used to match event candidates with injections (default = \"inspiral\").")
78 parser.add_option(
"-r",
"--revert", action =
"store_true", help =
"Revert a previously-processed XML file to its pre-lalapps_inspinjfind state, allowing it to be re-processed. This is achieved by removing lalapps_inspinjfind's entries from the process metadata tables, removing injection-related entries from the coinc_definer table, and removing all coincs created by lalapps_inspinjfind. NOTE: generally this is only possible if lalapps_inspinjfind was the last transformation applied to the file, otherwise data that has been added subsequently might be broken due to dangling cross-references to deleted data. It is left as an exercise to the user to ensure that reverting the file is sensible.")
79 parser.add_option(
"-w",
"--time-window", metavar =
"seconds", type =
'float', default = 9., help =
"Set the time window used by the \"inspiral\" match algorithm (default = 9.0).")
80 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
81 options, filenames = parser.parse_args()
83 paramdict = options.__dict__.copy()
85 if options.match_algorithm
is None:
86 raise ValueError(
"missing required --match-algorithm option")
87 if options.match_algorithm
not in (
"inspiral",):
88 raise ValueError(
"unrecognized --match-algorithm \"%s\"" % options.match_algorithm)
90 if options.time_window < 0.:
91 raise ValueError(
"--time-window must be non-negative")
93 return options, paramdict, (filenames
or [
None])
114 "inspiral":
"inspiral"
115}[options.match_algorithm]
125 Returns 0 if sim and sngl are less than twindow apart.
127 dt = sim.time_geocent - sngl.end
128 return 0
if abs(dt) < twindow
else dt
131NearCoincCompare = InspiralSnglCompare
134snglcomparefunc, nearcoinccomparefunc = {
135 "inspiral": (InspiralSnglCompare, NearCoincCompare)
136}[options.match_algorithm]
144for n, filename
in enumerate(filenames, start = 1):
150 print(
"%d/%d:" % (n, len(filenames)), end=
' ', file=sys.stderr)
151 xmldoc = ligolw_utils.load_filename(filename, verbose = options.verbose)
158 inspinjfind.revert(xmldoc, process_program_name, verbose = options.verbose)
164 if ligolw_process.doc_includes_process(xmldoc, process_program_name):
166 print(
"warning: %s already processed," % (filename
or "stdin"), end=
' ', file=sys.stderr)
167 if not options.force:
169 print(
"skipping (use --force to force)", file=sys.stderr)
172 print(
"continuing by --force", file=sys.stderr)
178 process = ligolw_process.register_to_xmldoc(xmldoc, process_program_name, paramdict, version = __version__, cvs_repository =
u"lscsoft", cvs_entry_time = __date__, comment = options.comment)
184 inspinjfind.ligolw_inspinjfind(
189 nearcoinccomparefunc,
190 end_time_bisect_window = 1.5 * options.time_window,
191 verbose = options.verbose
198 process.set_end_time_now()
204 ligolw_utils.write_filename(xmldoc, filename, verbose = options.verbose)
206 lsctables.reset_next_ids(lsctables.TableByName.values())
def InspiralSnglCompare(sim, sngl, twindow=lsctables.LIGOTimeGPS(options.time_window))
Returns 0 if sim and sngl are less than twindow apart.