I am currently dealing with some X-Ray data analysis, which in principle could be in principle done with the package PyMca https://www.silx.org/doc/PyMca/dev/index.html. However, I am trying to do stuff myself in python, since the above mentioned tool is very poorly documented. Now it seems that X-Ray physisists use the Split-Pseudo-Voigt profile https://docs.mantidproject.org/nightly/fitting/fitfunctions/PseudoVoigt.html, https://en.wikipedia.org/wiki/Voigt_profile#Pseudo-Voigt_approximation which is also present in PyMca to fit the X-Ray peaks.
Here my trouble begins, since there is no definition of this function in standard python libraries and my own one failed at curve_fit. Here is my definition:
def pV(x, mu, sigma, eta):
Gamma = 2*np.sqrt(2*np.log(2))*sigma
return (1-eta)*Gaussian(x,mu,sigma) + eta*Lorentzian(x,mu,Gamma)
def SplitVoigt(x, mu, sigma_1, sigma_2, eta):
'''
Function generates a Pseudo Voigt profile by linear combination
of Gaussian and Lorentzian in certain mixing ratio. The functions
needs proper definition of its constituents
'''
x, y, ind = np.asarray(x), [], []
for i in range(x.shape[0]):
if x[i] <= mu:
y_temp = pV(x[i], mu, sigma_1, eta)
y.append(y_temp)
else:
y_temp = pV(x[i], mu, sigma_2, eta)
y.append(y_temp)
ind.append(i)
'''
Finding the correct ratio at the jump from left to
right side to make distribution continuous
'''
y, ind = np.asarray(y),ind[0]
ratio = y[ind]/y[ind-1]
y[ind:-1] = y[ind:-1]/ratio
'''
Normalisation of distribution by total integral
'''
y = y/np.trapz(y,x)
return y
In a simple plot this functions works and looks fine, but curve fit will not accept it/fit will not converge. Now my question: is there a build in definition of this function, has someone already tried to do that or what could be wrong with my own one? Thanks in advance for your help!
Kind regards, Philipp