Skip to content

Commit

Permalink
Revert to maks_n_clustered in sngls_minifollowup [v23_ branch]
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Jul 25, 2024
1 parent f13078a commit 0279ab8
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions bin/minifollowups/pycbc_sngl_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -249,50 +249,39 @@ if args.maximum_duration is not None:
logging.info('Finding loudest clustered events')
rank_method = stat.get_statistic_from_opts(args, [args.instrument])

extra_kwargs = {}
for inputstr in args.statistic_keywords:
try:
key, value = inputstr.split(':')
extra_kwargs[key] = value
except ValueError:
err_txt = "--statistic-keywords must take input in the " \
"form KWARG1:VALUE1 KWARG2:VALUE2 KWARG3:VALUE3 ... " \
"Received {}".format(args.statistic_keywords)
raise ValueError(err_txt)

logging.info("Calculating statistic for %d triggers", len(trigs.snr))
sds = rank_method.single(trigs)
stat = rank_method.rank_stat_single((args.instrument, sds), **extra_kwargs)
logging.info("Clustering events over %.3fs window", args.cluster_window)
cid = coinc.cluster_over_time(stat, trigs.end_time,
args.cluster_window)
trigs.apply_mask(cid)
stat = stat[cid]
if len(trigs.snr) < num_events:
num_events = len(trigs.snr)

logging.info("Finding the loudest triggers")
loudest_idx = sorted(numpy.argsort(stat)[::-1][:num_events])
trigs.apply_mask(loudest_idx)
stat = stat[loudest_idx]
trigs.mask_to_n_loudest_clustered_events(
rank_method,
n_loudest=num_events,
cluster_window=args.cluster_window,
)

times = trigs.end_time
tids = trigs.template_id
trig_stat = trigs.stat
trig_snrs = trigs.snr

if isinstance(trigs.mask, numpy.ndarray) and trigs.mask.dtype == bool:
trigger_ids = numpy.flatnonzero(trigs.mask)
else:
trigger_ids = trigs.mask

# loop over number of loudest events to be followed up
order = stat.argsort()[::-1]
order = trig_stat.argsort()[::-1]
for rank, num_event in enumerate(order):
logging.info('Processing event: %s', num_event)
logging.info('Processing event: %s', rank)

files = wf.FileList([])
time = times[num_event]
ifo_time = '%s:%s' %(args.instrument, str(time))
if isinstance(trigs.mask, numpy.ndarray) and trigs.mask.dtype == bool:
tid = numpy.flatnonzero(trigs.mask)[num_event]
else:
tid = trigs.mask[num_event]
tid = trigger_ids[num_event]
ifo_tid = '%s:%s' %(args.instrument, str(tid))

print(num_event)
print(tid)
print(trig_stat[num_event])
print(trig_snrs[num_event])
print(time)
print('\n'*2)

layouts += (mini.make_sngl_ifo(workflow, sngl_file, tmpltbank_file,
tid, args.output_dir, args.instrument,
statfiles=statfiles,
Expand Down

0 comments on commit 0279ab8

Please sign in to comment.