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

add gstlal_inspiral_plot_snr

add plotsnr.py
parent 2e8c9438
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ dist_bin_SCRIPTS = \
gstlal_inspiral_plot_kernels \
gstlal_inspiral_plot_psd_horizon \
gstlal_inspiral_plot_sensitivity \
gstlal_inspiral_plot_snr \
gstlal_inspiral_plotsummary \
gstlal_inspiral_plot_svd_bank \
gstlal_inspiral_rate_posterior \
......
#!/usr/bin/env python
"""
Plotter for gstlal_inspiral_calc_snr
"""
import sys
from optparse import OptionParser
from gstlal import plotsnr
def parse_command_line():
parser = OptionParser(description = __doc__)
parser.add_option("-o", "--output", metavar = "filename", help = "The output filename for the SNR plot (require).")
parser.add_option("-i", "--input", metavar = "filename", help = "A LIGO light-weight XML file containing SNR time series data (require).")
parser.add_option("--center", metavar = "gpsSeconds", type = "float", help = "Center the plot to --center (optional).")
parser.add_option("--span", metavar = "seconds", type = "float", help = "The time span around --center (optional).")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
options, args = parser.parse_args()
missing_required_options = []
if options.input is None:
missing_required_options.append("--input")
if options.output is None:
missing_required_options.append("--output")
if missing_required_options:
raise ValueError("Missing required option(s) %s" % ", ".join(missing_required_options))
return options
options = parse_command_line()
plotsnr.plot_snr(options.input, output = options.output, center = options.center, span = options.span, verbose = options.verbose)
......@@ -26,6 +26,7 @@ pkgpython_PYTHON = \
plotfar.py \
plotsegments.py \
plotsensitivity.py \
plotsnr.py \
rate_estimation.py \
snglinspiraltable.py \
spawaveform.py \
......
"""
Plotting SNR from LIGO light-weight XML file
"""
import sys
import numpy
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot
from gstlal import svd_bank_snr
def plot_snr(filename, output = None, center = None, span = None, verbose = False):
xmldoc = svd_bank_snr.read_url(filename, contenthandler = svd_bank_snr.SNRContentHandler, verbose = verbose)
SNR_dict = svd_bank_snr.read_xmldoc(xmldoc)
start = None
mid = 0
end = None
if verbose:
sys.stderr.write("Ploting SNR ...\n")
for instrument, SNR in SNR_dict.items():
if verbose and center and span:
sys.stderr.write("Locating SNR at GPSTime: %f spanning %f s\n" % (center, span))
if center and span:
start = find_nearest(SNR, center - span)[1]
mid = find_nearest(SNR, center)[1]
end = find_nearest(SNR, center + span)[1]
gps_time = (SNR.epoch.gpsSeconds + SNR.epoch.gpsNanoSeconds * 10.**-9 + (numpy.arange(SNR.data.length) * SNR.deltaT))
relative_gps_time = (gps_time - gps_time[mid])[start:end]
data = SNR.data.data[start:end]
fig, ax = pyplot.subplots(nrows = 1, ncols = 1, figsize = [15,6])
ax.plot(relative_gps_time, data)
ax.set_xlabel("GPS Time Since %f" % gps_time[mid])
ax.set_ylabel("SNR")
pyplot.tight_layout()
if output is None:
output = "SNR_%s_since_%d.svg" %(SNR.name, gps_time[mid])
if verbose:
sys.stderr.write("%s --> Done\n" % output)
fig.savefig(output)
else:
if verbose:
sys.stderr.write("%s --> Done\n" % output)
fig.savefig(output)
pyplot.close()
def find_nearest(snr_series, time):
gps_start = snr_series.epoch.gpsSeconds + snr_series.epoch.gpsNanoSeconds * 10.**-9
gps = gps_start + numpy.arange(snr_series.data.length) * snr_series.deltaT
if time - gps[0] > 0 and time - gps[-1] <0:
index = abs(gps - time).argmin()
else:
raise ValueError("Invalid choice of center time %f." % time)
return (snr_series.data.data[index], index)
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