added quick estimation for peak tau and height of non Gaussian
This commit is contained in:
@@ -357,6 +357,38 @@ def quick1etau(t: ArrayLike, C: ArrayLike, n: int = 7) -> float:
|
||||
return tau_est
|
||||
|
||||
|
||||
def quicknongaussfit(t, C, width=4):
|
||||
"""
|
||||
Estimates the time and height of the peak in the non-Gaussian function.
|
||||
C is C(t) the correlation function
|
||||
"""
|
||||
# TODO this is a very experimental interpolation, can fail
|
||||
def ppoly(x,a,b,c,d,e,A,mu,sig):
|
||||
return A*np.exp(-(x - mu)**2 / (2 * sig**2))+a+(b*x+e)*1/(1+np.exp(c*(x-d)))
|
||||
# first rough estimate, the closest time. This is returned if the interpolation fails!
|
||||
tau_est = t[np.argmax(C)]
|
||||
nG_max = np.amax(C)
|
||||
try:
|
||||
with np.errstate(invalid='ignore'):
|
||||
corr = C[t > 0]
|
||||
time = np.log10(t[t > 0])
|
||||
tau = time[np.argmax(corr)]
|
||||
mask = (time>tau-width/2) & (time<tau+width/2)
|
||||
time = time[mask] ; corr = corr[mask]
|
||||
guess = [0.001,-0.001,5,tau-0.5,1.0,nG_max, tau, 1.5]
|
||||
popt = curve_fit(ppoly, time, corr, p0=guess, maxfev=10000)[0]
|
||||
# TODO instead use some root or solve
|
||||
xspace = np.linspace(*time[[0,-1]], 10000)
|
||||
y = ppoly(xspace, *popt)
|
||||
tau_est = xspace[np.argmax(y)]
|
||||
nG_max = np.amax(y)
|
||||
except:
|
||||
pass
|
||||
if np.isnan(tau_est):
|
||||
tau_est = np.inf
|
||||
return tau_est, nG_max
|
||||
|
||||
|
||||
def susceptibility(
|
||||
time: NDArray, correlation: NDArray, **kwargs
|
||||
) -> tuple[NDArray, NDArray]:
|
||||
|
Reference in New Issue
Block a user