Подгонка функции Voigt к профилю поглощения python - PullRequest
0 голосов
/ 25 февраля 2020

Я пытаюсь приспособить функцию voigt к профилю поглощения, но делает его слишком широким. Я не совсем понимаю, так как сигма, которую я вставил, довольно мала. (То же самое, что и в случае с гауссовой посадкой, которая хорошо выполняет свою работу.) Кто-нибудь знает, как я могу добиться лучшей подгонки?

Мой код указан ниже.

enter image description here

def Gauss(x, y0, a, x0, sigma):
    return y0 + a * np.exp(-(x - x0)**2 / (2 * sigma**2))

def Voigt(x, x0, a, sigma, gamma):
    """
        Return the Voigt line shape at x with Lorentzian component HWHM gamma
        and Gaussian component HWHM alpha.

        """
    #sigma = alpha / np.sqrt(2 * np.log(2))

    return a * np.real(wofz((x - x0 + 1j*gamma)/sigma/np.sqrt(2))) / sigma /np.sqrt(2*np.pi)

def fitgauss(x,y):

    mean = sum(x * y) / sum(y)
    minx = x[np.where(y == np.min(y))][0]
    sigma = np.sqrt(sum(y * (x - mean)**2) / sum(y))
    print(sigma, mean, -(max(y)-min(y)), minx)

    try:
        #popt, pcov = curve_fit(Gauss, x, y, p0=[max(y), -(max(y)-min(y)), mean, sigma])
        popt, pcov = curve_fit(Voigt, x, y, p0=[minx, -(max(y)-min(y)),  sigma, 1])
    except RuntimeError:
        print("Error - curve_fit failed, putting in 0.")

    return popt

y= np.array([22910.756 , 17401.46  ,  9381.714 ,  6923.935 ,  6015.0757,
         5792.314 ,  5454.933 ,  5244.275 ,  5170.7695,  5011.3506,
         5344.995 ,  6036.098 , 12318.398])
xx = np.array([6561.49999988, 6562.        , 6562.19999999, 6562.39999998,
       6562.69999999, 6562.84999999, 6563.        , 6563.15000001,
       6563.30000001, 6563.60000002, 6563.80000001, 6564.        ,
       6564.50000012])
popt = fitgauss(xx,y)
plt.plot(xx, y, 'b+:', label='data')
plt.plot(xx, Voigt(xx, *popt), 'r-', label='fit')
plt.legend()
plt.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...