Skip to content

Commit

Permalink
Efficiency plots and exclusion distance tables in PyGRB webpages (#4903)
Browse files Browse the repository at this point in the history
* Efficiency plots and exclusion distance tables for the injection sets (both for the on-source and off-source trials) in PyGRB webpages
  • Loading branch information
pannarale authored Oct 10, 2024
1 parent 1735851 commit 2312ca2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
64 changes: 60 additions & 4 deletions bin/pygrb/pycbc_pygrb_pp_workflow
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,29 @@ offtrials = [f"offtrial_{i+1}" for i in range(num_trials)]
# Sensitivity plots of each injection set
out_dir = rdir['exclusion_distances']
_workflow.makedir(out_dir)
bkgd_plots = []
for inj_set in inj_sets:
# Retrieve the injections result File for the inj_set label
inj_file = inj_files.find_output_with_tag(inj_set,
fail_if_not_single_file=True)
tags = [offtrials[0]] + inj_file.tags
plot_node, output_files = \
_workflow.make_pygrb_plot(wflow, 'pygrb_efficiency',
out_dir, trig_file=offsource_file,
inj_file=inj_file,
bank_file=bank_file,
seg_files=seg_files, tags=tags,
plot_bkgd=True)
plotting_nodes.append(plot_node)
bkgd_plots += [output_files[0]]
bkgd_plots = list(layout.grouper(bkgd_plots, 2))
layout.two_column_layout(out_dir, bkgd_plots)

# Exclusion distances of each injection set
for i, offtrial in enumerate(offtrials):
out_dir = rdir[f'exclusion_distances/{offtrial}']
_workflow.makedir(out_dir)
files = _workflow.FileList([])
eff_layout = []
for inj_set in inj_sets:
# Retrieve the injections result File for the inj_set label
inj_file = inj_files.find_output_with_tag(inj_set,
Expand All @@ -508,10 +527,20 @@ for i, offtrial in enumerate(offtrials):
onsource_file=offtrial_files[i],
inj_file=inj_file,
bank_file=bank_file,
seg_files=seg_files, tags=tags)
seg_files=seg_files, tags=tags,
plot_bkgd=False)
plotting_nodes.append(plot_node)
files.extend(output_files)
eff_layout = list(layout.grouper(files, 2))
eff_plot = output_files[0]
json_input = output_files[1]
# Create information table about exclusion distances
excl_dist_table_node, excl_dist_table = \
_workflow.make_pygrb_info_table(wflow,
'pygrb_exclusion_dist_table',
out_dir,
in_files=json_input,
tags=tags)
html_nodes.append(excl_dist_table_node)
eff_layout += [(eff_plot, excl_dist_table[0])]
layout.two_column_layout(out_dir, eff_layout, offtrial)

# Make room for throughput histograms (TODO)
Expand Down Expand Up @@ -602,6 +631,33 @@ else:
tags=['loudest_onsource_event'])
logging.info("Leaving onsource minifollowups")

# Exclusion distances and efficiency plots based on the on-source
out_dir = rdir['open_box/exclusion_distances']
eff_layout = []
for inj_set in inj_sets:
# Retrieve the injections result File corresponding to the inj_set label
inj_file = inj_files.find_output_with_tag(inj_set,
fail_if_not_single_file=True)
tags = ['onsource'] + inj_file.tags
plot_node, output_files = \
_workflow.make_pygrb_plot(wflow, 'pygrb_efficiency',
out_dir, trig_file=offsource_file,
onsource_file=onsource_file,
inj_file=inj_file,
bank_file=bank_file,
seg_files=seg_files, tags=tags,
plot_bkgd=False)
plotting_nodes.append(plot_node)
eff_plot = output_files[0]
json_input = output_files[1]
# Create information table about exclusion distances
excl_dist_table_node, excl_dist_table = \
_workflow.make_pygrb_info_table(wflow, 'pygrb_exclusion_dist_table',
out_dir, in_files=json_input,
tags=tags)
html_nodes.append(excl_dist_table_node)
eff_layout += [(eff_plot, excl_dist_table[0])]
layout.two_column_layout(out_dir, eff_layout)

# Close the log and flush to the html file
logging.shutdown()
Expand Down
30 changes: 17 additions & 13 deletions pycbc/workflow/grb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def build_segment_filelist(seg_dir):
def make_pygrb_plot(workflow, exec_name, out_dir,
ifo=None, inj_file=None, trig_file=None,
onsource_file=None, bank_file=None,
seg_files=None, tags=None):
seg_files=None, tags=None, **kwargs):
"""Adds a node for a plot of PyGRB results to the workflow"""

tags = [] if tags is None else tags
Expand Down Expand Up @@ -515,20 +515,24 @@ def make_pygrb_plot(workflow, exec_name, out_dir,
if exec_name == 'pygrb_efficiency':
# In this case tags[0] is the offtrial number
node.add_input_list_opt('--seg-files', seg_files)
node.add_input_opt('--onsource-file',
onsource_file)
node.add_input_opt('--bank-file', bank_file)
node.new_output_file_opt(workflow.analysis_time, '.png',
'--background-output-file',
tags=extra_tags+['max_background'])
node.new_output_file_opt(workflow.analysis_time, '.png',
'--onsource-output-file',
tags=extra_tags+['onsource'])
node.new_output_file_opt(workflow.analysis_time, '.json',
'--exclusion-dist-output-file',
tags=extra_tags)
node.add_opt('--injection-set-name', tags[1])
node.add_opt('--trial-name', tags[0])
node.add_opt('--injection-set-name', tags[1])
# Output the sensitivity plot
if kwargs['plot_bkgd']:
node.new_output_file_opt(workflow.analysis_time, '.png',
'--background-output-file',
tags=extra_tags+['max_background'])
# Output the exclusion distance plot and table
else:
node.add_input_opt('--onsource-file',
onsource_file)
node.new_output_file_opt(workflow.analysis_time, '.png',
'--onsource-output-file',
tags=['onsource']+extra_tags)
node.new_output_file_opt(workflow.analysis_time, '.json',
'--exclusion-dist-output-file',
tags=extra_tags)
else:
node.new_output_file_opt(workflow.analysis_time, '.png',
'--output-file', tags=extra_tags)
Expand Down

0 comments on commit 2312ca2

Please sign in to comment.