Lorentzian
Simples example
>>> from ffit.funcs.lorentzian import Lorentzian
# Call the fit method with x and y data.
>>> fit_result = Lorentzian().fit(x, y)
# The result is a FitResult object that can be unpacked.
>>> res, res_func = fit_result.res_and_func()
# The parameters can be accessed as attributes.
>> amplitude = fit_result.amplitude
# One can combine multiple calls in one line.
>>> res = Lorentzian().fit(x, y, guess=[1, 2, 3, 4]).plot(ax)
Final parameters
Lorentzian parameters.
Attributes:
Name | Type | Description |
---|---|---|
amplitude |
float
|
The height of the peak. |
gamma |
float
|
The half-width at half-maximum. |
x0 |
float
|
The position of the peak. |
offset |
float
|
The baseline offset. |
Additional attributes
sigma (float): The full width at half-maximum.
Source code in ffit/funcs/lorentzian.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Lorentzian function.
f(x) = amplitude * gamma**2 / ((x - x0) ** 2 + gamma**2) + offset
In this notation, the width at half-height: \(\sigma = 2\gamma\)
Final parameters
The final parameters are given by LorentzianParam
dataclass.
Source code in ffit/funcs/lorentzian.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
fit
fit(x, data, *, mask=None, guess=None, method='leastsq', maxfev=10000, **kwargs)
Fit the data using the specified fitting function.
This function returns FitResult see the documentation for more information what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_ARRAY
|
The dependent variable. |
required |
mask
|
Optional[Union[_ARRAY, float]]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use. Valid options are "least_squares", "leastsq", and "curve_fit" (default: "leastsq"). |
'leastsq'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit, including the fitted parameters and the fitted function. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid fitting method is provided. |
Source code in ffit/fit_logic.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
async_fit
async
async_fit(x, data, *, mask=None, guess=None, method='leastsq', maxfev=10000, **kwargs)
Asynchronously fits the model to the provided data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable data. |
required |
data
|
_ARRAY
|
The dependent variable data to fit. |
required |
mask
|
Optional[Union[_ARRAY, float]]
|
An optional mask to apply to the data. Defaults to None. |
None
|
guess
|
Optional[_T]
|
An optional initial guess for the fitting parameters. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments to pass to the fitting function. |
{}
|
Returns:
Type | Description |
---|---|
_T
|
FitWithErrorResult[_T]: The result of the fitting process, including the fitted parameters and associated errors. |
Source code in ffit/fit_logic.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
guess
classmethod
guess(x, data, mask=None, guess=None, **kwargs)
Guess the initial fit parameters.
This function returns an object of the class FitResult
.
See its documentation for more information on what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
The independent variable. |
required | |
data
|
The dependent variable. |
required | |
mask
|
Optional[Union[_ARRAY, float]]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[_T]
|
The initial guess for the fit parameters (optional). |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The guess, including the guess parameters and the function based on the guess. |
Examples:
>>> x = [1, 2, 3, 4, 5]
>>> data = [2, 4, 6, 8, 10]
>>> fit_guess = FitLogic.guess(x, data)
>>> fit_guess.plot()
Source code in ffit/fit_logic.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
bootstrapping
bootstrapping(x, data, mask=None, guess=None, method='leastsq', num_of_permutations=None, **kwargs)
Fit the data using the specified fitting function.
This function returns FitResult see the documentation for more information what is possible with it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_ARRAY
|
The independent variable. |
required |
data
|
_ARRAY
|
The dependent variable. |
required |
mask
|
Optional[Union[_ARRAY, float]]
|
The mask array or threshold for data filtering (optional). |
None
|
guess
|
Optional[Union[_T, tuple, list]]
|
The initial guess for fit parameters (optional). |
None
|
method
|
Literal['least_squares', 'leastsq', 'curve_fit']
|
The fitting method to use. Valid options are "least_squares", "leastsq", and "curve_fit" (default: "leastsq"). |
'leastsq'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FitResult |
_T
|
The result of the fit, including the fitted parameters and the fitted function. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid fitting method is provided. |
Source code in ffit/fit_logic.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
|