# # check for saved work # if opts.checkpoint and os.path.exists(opts.output_filename + "_checkpoint.gz"): xmldoc = utils.load_filename(opts.output_filename + "_checkpoint.gz", contenthandler=ContentHandler) tbl = lsctables.SnglInspiralTable.get_table(xmldoc) [ bank.insort(t) for t in Bank.from_sngls( tbl, tmplt_class, 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) ] if opts.verbose: print >> sys.stdout, "Found checkpoint file %s with %d precomputed templates." % ( opts.output_filename + "_checkpoint.gz", len(tbl)) print >> sys.stdout, "Resuming from checkpoint with %d total templates..." % len( bank) # reset rng state rng_state = np.load(opts.output_filename + "_checkpoint.rng.npz")
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 # if opts.checkpoint and os.path.exists( fout + "_checkpoint.gz" ): xmldoc = utils.load_filename(fout + "_checkpoint.gz", contenthandler=ContentHandler) tbl = table.get_table(xmldoc, lsctables.SnglInspiralTable.tableName) [bank.insort(t) for t in Bank.from_sngls(tbl, 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)]
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(
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..." # Choose proposal function # TODO: Implement more of these # populate params dictionary to be passed to the generators params = {'mass1': (opts.mass1_min, opts.mass1_max), 'mass2': (opts.mass2_min, opts.mass2_max), 'mtotal': (opts.mtotal_min, opts.mtotal_max), 'mratio': (opts.qmin, opts.qmax), 'mchirp': (opts.mchirp_min, opts.mchirp_max),
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, "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) 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: