3 """ Plot horizon history from ranking statistics"""
10 from matplotlib
import pyplot
11 from optparse
import OptionParser
14 from gstlal
import far
15 from gstlal.plots
import util as plotutil
16 from lal.utils
import CacheEntry
19 def parse_command_line():
20 parser = OptionParser(description = __doc__)
22 parser.add_option(
"-o",
"--outdir", default =
".", help =
"output directory for plots (Default: current directory)" )
23 parser.add_option(
"-v",
"--verbose", action =
"store_true", help =
"be verbose")
25 options, args = parser.parse_args()
28 raise ValueError(
"Ranking statistics cannot be empty.")
32 options, caches = parse_command_line()
34 urls = [CacheEntry(line).url for cache in caches for line in open(cache)]
36 for key,
group in itertools.groupby(sorted(urls,key = lambda x: CacheEntry.from_T050017(x).description), lambda x: CacheEntry.from_T050017(x).description):
37 rankingstat = far.marginalize_pdf_urls(list(
group),
"RankingStat", verbose = options.verbose)
38 horizon_history_dict = rankingstat.numerator.horizon_history
40 fig, ax = pyplot.subplots(1, 2, figsize=(12,4))
41 pyplot.tight_layout(pad = 2.5, w_pad = 2.5, h_pad = 2.5)
44 for detector, horizon_history in horizon_history_dict.items():
45 GPSTime = numpy.array(horizon_history.keys())
46 horizon_dist = horizon_history.values()
48 minh, maxh = (float(
"inf"), 0)
49 maxh = max(maxh, max(horizon_dist))
50 minh = min(minh, min(horizon_dist))
51 mint = int(GPSTime.min())
52 SinceGPSTime = (GPSTime - mint)/1000.
53 binvec = numpy.linspace(minh, maxh, 25)
56 ax[0].semilogy(SinceGPSTime, horizon_dist,
"x", color = plotutil.colour_from_instruments([detector]), label = detector)
57 ax[1].hist(horizon_dist, binvec, alpha = 0.5, color = plotutil.colour_from_instruments([detector]), label = detector)
60 sys.stderr.write(
"plotting " + key +
".png\n")
62 #pyplot.suptitle(
"%s : Horizon Distance" % detector)
63 ax[0].set_xlabel(
"Time (ks) from GPS {:d}".format(min(gmint)))
64 ax[0].set_ylabel(
"Mpc")
65 ax[0].legend(loc =
"best")
68 ax[1].set_xlabel(
"Mpc")
69 ax[1].set_ylabel(
"Count")
70 ax[1].legend(loc =
"best")
71 fig.savefig(os.path.join(options.outdir, key +
".png"))
75 sys.stderr.write(
"done\n")
def group
group a list roughly according to the distribution in parts, e.g.