30from optparse
import OptionParser
37from igwn_ligolw
import dbtables
38from igwn_ligolw
import utils
as ligolw_utils
39from lalburst
import burca_tailor
40from lalburst
import SnglBurstUtils
42from lalburst
import git_version
43import igwn_segments
as segments
47T010150_letters = set(string.ascii_lowercase + string.ascii_uppercase + string.digits +
"_+#")
50__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
51__version__ =
"git id %s" % git_version.id
52__date__ = git_version.date
65 parser = OptionParser(
66 version =
"Name: %%prog\n%s" % git_version.verbose_msg,
67 usage =
"%prog [options] [filename ...]",
68 description =
"%prog analyzes a collection of SQLite3 database files containing lalburst_coinc outputs, and measures probability distributions for a variety of parameters computed from the coincidences therein. The distributions are written to a likelihood data file in XML format, which can be used by lalburst_coinc for the excesspower2 algorithm in which a second pass assigns likelihoods to each coincidence. The command line arguments are used to provide shell patterns for the files from which to obtain injection and backgroun coincidences. If file names are given on the command line following the arguments, then likelihood data is loaded from those files and added to the output."
70 parser.add_option(
"--add-from", metavar =
"filename", default = [], action =
"append", help =
"Also add likelihood data from this XML file.")
71 parser.add_option(
"--add-from-cache", metavar =
"filename", help =
"Also add likelihood data from all XML files listed in this LAL cache.")
72 parser.add_option(
"-o",
"--output", metavar =
"filename", default =
None, help =
"Set the name of the likelihood control file to write (default = stdout).")
73 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.")
74 parser.add_option(
"--T010150", metavar =
"description", default =
None, help =
"Write the output to a file whose name is compatible with the file name format described in LIGO-T010150-00-E, \"Naming Convention for Frame Files which are to be Processed by LDAS\". The description string will be used to form the second field in the file name.")
75 parser.add_option(
"-p",
"--live-time-program", metavar =
"program", default =
"lalapps_power", help =
"Program from which to draw the livetime segments. (Necessary in case of giving --T010150.")
76 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
77 options, filenames = parser.parse_args()
79 if options.T010150
is not None:
80 if options.output
is not None:
81 raise ValueError(
"cannot set both --T010150 and --output")
82 if options.T010150 ==
"":
83 options.T010150 =
"EXCESSPOWER_LIKELIHOOD"
84 elif set(options.T010150) - T010150_letters:
85 raise ValueError(
"invalid characters in description \"%s\"" % options.T010150)
87 if options.add_from_cache:
88 options.add_from += [CacheEntry(line).path
for line
in file(options.add_from_cache)]
90 return options, filenames
115distributions = burca_tailor.EPGalacticCoreCoincParamsDistributions()
116segs = segments.segmentlistdict()
125 c, s = distributions.from_filenames(options.add_from,
"lalburst_power_meas_likelihood", verbose = options.verbose)
137for n, filename
in enumerate(filenames):
143 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
145 working_filename = dbtables.get_connection_filename(filename, tmp_path = options.tmp_space, verbose = options.verbose)
146 connection = sqlite3.connect(str(working_filename))
147 connection.execute(
"PRAGMA synchronous = OFF;")
148 connection.execute(
"PRAGMA temp_store_directory = '%s';" % dbtables.tempfile.gettempdir())
154 database = SnglBurstUtils.CoincDatabase(connection, options.live_time_program)
156 SnglBurstUtils.summarize_coinc_database(database)
157 segs |= database.seglists
164 if database.sim_burst_table
is None:
166 for is_background, events, offsetvector
in database.get_noninjections():
167 params = distributions.coinc_params(events, offsetvector, MW_CENTER_J2000_RA_RAD, MW_CENTER_J2000_DEC_RAD)
168 if params
is not None:
170 distributions.denominator.increment(params)
172 distributions.candidates.increment(params)
176 for sim, events, offsetvector
in database.get_injections():
177 params = distributions.coinc_params(events, offsetvector, MW_CENTER_J2000_RA_RAD, MW_CENTER_J2000_DEC_RAD)
178 if params
is not None:
179 distributions.numerator.increment(params)
185 del database, connection
186 dbtables.discard_connection_filename(filename, working_filename, verbose = options.verbose)
195 seg = seglists.extent_all()
196 return "%s-%s-%s-%s" % (
"+".join(sorted(seglists.keys())), description, str(int(seg[0])), str(int(math.ceil(abs(seg)))))
202 filename = options.output
205xmldoc = burca_tailor.gen_likelihood_control(distributions, segs)
206ligolw_utils.write_filename(xmldoc, filename, verbose = options.verbose)
def T010150_basename(description, seglists)