Skip to content
Snippets Groups Projects
Commit 3b7d2a21 authored by ChiWai Chan's avatar ChiWai Chan
Browse files

gstlal_inspiral_plot_snr && plotsnr.py

	-- add support for multiple instruments
parent 8e70cb87
No related branches found
No related tags found
No related merge requests found
......@@ -2,14 +2,13 @@
"""
Plotter for gstlal_inspiral_calc_snr
"""
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot
import os
import sys
from optparse import OptionParser
from gstlal import plotsnr
from gstlal import svd_bank_snr
from lal.utils import CacheEntry
......@@ -38,9 +37,27 @@ def parse_command_line():
options = parse_command_line()
with open(options.input) as f:
suffix = ".svg" if (options.format is None) else options.format
for snr_file in f:
figure = plotsnr.plot_snr(CacheEntry(snr_file).url, width = options.width, center = options.center, span = options.span, verbose = options.verbose)
figure.savefig(os.path.join(options.outdir, CacheEntry(snr_file).description+suffix))
pyplot.close(pyplot.gcf())
suffix = ".svg" if (options.format is None) else options.format
urls = []
description = None
segment = None
with open(options.input) as cache:
for line in cache.readlines():
entry = CacheEntry(line)
urls.append(entry.url)
if description is None and segment is None:
description = entry.description
segment = "-" + str(entry.segment[0]) + "-" + str(entry.segment[1] - entry.segment[0])
else:
assert description + segment == entry.description + "-" + str(entry.segment[0]) + "-" + str(entry.segment[1] - entry.segment[0]), "Cannot plot snrs with different segments or for different template."
SNRs_dict = {}
for url in urls:
SNRs_dict.update(svd_bank_snr.read_xmldoc(svd_bank_snr.read_url(url, svd_bank_snr.SNRContentHandler, verbose = options.verbose)))
for row, snrs_group in enumerate(zip(*SNRs_dict.values())):
figure = plotsnr.plot_snr(dict(zip(SNRs_dict.keys(), zip(snrs_group))), width = options.width, center = options.center, span = options.span, verbose = options.verbose)
if len(zip(*SNRs_dict.values())) == 1:
figure.savefig(os.path.join(options.outdir, "%s-" % "".join(SNRs_dict.keys()) + description + segment + suffix))
else:
figure.savefig(os.path.join(options.outdir, "%s-" % "".join(SNRs_dict.keys()) + description + "-"+ str(row) + segment + suffix))
......@@ -40,13 +40,13 @@ def axes_add_snr(axes, snrdict, center = None, span = None):
axes[col].tick_params(labelbottom = True)
col += 1
def plot_snr(filename, width = 6, center = None, span = None, verbose = False):
def plot_snr(SNR_dict, width = 8, center = None, span = None, verbose = False):
"""
Plot snr time series from LIGO light-weighted XML file
Plot snr time series from snrdicts
Args:
filename: A LIGO light-weighted XML file
SNR_dict: A dictionary containing (instrument, LAL series) pairs
width (int): width of the output figure in inch
center (float): the center gpstime of the plot
span (float): seconds to span around center
......@@ -57,16 +57,13 @@ def plot_snr(filename, width = 6, center = None, span = None, verbose = False):
fig (object): matplotlib figure
"""
xmldoc = svd_bank_snr.read_url(filename, svd_bank_snr.SNRContentHandler, verbose = verbose)
SNRs_dict = svd_bank_snr.read_xmldoc(xmldoc)
nrows = len(SNRs_dict.keys())
nrows = len(SNR_dict.keys())
ncols = 1
fig, axes = pyplot.subplots(nrows = nrows, ncols = ncols, sharex = True)
if nrows == 1:
axes = [axes]
axes_add_snr(axes, SNRs_dict, center = center, span = span)
axes_add_snr(axes, SNR_dict, center = center, span = span)
fig.set_size_inches(width, int(round(width/plotutil.golden_ratio)))
fig.tight_layout(pad = 0.8)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment