mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 23:00:25 +01:00
Corr objects now support slicing, T_symmetry implemented for Corr
objects
This commit is contained in:
parent
063b8b2404
commit
c7f5612717
2 changed files with 19 additions and 20 deletions
|
@ -62,6 +62,9 @@ class Corr:
|
||||||
|
|
||||||
self.gamma_method()
|
self.gamma_method()
|
||||||
|
|
||||||
|
def __getitem__(self, idx):
|
||||||
|
return self.content[idx]
|
||||||
|
|
||||||
def gamma_method(self):
|
def gamma_method(self):
|
||||||
for item in self.content:
|
for item in self.content:
|
||||||
if not(item is None):
|
if not(item is None):
|
||||||
|
@ -206,6 +209,22 @@ class Corr:
|
||||||
def reverse(self):
|
def reverse(self):
|
||||||
return Corr(self.content[::-1])
|
return Corr(self.content[::-1])
|
||||||
|
|
||||||
|
def T_symmetry(partner, parity=+1):
|
||||||
|
if not isinstance(partner, Corr):
|
||||||
|
raise Exception("T partner has to be a Corr object.")
|
||||||
|
if parity not in [+1, -1]:
|
||||||
|
raise Exception("Parity has to be +1 or -1.")
|
||||||
|
T_partner = parity * partner.reverse()
|
||||||
|
t_slices = []
|
||||||
|
for x0, t_slice in enumerate(self - T_partner):
|
||||||
|
if t_slice is not None:
|
||||||
|
if not t_slice.is_zero_within_error(3):
|
||||||
|
t_slices.append(x0)
|
||||||
|
if t_slices:
|
||||||
|
warnings.warn("T symmetry partner do not agree within 5 sigma on time slices" + str(t_slices) + ".", RuntimeWarning)
|
||||||
|
|
||||||
|
return (self + T_partner) / 2
|
||||||
|
|
||||||
def deriv(self, symmetric=True): # Defaults to symmetric derivative
|
def deriv(self, symmetric=True): # Defaults to symmetric derivative
|
||||||
if not symmetric:
|
if not symmetric:
|
||||||
newcontent = []
|
newcontent = []
|
||||||
|
|
|
@ -1405,26 +1405,6 @@ def covariance3(obs1, obs2, correlation=False, **kwargs):
|
||||||
return cov
|
return cov
|
||||||
|
|
||||||
|
|
||||||
def use_time_reversal_symmetry(data1, data2, **kwargs):
|
|
||||||
"""Combine two correlation functions (lists of Obs) according to time reversal symmetry
|
|
||||||
|
|
||||||
Keyword arguments
|
|
||||||
-----------------
|
|
||||||
minus -- if True, multiply the second correlation function by a minus sign.
|
|
||||||
"""
|
|
||||||
if kwargs.get('minus'):
|
|
||||||
sign = -1
|
|
||||||
else:
|
|
||||||
sign = 1
|
|
||||||
|
|
||||||
result = []
|
|
||||||
T = int(len(data1))
|
|
||||||
for i in range(T):
|
|
||||||
result.append(derived_observable(lambda x, **kwargs: (x[0] + sign * x[1]) / 2, [data1[i], data2[T - i - 1]], **kwargs))
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def pseudo_Obs(value, dvalue, name, samples=1000):
|
def pseudo_Obs(value, dvalue, name, samples=1000):
|
||||||
"""Generate a pseudo Obs with given value, dvalue and name
|
"""Generate a pseudo Obs with given value, dvalue and name
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue