def getParameter(parameter): ## Prepare to read in parameters datafile = folder + data_name fp = InferenceFile("%s" % datafile, "r") ## Take last iteration of each walker parameter_values = np.array([]) for aa in range(num_walkers): samples = fp.read_samples("%s" % parameter, walkers=aa) temp = getattr(samples, parameter) parameter_values = np.append(parameter_values, temp[-1]) return parameter_values
def results_from_cli(opts, load_samples=True, walkers=None): """ Loads an inference result file along with any labels associated with it from the command line options. Parameters ---------- opts : ArgumentParser options The options from the command line. load_samples : {True, bool} Load samples from the results file using the parameters, thin_start, and thin_interval specified in the options. The samples are returned as a WaveformArray instance. walkers : {None, (list of) int} If loading samples, the walkers to load from. If None, will load from all walkers. Returns ------- result_file : pycbc.io.InferenceFile The result file as an InferenceFile. parameters : list List of the parameters to use, parsed from the parameters option. labels : list List of labels to associate with the parameters. samples : {None, WaveformArray} If load_samples, the samples as a WaveformArray; otherwise, None. """ logging.info("Reading input file") fp = InferenceFile(opts.input_file, "r") parameters = fp.variable_args if opts.parameters is None \ else opts.parameters # load the labels labels = [] for ii, p in enumerate(parameters): if len(p.split(':')) == 2: p, label = p.split(':') parameters[ii] = p else: label = fp.read_label(p) labels.append(label) if load_samples: logging.info("Loading samples") samples = fp.read_samples(parameters, walkers=walkers, thin_start=opts.thin_start, thin_interval=opts.thin_interval, thin_end=opts.thin_end, iteration=opts.iteration) else: samples = None return fp, parameters, labels, samples
def results_from_cli(opts, load_samples=True, walkers=None): """ Loads an inference result file along with any labels associated with it from the command line options. Parameters ---------- opts : ArgumentParser options The options from the command line. load_samples : {True, bool} Load samples from the results file using the parameters, thin_start, and thin_interval specified in the options. The samples are returned as a WaveformArray instance. walkers : {None, (list of) int} If loading samples, the walkers to load from. If None, will load from all walkers. Returns ------- result_file : pycbc.io.InferenceFile The result file as an InferenceFile. parameters : list List of the parameters to use, parsed from the parameters option. labels : list List of labels to associate with the parameters. samples : {None, WaveformArray} If load_samples, the samples as a WaveformArray; otherwise, None. """ logging.info("Reading input file") fp = InferenceFile(opts.input_file, "r") parameters = fp.variable_args if opts.parameters is None \ else opts.parameters # load the labels labels = [] for ii,p in enumerate(parameters): if len(p.split(':')) == 2: p, label = p.split(':') parameters[ii] = p else: label = fp.read_label(p) labels.append(label) if load_samples: logging.info("Loading samples") samples = fp.read_samples(parameters, walkers=walkers, thin_start=opts.thin_start, thin_interval=opts.thin_interval, thin_end=opts.thin_end) else: samples = None return fp, parameters, labels, samples
def results_from_cli(opts, load_samples=True, **kwargs): """ Loads an inference result file along with any labels associated with it from the command line options. Parameters ---------- opts : ArgumentParser options The options from the command line. load_samples : {True, bool} Load samples from the results file using the parameters, thin_start, and thin_interval specified in the options. The samples are returned as a FieldArray instance. \**kwargs : All other keyword arguments are passed to the InferenceFile's read_samples function. Returns ------- result_file : pycbc.io.InferenceFile The result file as an InferenceFile. parameters : list List of the parameters to use, parsed from the parameters option. labels : list List of labels to associate with the parameters. samples : {None, FieldArray} If load_samples, the samples as a FieldArray; otherwise, None. """ logging.info("Reading input file") fp = InferenceFile(opts.input_file, "r") parameters = fp.variable_args if opts.parameters is None \ else opts.parameters # load the labels parameters, ldict = parse_parameters_opt(parameters) # convert labels dict to list labels = [] for p in parameters: try: label = ldict[p] except KeyError: label = fp.read_label(p) labels.append(label) # load the samples if load_samples: logging.info("Loading samples") # check if need extra parameters for a non-sampling parameter file_parameters, ts = transforms.get_common_cbc_transforms( parameters, fp.variable_args) # read samples from file samples = fp.read_samples(file_parameters, thin_start=opts.thin_start, thin_interval=opts.thin_interval, thin_end=opts.thin_end, iteration=opts.iteration, samples_group=opts.parameters_group, **kwargs) # add parameters not included in file samples = transforms.apply_transforms(samples, ts) else: samples = None return fp, parameters, labels, samples
def results_from_cli(opts, load_samples=True, **kwargs): """ Loads an inference result file along with any labels associated with it from the command line options. Parameters ---------- opts : ArgumentParser options The options from the command line. load_samples : {True, bool} Load samples from the results file using the parameters, thin_start, and thin_interval specified in the options. The samples are returned as a FieldArray instance. \**kwargs : All other keyword arguments are passed to the InferenceFile's read_samples function. Returns ------- fp_all : pycbc.io.InferenceFile The result file as an InferenceFile. If more than one input file, then it returns a list. parameters_all : list List of the parameters to use, parsed from the parameters option. If more than one input file, then it returns a list. labels_all : list List of labels to associate with the parameters. If more than one input file, then it returns a list. samples_all : {None, FieldArray} If load_samples, the samples as a FieldArray; otherwise, None. If more than one input file, then it returns a list. """ # lists for files and samples from all input files fp_all = [] parameters_all = [] labels_all = [] samples_all = [] # loop over all input files for input_file in opts.input_file: logging.info("Reading input file %s", input_file) # read input file fp = InferenceFile(input_file, "r") # get parameters and a dict of labels for each parameter parameters = fp.variable_args if opts.parameters is None \ else opts.parameters parameters, ldict = parse_parameters_opt(parameters) # convert labels dict to list labels = [] for p in parameters: try: label = ldict[p] except KeyError: label = fp.read_label(p) labels.append(label) # load the samples if load_samples: logging.info("Loading samples") # check if need extra parameters for a non-sampling parameter file_parameters, ts = transforms.get_common_cbc_transforms( parameters, fp.variable_args) # read samples from file samples = fp.read_samples( file_parameters, thin_start=opts.thin_start, thin_interval=opts.thin_interval, thin_end=opts.thin_end, iteration=opts.iteration, samples_group=opts.parameters_group, **kwargs) # add parameters not included in file samples = transforms.apply_transforms(samples, ts) # else do not read samples else: samples = None # add results to lists from all input files if len(opts.input_file) > 1: fp_all.append(fp) parameters_all.append(parameters) labels_all.append(labels) samples_all.append(samples) # else only one input file then do not return lists else: fp_all = fp parameters_all = parameters labels_all = labels samples_all = samples return fp_all, parameters_all, labels_all, samples_all
import matplotlib.pyplot as plt import numpy as np from pycbc.io import InferenceFile #Pick parameter and file parameter="penis" folder="jobs/20170325-151901/" walker=45 #Set up composite variables data_name="output.hdf" datafile=folder+data_name #Read file and print out length fp = InferenceFile("%s" % datafile, "r") samples = fp.read_samples("%s" % parameter, walkers=walker) temp=getattr(samples,parameter) print temp