Merge branch 'develop' into documentation

This commit is contained in:
fjosw 2021-11-17 16:07:02 +00:00
commit aac77b5e74
2 changed files with 28 additions and 0 deletions

View file

@ -1564,6 +1564,25 @@ def load_object(path):
return pickle.load(file)
def import_jackknife(jacks, name):
"""Imports jackknife samples and returns an Obs
Parameters
----------
jacks : numpy.ndarray
numpy array containing the mean value as zeroth entry and
the N jackknife samples as first to Nth entry.
name : str
name of the ensemble the samples are defined on.
"""
length = len(jacks) - 1
prj = (np.ones((length, length)) - (length - 1) * np.identity(length))
samples = jacks[1:] @ prj
new_obs = Obs([samples], [name])
new_obs._value = jacks[0]
return new_obs
def merge_obs(list_of_obs):
"""Combine all observables in list_of_obs into one new observable

View file

@ -534,3 +534,12 @@ def test_jackknife():
my_new_obs = my_obs + pe.Obs([full_data], ['test2'])
with pytest.raises(Exception):
my_new_obs.export_jackknife()
def test_import_jackknife():
full_data = np.random.normal(1.105, 0.021, 754)
my_obs = pe.Obs([full_data], ['test'])
my_jacks = my_obs.export_jackknife()
reconstructed_obs = pe.import_jackknife(my_jacks, 'test')
assert my_obs == reconstructed_obs