29matplotlib.rcParams.update({
31 "axes.titlesize": 10.0,
32 "axes.labelsize": 10.0,
33 "xtick.labelsize": 8.0,
34 "ytick.labelsize": 8.0,
35 "legend.fontsize": 8.0,
40from matplotlib
import figure
41from matplotlib.backends.backend_agg
import FigureCanvasAgg
as FigureCanvas
46from igwn_ligolw
import lsctables
47from igwn_ligolw
import dbtables
48from igwn_ligolw.utils
import search_summary
as ligolw_search_summary
49from igwn_ligolw.utils
import segments
as ligolw_segments
50from .offsetvector
import offsetvector
53__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
54from .git_version
import date
as __date__
55from .git_version
import version
as __version__
68 def __init__(self, connection, live_time_program, search = "excesspower", veto_segments_name = None):
70 Compute and record some summary information about the
71 database. Call this after all the data has been inserted,
72 and before you want any of this information.
76 self.xmldoc = dbtables.get_xml(connection)
101 self.
seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(self.
xmldoc, live_time_program).coalesce()
103 if veto_segments_name
is not None:
104 self.
vetoseglists = ligolw_segments.segmenttable_get_by_name(self.
xmldoc, veto_segments_name).coalesce()
106 self.
vetoseglists = ligolw_segments.segments.segmentlistdict()
136 Generator function to return
138 is_background, event_list, offsetvector
140 tuples by querying the coinc_event
and sngl_burst tables
in
141 the database. Only coincs corresponding to
142 sngl_burst<-->sngl_burst coincs will be retrieved.
145 for coinc_event_id, time_slide_id
in self.
connection.cursor().execute(
"""
153 """, (self.bb_definer_id,)):
154 rows = [(self.sngl_burst_table.row_from_cols(row), row[-1]) for row
in cursor.execute(
"""
161 coinc_event_map.table_name == 'sngl_burst'
162 AND sngl_burst.event_id == coinc_event_map.event_id
165 time_slide.instrument == sngl_burst.ifo
168 coinc_event_map.coinc_event_id == ?
169 AND time_slide.time_slide_id == ?
170 """, (coinc_event_id, time_slide_id))]
171 offsets = offsetvector((event.ifo, offset) for event, offset
in rows)
172 yield any(offsets.values()), [event
for event, offset
in rows], offsets
178 Generator function to return
180 sim, event_list, offsetvector
182 tuples by querying the sim_burst, coinc_event
and
183 sngl_burst tables
in the database. Only coincs
184 corresponding to
"exact" sim_burst<-->coinc_event coincs
188 for values
in self.
connection.cursor().execute(
"""
191 burst_coinc_event_map.event_id
194 JOIN coinc_event_map AS sim_coinc_event_map ON (
195 sim_coinc_event_map.table_name == 'sim_burst'
196 AND sim_coinc_event_map.event_id == sim_burst.simulation_id
198 JOIN coinc_event AS sim_coinc_event ON (
199 sim_coinc_event.coinc_event_id == sim_coinc_event_map.coinc_event_id
201 JOIN coinc_event_map AS burst_coinc_event_map ON (
202 burst_coinc_event_map.coinc_event_id == sim_coinc_event_map.coinc_event_id
203 AND burst_coinc_event_map.table_name ==
'coinc_event'
206 sim_coinc_event.coinc_def_id == ?
207 """, (self.sce_definer_id,)):
210 coinc_event_id = values[-1]
214 rows = [(self.
sngl_burst_table.row_from_cols(row), row[-1])
for row
in cursor.execute(
"""
220 JOIN coinc_event_map ON (
221 coinc_event_map.table_name == 'sngl_burst'
222 AND coinc_event_map.event_id == sngl_burst.event_id
224 JOIN coinc_event ON (
225 coinc_event.coinc_event_id == coinc_event_map.coinc_event_id
228 coinc_event.time_slide_id == time_slide.time_slide_id
229 AND time_slide.instrument == sngl_burst.ifo
232 coinc_event.coinc_event_id == ?
233 """, (coinc_event_id,))]
235 yield sim, [event
for event, offset
in rows],
offsetvector((event.ifo, offset)
for event, offset
in rows)
243 filename =
"%s: " % filename
244 cursor = contents.connection.cursor()
245 print(
"%sdatabase stats:" % filename, file=sys.stderr)
246 for instrument, seglist
in sorted(contents.seglists.items()):
247 print(
"\t%s%s livetime: %g s (%g%% vetoed)" % (filename, instrument, abs(seglist), 100.0 * float(abs(instrument
in contents.vetoseglists
and (seglist & contents.vetoseglists[instrument])
or 0.0)) / float(abs(seglist))), file=sys.stderr)
248 if contents.sngl_burst_table
is not None:
249 print(
"\t%sburst events: %d" % (filename, len(contents.sngl_burst_table)), file=sys.stderr)
250 if contents.sim_burst_table
is not None:
251 print(
"\t%sburst injections: %d" % (filename, len(contents.sim_burst_table)), file=sys.stderr)
252 if contents.time_slide_table
is not None:
253 print(
"\t%stime slides: %d" % (filename, cursor.execute(
"SELECT COUNT(DISTINCT(time_slide_id)) FROM time_slide").fetchone()[0]), file=sys.stderr)
254 if contents.coinc_def_table
is not None:
255 for description, n
in cursor.execute(
"SELECT description, COUNT(*) FROM coinc_definer NATURAL JOIN coinc_event GROUP BY coinc_def_id ORDER BY description"):
256 print(
"\t%s%s: %d" % (filename, description, n), file=sys.stderr)
261 for values
in contents.connection.cursor().execute(
"""
262SELECT sngl_burst.* FROM
264 JOIN coinc_event_map ON (
265 sngl_burst.event_id == coinc_event_map.event_id
266 AND coinc_event_map.table_name == 'sngl_burst'
269 coinc_event_map.coinc_event_id == ?
270 """, (coinc_event_id,)):
271 yield contents.sngl_burst_table.row_from_cols(values)
285 Query the database for the IDs and offsets of all time slides, and
286 return two dictionaries one containing the all-zero time slides and
287 the other containing the not-all-zero time slides.
289 time_slides = dbtables.TimeSlideTable(connection = connection).as_dict()
291 zero_lag_time_slides =
dict((time_slide_id, offsetvector)
for time_slide_id, offsetvector
in time_slides.items()
if not any(offsetvector.values()))
292 background_time_slides =
dict((time_slide_id, offsetvector)
for time_slide_id, offsetvector
in time_slides.items()
if any(offsetvector.values()))
294 return zero_lag_time_slides, background_time_slides
299 Given a sequence of time slides (each of which is an instrument -->
300 offset dictionary), use the segmentlistdict dictionary of segment
301 lists to compute the live time in each time slide. Return the sum
302 of the live times from all slides.
305 old_offsets = seglists.offsets.copy()
308 print("computing the live time for %d time slides:" % N, file=sys.stderr)
309 for n, time_slide
in enumerate(time_slides):
311 print(
"\t%.1f%%\r" % (100.0 * n / N), end=
' ', file=sys.stderr)
312 seglists.offsets.update(time_slide)
313 livetime += float(abs(seglists.intersection(time_slide.keys())))
314 seglists.offsets.update(old_offsets)
316 print(
"\t100.0%", file=sys.stderr)
329floatpattern = re.compile(
"([+-]?[.0-9]+)[Ee]([+-]?[0-9]+)")
333 Convert a string of the form "d.dddde-dd" to "d.dddd \\times
339 >>> print latexnumber("%.16e" % math.pi)
340 3.1415926535897931 \\times 10^{0}
342 m, e = floatpattern.match(s).groups()
343 return r"%s \times 10^{%d}" % (m, int(e))
359 fig = figure.Figure()
362 fig.set_size_inches(width / 25.4, width / 25.4 / ((1 + math.sqrt(5)) / 2))
365 axes.set_xlabel(x_label)
366 axes.set_ylabel(y_label)
def get_injections(self)
Generator function to return.
def __init__(self, connection, live_time_program, search="excesspower", veto_segments_name=None)
Compute and record some summary information about the database.
def get_noninjections(self)
Generator function to return.
Subclass of the dict built-in type for storing mappings of instrument to time offset.
def latexnumber(s)
Convert a string of the form "d.dddde-dd" to "d.dddd \\times 10^{-dd}".
def get_time_slides(connection)
Query the database for the IDs and offsets of all time slides, and return two dictionaries one contai...
def coinc_sngl_bursts(contents, coinc_event_id)
def summarize_coinc_database(contents, filename=None)
def make_burst_plot(x_label, y_label, width=165.0)
width is in mm
def time_slides_livetime(seglists, time_slides, verbose=False)
Given a sequence of time slides (each of which is an instrument --> offset dictionary),...