results¶
lmfit results interpreter
FitResults
¶
FitResults Class Wrapper for lmfit results object with additional functions specific to i16_peakfit
res = model.fit(ydata, x=xdata) # lmfit ouput fitres = FitResults(res)
--- Parameters --- fitres.res # lmfit output
data from fit:¶
fitres.npeaks # number of peak models used, fitres.chisqr # Chi^2 of fit, fitres.xdata # x-data used for fit, fitres.ydata # y-data used for fit, fitres.yfit # y-fit values, fitres.weights # res.weights, fitres.yerror # 1 / res.weights if res.weights is not None else 0 * res.data,
data from components, e.g.¶
fitres.p1_amplitude # Peak 1 area, fitres.p1_fwhm # Peak 1 full-width and half-maximum fitres.p1_center # Peak 1 peak position fitres.p1_height # Peak 1 fitted height,
data for total fit:¶
fitres.amplitude # Total summed area, fitres.center # average centre of peaks, fitres.height # average height of peaks, fitres.fwhm # average FWHM of peaks, fitres.background # fitted background,
errors on all parameters, e.g.¶
fitres.stderr_amplitude # error on 'amplitude
--- Functions --- print(fitres) # prints formatted str with results ouputdict = fitres.results() # creates ouput dict xdata, yfit = fitres.fit(ntimes=10) # interpolated fit results fig = fitres.plot(axes, xlabel, ylabel, title) # create plot
Source code in mmg_toolbox/fitting/results.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
Peak
¶
Peak object
Source code in mmg_toolbox/fitting/results.py
fit_data(x_data=None, ntimes=10)
¶
Returns interpolated x, y fit arrays
Source code in mmg_toolbox/fitting/results.py
get_string(name)
¶
Returns fit parameter string including error in standard form
get_value(name)
¶
Returns fit parameter value and associated error
Source code in mmg_toolbox/fitting/results.py
plot(axes, x_data=None, ntimes=10)
¶
peak_results(res)
¶
Generate dict of fit results, including summed totals totals = peak_results(res) totals = { 'lmfit': lmfit_result (res), 'npeaks': number of peak models used, 'chisqr': Chi^2 of fit, 'xdata': x-data used for fit, 'ydata': y-data used for fit, 'yfit': y-fit values, 'weights': res.weights, 'yerror': 1 / res.weights if res.weights is not None else 0 * res.data, # plus data from components, e.g. 'p1_amplitude': Peak 1 area, 'p1_fwhm': Peak 1 full-width and half-maximum 'p1_center': Peak 1 peak position 'p1_height': Peak 1 fitted height, # plus data for total fit: 'amplitude': Total summed area, 'center': average centre of peaks, 'height': average height of peaks, 'fwhm': average FWHM of peaks, 'background': fitted background, # plut the errors on all parameters, e.g. 'stderr_amplitude': error on 'amplitude', }
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ModelResult
|
lmfit fit result - ModelResult |
required |
Returns:
| Type | Description |
|---|---|
dict
|
{totals: (value, error)} |
Source code in mmg_toolbox/fitting/results.py
peak_results_fit(res, ntimes=10, x_data=None)
¶
Generate xfit, yfit data, interpolated to give smoother variation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ModelResult
|
lmfit_result |
required |
ntimes
|
int
|
int, number of points * old number of points |
10
|
x_data
|
ndarray | None
|
x data to interpolate or None to use data from fit |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
xfit, yfit |
Source code in mmg_toolbox/fitting/results.py
peak_results_plot(res, axes=None, xlabel=None, ylabel=None, title=None)
¶
Plot peak results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ModelResult
|
lmfit result |
required |
axes
|
None or matplotlib axes |
None
|
|
xlabel
|
str
|
None or str |
None
|
ylabel
|
str
|
None or str |
None
|
title
|
str
|
None or str |
None
|
Returns:
| Type | Description |
|---|---|
|
matplotlib figure or axes |
Source code in mmg_toolbox/fitting/results.py
peak_results_str(res)
¶
Generate output str from lmfit results, including totals
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ModelResult
|
lmfit_result |
required |
Returns:
| Type | Description |
|---|---|
str
|
str |