diff --git a/pyerrors/__init__.py b/pyerrors/__init__.py index 694f9017..f2194cdb 100644 --- a/pyerrors/__init__.py +++ b/pyerrors/__init__.py @@ -246,10 +246,10 @@ See `pyerrors.obs.Obs.export_jackknife` for details. from .obs import * from .correlators import * from .fits import * +from .misc import * from . import dirac from . import input from . import linalg -from . import misc from . import mpm from . import roots diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 7e333cdb..a63a2b49 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -3,7 +3,8 @@ import numpy as np import autograd.numpy as anp import matplotlib.pyplot as plt import scipy.linalg -from .obs import Obs, dump_object, reweight, correlate +from .obs import Obs, reweight, correlate +from .misc import dump_object from .fits import least_squares from .linalg import eigh, inv, cholesky from .roots import find_root diff --git a/pyerrors/misc.py b/pyerrors/misc.py index 1baa5e53..aee6da37 100644 --- a/pyerrors/misc.py +++ b/pyerrors/misc.py @@ -1,7 +1,40 @@ +import pickle import numpy as np from .obs import Obs +def dump_object(obj, name, **kwargs): + """Dump object into pickle file. + + Parameters + ---------- + obj : object + object to be saved in the pickle file + name : str + name of the file + path : str + specifies a custom path for the file (default '.') + """ + if 'path' in kwargs: + file_name = kwargs.get('path') + '/' + name + '.p' + else: + file_name = name + '.p' + with open(file_name, 'wb') as fb: + pickle.dump(obj, fb) + + +def load_object(path): + """Load object from pickle file. + + Parameters + ---------- + path : str + path to the file + """ + with open(path, 'rb') as file: + return pickle.load(file) + + def gen_correlated_data(means, cov, name, tau=0.5, samples=1000): """ Generate observables with given covariance and autocorrelation times. diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 56a67e57..709664b7 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1527,38 +1527,6 @@ def pseudo_Obs(value, dvalue, name, samples=1000): return res -def dump_object(obj, name, **kwargs): - """Dump object into pickle file. - - Parameters - ---------- - obj : object - object to be saved in the pickle file - name : str - name of the file - path : str - specifies a custom path for the file (default '.') - """ - if 'path' in kwargs: - file_name = kwargs.get('path') + '/' + name + '.p' - else: - file_name = name + '.p' - with open(file_name, 'wb') as fb: - pickle.dump(obj, fb) - - -def load_object(path): - """Load object from pickle file. - - Parameters - ---------- - path : str - path to the file - """ - with open(path, 'rb') as file: - return pickle.load(file) - - def import_jackknife(jacks, name, idl=None): """Imports jackknife samples and returns an Obs