Skip to content

Commit

Permalink
axis needed for np sum in far calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Davies committed Jul 3, 2019
1 parent 0a1de41 commit e65846a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
32 changes: 14 additions & 18 deletions bin/hdfcoinc/pycbc_multiifo_add_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,19 @@ del available_combos

logging.info('Calculating n_louder background triggers in each type for all foreground events')

fnlouder = {}
fnlouder_exc = {}
far = {}
far_exc = {}
for f_in in files:
ifo_combo_key = f_in.attrs['ifos'].replace(' ','')
_, fnlouder[ifo_combo_key] = coinc.calculate_n_louder(
f_in['background/stat'][:],
_, fnlouder = coinc.calculate_n_louder(f_in['background/stat'][:],
f['foreground/stat'][:],
f_in['background/decimation_factor'][:])
far[ifo_combo_key] = (fnlouder + 1) / f_in.attrs['background_time']
_, fnlouder_exc = coinc.calculate_n_louder(f_in['background_exc/stat'][:],
f['foreground/stat'][:],
f_in['background/decimation_factor'][:]
)
_, fnlouder_exc[ifo_combo_key] = coinc.calculate_n_louder(
f_in['background_exc/stat'][:],
f['foreground/stat'][:],
f_in['background_exc/decimation_factor'][:]
)
f_in['background_exc/decimation_factor'][:])
far_exc[ifo_combo_key] = (fnlouder_exc + 1) / f_in.attrs['background_time_exc']

logging.info('Recalculating ifar according to summed trigger distributions')

fg_ifar = np.zeros_like(f['foreground/decimation_factor'][:])
Expand All @@ -185,13 +184,10 @@ for ct in all_combo_types:
fg_ifar_exc[idx[ct]] = f['foreground/ifar_exc'][:][idx[ct]]
continue
logging.info('Recalculating ifar for coincidences which are in {} time'.format(ct))
largest_combination = cts[np.argmax([len(ifo_c) for ifo_c in cts])]
bg_time = f[largest_combination].attrs['background_time']
bg_time_exc = f[largest_combination].attrs['background_time_exc']
fnlouder = np.sum([fnlouder[ifo_combo_key][idx[ct]] for ifo_combo_key in cts])
fnlouder_exc = np.sum([fnlouder_exc[ifo_combo_key][idx[ct]] for ifo_combo_key in cts])
ifar = bg_time / (fnlouder + 1)
ifar_exc = bg_time_exc / (fnlouder_exc + 1)
far_new = np.sum([far[ifo_combo_key][idx[ct]] for ifo_combo_key in cts], axis=0)
far_new_exc = np.sum([far_exc[ifo_combo_key][idx[ct]] for ifo_combo_key in cts], axis=0)
ifar = 1 / np.array(far_new)
ifar_exc = 1 / np.array(far_new_exc)
fg_ifar[idx[ct]] = conv.sec_to_year(ifar)
fg_ifar_exc[idx[ct]] = conv.sec_to_year(ifar_exc)

Expand Down
25 changes: 13 additions & 12 deletions bin/hdfcoinc/pycbc_multiifo_coinc_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ veto_time = abs(veto.start_end_to_segments(remove_start_time,

# Veto indices from list of triggers for times in ifo 1&2 around the window
# times. This gives exclusive background triggers.
veto_indeces = {}
exc_zero_trigs = all_trigs.remove([]) # Start by copying existing triggers
for ifo in ifos:
veto_indeces[ifo] = veto.indices_within_times(all_trigs.data['%s/time' % ifo], remove_start_time,
remove_end_time)
exc_zero_trigs = all_trigs.remove(veto_indeces[ifo])
fg_veto_ids = veto.indices_within_times(
exc_zero_trigs.data['%s/time' % ifo],
remove_start_time, remove_end_time)
exc_zero_trigs = exc_zero_trigs.remove(fg_veto_ids)

logging.info("Clustering coinc triggers (inclusive of zerolag)")
all_trigs = all_trigs.cluster(args.cluster_window)
Expand Down Expand Up @@ -361,16 +362,16 @@ while numpy.any(louder_foreground == 0):
fore_locs = all_trigs.timeslide_id == 0
# The foreground trigger has been removed, continue with typical statmap operations.
# Calculate the change to foreground trigger time and vetoed out time
fore_time = {}
for ifo in args.ifos:
fore_time[ifo] = all_trigs.data['%s/time' % ifo][fore_locs]
# fore_time = {}
# for ifo in args.ifos:
# fore_time[ifo] = all_trigs.data['%s/time' % ifo][fore_locs]

ave_fore_time = 0
for ifo in args.ifos:
ave_fore_time += fore_time[ifo] / len(args.ifos)
# ave_fore_time = 0
# for ifo in args.ifos:
# ave_fore_time += fore_time[ifo] / len(args.ifos)

remove_start_time = ave_fore_time - args.veto_window
remove_end_time = ave_fore_time + args.veto_window
# remove_start_time = ave_fore_time - args.veto_window
# remove_end_time = ave_fore_time + args.veto_window

logging.info("We have %s triggers after hierarchical removal." % len(all_trigs.stat))

Expand Down

0 comments on commit e65846a

Please sign in to comment.