Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyGRB: Propagating slide_id information across postprocessing plotting scripts #4809

Merged
merged 39 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c35e331
Update pygrb_plotting_utils.py
sebastiangomezlopez Jul 2, 2024
6acfa6c
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 2, 2024
2550c13
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 2, 2024
4908130
Update pycbc_pygrb_plot_chisq_veto
sebastiangomezlopez Jul 2, 2024
45b13c2
Update pycbc_pygrb_plot_coh_ifosnr
sebastiangomezlopez Jul 2, 2024
6f7cec5
Update pycbc_pygrb_plot_null_stats
sebastiangomezlopez Jul 2, 2024
5ce9fa3
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
7b50899
Update pycbc_pygrb_plot_chisq_veto
sebastiangomezlopez Jul 19, 2024
152f167
Update pycbc_pygrb_plot_chisq_veto
sebastiangomezlopez Jul 19, 2024
c9acf43
Update pycbc_pygrb_plot_chisq_veto
sebastiangomezlopez Jul 19, 2024
ddfbe09
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 19, 2024
f124f98
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
f81f073
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
ba5544f
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
d43b170
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
b1ca9d4
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 19, 2024
ece6854
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 22, 2024
e46cdcd
Update pygrb_plotting_utils.py
sebastiangomezlopez Jul 22, 2024
0829a26
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 22, 2024
c67a4a6
Update pygrb_plotting_utils.py
sebastiangomezlopez Jul 22, 2024
6554596
Update pygrb_plotting_utils.py
sebastiangomezlopez Jul 22, 2024
cbc36e4
Merge branch 'gwastro:master' into slides_postp
sebastiangomezlopez Jul 22, 2024
25e9726
Propagating slide_id information to some pygrb plotting scripts
sebastiangomezlopez Jul 22, 2024
28c7278
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 22, 2024
bb20dcc
Modification to slides parser. Update to plotting scripts
sebastiangomezlopez Jul 24, 2024
085b1ea
Merge branch 'slides_postp' of github.com:sebastiangomezlopez/pycbc i…
sebastiangomezlopez Jul 24, 2024
5ca8eb8
Merge branch 'gwastro:master' into slides_postp
sebastiangomezlopez Jul 24, 2024
3351184
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 24, 2024
08db76f
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 24, 2024
18ea7b1
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 24, 2024
55a4312
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 25, 2024
368e14a
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 25, 2024
229ca55
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 25, 2024
c991754
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 25, 2024
678da8b
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 25, 2024
a7bfb0f
Update pycbc_pygrb_plot_snr_timeseries
sebastiangomezlopez Jul 25, 2024
bc81979
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 25, 2024
a53fef0
Update pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 25, 2024
2c7c177
Update pycbc/results/pygrb_postprocessing_utils.py
sebastiangomezlopez Jul 26, 2024
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
15 changes: 10 additions & 5 deletions bin/pygrb/pycbc_pygrb_plot_chisq_veto
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ __program__ = "pycbc_pygrb_plot_chisq_veto"
# Functions
# =============================================================================
# Function to load trigger data: includes applying cut in reweighted SNR
def load_data(input_file, ifos, vetoes, opts, injections=False):
def load_data(input_file, ifos, vetoes, opts, injections=False, slide_id=None):
"""Load data from a trigger/injection file"""

snr_type = opts.snr_type
Expand All @@ -71,12 +71,14 @@ def load_data(input_file, ifos, vetoes, opts, injections=False):
# This will eventually become load_injections
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=rw_snr_threshold)
rw_snr_threshold=rw_snr_threshold,
slide_id=slide_id)
else:
logging.info("Loading triggers...")
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=rw_snr_threshold)
rw_snr_threshold=rw_snr_threshold,
slide_id=slide_id)

# Count surviving points
num_trigs_or_injs = len(trigs_or_injs['network/reweighted_snr'])
Expand Down Expand Up @@ -194,6 +196,7 @@ init_logging(opts.verbose, format="%(asctime)s: %(levelname)s: %(message)s")

# Check options
trig_file = os.path.abspath(opts.trig_file)
print(trig_file)
titodalcanton marked this conversation as resolved.
Show resolved Hide resolved
found_missed_file = os.path.abspath(opts.found_missed_file) \
if opts.found_missed_file else None
zoom_in = opts.zoom_in
Expand Down Expand Up @@ -250,10 +253,11 @@ if ifo and ifo not in ifos:
raise RuntimeError(err_msg)

# Extract trigger data
trig_data = load_data(trig_file, ifos, vetoes, opts)
trig_data = load_data(trig_file, ifos, vetoes, opts, slide_id=0)

# Extract (or initialize) injection data
inj_data = load_data(found_missed_file, ifos, vetoes, opts, injections=True)
inj_data = load_data(found_missed_file, ifos, vetoes, opts,
injections=True, slide_id=0)

# Sanity checks
if trig_data[snr_type] is None and inj_data[snr_type] is None:
Expand Down Expand Up @@ -315,3 +319,4 @@ plu.pygrb_plotter(trigs, injs, x_label, y_label, opts,
snr_vals=snr_vals, conts=conts, colors=colors,
shade_cont_value=cont_value, vert_spike=True,
cmd=' '.join(sys.argv))
321,41 Bot
titodalcanton marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 5 additions & 3 deletions bin/pygrb/pycbc_pygrb_plot_coh_ifosnr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ __program__ = "pycbc_pygrb_plot_coh_ifosnr"
# Functions
# =============================================================================
# Function to load trigger data
def load_data(input_file, ifos, vetoes, opts, injections=False):
def load_data(input_file, ifos, vetoes, opts, injections=False, slide_id=None):
"""Load data from a trigger/injection file"""

# Initialize the dictionary
Expand All @@ -74,6 +74,7 @@ def load_data(input_file, ifos, vetoes, opts, injections=False):
ifos,
vetoes,
rw_snr_threshold=opts.newsnr_threshold,
slide_id=slide_id
)
else:
logging.info("Loading triggers...")
Expand All @@ -82,6 +83,7 @@ def load_data(input_file, ifos, vetoes, opts, injections=False):
ifos,
vetoes,
rw_snr_threshold=opts.newsnr_threshold,
slide_id=slide_id
)

# Load SNR data
Expand Down Expand Up @@ -233,10 +235,10 @@ ifos, vetoes = ppu.extract_ifos_and_vetoes(
)

# Extract trigger data
trig_data = load_data(trig_file, ifos, vetoes, opts)
trig_data = load_data(trig_file, ifos, vetoes, opts, slide_id=0)

# Extract (or initialize) injection data
inj_data = load_data(found_file, ifos, vetoes, opts, injections=True)
inj_data = load_data(found_file, ifos, vetoes, opts, injections=True, slide_id=0)
sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved

# Generate plots
logging.info("Plotting...")
Expand Down
13 changes: 8 additions & 5 deletions bin/pygrb/pycbc_pygrb_plot_null_stats
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ __program__ = "pycbc_pygrb_plot_null_stats"
# Functions
# =============================================================================
# Function to load trigger data
def load_data(input_file, ifos, vetoes, opts, injections=False):
def load_data(input_file, ifos, vetoes, opts, injections=False, slide_id=None):
"""Load data from a trigger/injection file"""

null_stat_type = opts.y_variable
Expand All @@ -63,12 +63,14 @@ def load_data(input_file, ifos, vetoes, opts, injections=False):
# This will eventually become ppu.load_injections()
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=opts.newsnr_threshold)
rw_snr_threshold=opts.newsnr_threshold,
slide_id=slide_id)
else:
logging.info("Loading triggers...")
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=opts.newsnr_threshold)
rw_snr_threshold=opts.newsnr_threshold,
slide_id=slide_id)

# Coherent SNR is always used
data['coherent'] = trigs_or_injs['network/coherent_snr']
Expand Down Expand Up @@ -183,10 +185,11 @@ ifos, vetoes = ppu.extract_ifos_and_vetoes(trig_file, opts.veto_files,
opts.veto_category)

# Extract trigger data
trig_data = load_data(trig_file, ifos, vetoes, opts)
trig_data = load_data(trig_file, ifos, vetoes, opts, slide_id=0)

# Extract (or initialize) injection data
inj_data = load_data(found_missed_file, ifos, vetoes, opts, injections=True)
inj_data = load_data(found_missed_file, ifos, vetoes, opts,
injections=True, slide_id=0)

# Generate plots
logging.info("Plotting...")
Expand Down
22 changes: 11 additions & 11 deletions bin/pygrb/pycbc_pygrb_plot_snr_timeseries
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ __version__ = pycbc.version.git_verbose_msg
__date__ = pycbc.version.date
__program__ = "pycbc_pygrb_plot_snr_timeseries"


sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved
# =============================================================================
# Functions
# =============================================================================
# Load trigger data
def load_data(input_file, ifos, vetoes, rw_snr_threshold=None,
injections=False):
injections=False, slide_id=None):
"""Load data from a trigger/injection file"""

trigs_or_injs = None
Expand All @@ -60,13 +59,12 @@ def load_data(input_file, ifos, vetoes, rw_snr_threshold=None,
# This will eventually become load_injections
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=rw_snr_threshold)
rw_snr_threshold=rw_snr_threshold,slide_id=slide_id)
pannarale marked this conversation as resolved.
Show resolved Hide resolved
else:
logging.info("Loading triggers...")
trigs_or_injs = \
ppu.load_triggers(input_file, ifos, vetoes,
rw_snr_threshold=rw_snr_threshold)

rw_snr_threshold=rw_snr_threshold,slide_id=slide_id)
return trigs_or_injs


Expand Down Expand Up @@ -137,21 +135,21 @@ ifos, vetoes = ppu.extract_ifos_and_vetoes(trig_file, opts.veto_files,
# points to show the impact of the cut, otherwise remove points with
# reweighted SNR below threshold
if snr_type == 'reweighted':
trig_data = load_data(trig_file, ifos, vetoes)
trig_data = load_data(trig_file, ifos, vetoes, slide_id=0)
trig_data['network/reweighted_snr'] = \
reweightedsnr_cut(trig_data['network/reweighted_snr'],
opts.newsnr_threshold)
inj_data = load_data(inj_file, ifos, vetoes, injections=True)
inj_data = load_data(inj_file, ifos, vetoes, injections=True,slide_id=0)
if inj_data is not None:
inj_data['network/reweighted_snr'] = \
reweightedsnr_cut(inj_data['network/reweighted_snr'],
opts.newsnr_threshold)
else:
trig_data = load_data(trig_file, ifos, vetoes,
rw_snr_threshold=opts.newsnr_threshold)
rw_snr_threshold=opts.newsnr_threshold, slide_id=0)
inj_data = load_data(inj_file, ifos, vetoes,
rw_snr_threshold=opts.newsnr_threshold,
injections=True)
injections=True, slide_id=0)

# Specify HDF file keys for x quantity (time) and y quantity (SNR)
if snr_type == 'single':
Expand All @@ -166,8 +164,9 @@ trig_data_time = trig_data[x_key][:]
inj_data_time = inj_data[x_key][:] if inj_file else None

# Obtain SNRs

sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved
trig_data_snr = trig_data[y_key][:]
inj_data_snr = inj_data[y_key][:] if inj_file else None
inj_data_snr = inj_data[y_key][:] if inj_file else None
titodalcanton marked this conversation as resolved.
Show resolved Hide resolved

# Determine the central time (t=0) for the plot
central_time = opts.trigger_time
Expand Down Expand Up @@ -203,7 +202,8 @@ xlims = [start, end]
if opts.x_lims:
xlims = opts.x_lims
xlims = map(float, xlims.split(','))

sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved
plu.pygrb_plotter([trig_data_time, trig_data_snr],
[inj_data_time, inj_data_snr],
"Time since %.3f (s)" % (central_time), y_label,
opts, cmd=' '.join(sys.argv))
opts, cmd=' '.join(sys.argv), fig=plt.figure())
sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions pycbc/results/pygrb_plotting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ def axis_min_value(trig_values, inj_values, inj_file):
# =============================================================================
def pygrb_plotter(trigs, injs, xlabel, ylabel, opts,
snr_vals=None, conts=None, shade_cont_value=None,
colors=None, vert_spike=False, cmd=None):
colors=None, vert_spike=False, cmd=None, fig=None):
pannarale marked this conversation as resolved.
Show resolved Hide resolved
"""Master function to plot PyGRB results"""
from matplotlib import pyplot as plt

# Set up plot
fig = plt.figure()
if fig is None:
fig = plt.figure()

pannarale marked this conversation as resolved.
Show resolved Hide resolved
cax = fig.gca()
# Plot trigger-related and (if present) injection-related quantities
cax_plotter = cax.loglog if opts.use_logs else cax.plot
Expand Down
19 changes: 18 additions & 1 deletion pycbc/results/pygrb_postprocessing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ def pygrb_add_bestnr_cut_opt(parser):
"Default 0: all events are considered.")


# =============================================================================
# Wrapper to pick triggers with certain slide_ids
# =============================================================================
def slide_filter(File, data, slide_id=None):
""" """
mask = numpy.where(File['network/slide_id'][:]==slide_id)[0]

if slide_id is not None:
return data[mask]
else:
return data
sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved


# =============================================================================
# Wrapper to read segments files
# =============================================================================
Expand Down Expand Up @@ -356,7 +369,7 @@ def dataset_iterator(g, prefix=''):
yield from dataset_iterator(item, path)


def load_triggers(input_file, ifos, vetoes, rw_snr_threshold=None):
def load_triggers(input_file, ifos, vetoes, rw_snr_threshold=None, slide_id=None):
"""Loads triggers from PyGRB output file, returning a dictionary"""

trigs = h5py.File(input_file, 'r')
Expand Down Expand Up @@ -407,6 +420,10 @@ def load_triggers(input_file, ifos, vetoes, rw_snr_threshold=None):
else:
trigs_dict[path] = dset[above_thresh]

if trigs_dict[path].size==trigs['network/slide_id'][:].size:
trigs_dict[path] = slide_filter(trigs,trigs_dict[path],
slide_id=slide_id)

return trigs_dict


Expand Down
Loading