Existing metafile bug
Will Farr found a bug when he was trying to read in more than one result file at once. See the traceback below:
from pesummary.gw.file.read import read as GWread
d = GWread('posterior_samples.json')
repeatedly, at some point the loading would fail with an error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/read.py in read(path)
67 try:
---> 68 return PESummary.load_file(path)
69 except Exception:
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/pesummary.py in load_file(cls, path)
64 raise Exception("%s does not exist" % (path))
---> 65 return cls(path)
66
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/pesummary.py in __init__(self, path_to_results_file, **kwargs)
46 def __init__(self, path_to_results_file, **kwargs):
---> 47 super(PESummary, self).__init__(path_to_results_file)
48 load_kwargs = {
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/pesummary.py in __init__(self, path_to_results_file)
50 self.load(self._grab_data_from_pesummary_file)
---> 51 self.samples_dict = None
52
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/pesummary.py in samples_dict(self, samples_dict)
190 likelihood_inds = [self.parameters[idx].index("log_likelihood") for
--> 191 idx in range(len(self.labels))]
192 likelihoods = [[i[likelihood_inds[idx]] for i in self.samples[idx]]
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/pesummary.py in <listcomp>(.0)
190 likelihood_inds = [self.parameters[idx].index("log_likelihood") for
--> 191 idx in range(len(self.labels))]
192 likelihoods = [[i[likelihood_inds[idx]] for i in self.samples[idx]]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/default.py in __init__(self, path_to_results_file)
40 try:
---> 41 self.load(self.load_function)
42 except Exception:
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/base_read.py in load(self, function, **kwargs)
46 data = self.load_from_function(
---> 47 function, self.path_to_results_file, **kwargs)
48 parameters, samples = self.translate_parameters(
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/base_read.py in load_from_function(function, path_to_file, **kwargs)
40 """
---> 41 return function(path_to_file, **kwargs)
42
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/default.py in _grab_data_from_json_file(path)
75 parameters, samples = GWRead._grab_params_and_samples_from_json_file(
---> 76 path)
77 injection = {i: float("nan") for i in parameters}
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/base_read.py in _grab_params_and_samples_from_json_file(path)
207 else reduced_data[j][i]["real"] for j in parameters] for i in
--> 208 range(len(reduced_data[parameters[0]]))]
209 return parameters, samples
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/base_read.py in <listcomp>(.0)
206 reduced_data[j][i] if not isinstance(reduced_data[j][i], dict)
--> 207 else reduced_data[j][i]["real"] for j in parameters] for i in
208 range(len(reduced_data[parameters[0]]))]
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/core/file/formats/base_read.py in <listcomp>(.0)
206 reduced_data[j][i] if not isinstance(reduced_data[j][i], dict)
--> 207 else reduced_data[j][i]["real"] for j in parameters] for i in
208 range(len(reduced_data[parameters[0]]))]
KeyError: 0
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-27-62f2bbe106df> in <module>
----> 1 d = GWread('/Users/wfarr/Downloads/posterior_samples-2.json')
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/read.py in read(path)
68 return PESummary.load_file(path)
69 except Exception:
---> 70 return Default.load_file(path)
71 else:
72 return Default.load_file(path)
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/default.py in load_file(cls, path)
48 if not os.path.isfile(path):
49 raise Exception("%s does not exist" % (path))
---> 50 return cls(path)
51
52 @staticmethod
~/anaconda3/envs/o3mmax/lib/python3.7/site-packages/pesummary/gw/file/formats/default.py in __init__(self, path_to_results_file)
42 except Exception:
43 raise Exception(
---> 44 "Failed to read data for file %s" % (self.path_to_results_file))
45
46 @classmethod
Exception: Failed to read data for file posterior_samples.json
Once this exception occurs, it is not possible to load another metafile (even ones that load successfully before the exception occurs); also, files that cause this exception when loaded as the 5th (say) metafile in a list do not cause the exception if they are loaded alone into a fresh Python environment.