29from __future__
import print_function
32from optparse
import OptionParser
37from igwn_ligolw
import dbtables
39from lalburst
import git_version
40from lalburst
import calc_likelihood
41from lalburst
import SnglBurstUtils
42from lalburst
import stringutils
45__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
46__version__ =
"git id %s" % git_version.id
47__date__ = git_version.date
60 parser = OptionParser(
61 version =
"Name: %%prog\n%s" % git_version.verbose_msg
63 parser.add_option(
"-c",
"--input-cache", metavar =
"filename", help =
"Also process the files named in this LAL cache. See lalapps_path2cache for information on how to produce a LAL cache file.")
64 parser.add_option(
"-l",
"--likelihood-file", metavar =
"filename", action =
"append", help =
"Set the name of the likelihood ratio data file to use. Can be given more than once.")
65 parser.add_option(
"--likelihood-cache", metavar =
"filename", help =
"Also load the likelihood ratio data files listsed in this LAL cache. See lalapps_path2cache for information on how to produce a LAL cache file.")
66 parser.add_option(
"-t",
"--tmp-space", metavar =
"path", help =
"Path to a directory suitable for use as a work area while manipulating the database file. The database file will be worked on in this directory, and then moved to the final location when complete. This option is intended to improve performance when running in a networked environment, where there might be a local disk with higher bandwidth than is available to the filesystem on which the final output will reside.")
67 parser.add_option(
"--vetoes-name", metavar =
"name", help =
"Set the name of the segment lists to use as vetoes (default = do not apply vetoes).")
68 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
69 options, filenames = parser.parse_args()
71 options.likelihood_filenames = []
72 if options.likelihood_file
is not None:
73 options.likelihood_filenames += options.likelihood_file
74 if options.likelihood_cache
is not None:
75 options.likelihood_filenames += [CacheEntry(line).path
for line
in open(options.likelihood_cache)]
76 if not options.likelihood_filenames:
77 raise ValueError(
"no ranking statistic likelihood data files specified")
79 if options.input_cache:
80 filenames += [CacheEntry(line).path
for line
in open(options.input_cache)]
82 raise ValueError(
"no candidate databases specified")
84 return options, filenames
109coincparamsdistributions, likelihood_seglists = stringutils.load_likelihood_data(options.likelihood_filenames, verbose = options.verbose)
111 print(
"computing event densities ...", file=sys.stderr)
112coincparamsdistributions.finish()
120for n, filename
in enumerate(filenames):
126 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
128 working_filename = dbtables.get_connection_filename(filename, tmp_path = options.tmp_space, verbose = options.verbose)
129 connection = sqlite3.connect(str(working_filename))
130 if options.tmp_space
is not None:
131 dbtables.set_temp_store_directory(connection, options.tmp_space, verbose = options.verbose)
137 contents = SnglBurstUtils.CoincDatabase(connection, live_time_program =
"StringSearch", search =
"StringCusp", veto_segments_name = options.vetoes_name)
139 SnglBurstUtils.summarize_coinc_database(contents)
140 if not contents.seglists
and options.verbose:
141 print(
"\twarning: no segments found", file=sys.stderr)
149 triangulators = stringutils.triangulators(dict.fromkeys(contents.instruments, 8e-5))
155 calc_likelihood.assign_likelihood_ratios(
156 connection = contents.connection,
157 coinc_def_id = contents.bb_definer_id,
158 offset_vectors = contents.time_slide_table.as_dict(),
159 vetoseglists = contents.vetoseglists,
160 events_func =
lambda cursor, coinc_event_id: calc_likelihood.sngl_burst_events_func(cursor, coinc_event_id, contents.sngl_burst_table.row_from_cols),
161 veto_func = calc_likelihood.sngl_burst_veto_func,
162 ln_likelihood_ratio_func = coincparamsdistributions.ln_lr_from_triggers,
163 verbose = options.verbose
170 contents.xmldoc.unlink()
172 dbtables.put_connection_filename(filename, working_filename, verbose = options.verbose)