Skip to content
Snippets Groups Projects

gstlal_inspiral_svd_bank: add time-reversed template functionality

Merged Patrick Godwin requested to merge add_time_reversed_svd_bank into master
@@ -81,6 +81,8 @@ from gstlal.stats import inspiral_lr
parser = OptionParser(description = __doc__)
parser.add_option("--flow", metavar = "Hz", type = "float", default = 40.0, help = "Set the template low-frequency cut-off (default = 40.0).")
parser.add_option("--sample-rate", metavar = "Hz", type = "int", help = "Set the sample rate. If not set, the sample rate will be based on the template frequency. The sample rate must be at least twice the highest frequency in the templates. If provided it must be a power of two")
parser.add_option("--append-time-reversed-template", action = "store_true", help = "A shortcut for appending time reversed template bank to the output file without manually adding --bank-type. (optional; cannot combined with --bank-type.)")
parser.add_option("--bank-type", type= "string", metavar = "N", action = "append", default = [], help = "Define the type of the template bank: is it used to produce signal candidates or it is used to produce noise candidate? Use 'noise_model' to indicate that it's for noise candidates or 'signal_model' to indicate for signal candidates (default). (optional; if provided, it must be as many as --template-bank).")
parser.add_option("--padding", metavar = "pad", type = "float", default = 1.5, help = "Fractional amount to pad time slices.")
parser.add_option("--svd-tolerance", metavar = "match", type = "float", default = 0.9999, help = "Set the SVD reconstruction tolerance (default = 0.9999).")
parser.add_option("--reference-psd", metavar = "filename", help = "Load the spectrum from this LIGO light-weight XML file (required).")
@@ -100,12 +102,24 @@ options, template_banks = parser.parse_args()
if options.template_bank_cache:
template_banks.extend([CacheEntry(line).url for line in open(options.template_bank_cache)])
if len(options.bank_type) > 0 and options.append_time_reversed_template:
raise ValueError("--bank-type and --append-time-reversed-template cannot be used together")
if len(options.bank_type) == 0:
options.bank_type = ["signal_model"] * len(template_banks)
required_options = ("reference_psd", "write_svd_bank")
missing_options = [option for option in required_options if getattr(options, option) is None]
if missing_options:
raise ValueError("missing required option(s) %s" % ", ".join("--%s" % option.replace("_", "-") for option in sorted(missing_options)))
if not (len(template_banks) == len(options.bank_type)):
raise ValueError("must give --template-bank, --bank-type options in equal amounts")
if any([bank_type not in ("signal_model", "noise_model") for bank_type in options.bank_type]):
raise ValueError("--bank-type must be either 'signal_model' or 'noise_model'")
if not options.autocorrelation_length % 2:
raise ValueError("--autocorrelation-length must be odd")
@@ -140,19 +154,29 @@ cliplefts, cliprights, bank_ids = extract_subbank_info(template_banks)
cliplefts = [int(cl) for cl in cliplefts]
cliprights = [int(cr) for cr in cliprights]
psd = lal.series.read_psd_xmldoc(ligolw_utils.load_filename(options.reference_psd, verbose=options.verbose, contenthandler=lal.series.PSDContentHandler))
if options.append_time_reversed_template:
ID, N = bank_ids[-1].split("_")
bank_ids += [ID + "_" + str(i) for i in range(int(N)+1, int(N) + len(template_banks) + 1)]
options.bank_type = ["signal_model"] * len(template_banks) + ["noise_model"] * len(template_banks)
cliplefts += cliplefts
cliprights += cliprights
template_banks += template_banks
psd = lal.series.read_psd_xmldoc(ligolw_utils.load_filename(options.reference_psd, verbose=options.verbose, contenthandler=lal.series.PSDContentHandler))
svd_bank.write_bank(
options.write_svd_bank,
[svd_bank.build_bank(
banks = []
for (template_bank, bank_id, clipleft, clipright, bank_type) in zip(template_banks, bank_ids, cliplefts, cliprights, options.bank_type):
bank = svd_bank.build_bank(
template_bank,
psd,
options.flow,
options.ortho_gate_fap,
inspiral_lr.LnLRDensity.snr_min,
options.svd_tolerance,
clipleft,
clipright,
padding = options.padding,
bank_type = bank_type,
verbose = options.verbose,
autocorrelation_length = options.autocorrelation_length,
samples_min = options.samples_min,
@@ -163,8 +187,7 @@ svd_bank.write_bank(
contenthandler = svd_bank.DefaultContentHandler,
sample_rate = options.sample_rate,
instrument_override = options.instrument_override
) for (template_bank, bank_id) in zip(template_banks, bank_ids)],
psd,
cliplefts,
cliprights
)
)
banks.append(bank)
svd_bank.write_bank(options.write_svd_bank, banks, psd)
Loading