From 78ff4bb1173ab32dda873d7b9d2f328f05ba1869 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Wed, 19 Jan 2022 10:55:51 +0000 Subject: [PATCH] refactor: moved _assert_equal_properties from input.json to misc --- pyerrors/input/json.py | 15 +-------------- pyerrors/misc.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pyerrors/input/json.py b/pyerrors/input/json.py index 816be57e..1214019f 100644 --- a/pyerrors/input/json.py +++ b/pyerrors/input/json.py @@ -9,6 +9,7 @@ import warnings from ..obs import Obs from ..covobs import Covobs from ..correlators import Corr +from ..misc import _assert_equal_properties from .. import version as pyerrorsversion @@ -104,20 +105,6 @@ def create_json_string(ol, description='', indent=1): dl.append(ed) return dl - def _assert_equal_properties(ol, otype=Obs): - for o in ol: - if not isinstance(o, otype): - raise Exception("Wrong data type in list.") - for o in ol[1:]: - if not ol[0].is_merged == o.is_merged: - raise Exception("All Obs in list have to be defined on the same set of configs.") - if not ol[0].reweighted == o.reweighted: - raise Exception("All Obs in list have to have the same property 'reweighted'.") - if not ol[0].e_content == o.e_content: - raise Exception("All Obs in list have to be defined on the same set of configs.") - if not ol[0].idl == o.idl: - raise Exception("All Obs in list have to be defined on the same set of configurations.") - def write_Obs_to_dict(o): d = {} d['type'] = 'Obs' diff --git a/pyerrors/misc.py b/pyerrors/misc.py index e3bfbc33..edbdc369 100644 --- a/pyerrors/misc.py +++ b/pyerrors/misc.py @@ -70,3 +70,19 @@ def gen_correlated_data(means, cov, name, tau=0.5, samples=1000): data.append(np.sqrt(1 - a ** 2) * rand[i] + a * data[-1]) corr_data = np.array(data) - np.mean(data, axis=0) + means return [Obs([dat], [name]) for dat in corr_data.T] + + +def _assert_equal_properties(ol, otype=Obs): + for o in ol: + if not isinstance(o, otype): + raise Exception("Wrong data type in list.") + for o in ol[1:]: + if not ol[0].is_merged == o.is_merged: + raise Exception("All Obs in list have to be defined on the same set of configs.") + if not ol[0].reweighted == o.reweighted: + raise Exception("All Obs in list have to have the same property 'reweighted'.") + if not ol[0].e_content == o.e_content: + raise Exception("All Obs in list have to be defined on the same set of configs.") + if not ol[0].idl == o.idl: + raise Exception("All Obs in list have to be defined on the same set of configurations.") +