Skip to content
Snippets Groups Projects
Commit 613f6194 authored by Matthew David Pitkin's avatar Matthew David Pitkin
Browse files

Write/read bilby priors as a JSON dictionary to/from HDF5 file output

parent 2b12d397
No related branches found
No related tags found
No related merge requests found
......@@ -358,10 +358,25 @@ class Result(object):
if os.path.isfile(filename):
dictionary = deepdish.io.load(filename)
# Some versions of deepdish/pytables return the dictionanary as
# Some versions of deepdish/pytables return the dictionary as
# a dictionary with a key 'data'
if len(dictionary) == 1 and 'data' in dictionary:
dictionary = dictionary['data']
if "priors" in dictionary:
# parse priors from JSON string (allowing for backwards
# compatibility)
if not isinstance(dictionary["priors"], PriorDict):
try:
dictionary["priors"] = PriorDict._get_from_json_dict(
dictionary["priors"]
)
except Exception as e:
raise IOError(
"Unable to parse priors from '{}':\n{}".format(
filename, e,
)
)
try:
if isinstance(dictionary.get('posterior', None), dict):
dictionary['posterior'] = pd.DataFrame(dictionary['posterior'])
......@@ -609,8 +624,9 @@ class Result(object):
dictionary['sampler_kwargs'][key] = str(dictionary['sampler_kwargs'])
try:
# convert priors to JSON dictionary for both JSON and hdf5 files
dictionary["priors"] = dictionary["priors"]._get_json_dict()
if extension == 'json':
dictionary["priors"] = dictionary["priors"]._get_json_dict()
if gzip:
import gzip
# encode to a string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment