Skip to content
Snippets Groups Projects
Commit 42f2e5e6 authored by Patrick Godwin's avatar Patrick Godwin
Browse files

fix issues, syntax in various plotting scripts and submodules

parent a78a8235
No related branches found
No related tags found
1 merge request!26Refactor plotting routines + remove unused functionality
......@@ -25,7 +25,6 @@ import os
import sqlite3
import sys
from matplotlib import pyplot
import numpy
from ligo.lw import ligolw
......@@ -42,15 +41,13 @@ from lal.utils import CacheEntry
from gstlal import imr_utils
from gstlal import dagparts
from gstlal.plots import sensitivity as plotsens
from matplotlib import pyplot
__author__ = "Stephen Privitera <sprivite@caltech.edu>, Chad Hanna <channa@perimeterinstitute.ca>, Kipp Cannon <kipp.cannon@ligo.org>"
__version__ = "git id %s" % "" # FIXME
__date__ = "" # FIXME
pyplot.rc('font',**{'family':'serif','serif':['Computer Modern Roman']})
matplotlib.rcParams.update({"text.usetex": True})
def source_type_distance_chirp_mass_bins_from_sims(sims, distbins = 200):
"""
......@@ -107,7 +104,7 @@ class upper_limit(object):
# read the zero lag databases first
for f in self.opts.zero_lag_database:
if opts.verbose:
print >> sys.stdout, "\nGathering search data from zero-lag database: %s...." % (f,)
print(f"Gathering search data from zero-lag database: {f}....", file=sys.stderr)
working_filename = dbtables.get_connection_filename(f, tmp_path=opts.tmp_space, verbose = opts.verbose)
connection = sqlite3.connect(str(working_filename))
......@@ -130,7 +127,7 @@ class upper_limit(object):
self.total_injections = {}
for f in self.opts.injection_database:
if opts.verbose:
print("Reading results of injection analysis from %s ..."%f)
print(f"Reading results of injection analysis from {f} ...", file=sys.stderr)
working_filename = dbtables.get_connection_filename(f, tmp_path=opts.tmp_space, verbose = opts.verbose)
connection = sqlite3.connect(str(working_filename))
for inst in self.instrument_combos:
......@@ -593,7 +590,7 @@ for bin_type in opts.bin_types:
fig_far = plotsens.plot_sensitivity_vs_far(far_vols, fars, UL.livetime, instr, bins, bin_type)
fig_far_range = plotsens.plot_range_vs_far(far_vols, fars, UL.livetime, instr, bins, bin_type)
fig_snr = plotsens.plot_sensitivity_vs_far(snr_vols, snrs, UL.livetime, instr, bins, bin_type)
fig_eff = plotsens.plot_fiducial_efficiency(eff_fids, opts.fiducial_far, inste, bins, bin_type)
fig_eff = plotsens.plot_fiducial_efficiency(eff_fids, opts.fiducial_far, instr, bins, bin_type)
# save and close figures
ifostr = "%s_%s" % (UL.searched_instruments, "".join(sorted(instr)))
......
......@@ -794,7 +794,7 @@ FROM
for participating_instruments, sims in sorted(self.found_in.items(), key = (lambda x: lsctables.instrumentsproperty.set(x[0]))):
if cnt == 0:
ifo_count_summary["".join(sorted(participating_instruments))] = len(sims)
found[participating_instruments] = (
found_data[participating_instruments] = (
[x_func(sim) for sim in sims],
[y_func(sim, participating_instruments) for sim in sims]
)
......@@ -960,7 +960,7 @@ class ParameterAccuracyPlots(object):
r"Inj. $M_{\mathrm{total}}$ ($\mathrm{M}_{\odot}$)",
r"(Rec. $M_{\mathrm{total}}$ - Inj. $M_{\mathrm{total}}$) / Inj. $M_{\mathrm{total}}$",
"FAR (Hz)",
r"Fractional $M_{\mathrm{total}}$ Accuracy in %s (%s Injections)" % waveform.replace("_", "\_"))
r"Fractional $M_{\mathrm{total}}$ Accuracy in %s (%s Injections)" % (instrument, waveform.replace("_", "\_"))
)
yield fig, "mtotal_acc_frac_scatter_%s_%s" % (waveform, instrument), False
......@@ -1011,7 +1011,7 @@ class ParameterAccuracyPlots(object):
[sim.time_at_instrument(sngl.ifo, {sngl.ifo: 0.0}) for sim, sngl, far in pairs],
[(sngl.end - sim.time_at_instrument(sngl.ifo, {sngl.ifo: 0.0}))*1000. for sim, sngl, far in pairs],
r"Injection End Time (GPS s)",
r"Rec. End Time - Injection End Time (ms)"
r"Rec. End Time - Injection End Time (ms)",
r"End Time Accuracy in %s (%s Injections)" % (instrument, waveform.replace("_", "\_"))
)
yield fig, "t_acc_scatter_%s_%s" % (waveform, instrument), False
......@@ -1044,7 +1044,7 @@ class ParameterAccuracyPlots(object):
fig = plotsumm.plot_param_accuracy_histogram(
numpy.array([(sngl.snr - self.get_inj_snr(sim, instrument)) for sim, sngl, far in pairs]),
r"(Rec. SNR - Inj SNR)", "Number",
r"(Rec. SNR - Inj SNR)",
r"SNR Diff in %s (%s Injections)" % (instrument, waveform.replace("_", "\_"))
)
yield fig, "snr_diff_hist_%s_%s" % (waveform, instrument), False
......@@ -1188,7 +1188,7 @@ WHERE
bg_chieffs = numpy.array(self.background[instrument].chieff)[sortable]
# mass dependence of chisq
fig = plot_mass_chi2_snr2_background(inj_mcs, inj_chisq, inj_snrs, bg_mcs, bg_chisq, bg_snrs, instrument)
fig = plotsumm.plot_mass_chi2_snr2_background(inj_mcs, inj_chisq, inj_snrs, bg_mcs, bg_chisq, bg_snrs, instrument)
yield fig, "chi2_vs_mc_vs_rho_%s" % instrument, False
# background parameter distributions
......@@ -1422,10 +1422,10 @@ WHERE
self.zerolag_snr.append(snr)
def finish(self):
fig = plot_candidate_lnL_vs_snr(self.snr_min, self.background_snr, self.background_ln_likelihood_ratio)
fig = plotsumm.plot_candidate_lnL_vs_snr(self.snr_min, self.background_snr, self.background_ln_likelihood_ratio)
yield fig, "lr_vs_snr", False
fig = plot_candidate_lnL_vs_snr(
fig = plotsumm.plot_candidate_lnL_vs_snr(
self.snr_min, self.background_snr, self.background_ln_likelihood_ratio,
self.zerolag_snr, self.zerolag_ln_likelihood_ratio
)
......@@ -1441,7 +1441,7 @@ WHERE
if ln_likelihood_ratio:
# ln(L) in ascending order
zerolag_stats = numpy.array(sorted(ln_likelihood_ratio, reverse = True))
fig = plotsumm.create_rate_vs_lnL_plot(zerolag_stats, self.fapfar, is_open_box)
fig = plotsumm.plot_rate_vs_lnL(zerolag_stats, self.fapfar, is_open_box)
yield fig, "count_vs_lr", is_open_box
if self.background_ln_likelihood_ratio:
......
......@@ -88,11 +88,11 @@ def fiducial_efficiency_to_range_label(eff_fid, bins, zero_bin, bin_type):
iterutils.MultiIter(*bins.upper())
):
ds = (zero_bin.lower() + zero_bin.upper()) / 2
center = numpy.array([eff_fid[(d,) + bin_mid] for d in ds])
lo = numpy.array([eff_fid_lo[(d,) + bin_mid] for d in ds])
hi = numpy.array([eff_fid_hi[(d,) + bin_mid] for d in ds])
center = numpy.array([eff_fid[1][(d,) + bin_mid] for d in ds])
lo = numpy.array([eff_fid[0][(d,) + bin_mid] for d in ds])
hi = numpy.array([eff_fid[2][(d,) + bin_mid] for d in ds])
yield lo, center, hi, bin_type_to_label(bin_type, bin_lo, bin_mid, bin_hi)
yield lo, center, hi, ds, bin_type_to_label(bin_type, bin_lo, bin_mid, bin_hi)
def vt_to_range(volume, livetime):
return (volume / (4 * math.pi * livetime / 3))**(1./3)
......@@ -212,12 +212,12 @@ def plot_fiducial_efficiency(eff_fids, fiducial_far, ifos, bins, bin_type):
# plot the volume/range versus far/snr for each bin
mbins = rate.NDBins(bins[1:])
labels = []
for lo, center, hi, label in fiducial_efficiency_to_range_label(eff_fids, mbins, bins[0], bin_type):
for lo, eff, hi, ds, label in fiducial_efficiency_to_range_label(eff_fids, mbins, bins[0], bin_type):
labels.append(label)
# NOTE create regular plots, and define log x,y scales below
# since otherwise, fill_between allocates too many blocks and crashes
line, = ax_eff.plot(ds, eff, label=label, linewidth=2 )
line, = ax_eff.plot(ds, eff, label=label, linewidth=2)
ax_eff.fill_between(ds, lo, hi, alpha=0.5, color=line.get_color())
ax_eff.set_xlabel("Distance (Mpc)")
......
......@@ -172,7 +172,7 @@ def plot_snr_chi2_background(ifo, min_snr, injections, background, zerolag=None)
axes.loglog(injections[ifo].snr, injections[ifo].chi2, 'r.', label = "Inj")
axes.loglog(background[ifo].snr, background[ifo].chi2, "kx", label = "Background")
if zerolag:
axes.loglog(zerolag[ifo].snr, self.zerolag[ifo].chi2, "bx", label = "Zero-lag")
axes.loglog(zerolag[ifo].snr, zerolag[ifo].chi2, "bx", label = "Zero-lag")
axes.set_title(fr"$\chi^{2}$ vs.\ $\rho$ in {ifo}")
else:
axes.set_title(fr"$\chi^{2}$ vs.\ $\rho$ in {ifo} (Closed box)")
......
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