30from matplotlib
import cm, colors, collections
32from optparse
import OptionParser
37from lalburst
import git_version
38from lalburst
import SnglBurstUtils
41__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
42__version__ =
"git id %s" % git_version.id
43__date__ = git_version.date
56 parser = OptionParser(
57 version =
"Name: %%prog\n%s" % git_version.verbose_msg
59 parser.add_option(
"-b",
"--base", metavar =
"base", default =
"plotbinjtf_", help =
"set the prefix for output filenames (default = plotbinj_)")
60 parser.add_option(
"-f",
"--format", metavar =
"format", default =
"png", help =
"set the output image format (default = png)")
61 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"be verbose")
62 options, filenames = parser.parse_args()
64 return options, (filenames
or [
None])
79 fig = SnglBurstUtils.figure.Figure()
80 SnglBurstUtils.FigureCanvas(fig)
82 fig.set_size_inches(6.5, 6.5 / ((1 + math.sqrt(5)) / 2))
88 t_sim = sim.time_at_instrument(instrument)
90 axes = fig.add_subplot(211)
93 axes.set_ylabel(
"$f - f_{\\mathrm{injection}}$ (Hz)")
94 axes.set_title(
"%s Triggers Matching %g Hz Injection at GPS %s" % (instrument, sim.frequency, t_sim))
106 for burst
in map(database.sngl_burst_table.row_from_cols, database.connection.cursor().execute(
"""
107SELECT sngl_burst.* FROM
109 JOIN coinc_event_map AS a ON (
110 sngl_burst.event_id == a.event_id
111 AND a.table_name == 'sngl_burst'
113 JOIN coinc_event_map AS b ON (
114 a.coinc_event_id == b.coinc_event_id
115 AND b.table_name ==
'sim_burst'
121 sngl_burst.confidence ASC
122 """, (instrument, sim.simulation_id))):
123 match_ids.append(burst.event_id)
126 tmin = float(burst.start - t_sim)
127 tmax = float(burst.start + burst.duration - t_sim)
128 fmin = burst.central_freq - burst.bandwidth / 2 - sim.frequency
129 fmax = burst.central_freq + burst.bandwidth / 2 - sim.frequency
130 verts.append(((tmin, fmin), (tmax, fmin), (tmax, fmax), (tmin, fmax)))
131 colours.append(burst.confidence)
135 tmin = float(burst.ms_start - t_sim)
136 tmax = float(burst.ms_start + burst.ms_duration - t_sim)
137 fmin = burst.ms_flow - sim.frequency
138 fmax = burst.ms_flow + burst.ms_bandwidth - sim.frequency
139 verts.append(((tmin, fmin), (tmax, fmin), (tmax, fmax), (tmin, fmax)))
140 colours.append(burst.ms_confidence)
141 except AttributeError:
144 peakx.append(float(burst.peak - t_sim))
147 peaky.append(burst.peak_frequency - sim.frequency)
148 except AttributeError:
149 peaky.append(burst.central_freq - sim.frequency)
152 tmin = float(burst.start - t_sim)
153 tmax = float(burst.start + burst.duration - t_sim)
154 fmin = burst.central_freq - burst.bandwidth / 2 - sim.frequency
155 fmax = burst.central_freq + burst.bandwidth / 2 - sim.frequency
156 xmin =
min(xmin, tmin)
157 xmax =
max(xmax, tmax)
158 ymin =
min(ymin, fmin)
159 ymax =
max(ymax, fmax)
161 polys = collections.PolyCollection(verts)
162 polys.set_array(numpy.array(colours))
164 polys.set_cmap(cm.get_cmap())
165 polys.set_norm(colors.normalize())
166 axes.add_collection(polys)
168 axes.plot(peakx, peaky,
"k+")
170 axes.axvline(0, color =
"k")
171 axes.axhline(0, color =
"k")
174 axes.set_xlim([1.4 * xmin, 1.4 * xmax])
175 axes.set_ylim([1.4 * ymin, 1.4 * ymax])
181 axes = fig.add_subplot(212)
183 axes.set_xlabel(
"$t - t_{\\mathrm{injection}}$ (s)")
184 axes.set_ylabel(
"$f - f_{\\mathrm{injection}}$ (Hz)")
196 for burst
in map(database.sngl_burst_table.row_from_cols, database.connection.cursor().execute(
"""
201 AND start_time BETWEEN ? AND ?
202 AND central_freq BETWEEN ? AND ?
204 sngl_burst.confidence ASC
205 """, (instrument, int(t_sim - 2), int(t_sim + 2), sim.frequency - 300, sim.frequency + 300))):
207 tmin = float(burst.start - t_sim)
208 tmax = float(burst.start + burst.duration - t_sim)
209 fmin = burst.central_freq - burst.bandwidth / 2 - sim.frequency
210 fmax = burst.central_freq + burst.bandwidth / 2 - sim.frequency
211 verts.append(((tmin, fmin), (tmax, fmin), (tmax, fmax), (tmin, fmax)))
212 colours.append(burst.confidence)
213 if burst.event_id
in match_ids:
214 edgecolours.append(
"g")
216 edgecolours.append(
"k")
218 peakx.append(float(burst.peak - t_sim))
221 peaky.append(burst.peak_frequency - sim.frequency)
223 peaky.append(burst.central_freq - sim.frequency)
226 xmin =
min(xmin, tmin)
227 xmax =
max(xmax, tmax)
228 ymin =
min(ymin, fmin)
229 ymax =
max(ymax, fmax)
231 polys = collections.PolyCollection(verts, edgecolors = edgecolours)
232 polys.set_array(numpy.array(colours))
234 polys.set_cmap(cm.get_cmap())
235 polys.set_norm(colors.normalize())
236 axes.add_collection(polys)
238 axes.plot(peakx, peaky,
"k+")
240 axes.axvline(0, color =
"k")
241 axes.axhline(0, color =
"k")
244 axes.set_xlim([1.4 * xmin, 1.4 * xmax])
245 axes.set_ylim([1.4 * ymin, 1.4 * ymax])
261 for values
in contents.connection.cursor().execute(
"""
268 -- Find a link through the coinc_event_map table to a row
269 -- in the sngl_burst table
with the correct ifo value.
274 JOIN coinc_event_map AS b ON (
275 a.coinc_event_id == b.coinc_event_id
278 b.table_name ==
'sngl_burst'
279 AND b.event_id == sngl_burst.event_id
282 a.table_name ==
'sim_burst'
283 AND a.event_id == sim_burst.simulation_id
284 AND sngl_burst.ifo == ?
287 yield contents.sim_burst_table.row_from_cols(values)
290for n, filename
in enumerate(filenames):
292 print(
"%d/%d: %s" % (n + 1, len(filenames), filename), file=sys.stderr)
293 database = SnglBurstUtils.CoincDatabase(sqlite3.connect(filename),
"lalapps_power")
295 SnglBurstUtils.summarize_coinc_database(database)
296 for instrument
in database.instruments:
298 plotname =
"%s%d_%s.%s" % (options.base, sim.time_at_instrument(instrument).seconds, instrument, options.format)
300 print(
"--> %s" % plotname, file=sys.stderr)
302 database.connection.close()
static double max(double a, double b)
static double min(double a, double b)
def found_injections(contents, instrument)
def time_freq_plot(database, instrument, sim)