-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make start file from dynesty output (#3444)
* script to convert dynesty to emcee_pt_file * test * update * update * fixes * update * fixes
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/env python | ||
""" Convert inference file to parallel temperred compatible start format | ||
""" | ||
|
||
import argparse | ||
import numpy | ||
import h5py | ||
from numpy.random import choice | ||
from pycbc.inference.io import loadfile | ||
from pycbc.inference.sampler import samplers | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--input-file') | ||
parser.add_argument('--output-file') | ||
parser.add_argument('--sampler', default='emcee_pt', | ||
help="The output sampler type, if none, we assume emcee_pt") | ||
parser.add_argument('--ntemps', type=int) | ||
parser.add_argument('--nwalkers', type=int) | ||
args = parser.parse_args() | ||
|
||
# populate an emcee start file with | ||
# values chosen from a dynesty file | ||
# each temperature and walker will get a random | ||
# point from the dynesty output | ||
|
||
ntemps = args.ntemps | ||
nwalkers = args.nwalkers | ||
|
||
f = loadfile(args.input_file) | ||
params = list(f.variable_params) + ['loglikelihood'] | ||
samples = f.read_samples(params) | ||
nsample = len(samples) | ||
|
||
# These are the ids we'll use for the temps / walkers | ||
use = choice(nsample, replace=False, size=ntemps * nwalkers) | ||
|
||
o = loadfile(args.output_file, 'w', filetype=samplers[args.sampler]._io.name) | ||
for k in params: | ||
data = samples[k][use] | ||
o['samples/' + k] = data.reshape(ntemps, nwalkers, 1) | ||
|
||
o.attrs['static_params'] = [] | ||
o.attrs['variable_params'] = f.variable_params | ||
o.create_group('sampler_info') | ||
o['sampler_info'].attrs['nchains'] = nwalkers | ||
|
||
o.close() | ||
f.close() |