Skip to content

Commit

Permalink
Further thoughts and suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
titodalcanton committed Jan 11, 2024
1 parent 56617f7 commit 5c18ccf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
32 changes: 15 additions & 17 deletions bin/minifollowups/pycbc_injection_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,33 @@ from pycbc.workflow.core import resolve_url_to_file
from pycbc.io.hdf import SingleDetTriggers, HFile


def sort_injections(args, inj_group, missed, sort_by):
"""Return an array of indices to sort the missed injections according to a
metric of choice.
def sort_injections(args, inj_group, missed):
"""Return an array of indices to sort the missed injections from most to
least likely to be detected, according to a metric of choice.
Parameters
----------
args : object
CLI arguments parsed by argparse.
CLI arguments parsed by argparse. Must have a `distance_type` attribute
to specify how to sort.
inj_group : h5py group object
HDF5 group object containing the injection definition.
missed : array
Array of indices of missed injections into `inj_group`.
sort_by : str
Which metric to sort by.
Returns
-------
missed_sorted : array
Array of indices of missed injections sorted as requested.
"""
if 'optimal_snr' in sort_by:
if 'optimal_snr' in args.distance_type:
optimal_snrs = [
inj_group[dsn][:][missed] for dsn in inj_group.keys()
if dsn.startswith('optimal_snr_')
]
assert optimal_snrs, 'These injections do not have optimal SNRs'

if sort_by == 'decisive_optimal_snr':
if args.distance_type == 'decisive_optimal_snr':
# descending order of decisive (2nd largest) optimal SNR
dec_snr = numpy.array([
sorted(snrs)[-2] for snrs in zip(*optimal_snrs)
Expand All @@ -72,14 +71,14 @@ def sort_injections(args, inj_group, missed, sort_by):
sorter = dec_snr.argsort()[::-1]
return missed[sorter]

if sort_by == 'network_optimal_snr':
if args.distance_type == 'comb_optimal_snr':
# descending order of network optimal SNR
optimal_snrs = numpy.vstack(optimal_snrs)
net_opt_snrs_squared = (optimal_snrs ** 2).sum(axis=0)
sorter = net_opt_snrs_squared.argsort()[::-1]
return missed[sorter]

if sort_by == 'decisive_eff_dist':
if args.distance_type == 'dec_chirp_distance':
# ascending order of decisive (2nd smallest) chirp distance
from pycbc.conversions import mchirp_from_mass1_mass2, chirp_distance

Expand All @@ -103,7 +102,7 @@ def sort_injections(args, inj_group, missed, sort_by):
sorter = dec_chirp_dist.argsort()
return missed[sorter]

raise ValueError(f'Invalid injection sorting method "{sort_by}"')
raise ValueError(f'Invalid injection sorting method "{args.distance_type}"')


parser = argparse.ArgumentParser(description=__doc__)
Expand Down Expand Up @@ -136,6 +135,10 @@ parser.add_argument('--nearby-triggers-window', type=float, default=0.05,
help="Maximum time difference between the missed "
"injection and the loudest SNR nearby trigger to "
"display, seconds. Default=0.05")
parser.add_argument('--distance-type',
required=True,
help="How to sort missed injections from most to least "
"likely to be detected")
wf.add_workflow_command_line_group(parser)
wf.add_workflow_settings_cli(parser, include_subdax_opts=True)
args = parser.parse_args()
Expand Down Expand Up @@ -246,12 +249,7 @@ if len(missed) < num_events:
num_events = len(missed)

# sort the injections
sort_by = workflow.cp.get_opt_tags(
'workflow-injection_minifollowups',
'sort-by',
''
)
missed = sort_injections(args, inj_def, missed, sort_by)
missed = sort_injections(args, inj_def, missed)

# loop over sorted missed injections to be followed up
found_inj_idxes = f['found_after_vetoes/injection_index'][:]
Expand Down
6 changes: 3 additions & 3 deletions examples/search/plotting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ section-header = all
[workflow-injection_minifollowups]
num-events=1
subsection-suffix=with_ifar_lt_1_year
sort-by=decisive_optimal_snr

[foreground_minifollowup]
[foreground_minifollowup-foreground]
Expand All @@ -36,6 +35,9 @@ non-coinc-time-only =
[injection_minifollowup]
ifar-threshold = 1

[injection_minifollowup&plot_foundmissed-sub_mchirp_grad&plot_foundmissed-all_mchirp_grad&plot_foundmissed-summary]
distance-type = comb_optimal_snr

[page_snglinfo]
ranking-statistic = single_ranking_only
sngl-ranking = newsnr_sgveto_psdvar
Expand Down Expand Up @@ -140,14 +142,12 @@ log-dist =
far-type = exclusive

[plot_foundmissed-sub_mchirp_grad&plot_foundmissed-all_mchirp_grad&plot_foundmissed-summary]
distance-type = comb_optimal_snr
axis-type = mchirp
log-x =
log-distance =
gradient-far =

[plot_foundmissed-sub_mchirp_gradm&plot_foundmissed-all_mchirp_gradm&plot_foundmissed-summarym]
distance-type = comb_optimal_snr
axis-type = mchirp
log-x =
log-distance =
Expand Down

0 comments on commit 5c18ccf

Please sign in to comment.