From 1582e90dd9e5089d249157544414b13c6adacc97 Mon Sep 17 00:00:00 2001 From: Gareth Davies Date: Thu, 18 Jul 2019 15:03:26 +0200 Subject: [PATCH] add median_sigma to fit_by_template and fit_over_multiparam (#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 --- bin/hdfcoinc/pycbc_fit_sngls_by_template | 6 ++++++ bin/hdfcoinc/pycbc_fit_sngls_over_multiparam | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/hdfcoinc/pycbc_fit_sngls_by_template b/bin/hdfcoinc/pycbc_fit_sngls_by_template index 389cf3d388d..474cbbe70db 100755 --- a/bin/hdfcoinc/pycbc_fit_sngls_by_template +++ b/bin/hdfcoinc/pycbc_fit_sngls_by_template @@ -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="", @@ -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) @@ -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()) diff --git a/bin/hdfcoinc/pycbc_fit_sngls_over_multiparam b/bin/hdfcoinc/pycbc_fit_sngls_over_multiparam index 4d3a9b445e4..2642c9ba665 100755 --- a/bin/hdfcoinc/pycbc_fit_sngls_over_multiparam +++ b/bin/hdfcoinc/pycbc_fit_sngls_over_multiparam @@ -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., @@ -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() @@ -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 @@ -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):