Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/pygrb/pycbc_pygrb_plot_chisq_veto
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ if opts.plot_title is None:
else:
opts.plot_title += f" vs {snr_type.capitalize()} SNR"
if opts.plot_caption is None:
opts.plot_caption = ("Blue crosses: background triggers. ")
if found_missed_file:
opts.plot_caption += "Red crosses: injections triggers. "
opts.plot_caption = "Blue crosses: background triggers. "\
"Red crosses: injections triggers. "
else:
opts.plot_caption = "Distribution of background triggers. "
if veto_type == 'network':
opts.plot_caption += ("Gray shaded region: area cut by the " +
"reweighted SNR threshold. " +
Expand Down
7 changes: 4 additions & 3 deletions bin/pygrb/pycbc_pygrb_plot_null_stats
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ y_labels = {'null': "Null SNR",
if opts.plot_title is None:
opts.plot_title = y_labels[opts.y_variable] + " vs Coherent SNR"
if opts.plot_caption is None:
opts.plot_caption = ("Blue crosses: background triggers. ")
if found_missed_file:
opts.plot_caption = opts.plot_caption +\
("Red crosses: injections triggers. ")
opts.plot_caption = "Blue crosses: background triggers. "\
"Red crosses: injections triggers. "
else:
opts.plot_caption = "Distribution of background triggers. "

if opts.y_variable == 'coincident':
opts.plot_caption += ("Green line: coincident SNR = coherent SNR.")
Expand Down
9 changes: 6 additions & 3 deletions bin/pygrb/pycbc_pygrb_plot_snr_timeseries
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,18 @@ y_label = y_labels[snr_type]
# Determine title and caption
if opts.plot_title is None:
opts.plot_title = y_label + " vs Time"

if opts.plot_caption is None:
opts.plot_caption = ("Blue crosses: background triggers. ")
if inj_file:
opts.plot_caption += ("Red crosses: injections triggers.")
opts.plot_caption = ("Blue crosses: background triggers. "\
"Red crosses: injections triggers.")
else:
opts.plot_caption = ("Distribution of background triggers.")

# Single IFO SNR versus time plots
if not opts.x_lims:
opts.x_lims = f"{start},{end}"
plu.pygrb_plotter([trig_data_time, trig_data_snr],
[inj_data_time, inj_data_snr],
f"Time since {central_time:.3f} (s)", y_label,
opts, cmd=' '.join(sys.argv))
opts, cmd=' '.join(sys.argv))
50 changes: 37 additions & 13 deletions pycbc/results/pygrb_plotting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,48 @@ def pygrb_plotter(trigs, injs, xlabel, ylabel, opts,
colors=None, vert_spike=False, cmd=None):
"""Master function to plot PyGRB results"""
from matplotlib import pyplot as plt
import matplotlib

# Set up plot
fig = plt.figure()
cax = fig.gca()
# Axes: labels and limits
cax.set_xlabel(xlabel)
cax.set_ylabel(ylabel)
if opts.x_lims:
x_lims = map(float, opts.x_lims.split(','))
cax.set_xlim(x_lims)
if opts.y_lims:
y_lims = map(float, opts.y_lims.split(','))
cax.set_ylim(y_lims)
# Plot trigger-related and (if present) injection-related quantities
cax_plotter = cax.loglog if opts.use_logs else cax.plot
cax_plotter(trigs[0], trigs[1], 'bx')
if not (injs[0] is None and injs[1] is None):
if (injs[0] is None and injs[1] is None) or \
(len(injs[0]) == 0 and len(injs[1]) == 0):
scales = ['log', 'log'] if opts.use_logs else ['linear', 'linear']
## Necessary trick to avoid artifacts
xmin, xmax = cax.get_xlim()
if not isinstance(trigs[0], numpy.ndarray):
trigs[0] = numpy.array(trigs[0])
if not isinstance(trigs[1], numpy.ndarray):
trigs[1] = numpy.array(trigs[1])
mask = (trigs[0] >= xmin) & (trigs[0] <= xmax)
norm = matplotlib.colors.LogNorm()
gsize = 300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bins are a bit too small here, isolated single triggers are hard to see. I suggest using 150 here. I also noticed the logic below to choose the bins based on the number of samples. I think if you use 150 it will be good in all cases. We can complicate the logic once we have looked at several cases later.

if mask.sum() == 0:
## Necessary to make plot appear even in absence of points
norm = matplotlib.colors.LogNorm(vmin=1, vmax=10)
elif mask.sum() < 100:
gsize = 100
ax = cax.hexbin(trigs[0][mask], trigs[1][mask], gridsize=gsize, xscale=scales[0],
yscale=scales[1], lw=0.04, mincnt=1,
norm=norm, zorder=2)
cb = plt.colorbar(ax)
cb.set_label('Trigger Density')
else:
cax_plotter = cax.loglog if opts.use_logs else cax.plot
cax_plotter(trigs[0], trigs[1], 'bx')
cax_plotter(injs[0], injs[1], 'r+')

cax.grid()
# Plot contours
if conts is not None:
Expand All @@ -212,18 +245,9 @@ def pygrb_plotter(trigs, injs, xlabel, ylabel, opts,
polyx = numpy.append(polyx, [max(snr_vals), min(snr_vals)])
polyy = numpy.append(polyy, [limy, limy])
cax.fill(polyx, polyy, color='#dddddd')
# Axes: labels and limits
cax.set_xlabel(xlabel)
cax.set_ylabel(ylabel)
if opts.x_lims:
x_lims = map(float, opts.x_lims.split(','))
cax.set_xlim(x_lims)
if opts.y_lims:
y_lims = map(float, opts.y_lims.split(','))
cax.set_ylim(y_lims)
# Wrap up
plt.tight_layout()
save_fig_with_metadata(fig, opts.output_file, cmd=cmd,
title=opts.plot_title,
caption=opts.plot_caption)
plt.close()
plt.close()
Loading