diff --git a/peyote/result.py b/peyote/result.py index 372b7cd27b379d4f796f3785a9471ec5d99ee178..fb12a82ebfdf36650ea05020a1ecd49564ec8182 100644 --- a/peyote/result.py +++ b/peyote/result.py @@ -1,6 +1,6 @@ import logging import os -import pickle +import deepdish class Result(dict): @@ -24,7 +24,7 @@ class Result(dict): self.logzerr)) def save_to_file(self, outdir, label): - file_name = '{}/{}_results.p'.format(outdir, label) + file_name = '{}/{}_result.h5'.format(outdir, label) if os.path.isdir(outdir) is False: os.makedirs(outdir) if os.path.isfile(file_name): @@ -34,5 +34,4 @@ class Result(dict): os.rename(file_name, file_name + '.old') logging.info("Saving result to {}".format(file_name)) - with open(file_name, 'wb+') as f: - pickle.dump(self, f) + deepdish.io.save(file_name, self) diff --git a/peyote/sampler.py b/peyote/sampler.py index 6cf6320458bd91bc57ab72f1900af46d29572462..d8c426d0843cd41248641b3c0e6de726e975e708 100644 --- a/peyote/sampler.py +++ b/peyote/sampler.py @@ -247,7 +247,7 @@ class Pymultinest(Sampler): def run_sampler(likelihood, priors, label='label', outdir='outdir', - sampler='nestle', use_ratio=False, + sampler='nestle', use_ratio=False, injection_parameters=None, **sampler_kwargs): """ The primary interface to easy parameter estimation @@ -268,6 +268,9 @@ def run_sampler(likelihood, priors, label='label', outdir='outdir', use_ratio: bool (False) If True, use the likelihood's loglikelihood_ratio, rather than just the loglikelhood. + injection_parameters: dict + A dictionary of injection parameters used in creating the data (if + using simulated data). Appended to the result object and saved. **sampler_kwargs: All kwargs are passed directly to the samplers `run` functino @@ -289,7 +292,7 @@ def run_sampler(likelihood, priors, label='label', outdir='outdir', result = sampler.run_sampler() result.noise_logz = likelihood.noise_log_likelihood() result.log_bayes_factor = result.logz - result.noise_logz - print("") + result.injection_parameters = injection_parameters result.save_to_file(outdir=outdir, label=label) return result, sampler else: diff --git a/requirements.txt b/requirements.txt index c68adb35ece2399d821369c2fc624bb0479bc18e..31cb609d557582f664e393911d1756f5cbf8b7d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ gwsurrogate NRSur7dq2 chainconsumer nestle +deepdish diff --git a/tutorials/BasicTutorial.py b/tutorials/BasicTutorial.py index 927d9177312464f2254dd60dd7c58aa36967515e..3828882701e681cc44521a1db19c1780486c7ea9 100644 --- a/tutorials/BasicTutorial.py +++ b/tutorials/BasicTutorial.py @@ -84,6 +84,6 @@ sampling_parameters['luminosity_distance'] = peyote.prior.Uniform(lower=30, uppe result, sampler = peyote.sampler.run_sampler( likelihood, priors=sampling_parameters, label='BasicTutorial', - sampler='nestle', verbose=True) + sampler='nestle', verbose=True, injection_parameters=injection_parameters) sampler.plot_corner() print(result)