sims = lsctables.SimInspiralTable.get_table(xmldoc2)

#
# sometime inspinj doesn't give us everything we want, so we give the
# user a little extra control here over the injections acutally used
#
newtbl = lsctables.SimInspiralTable()
for s in sims:
    if 1./opts.mratio_max <= s.mass1/s.mass2 <= opts.mratio_max and opts.mtotal_min <= s.mass1 + s.mass2 <= opts.mtotal_max and lalsim.SimIMRSEOBNRv4ROMTimeOfFrequency(opts.flow, s.mass1 * MSUN_SI, s.mass2* MSUN_SI, s.spin1z, s.spin2z) > opts.duration_min:
        s.polarization = np.random.uniform(0, 2*np.pi)
        newtbl.append(s)
sims = newtbl

h5file.create_dataset("/sim_inspiral", data=ligolw_table_to_array(sims), compression='gzip', compression_opts=1)
h5file.flush()
inj_wfs = Bank.from_sims(sims, inj_approx, noise_model, flow)
del xmldoc2, sims[:]
if verbose:
    print "Loaded %d injections" % len(inj_wfs)
    inj_format = "".join("%s: %s   " % name_format for name_format in zip(inj_approx.param_names, inj_approx.param_formats))

# main worker loop
match_map = np.empty(len(inj_wfs), dtype=[("inj_index", np.uint32), ("inj_sigmasq", np.float32), ("match", np.float32), ("best_match_tmplt_index", np.uint32)])
for inj_ind, inj_wf in enumerate(inj_wfs):

    if verbose:
        print "injection %d/%d" % (inj_ind+1, len(inj_wfs))
        print inj_format % inj_wf.params

    # NB: sigmasq set during argmax_match
    match_tup = bank.argmax_match(inj_wf)
    # so set the PSD to infinity above the max original frequency
    noise_model = lambda g: np.where(g < f_max_orig, np.exp(interpolator(g)),
                                     np.inf)

else:
    noise_model = noise_models[opts.noise_model]

#
# initialize the bank
#
bank = Bank(noise_model,
            opts.flow,
            opts.use_metric,
            opts.cache_waveforms,
            opts.neighborhood_size,
            opts.neighborhood_param,
            coarse_match_df=opts.coarse_match_df,
            iterative_match_df_max=opts.iterative_match_df_max,
            fhigh_max=opts.fhigh_max,
            optimize_flow=opts.optimize_flow,
            flow_column=opts.flow_column)
for file_approx in opts.bank_seed:

    # if no approximant specified, use same approximant as the
    # templates we will add
    if len(file_approx.split(":")) == 1:
        seed_file = file_approx
        approx = opts.approximant
    else:
        # if this fails, you have an input error
        seed_file, approx = file_approx.split(":")
Esempio n. 3
0
#    cvs_repository="sbank", cvs_entry_time=git_version.date) FIXME
process = ligolw_process.register_to_xmldoc(
    fake_xmldoc,
    "lalapps_cbc_sbank_sim",
    opts_dict,
    version="no version",
    cvs_repository="sbank",
    cvs_entry_time=strftime('%Y/%m/%d %H:%M:%S'))

# load templates
#
# initialize the bank
#
bank = Bank(noise_model,
            flow,
            use_metric=False,
            cache_waveforms=opts.cache_waveforms,
            nhood_size=opts.neighborhood_size,
            nhood_param=opts.neighborhood_param)
for file_approx in opts.template_bank:

    # if no approximant specified, take from opts.template_approx
    if len(file_approx.split(":")) == 1:
        seed_file = file_approx
        approx = opts.template_approx
    else:
        # if this fails, you have an input error
        seed_file, approx = file_approx.split(":")

    # add templates to bank
    tmpdoc = utils.load_filename(seed_file, contenthandler=ContentHandler)
    sngl_inspiral = lsctables.SnglInspiralTable.get_table(tmpdoc)
    noise_model = lambda g: np.where(g < f_max_orig, np.exp(interpolator(g)), np.inf)
else:
    noise_model = noise_models[opts.noise_model]

# Set up PSD for metric computation
# calling into pylal, so need pylal types
psd = REAL8FrequencySeries(name="psd", f0=0., deltaF=1., data=get_PSD(1., opts.flow, 1570., noise_model))


#
# seed the bank, if applicable
#
if opts.bank_seed is None:
    # seed the process with an empty bank
    # the first proposal will always be accepted
    bank = Bank(waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max)
else:
    # seed bank with input bank. we do not prune the bank
    # for overcoverage, but take it as is
    tmpdoc = utils.load_filename(opts.bank_seed, contenthandler=ContentHandler)
    sngl_inspiral = table.get_table(tmpdoc, lsctables.SnglInspiralTable.tableName)
    bank = Bank.from_sngls(sngl_inspiral, waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms, opts.neighborhood_size, opts.neighborhood_param, coarse_match_df=opts.coarse_match_df, iterative_match_df_max=opts.iterative_match_df_max, fhigh_max=opts.fhigh_max)

    tmpdoc.unlink()
    del sngl_inspiral, tmpdoc
    if opts.verbose:
        print>>sys.stdout,"Initialized the template bank to seed file %s with %d precomputed templates." % (opts.bank_seed, len(bank))


#
# check for saved work
    opts_dict,
    version="no version",
    cvs_repository="sbank",
    cvs_entry_time=strftime("%Y/%m/%d %H:%M:%S"),
)
h5file = H5File("%s.h5" % usertag, "w")

# load templates
xmldoc = utils.load_filename(tmplt_file, contenthandler=ContentHandler)
ligolw_copy_process(xmldoc, fake_xmldoc)
sngls = table.get_table(xmldoc, lsctables.SnglInspiralTable.tableName)
bank = Bank.from_sngls(
    sngls,
    tmplt_approx,
    noise_model,
    flow,
    use_metric=False,
    cache_waveforms=opts.cache_waveforms,
    nhood_size=opts.neighborhood_size,
    nhood_param=opts.neighborhood_param,
)
# write bank to h5 file, but note that from_sngls() has resorted the
# bank by neighborhood_param
sngls = lsctables.SnglInspiralTable()
for s in bank._templates:
    sngls.append(s.to_sngl())
h5file.create_dataset("/sngl_inspiral", data=ligolw_table_to_array(sngls), compression="gzip", compression_opts=1)
h5file.flush()
del xmldoc, sngls[:]
if verbose:
    print "Loaded %d templates" % len(bank)
    tmplt_format = "".join(
psd = REAL8FrequencySeries(name="psd",
                           f0=0.,
                           deltaF=1.,
                           data=get_PSD(1., opts.flow, 1570., noise_model))

#
# seed the bank, if applicable
#
if opts.bank_seed is None:
    # seed the process with an empty bank
    # the first proposal will always be accepted
    bank = Bank(waveform,
                noise_model,
                opts.flow,
                opts.use_metric,
                opts.cache_waveforms,
                opts.neighborhood_size,
                opts.neighborhood_param,
                coarse_match_df=opts.coarse_match_df,
                iterative_match_df_max=opts.iterative_match_df_max,
                fhigh_max=opts.fhigh_max)
else:
    # seed bank with input bank. we do not prune the bank
    # for overcoverage, but take it as is
    tmpdoc = utils.load_filename(opts.bank_seed, contenthandler=ContentHandler)
    sngl_inspiral = table.get_table(tmpdoc,
                                    lsctables.SnglInspiralTable.tableName)
    bank = Bank.from_sngls(sngl_inspiral,
                           waveform,
                           noise_model,
                           opts.flow,
                           opts.use_metric,
Esempio n. 7
0
waveform = waveforms[opts.approximant]

# Choose noise model
if opts.reference_psd is not None:
    psd = read_psd(opts.reference_psd)[opts.instrument]
    f_orig = psd.f0 + np.arange(len(psd.data)) * psd.deltaF
    interpolator = UnivariateSpline(f_orig, np.log(psd.data), s=0)
    noise_model = lambda g: np.exp(interpolator(g))
else:
    noise_model = noise_models[opts.noise_model]

# Seed the bank
if opts.bank_seed is None:
    # seed the process with an empty bank
    # the first proposal will always be accepted
    bank = Bank(waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms)
else:
    # seed bank with input bank. we do not prune the bank
    # for overcoverage, but take it as is
    if opts.verbose:
        print>>sys.stdout,"Seeding the template bank..."
    tmpdoc = utils.load_filename(opts.bank_seed, contenthandler=ContentHandler)
    sngl_inspiral = table.get_table(tmpdoc, lsctables.SnglInspiralTable.tableName)
    bank = Bank.from_sngls(sngl_inspiral, waveform, noise_model, opts.flow, opts.use_metric, opts.cache_waveforms)

    tmpdoc.unlink()
    del sngl_inspiral, tmpdoc
    if opts.verbose:
        print>>sys.stdout,"\tinitial bank size: %d"%len(bank)
        print>>sys.stdout,"Filling regions of parameter space not covered by bank seed..."
Esempio n. 8
0
opts_dict = dict((k, v) for k, v in opts.__dict__.iteritems() if v is not False and v is not None)
#process = ligolw_process.register_to_xmldoc(fake_xmldoc, "lalapps_cbc_sbank_sim", FIXME
#    opts_dict, version=git_version.tag or git_version.id, FIXME
#    cvs_repository="sbank", cvs_entry_time=git_version.date) FIXME
process = ligolw_process.register_to_xmldoc(fake_xmldoc, "lalapps_cbc_sbank_sim",
    opts_dict, version="no version",
    cvs_repository="sbank", cvs_entry_time=strftime('%Y/%m/%d %H:%M:%S'))
h5file = H5File("%s.h5" % usertag, "w")

# load templates
xmldoc = utils.load_filename(tmplt_file, contenthandler=ContentHandler)
ligolw_copy_process(xmldoc, fake_xmldoc)
sngls = table.get_table(xmldoc, lsctables.SnglInspiralTable.tableName)
h5file.create_dataset("/sngl_inspiral", data=ligolw_table_to_array(sngls), compression='gzip', compression_opts=1)
h5file.flush()
bank = Bank.from_sngls(sngls, tmplt_approx, noise_model, flow, use_metric=False, cache_waveforms=opts.cache_waveforms)
del xmldoc, sngls[:]
if verbose:
    print "Loaded %d templates" % len(bank)
    tmplt_format = "".join("%s: %s   " % name_format for name_format in zip(tmplt_approx.param_names, tmplt_approx.param_formats))

# pick injection parameters
xmldoc2 = utils.load_filename(inj_file, contenthandler=ContentHandler)
ligolw_copy_process(xmldoc2, fake_xmldoc)
sims = table.get_table(xmldoc2, lsctables.SimInspiralTable.tableName)

#
# sort sims by mchirp before writing back to disk Bank.from_sims()
# sorts the waveforms by mchirp so we need to also sort here to get
# the injection --> best match mapping correct later
#
fake_xmldoc = ligolw.Document()
fake_xmldoc.appendChild(ligolw.LIGO_LW())
opts_dict = dict((k, v) for k, v in opts.__dict__.iteritems() if v is not False and v is not None)
#process = ligolw_process.register_to_xmldoc(fake_xmldoc, "lalapps_cbc_sbank_sim", FIXME
#    opts_dict, version=git_version.tag or git_version.id, FIXME
#    cvs_repository="sbank", cvs_entry_time=git_version.date) FIXME
process = ligolw_process.register_to_xmldoc(fake_xmldoc, "lalapps_cbc_sbank_sim",
    opts_dict, version="no version",
    cvs_repository="sbank", cvs_entry_time=strftime('%Y/%m/%d %H:%M:%S'))
h5file = H5File("%s.h5" % usertag, "w")

# load templates
#
# initialize the bank
#
bank = Bank(noise_model, flow, use_metric=False, cache_waveforms=opts.cache_waveforms, nhood_size=opts.neighborhood_size, nhood_param=opts.neighborhood_param)
for file_approx in opts.template_bank:

    # if no approximant specified, take from opts.template_approx
    if len(file_approx.split(":")) == 1:
        seed_file = file_approx
        approx = opts.template_approx
    else:
        # if this fails, you have an input error
        seed_file, approx = file_approx.split(":")

    # add templates to bank
    tmpdoc = utils.load_filename(seed_file, contenthandler=ContentHandler)
    sngl_inspiral = lsctables.SnglInspiralTable.get_table(tmpdoc)
    seed_waveform = waveforms[approx]
    bank.add_from_sngls(sngl_inspiral, seed_waveform)