import lmfit import numpy as np pv = lmfit.models.PseudoVoigtModel() def fitPeak(x,y,autorange=False): if autorange: # find fwhm idx = np.ravel(np.argwhere( ynp.argmax(y)][0] c = int( (p1+p2)/2 ) dp = int( np.abs(p1-p2) ) idx = slice(c-dp,c+dp) x = x[idx] y = y[idx] pars = pv.guess(y,x=x) ret = pv.fit(y,x=x,params=pars) return ret