simplified quick non gaussian fit function so that it is more robust
This commit is contained in:
@@ -357,14 +357,15 @@ def quick1etau(t: ArrayLike, C: ArrayLike, n: int = 7) -> float:
|
||||
return tau_est
|
||||
|
||||
|
||||
def quicknongaussfit(t, C, width=4):
|
||||
def quicknongaussfit(t, C, width=2):
|
||||
"""
|
||||
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)))
|
||||
def ffunc(t,y0,A_main,log_tau_main,sig_main):
|
||||
main_peak = A_main*np.exp(-(t - log_tau_main)**2 / (2 * sig_main**2))
|
||||
return y0 + main_peak
|
||||
|
||||
# first rough estimate, the closest time. This is returned if the interpolation fails!
|
||||
tau_est = t[np.argmax(C)]
|
||||
nG_max = np.amax(C)
|
||||
@@ -375,13 +376,11 @@ def quicknongaussfit(t, C, width=4):
|
||||
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)
|
||||
nG_min = C[t > 0].min()
|
||||
guess = [nG_min, nG_max-nG_min, tau, 0.6]
|
||||
popt = curve_fit(ffunc, time, corr, p0=guess, maxfev=10000)[0]
|
||||
tau_est = 10**popt[-2]
|
||||
nG_max = popt[0] + popt[1]
|
||||
except:
|
||||
pass
|
||||
if np.isnan(tau_est):
|
||||
|
Reference in New Issue
Block a user