From 0279ab8c7942b38c337c34f5a249d679059e80b9 Mon Sep 17 00:00:00 2001 From: GarethCabournDavies Date: Thu, 25 Jul 2024 06:34:39 -0700 Subject: [PATCH] Revert to maks_n_clustered in sngls_minifollowup [v23_ branch] --- bin/minifollowups/pycbc_sngl_minifollowup | 55 +++++++++-------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/bin/minifollowups/pycbc_sngl_minifollowup b/bin/minifollowups/pycbc_sngl_minifollowup index 4005802d08d..3057ea8d97d 100644 --- a/bin/minifollowups/pycbc_sngl_minifollowup +++ b/bin/minifollowups/pycbc_sngl_minifollowup @@ -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,