sloth.fit: fitting tools
sloth.fit.peakfit: peak fitting with Lmfit
Simple peak fitting utility with Lmfit
Current fitting backend: Lmfit
- sloth.fit.peakfit_lmfit.fit_peak(x, y, num=1, positions=[None], amplitudes=[None], widths=[None], expressions=None, bkgModel=None, peakModel=None)[source]
peak fit with lmfit
Description
This peak fitting model is built to fit one to three peaks (with prefixes: ‘p1_’, ‘p2_’, ‘p3_’). The main control parameter is the initial guess of the peaks positions.
Notes
For the Gaussian function, amplitude means weighting factor multiplying a unit-normalized Gaussian, so that the maximum height at the centroid is Amplitude/(sqrt(2pi)*sigma), and that the full-width at half maximum is ~2.355 sigma. In the fit, amplitude, center, and sigma can be varied, while height and fwhm are reported values, derived from these quantities.
To guess the Gaussian amplitude (A) from the peak maximum (H) and a guess width (W), one could use the simple relation:
A ~ 5.90 * H * W
- param num:
number of peaks to fit: currently between 1 and 3 [1]
- type num:
int
- param positions:
initial peaks positions
- type positions:
list of floats
- param amplitudes:
initial peaks amplitudes
- type amplitudes:
list of floats
- param widths:
initial peaks widths
- type widths:
list of floats
- param expressions:
parameters expressions
- type expressions:
None or dict
- param bkgModel:
if None: ConstantModel
- type bkgModel:
None or lmfit.Model (optional)
- param peakModel:
if None: VoigtModel
- type peakModel:
None or lmfit.Model (optional)
- returns:
- rtype:
lmfit.fit object
- sloth.fit.peakfit_lmfit.get_curves_fit(x, fitobj, components='p', with_initial_guess=False)[source]
get a list of curves from the fit object
- Parameters:
x (array) –
fitobj (lmfit.model.fit object) –
components (False or str (optional)) – if give, include components starting with ‘components’ string default is ‘p’ (=peaks only)
- Returns:
- curves = [[x, y_best, {‘legend’ – [x, y_initial, {‘legend’: ‘initial guess’, ‘color’: ‘gray’}]
[x, y_componentN], {‘legend’: ‘component prefix N’, ‘color’: ‘pink’}]
]
- Return type:
‘best fit’, ‘color’: ‘red’}]