Skip to content
Snippets Groups Projects
Commit a0bdf780 authored by ChiWai Chan's avatar ChiWai Chan Committed by Madeline Wade
Browse files

renamed gstlal_inspiral_plot_psd_horizon -->...

renamed gstlal_inspiral_plot_psd_horizon --> gstlal_inspiral_plot_rankingstats_horizon and use plots.horizon for plotting.
parent 4b1bd29b
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ dist_bin_SCRIPTS = \
gstlal_inspiral_plot_banks \
gstlal_inspiral_plot_extrinsic_params \
gstlal_inspiral_plot_kernels \
gstlal_inspiral_plot_psd_horizon \
gstlal_inspiral_plot_rankingstats_horizon \
gstlal_inspiral_plot_sensitivity \
gstlal_inspiral_plot_snr \
gstlal_inspiral_plotsummary \
......
#!/usr/bin/env python3
""" Plot horizon history from ranking statistics"""
import sys
import os
import itertools
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot
from optparse import OptionParser
import numpy
from gstlal import far
from gstlal.plots import util as plotutil
from lal.utils import CacheEntry
def parse_command_line():
parser = OptionParser(description = __doc__)
parser.add_option("-o", "--outdir", default = ".", help = "output directory for plots (Default: current directory)" )
parser.add_option("-v", "--verbose", action = "store_true", help = "be verbose")
options, args = parser.parse_args()
if len(args) == 0:
raise ValueError("Ranking statistics cannot be empty.")
return options, args
options, caches = parse_command_line()
urls = [CacheEntry(line).url for cache in caches for line in open(cache)]
for key, group in itertools.groupby(sorted(urls,key = lambda x: CacheEntry.from_T050017(x).description), lambda x: CacheEntry.from_T050017(x).description):
rankingstat = far.marginalize_pdf_urls(list(group), "RankingStat", verbose = options.verbose)
horizon_history_dict = rankingstat.numerator.horizon_history
fig, ax = pyplot.subplots(1, 2, figsize=(12,4))
pyplot.tight_layout(pad = 2.5, w_pad = 2.5, h_pad = 2.5)
gmint = []
for detector, horizon_history in horizon_history_dict.items():
GPSTime = numpy.array(horizon_history.keys())
horizon_dist = horizon_history.values()
minh, maxh = (float("inf"), 0)
maxh = max(maxh, max(horizon_dist))
minh = min(minh, min(horizon_dist))
mint = int(GPSTime.min())
SinceGPSTime = (GPSTime - mint)/1000.
binvec = numpy.linspace(minh, maxh, 25)
gmint.append(mint)
ax[0].semilogy(SinceGPSTime, horizon_dist, "x", color = plotutil.colour_from_instruments([detector]), label = detector)
ax[1].hist(horizon_dist, binvec, alpha = 0.5, color = plotutil.colour_from_instruments([detector]), label = detector)
if options.verbose:
sys.stderr.write("plotting " + key + ".png\n")
#pyplot.suptitle("%s : Horizon Distance" % detector)
ax[0].set_xlabel("Time (ks) from GPS {:d}".format(min(gmint)))
ax[0].set_ylabel("Mpc")
ax[0].legend(loc = "best")
ax[0].grid()
ax[1].set_xlabel("Mpc")
ax[1].set_ylabel("Count")
ax[1].legend(loc = "best")
fig.savefig(os.path.join(options.outdir, key + ".png"))
pyplot.close()
if options.verbose:
sys.stderr.write("done\n")
#!/usr/bin/env python3
#
# Copyright (C) 2021 ChiWai Chan
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Plot horizon history from ranking statistics
"""
from optparse import OptionParser
from gstlal.plots import horizon
def parse_command_line():
parser = OptionParser(description = __doc__)
parser.add_option("-o", "--output", help = "Set plot filename.")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose")
options, args = parser.parse_args()
if len(args) == 0:
raise ValueError("Must provide at least one ranking statistics file.")
if options.output is None:
raise ValueError("Must provide --output (output filename).")
return options, args
options, files = parse_command_line()
horizon_distance = horizon.HorizonDistance.from_rankingstats(files, verbose = options.verbose)
horizon_distance.savefig(options.output)
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