Commit 3a5771ef authored by Gregory Ashton's avatar Gregory Ashton

Fix writing of the prior

- Add the label to the saved prior
- Remove obsolete write function

Fixes one issue in #75
parent 1d347f56
Pipeline #20588 passed with stages
in 12 minutes and 58 seconds
......@@ -557,7 +557,7 @@ def test_redundancy(key, prior):
return redundant
def write_priors_to_file(priors, outdir):
def write_priors_to_file(priors, outdir, label):
"""
Write the prior distribution to file.
......@@ -565,13 +565,12 @@ def write_priors_to_file(priors, outdir):
----------
priors: dict
priors used
outdir: str
output directory
outdir, label: str
output directory and label
"""
if outdir[-1] != "/":
outdir += "/"
prior_file = outdir + "prior.txt"
logging.info("Writing priors to {}".format(prior_file))
prior_file = os.path.join(outdir, "{}_prior.txt".format(label))
logging.debug("Writing priors to {}".format(prior_file))
with open(prior_file, "w") as outfile:
for key in priors:
outfile.write("prior['{}'] = {}\n".format(key, priors[key]))
......@@ -186,17 +186,6 @@ class Result(dict):
"""
logging.warning("plot_distributions deprecated")
def write_prior_to_file(self, outdir):
"""
Write the prior distribution to file.
:return:
"""
outfile = outdir + '.prior'
with open(outfile, "w") as prior_file:
for key in self.prior:
prior_file.write(self.prior[key])
def samples_to_data_frame(self, likelihood=None, priors=None, conversion_function=None):
"""
Convert array of samples to data frame.
......
......@@ -495,7 +495,7 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
if priors is None:
priors = dict()
priors = fill_priors(priors, likelihood)
tupak.prior.write_priors_to_file(priors, outdir)
tupak.prior.write_priors_to_file(priors, outdir, label)
if implemented_samplers.__contains__(sampler.title()):
sampler_class = globals()[sampler.title()]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment