LALBurst 2.0.7.1-eeff03c
lalburst_injfind.py
Go to the documentation of this file.
1##python
2#
3# Copyright (C) 2006 Kipp Cannon
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the
7# Free Software Foundation; either version 2 of the License, or (at your
8# option) any later version.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13# Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19
20#
21# =============================================================================
22#
23# Preamble
24#
25# =============================================================================
26#
27
28
29"""
30Command-line interface to burst injection identification code.
31"""
32
33
34from optparse import OptionParser
35import sys
36
37
38from igwn_ligolw import lsctables
39from igwn_ligolw import utils as ligolw_utils
40from igwn_ligolw.utils import process as ligolw_process
41from lalburst import git_version
42from lalburst import binjfind
43
44
45__author__ = "Kipp Cannon <kipp.cannon@ligo.org>"
46__version__ = "git id %s" % git_version.id
47__date__ = git_version.date
48
49
50#
51# =============================================================================
52#
53# Command Line
54#
55# =============================================================================
56#
57
58
60 parser = OptionParser(
61 version = "Name: %%prog\n%s" % git_version.verbose_msg,
62 usage = "%prog [options] [file ...]",
63 description = "Accepts as input one or more LIGO Light Weight XML files, each containing burst candidates and a list of injections, and adds entries to the coincidence tables indicating which burst events match which injections."
64 )
65 parser.add_option("-f", "--force", action = "store_true", help = "Process even if file has already been processed.")
66 parser.add_option("--comment", metavar = "text", help = "Set the comment string to be written to the process table (default = None).")
67 parser.add_option("-c", "--match-algorithm", metavar = "[stringcusp|excesspower|omega|waveburst]", default = None, help = "Set the algorithm used to match burst candidates with injections (required).")
68 parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
69 options, filenames = parser.parse_args()
70
71 if options.match_algorithm is None:
72 raise ValueError("missing required --match-algorithm option")
73 if options.match_algorithm not in ("stringcusp", "excesspower", "omega", "waveburst"):
74 raise ValueError("unrecognized match algorithm \"%s\"" % options.match_algorithm)
75
76 return options, (filenames or [None])
77
78
79#
80# =============================================================================
81#
82# Main
83#
84# =============================================================================
85#
86
87
88#
89# command line
90#
91
92
93options, filenames = parse_command_line()
94
95# must match columns in sngl_burst table
96search = {
97 "stringcusp": "StringCusp",
98 "excesspower": "excesspower",
99 "omega": "omega",
100 "waveburst": "waveburst"
101}[options.match_algorithm]
102
103snglcomparefunc = {
104 "stringcusp": binjfind.StringCuspSnglCompare,
105 "excesspower": binjfind.ExcessPowerSnglCompare,
106 "omega": binjfind.OmegaSnglCompare,
107 "waveburst": binjfind.CWBSnglCompare
108}[options.match_algorithm]
109
110nearcoinccomparefunc = {
111 "stringcusp": binjfind.StringCuspNearCoincCompare,
112 "excesspower": binjfind.ExcessPowerNearCoincCompare,
113 "omega": binjfind.OmegaNearCoincCompare,
114 "waveburst": binjfind.CWBNearCoincCompare
115}[options.match_algorithm]
116
117
118#
119# loop over files
120#
121
122
123for n, filename in enumerate(filenames):
124 #
125 # load the document
126 #
127
128 if options.verbose:
129 print("%d/%d:" % (n + 1, len(filenames)), end=' ', file=sys.stderr)
130 xmldoc = ligolw_utils.load_filename(filename, verbose = options.verbose)
131
132 #
133 # have we already procesed it?
134 #
135
136 if ligolw_process.doc_includes_process(xmldoc, binjfind.process_program_name):
137 if options.verbose:
138 print("warning: %s already processed," % (filename or "stdin"), end=' ', file=sys.stderr)
139 if not options.force:
140 if options.verbose:
141 print("skipping (use --force to force)", file=sys.stderr)
142 continue
143 if options.verbose:
144 print("continuing by --force", file=sys.stderr)
145
146 #
147 # add process metadata to document
148 #
149
150 process = binjfind.append_process(xmldoc, match_algorithm = options.match_algorithm, comment = options.comment)
151
152 #
153 # run binjfind algorithm
154 #
155
156 binjfind.binjfind(xmldoc, process, search, snglcomparefunc, nearcoinccomparefunc, verbose = options.verbose)
157
158 #
159 # close out the process metadata
160 #
161
162 process.set_end_time_now()
163
164 #
165 # done
166 #
167
168 ligolw_utils.write_filename(xmldoc, filename, verbose = options.verbose)
169 xmldoc.unlink()
170 lsctables.reset_next_ids(lsctables.TableByName.values())