Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NestedSamples to take lists as well as numpy arrays as constructors #190

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, *args, **kwargs):
logzero = kwargs.pop('logzero', -1e30)
logL = kwargs.pop('logL', None)
if logL is not None:
logL = np.array(logL)
logL = np.where(logL <= logzero, -np.inf, logL)
self.tex = kwargs.pop('tex', {})
self.limits = kwargs.pop('limits', {})
Expand Down Expand Up @@ -487,6 +488,7 @@ def __init__(self, *args, **kwargs):
self._beta = kwargs.pop('beta', 1.)
logL_birth = kwargs.pop('logL_birth', None)
if not isinstance(logL_birth, int) and logL_birth is not None:
logL_birth = np.array(logL_birth)
logL_birth = np.where(logL_birth <= logzero, -np.inf,
logL_birth)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,14 @@ def test_plotting_with_integer_names():
assert_array_equal(samples_1.loc[:, 0], samples_1.iloc[:, 0])
with pytest.raises(KeyError):
samples_1['0']


def test_logL_list():
np.random.seed(5)
default = NestedSamples(root='./tests/example_data/pc')
logL = default.logL.tolist()
logL_birth = default.logL_birth.tolist()
data = default.iloc[:, :5].to_numpy().tolist()

samples = NestedSamples(data=data, logL=logL, logL_birth=logL_birth)
assert_array_equal(default, samples)