20 from __future__
import division
21 from argparse
import ArgumentParser
36 filename, min_snr=float(
"inf"), min_cands=-1, dropped_rho=float(
"-inf")
38 data = np.loadtxt(filename)
39 rho = data[:, rho_col]
40 sorted_inds = rho.argsort()[::-1]
44 if min_cands > 0
and min_cands < len(sorted_inds):
45 rho_to_drop = rho[sorted_inds[min_cands]]
46 if rho_to_drop > min_snr:
48 keep_cands = np.sum(rho > min_snr)
49 rho_to_drop = rho[sorted_inds[keep_cands - 1]]
51 keep_cands = min_cands
52 if dropped_rho < rho[sorted_inds[keep_cands]]:
53 dropped_rho = rho[sorted_inds[keep_cands]]
54 sorted_inds = sorted_inds[:keep_cands]
56 return data[sorted_inds, :], dropped_rho
59 parser = ArgumentParser()
61 "--input-toplist-files",
65 help=
"A space-separated list of toplist files to combine",
68 "--output-toplist-file",
71 help=
"Filename for output toplist",
74 "--min-cands-per-toplist",
78 help=
"Keep at least his many candidates from each toplist",
85 help=
"Keep all candidates with at least this SNR",
88 args = parser.parse_args()
90 dropped_rho = float(
"-inf")
92 outfile = open(args.output_toplist_file,
"w")
94 for filename
in args.input_toplist_files:
97 min_snr=args.min_snr_to_keep,
98 min_cands=args.min_cands_per_toplist,
99 dropped_rho=dropped_rho,
101 datatuple += (newdata,)
103 data = np.concatenate(datatuple)
104 sorted_inds = data[:, rho_col].argsort()[::-1]
105 data = data[sorted_inds]
109 "%.10f %.10f %.10g %.10f %.10g %.5f %.10g %.10g %.10g\n" % tuple(line)
111 print(
"Highest discarded candidate SNR was %f" % dropped_rho)
def read_and_sort_toplist(filename, min_snr=float("inf"), min_cands=-1, dropped_rho=float("-inf"))