29from __future__
import print_function
32from optparse
import OptionParser
37from igwn_ligolw
import dbtables
38from igwn_ligolw.utils
import segments
as ligolwsegments
39from lalburst
import git_version
42__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
43__version__ =
"git id %s" % git_version.id
44__date__ = git_version.date
57 parser = OptionParser(
58 version =
"Name: %%prog\n%s" % git_version.verbose_msg,
59 usage =
"%prog [options] [filename ...]",
60 description =
"%prog constructs or clears and then populates the string_vetoed_sngl table providing a list of the sngl_burst event_ids of vetoed triggers. This table is used by other post-processing tools like lalapps_string_meas_likelihood to determine which triggers have been vetoed and which haven't."
62 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.")
63 parser.add_option(
"-n",
"--vetoes-name", metavar =
"name", default =
"vetoes", help =
"Set the name of the segment lists to use as vetoes (default = \"vetoes\").")
64 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"Be verbose.")
65 options, filenames = parser.parse_args()
68 raise ValueError(
"no input files!")
70 return options, filenames
97 Creates a function named string_sngl_is_vetoed in the database at
98 connection. The function accepts three parameters --- the
99 instrument name, and the integer
and integer nanoseconds components
100 of a time ---
and returns true
if the instrument
is vetoed at that
101 time
or false otherwise. veto_segments_name sets the name of the
102 segment lists used to define the vetoes.
104 If veto_segments_name
is None then a no-op function
is created that
105 always returns
False.
107 Note: this funtion requires igwn_ligolw.dbtables
and
108 igwn_ligolw.utils.segments to be imported
as dbtables
and
109 ligolwsegments respectively.
111 if veto_segments_name is None:
112 connection.create_function("string_sngl_is_vetoed", 3,
lambda instrument, peak_time, peak_time_ns:
False)
114 xmldoc = dbtables.get_xml(connection)
115 seglists = ligolwsegments.segmenttable_get_by_name(xmldoc, options.vetoes_name).coalesce()
117 def is_vetoed(instrument, peak_time, peak_time_ns, seglists = seglists):
118 return instrument
in seglists
and dbtables.lsctables.LIGOTimeGPS(peak_time, peak_time_ns)
in seglists[instrument]
119 connection.create_function(
"string_sngl_is_vetoed", 3, is_vetoed)
122for n, filename
in enumerate(filenames):
128 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
130 working_filename = dbtables.get_connection_filename(filename, tmp_path = options.tmp_space, verbose = options.verbose)
131 connection = sqlite3.connect(str(working_filename))
143 cursor = connection.cursor()
145DROP TABLE IF EXISTS string_vetoed_sngl;
148CREATE TABLE string_vetoed_sngl (event_id TEXT PRIMARY KEY)
151INSERT OR REPLACE INTO
154 sngl_burst.event_id AS event_id
158 string_sngl_is_vetoed(sngl_burst.ifo, sngl_burst.peak_time, sngl_burst.peak_time_ns)
166 dbtables.discard_connection_filename(filename, working_filename, verbose = options.verbose)
def create_string_sngl_is_vetoed_function(connection, veto_segments_name=None)
Creates a function named string_sngl_is_vetoed in the database at connection.