forked from IPKM/nmreval
86 lines
1.9 KiB
Python
86 lines
1.9 KiB
Python
import abc
|
|
from warnings import warn
|
|
|
|
import numpy as np
|
|
|
|
|
|
class Distribution(abc.ABC):
|
|
name = 'Abstract distribution'
|
|
parameter = None
|
|
bounds = None
|
|
|
|
@classmethod
|
|
def __repr__(cls):
|
|
return cls.name
|
|
|
|
@staticmethod
|
|
@abc.abstractmethod
|
|
def distribution(taus, tau0, *args):
|
|
pass
|
|
|
|
@staticmethod
|
|
@abc.abstractmethod
|
|
def susceptibility(omega, tau, *args):
|
|
pass
|
|
|
|
@classmethod
|
|
def specdens(cls, omega, tau, *args):
|
|
return -cls.susceptibility(omega, tau, *args).imag / omega
|
|
|
|
@staticmethod
|
|
@abc.abstractmethod
|
|
def correlation(t, tau0, *args):
|
|
pass
|
|
|
|
@classmethod
|
|
def mean_value(cls, *args, mode='mean'):
|
|
if mode == 'mean':
|
|
return cls.mean(*args)
|
|
if mode == 'logmean':
|
|
return np.exp(cls.logmean(*args))
|
|
if mode in ['max', 'peak']:
|
|
return cls.max(*args)
|
|
|
|
return args[0]
|
|
|
|
@classmethod
|
|
def convert(cls, *args, from_='raw', to_='mean'):
|
|
if from_ == to_:
|
|
return args[0]
|
|
|
|
if from_ == 'raw':
|
|
return cls.mean_value(*args, mode=to_)
|
|
else:
|
|
# makes only sense as long as mean/peak is given by <x> = factor * x
|
|
factor = cls.mean_value(1, *args[1:], mode=from_)
|
|
try:
|
|
raw = args[0] / factor
|
|
except ZeroDivisionError:
|
|
raise ZeroDivisionError('Conversion between mean values impossible')
|
|
|
|
if to_ == 'raw':
|
|
return raw
|
|
else:
|
|
return cls.mean_value(raw, *args[1:], mode=to_)
|
|
|
|
@staticmethod
|
|
def logmean(*args):
|
|
"""
|
|
Return mean logarithmic tau
|
|
|
|
Args:
|
|
*args:
|
|
|
|
Returns:
|
|
|
|
"""
|
|
return np.log(args[0])
|
|
|
|
@staticmethod
|
|
def mean(*args):
|
|
return args[0]
|
|
|
|
@staticmethod
|
|
def max(*args):
|
|
return args[0]
|