Skip to content

Commit

Permalink
Fix a couple of rarely-used scripts, remove unused imports, whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Jan 29, 2024
1 parent 09d59de commit 7d0809d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_bin_trigger_rates_dq
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from pycbc.events.veto import (select_segments_by_definer,
start_end_to_segments,
segments_to_start_end)
from pycbc.types.optparse import MultiDetOptionAction
from pycbc.io.hdf import HFile, SingleDetTriggers
from pycbc.io.hdf import SingleDetTriggers
from pycbc.version import git_verbose_msg as version

parser = argparse.ArgumentParser(description=__doc__)
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_fit_sngls_split_binned
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from matplotlib import pyplot as plt
import numpy as np

from pycbc import events, bin_utils, results
from pycbc.io import HFile, SingleDetTriggers
from pycbc.io import SingleDetTriggers
from pycbc.events import triggers as trigs
from pycbc.events import trigger_fits as trstats
from pycbc.events import stat as pystat
Expand Down
27 changes: 16 additions & 11 deletions bin/pycbc_fit_sngl_trigs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ for ifo in opt.ifos:
elif trigformat == "hdf":
if opt.bank_file:
# io function can currently only handle 1 file
sngls = io.hdf.SingleDetTriggers(opt.inputs[0],
opt.bank_file, opt.veto_file, opt.veto_segment_name,
filter_func, ifo)
sngls = io.hdf.SingleDetTriggers(
opt.inputs[0],
ifo,
bank_file=opt.bank_file,
veto_file=opt.veto_file,
segment_name=opt.veto_segment_name,
filter_func=filter_func,
)
done_vetoing = True
else:
sngls = io.hdf.DataFromFiles(opt.inputs, group=ifo,
Expand Down Expand Up @@ -236,10 +241,10 @@ for ifo in opt.ifos:
#rchisq = np.maximum(rchisq, bank_rchisq)

if opt.veto_file and not done_vetoing:
logging.info("Applying vetoes from %s for ifo %s" %
logging.info("Applying vetoes from %s for ifo %s" %
(opt.veto_file, ifo))
keep_idx, segs = events.veto.indices_outside_segments(
sngls.get_column("end_time").astype(int),
sngls.get_column("end_time").astype(int),
[opt.veto_file], ifo=ifo,
segment_name=opt.veto_segment_name)
snr = snr[keep_idx]
Expand Down Expand Up @@ -304,7 +309,7 @@ for ifo in opt.ifos:
else:
mass1_inbin = mass1[pind == i]
mass2_inbin = mass2[pind == i]
mass_tuples = [(m1, m2) for m1, m2 in
mass_tuples = [(m1, m2) for m1, m2 in
zip(mass1_inbin, mass2_inbin)]
numtmpl = len(set(mass_tuples))
templates[ifo][i] = numtmpl
Expand All @@ -326,7 +331,7 @@ for ifo in opt.ifos:
stdev[ifo][th][i] = sig_alpha
_, ks_prob[ifo][th][i] = trstats.KS_test(
opt.fit_function, vals_inbin, alpha, th)
outfile.write("%s %.2f %.3g %.3g %d %d %.3f %.3f %.3g\n" %
outfile.write("%s %.2f %.3g %.3g %d %d %.3f %.3f %.3g\n" %
(ifo, th, lower, upper, numtmpl, counts[ifo][th][i], alpha,
sig_alpha, ks_prob[ifo][th][i]))

Expand All @@ -335,7 +340,7 @@ for ifo in opt.ifos:
histcounts, edges = np.histogram(vals_inbin, bins=50)
cum_counts = histcounts[::-1].cumsum()[::-1]
binlabel = r"%.2g - %.2g" % (lower, upper)
plt.semilogy(edges[:-1], cum_counts, linewidth=2,
plt.semilogy(edges[:-1], cum_counts, linewidth=2,
color=histcolors[i], label=binlabel, alpha=0.6)

plt.semilogy(plotrange, counts[ifo][th][i] * \
Expand All @@ -348,7 +353,7 @@ for ifo in opt.ifos:
plt.semilogy(plotrange, counts[ifo][th][i] * \
trstats.cum_fit(opt.fit_function, plotrange, alpha - \
sig_alpha, th), ":", alpha=0.6, color=histcolors[i])

if opt.plot_dir:
leg = plt.legend(labelspacing=0.2)
plt.setp(leg.get_texts(), fontsize=11)
Expand All @@ -370,7 +375,7 @@ if opt.plot_dir:
for ifo in fits.keys():
for th in opt.stat_threshold:
plt.errorbar(pbins.centres(), [fits[ifo][th][i] for i in binind],
yerr=[stdev[ifo][th][i] for i in binind], fmt="+-",
yerr=[stdev[ifo][th][i] for i in binind], fmt="+-",
label=ifo + " fit above %.2f" % th)
if opt.bin_spacing == "log": plt.semilogx()
plt.grid()
Expand All @@ -381,7 +386,7 @@ if opt.plot_dir:
plt.close()

for th in opt.stat_threshold:
plt.plot(pbins.centres(), [ks_prob[ifo][th][i] for i in binind],
plt.plot(pbins.centres(), [ks_prob[ifo][th][i] for i in binind],
'+--', label=ifo+' KS prob, thresh %.2f' % th)
if opt.bin_spacing == 'log': plt.loglog()
else : plt.semilogy()
Expand Down
11 changes: 8 additions & 3 deletions bin/pycbc_process_sngls
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ else:
if filter_func is not None:
logging.info('Will filter trigs using %s', filter_func)
# Filter will be stored as self.mask attribute of sngls instance
sngls = SingleDetTriggers(args.single_trig_file, args.bank_file,
args.veto_file, args.segment_name, filter_func,
args.detector)
sngls = SingleDetTriggers(
args.single_trig_file,
args.detector,
bank_file=args.bank_file,
veto_file=args.veto_file,
segment_name=args.segment_name,
filter_func=filter_func,
)

logging.info('Calculating stat')
rank_method = stat.get_statistic_from_opts(args, [args.detector])
Expand Down

0 comments on commit 7d0809d

Please sign in to comment.