diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 1d4b7154..178fc6c2 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -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 diff --git a/tests/obs_test.py b/tests/obs_test.py index 88b7ccaf..60016705 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -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 +