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 38 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
16 changes: 11 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 @@ -187,7 +189,9 @@ parser.add_argument("--snr-type", default='coherent',
'single'], help="SNR value to plot on x-axis.")
ppu.pygrb_add_bestnr_cut_opt(parser)
ppu.pygrb_add_bestnr_opts(parser)
ppu.pygrb_add_slide_opts(parser)
opts = parser.parse_args()
ppu.slide_opts_helper(opts)

init_logging(opts.verbose, format="%(asctime)s: %(levelname)s: %(message)s")

Expand Down Expand Up @@ -249,10 +253,12 @@ 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=opts.slide_id)

# 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
10 changes: 7 additions & 3 deletions bin/pygrb/pycbc_pygrb_plot_coh_ifosnr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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 @@ -75,6 +75,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 @@ -83,6 +84,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 @@ -186,7 +188,9 @@ parser.add_argument(
help="Output file a zoomed in version of the plot.",
)
ppu.pygrb_add_bestnr_cut_opt(parser)
ppu.pygrb_add_slide_opts(parser)
opts = parser.parse_args()
ppu.slide_opts_helper(opts)

init_logging(opts.verbose, format="%(asctime)s: %(levelname)s: %(message)s")

Expand Down Expand Up @@ -232,10 +236,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=opts.slide_id)

# 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)

# Generate plots
logging.info("Plotting...")
Expand Down
16 changes: 11 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 @@ -140,7 +142,9 @@ parser.add_argument("-y", "--y-variable", default=None,
help="Quantity to plot on the vertical axis.")
ppu.pygrb_add_null_snr_opts(parser)
ppu.pygrb_add_bestnr_cut_opt(parser)
ppu.pygrb_add_slide_opts(parser)
opts = parser.parse_args()
ppu.slide_opts_helper(opts)

init_logging(opts.verbose, format="%(asctime)s: %(levelname)s: %(message)s")

Expand Down Expand Up @@ -182,10 +186,12 @@ 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=opts.slide_id)

# 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
21 changes: 14 additions & 7 deletions bin/pygrb/pycbc_pygrb_plot_snr_timeseries
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ __program__ = "pycbc_pygrb_plot_snr_timeseries"
# =============================================================================
# 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,12 +60,14 @@ 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)
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 @@ -107,7 +109,9 @@ parser.add_argument("-y", "--y-variable", default=None,
choices=['coherent', 'single', 'reweighted', 'null'],
help="Quantity to plot on the vertical axis.")
ppu.pygrb_add_bestnr_cut_opt(parser)
ppu.pygrb_add_slide_opts(parser)
opts = parser.parse_args()
ppu.slide_opts_helper(opts)

init_logging(opts.verbose, format="%(asctime)s: %(levelname)s: %(message)s")

Expand Down Expand Up @@ -136,21 +140,24 @@ 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=opts.slide_id)
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=opts.slide_id)
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 Down
42 changes: 40 additions & 2 deletions pycbc/results/pygrb_postprocessing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,29 @@ def pygrb_initialize_plot_parser(description=None):
parser.add_argument('--plot-caption', default=None,
help="If provided, use the given string as the plot " +
"caption")

return parser


def pygrb_add_slide_opts(parser):
"""Add to parser object arguments related to short timeslides"""
parser.add_argument("--slide-id", type=str, default='0',
help="If all, the plotting scripts will use triggers" +
"from all short slides.")


def slide_opts_helper(args):
"""
This function overwrites the types of input slide_id information
when loading data in postprocessing scripts.
"""
if args.slide_id.isdigit():
args.slide_id = int(args.slide_id)
elif args.slide_id.lower() == "all":
args.slide_id = None
else:
raise ValueError("--slide-id must be all or int")
sebastiangomezlopez marked this conversation as resolved.
Show resolved Hide resolved


def pygrb_add_injmc_opts(parser):
"""Add to parser object the arguments used for Monte-Carlo on distance."""
if parser is None:
Expand Down Expand Up @@ -175,6 +194,20 @@ def pygrb_add_bestnr_cut_opt(parser):
"Default 0: all events are considered.")


# =============================================================================
# Wrapper to pick triggers with certain slide_ids
# =============================================================================
def slide_filter(trig_file, data, slide_id=None):
"""
This function adds the capability to select triggers with specific
slide_ids during the postprocessing stage of PyGRB.
"""
if slide_id is None:
return data
mask = numpy.where(trig_file['network/slide_id'][:] == slide_id)[0]
return data[mask]


# =============================================================================
# Wrapper to read segments files
# =============================================================================
Expand Down Expand Up @@ -359,7 +392,8 @@ 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 = HFile(input_file, 'r')
Expand Down Expand Up @@ -410,6 +444,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