29from optparse
import OptionParser
35from igwn_ligolw
import utils
as ligolw_utils
36from lalburst
import git_version
37from lalburst
import bucluster
40__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
41__version__ =
"git id %s" % git_version.id
42__date__ = git_version.date
55 parser = OptionParser(
56 version =
"Name: %%prog\n%s" % git_version.verbose_msg,
57 usage =
"%prog [options] [file ...]",
58 description =
"Run a single-instrument burst clustering algorithm on the sngl_burst events contained in LIGO Light Weight XML files. Files can be listed on the command line and/or in one or more LAL cache files. If no files are named, then input is read from stdin and written to stdout."
60 parser.add_option(
"--comment", metavar =
"text", help =
"Set the comment string to be recorded in the process table (default = None).")
61 parser.add_option(
"-c",
"--cluster-algorithm", metavar =
"[excesspower]", help =
"Set clustering method (required).")
62 parser.add_option(
"-i",
"--input-cache", metavar =
"filename", action =
"append", default = [], help =
"Process the files listed in this LAL cache.")
63 parser.add_option(
"-p",
"--program", metavar =
"name", default =
"lalapps_power", help =
"Set the name of the program that generated the events as it appears in the process table (default = \"lalapps_power\").")
64 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
65 options, filenames = parser.parse_args()
67 if options.cluster_algorithm
is None:
68 raise ValueError(
"missing required argument --cluster-algorithm")
69 if options.cluster_algorithm
not in (
"excesspower",):
70 raise ValueError(
"unrecognized --cluster-algorithm %s" % options.cluster_algorithm)
72 for cache
in options.input_cache:
73 filenames += [CacheEntry(line).path
for line
in file(cache)]
75 return options, (filenames
or [
None])
91 "excesspower": bucluster.ExcessPowerPreFunc
92}[options.cluster_algorithm]
94 "excesspower": bucluster.ExcessPowerPostFunc
95}[options.cluster_algorithm]
97 "excesspower": bucluster.ExcessPowerTestFunc
98}[options.cluster_algorithm]
100 "excesspower": bucluster.ExcessPowerSortKeyFunc
101}[options.cluster_algorithm]
103 "excesspower": bucluster.ExcessPowerBailoutFunc
104}[options.cluster_algorithm]
106 "excesspower": bucluster.ExcessPowerClusterFunc
107}[options.cluster_algorithm]
110for filename
in filenames:
115 xmldoc = ligolw_utils.load_filename(filename, verbose = options.verbose)
118 if options.cluster_algorithm
in (
"excesspower",):
119 bucluster.add_ms_columns(xmldoc)
125 process = bucluster.append_process(xmldoc, cluster_algorithm = options.cluster_algorithm, comment = options.comment)
131 xmldoc, changed = bucluster.bucluster(
133 program = options.program,
138 clusterfunc = clusterfunc,
139 sortkeyfunc = sortkeyfunc,
140 bailoutfunc = bailoutfunc,
141 verbose = options.verbose
148 process.set_end_time_now()
155 ligolw_utils.write_filename(xmldoc, filename, verbose = options.verbose)