Skip to content

Commit

Permalink
add median_sigma to fit_by_template and fit_over_multiparam (gwastro#…
Browse files Browse the repository at this point in the history
…2843)

* add median_sigma to fit_by_template and fit_over_multiparam

* fix: accidentally hardcoded H1

* logging

* couple of fixes to help/comments.

prefer not to build statements that something is 'recent' into code that might stay around for years
  • Loading branch information
Gareth Davies authored and OliverEdy committed Apr 3, 2023
1 parent 07b9c88 commit 1582e90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions bin/hdfcoinc/pycbc_fit_sngls_by_template
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_stat(statchoice, trigs, threshold):
# Return boolean area that selects the triggers above threshold
# along with the stat values above threshold
return np.concatenate(select), np.concatenate(stat)

#### MAIN ####

parser = argparse.ArgumentParser(usage="",
Expand Down Expand Up @@ -309,6 +310,10 @@ for tnum in trange:
if (tnum % 1000 == 0): logging.info('Fitted template %i / %i' %
(tnum - tmin, tmax - tmin))

logging.info("Calculating median sigma for each template")
median_sigma = [np.sqrt(np.median(trigf[args.ifo + '/sigmasq'][reg])) for reg in
trigf[args.ifo + '/sigmasq_template'][:]]

outfile = h5py.File(args.output, 'w')
# store template-dependent fit output
outfile.create_dataset("template_id", data=trange)
Expand All @@ -317,6 +322,7 @@ outfile.create_dataset("fit_coeff", data=fits)
if args.save_trig_param:
outfile.create_dataset("template_param", data=tpars)
outfile.create_dataset("count_in_template", data=counts_total)
outfile.create_dataset("median_sigma", data=median_sigma)
# add some metadata
outfile.attrs.create("ifo", data=args.ifo.encode())
outfile.attrs.create("fit_function", data=args.fit_function.encode())
Expand Down
14 changes: 8 additions & 6 deletions bin/hdfcoinc/pycbc_fit_sngls_over_multiparam
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ parser.add_argument("--fit-param", nargs='+',
"template fit file or choose from mchirp, mtotal, "
"chi_eff, eta, tau_0, tau_3, template_duration, "
"a frequency cutoff in pnutils or a frequency function"
"in LALSimulation. If the background is regressed over "
"multiple parameters, one can simply provide them as "
"a list.")
"in LALSimulation. To regress the background over "
"multiple parameters, provide them as a list.")
parser.add_argument("--approximant", default="SEOBNRv4",
help="Approximant for template duration. Default SEOBNRv4")
parser.add_argument("--f-lower", type=float, default=0.,
Expand All @@ -60,8 +59,7 @@ parser.add_argument("--log-param", nargs='+',
help="Take the log of the fit param before smoothing.")
parser.add_argument("--smoothing-width", type=float, nargs='+', required=True,
help="Distance in the space of fit param values (or the "
"logs of them) to smooth over. Required. For log "
"template duration, try 0.2"
"logs of them) to smooth over. Required. "
"This must be a list corresponding to the smoothing "
"parameters.")
args = parser.parse_args()
Expand Down Expand Up @@ -95,7 +93,7 @@ for param, slog in zip(args.fit_param, args.log_param):
else:
raise ValueError("invalid log param argument, use 'true', or 'false'")

if 'count_in_template' in fits.keys(): # recently introduced dataset
if 'count_in_template' in fits.keys(): # older files may not have this dataset
tcount = True
else:
tcount = False
Expand Down Expand Up @@ -132,6 +130,10 @@ outfile = h5py.File(args.output, 'w')
outfile['template_id'] = tid
outfile['count_above_thresh'] = nabove_smoothed
outfile['fit_coeff'] = alpha_smoothed
try:
outfile['median_sigma'] = fits['median_sigma'][:]
except KeyError:
logging.info('Median_sigma dataset not present in input file')
if tcount: outfile['count_in_template'] = ntotal_smoothed

for param, vals, slog in zip(args.fit_param, parvals, args.log_param):
Expand Down

0 comments on commit 1582e90

Please sign in to comment.