Modelling
Minimization models for curve fitting.
AutoPeakDetection
¶
Automatic detection of peaks in a spectrum.
Source code in spectrafit/models.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
|
estimate_distance: float
property
¶
Estimate the initial distance between peaks.
Returns:
Name | Type | Description |
---|---|---|
float | float | Estimated distance between peaks. |
estimate_height: Tuple[float, float]
property
¶
Estimate the initial height based on an inverse noise ratio of a signal.
About the estimation of the height
The lower end of the height is the inverse noise ratio of the data
, and upper limit is the maximum value of the data
. The noise ratio of the data
is based on the original implementation by SciPy
:
def signaltonoise(a, axis=0, ddof=0):
a = np.asanyarray(a)
m = a.mean(axis)
sd = a.std(axis=axis, ddof=ddof)
return np.where(sd == 0, 0, m / sd)
Returns:
Type | Description |
---|---|
Tuple[float, float] | Tuple[float, float]: Tuple of the inverse signal to noise ratio and the maximum value of the |
estimate_prominence: Tuple[float, float]
property
¶
Estimate the prominence of a peak.
About the estimation of the prominence
The prominence is the difference between the height of the peak and the bottom. To get a estimate of the prominence, the height of the peak is calculated by maximum value of the data
and the bottom is calculated by the harmonic mean of the data
.
Returns:
Type | Description |
---|---|
Tuple[float, float] | Tuple[float, float]: Tuple of the harmonic-mean and maximum value of |
estimate_threshold: Tuple[float, float]
property
¶
Estimate the threshold value for the peak detection.
Returns:
Type | Description |
---|---|
Tuple[float, float] | Tuple[float, float]: Minimum and maximum value of the spectrum |
estimated_plateau_size: Tuple[float, float]
property
¶
Estimate the plateau size for the peak detection.
Returns:
Type | Description |
---|---|
Tuple[float, float] | Tuple[float, float]: Estimated plateau size is set to |
estimated_rel_height: float
property
¶
Estimate the relative height of a peak.
About the estimation of the relative height
The relative height of a peak is approximated by the difference of the harmonic mean value of the data
and the minimum value of the data
divided by the factor of 4
. In case of negative ratios, the value will be set to Zero
.
Returns:
Name | Type | Description |
---|---|---|
float | float | Estimated relative height of a peak. |
estimated_width: Tuple[float, float]
property
¶
Estimate the width of a peak.
About the estimation of the width
The width of a peak is estimated for a lower and an upper end. For the lower end, the minimum stepsize is used. For the upper end, the stepsize between the half maximum and the minimum value of the data
is used as the width.
Returns:
Type | Description |
---|---|
Tuple[float, float] | Tuple[float, float]: Estimated width lower and uper end of the peaks. |
estimated_wlen: float
property
¶
Estimate the window length for the peak detection.
About the estimation of the window length
The window length is the length of the window for the peak detection is defined to be 1% of the length of the data
, consequently the len of the data
is divided by 100. In case of a window length smaller than 1, the window length will be set to numerical value of 1, which is defined by 1 + 1e-9
.
Returns:
Name | Type | Description |
---|---|---|
float | float | Estimated window length is set to the numeric value of > 1. |
__autodetect__()
¶
Return peak positions and properties.
Source code in spectrafit/models.py
876 877 878 879 880 881 882 883 884 885 886 887 888 |
|
__init__(x, data, args)
¶
Initialize the AutoPeakDetection class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
data | NDArray[np.float64] |
| required |
args | Dict[str, Any] | The input file arguments as a dictionary with additional information beyond the command line arguments. | required |
Source code in spectrafit/models.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
check_key_exists(key, args, value)
staticmethod
¶
Check if a key exists in a dictionary.
Please check for the reference key also scipy.signal.find_peaks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | Reference key of | required |
args | Dict[str, Any] | Reference values of | required |
value | Union[float, Tuple[float, float]] | Default value for the reference key. | required |
Returns:
Name | Type | Description |
---|---|---|
Any | Any | The reference value for |
Source code in spectrafit/models.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
|
default_values()
¶
Set the default values for the peak detection.
Source code in spectrafit/models.py
865 866 867 868 869 870 871 872 873 874 |
|
initialize_peak_detection()
¶
Initialize the peak detection.
Initialize the peak detection
This method is used to initialize the peak detection. The initialization can be activated by setting the initialize
attribute to True
, which will automatically estimate the default parameters for the peak detection. In case of the initialize
attribute is defined as dictionary, the proposed values are taken from the dictionary if th
Raise
Source code in spectrafit/models.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
|
Constants
dataclass
¶
Mathematical constants for the curve models.
Constants
-
Natural logarithm of 2
\[ ln2 = \log{2} \] -
Square root of 2 times pi
\[ sq2pi = \sqrt{2 \pi} \] -
Square root of pi
\[ sqpi = \sqrt{ \pi} \] -
Square root of 2
\[ sq2 = \sqrt{2} \] -
Full width at half maximum to sigma for Gaussian
\[ fwhmg2sig = \frac{1}{ 2 \sqrt{2\log{2}}} \] -
Full width at half maximum to sigma for Lorentzian
\[ fwhml2sig = \frac{1}{2} \] -
Full width at half maximum to sigma for Voigt according to the article by Olivero and Longbothum1, check also XPSLibary website.
$$ fwhm_{\text{Voigt}} \approx 0.5346 \cdot fwhm_{\text{Gaussian}} + \sqrt{ 0.2166 fwhm_{\text{Lorentzian}}^2 + fwhm_{\text{Gaussian}}^2 }
$$
In case of equal FWHM for Gaussian and Lorentzian, the Voigt FWHM can be defined as:
\[ fwhm_{\text{Voigt}} \approx 1.0692 + 2 \sqrt{0.2166 + 2 \ln{2}} \cdot \sigma \]\[ fwhmv2sig = \frac{1}{fwhm_{\text{Voigt}}} \]
-
J.J. Olivero, R.L. Longbothum, Empirical fits to the Voigt line width: A brief review, Journal of Quantitative Spectroscopy and Radiative Transfer, Volume 17, Issue 2, 1977, Pages 233-236, ISSN 0022-4073, https://doi.org/10.1016/0022-4073(77)90161-3. ↩
Source code in spectrafit/models.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
DistributionModels
¶
Distribution models for the fit.
About distribution models
DistributionModels
are wrapper functions for the distribution models. The overall goal is to extract from the best parameters the single contributions in the model. The superposition of the single contributions is the final model.
About the cumulative distribution
The cumulative distribution is the sum of the single contributions. The cumulative distribution is the model that is fitted to the data. In contrast to the single contributions, the cumulative distribution is not normalized and therefore the amplitude of the single contributions is not directly comparable to the amplitude of the cumulative distribution. Also, the cumulative distributions are consquently using the fwhm
parameter instead of the sigma
parameter.
Source code in spectrafit/models.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 250 251 252 253 254 255 256 257 258 259 260 261 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 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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 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 501 502 503 504 505 506 507 508 |
|
atan(x, amplitude=1.0, center=0.0, sigma=1.0)
staticmethod
¶
Return a 1-dimensional arctan step function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the arctan step function. Defaults to 1.0. | 1.0 |
center | float | Center of the arctan step function. Defaults to 0.0. | 0.0 |
sigma | float | Sigma of the arctan step function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Arctan step function of |
Source code in spectrafit/models.py
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 383 384 385 |
|
cgaussian(x, amplitude=1.0, center=0.0, fwhmg=1.0)
staticmethod
¶
Return a 1-dimensional cumulative Gaussian function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Gaussian function. Defaults to 1.0. | 1.0 |
center | float | Center of the Gaussian function. Defaults to 0.0. | 0.0 |
fwhmg | float | Full width at half maximum of the Gaussian function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Cumulative Gaussian function of |
Source code in spectrafit/models.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|
clorentzian(x, amplitude=1.0, center=0.0, fwhml=1.0)
staticmethod
¶
Return a 1-dimensional cumulative Lorentzian function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Lorentzian function. Defaults to 1.0. | 1.0 |
center | float | Center of the Lorentzian function. Defaults to 0.0. | 0.0 |
fwhml | float | Full width at half maximum of the Lorentzian function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Cumulative Lorentzian function of |
Source code in spectrafit/models.py
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 |
|
constant(x, amplitude=1.0)
staticmethod
¶
Return a 1-dimensional constant value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the constant. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Constant value of |
Source code in spectrafit/models.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
cvoigt(x, amplitude=1.0, center=0.0, fwhmv=1.0, gamma=1.0)
staticmethod
¶
Return a 1-dimensional cumulative Voigt function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Voigt function. Defaults to 1.0. | 1.0 |
center | float | Center of the Voigt function. Defaults to 0.0. | 0.0 |
fwhmv | float | Full width at half maximum of the Voigt function. Defaults to 1.0. | 1.0 |
gamma | float | Gamma of the Voigt function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Cumulative Voigt function of |
Source code in spectrafit/models.py
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 501 502 503 504 505 506 507 508 |
|
erf(x, amplitude=1.0, center=0.0, sigma=1.0)
staticmethod
¶
Return a 1-dimensional error function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the error function. Defaults to 1.0. | 1.0 |
center | float | Center of the error function. Defaults to 0.0. | 0.0 |
sigma | float | Sigma of the error function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Error function of |
Source code in spectrafit/models.py
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 |
|
exponential(x, amplitude=1.0, decay=1.0, intercept=0.0)
staticmethod
¶
Return a 1-dimensional exponential decay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the exponential function. Defaults to 1.0. | 1.0 |
decay | float | Decay of the exponential function. Defaults to 1.0. | 1.0 |
intercept | float | Intercept of the exponential function. Defaults to 0.0. | 0.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Exponential decay of |
Source code in spectrafit/models.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
gaussian(x, amplitude=1.0, center=0.0, fwhmg=1.0)
staticmethod
¶
Return a 1-dimensional Gaussian distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Gaussian distribution. Defaults to 1.0. | 1.0 |
center | float | Center of the Gaussian distribution. Defaults to 0.0. | 0.0 |
fwhmg | float | Full width at half maximum (FWHM) of the Gaussian distribution. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Gaussian distribution of |
Source code in spectrafit/models.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
heaviside(x, amplitude=1.0, center=0.0, sigma=1.0)
staticmethod
¶
Return a 1-dimensional Heaviside step function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Heaviside step function. Defaults to 1.0. | 1.0 |
center | float | Center of the Heaviside step function. Defaults to 0.0. | 0.0 |
sigma | float | Sigma of the Heaviside step function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Heaviside step function of |
Source code in spectrafit/models.py
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 |
|
linear(x, slope=1.0, intercept=0.0)
staticmethod
¶
Return a 1-dimensional linear function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
slope | float | Slope of the linear function. Defaults to 1.0. | 1.0 |
intercept | float | Intercept of the linear function. Defaults to 0.0. | 0.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Linear function of |
Source code in spectrafit/models.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
log(x, amplitude=1.0, center=0.0, sigma=1.0)
staticmethod
¶
Return a 1-dimensional logarithmic step function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the logarithmic step function. Defaults to 1.0. | 1.0 |
center | float | Center of the logarithmic step function. Defaults to 0.0. | 0.0 |
sigma | float | Sigma of the logarithmic step function. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Logarithmic step function of |
Source code in spectrafit/models.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
lorentzian(x, amplitude=1.0, center=0.0, fwhml=1.0)
staticmethod
¶
Return a 1-dimensional Lorentzian distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Lorentzian distribution. Defaults to 1.0. | 1.0 |
center | float | Center of the Lorentzian distribution. Defaults to 0.0. | 0.0 |
fwhml | float | Full width at half maximum (FWHM) of the Lorentzian distribution. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | Union[NDArray[np.float64], float]: Lorentzian distribution of |
Source code in spectrafit/models.py
80 81 82 83 84 85 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 |
|
power(x, amplitude=1.0, exponent=1.0, intercept=0.0)
staticmethod
¶
Return a 1-dimensional power function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the power function. Defaults to 1.0. | 1.0 |
exponent | float | Exponent of the power function. Defaults to 1.0. | 1.0 |
intercept | float | Intercept of the power function. Defaults to 0.0. | 0.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: power function of |
Source code in spectrafit/models.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
pseudovoigt(x, amplitude=1.0, center=0.0, fwhmg=1.0, fwhml=1.0)
staticmethod
¶
Return a 1-dimensional Pseudo-Voigt distribution.
See also:
J. Appl. Cryst. (2000). 33, 1311-1316 https://doi.org/10.1107/S0021889800010219
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
amplitude | float | Amplitude of the Pseudo-Voigt distribution. Defaults to 1.0. | 1.0 |
center | float | Center of the Pseudo-Voigt distribution. Defaults to 0.0. | 0.0 |
fwhmg | float | Full width half maximum of the Gaussian distribution in the Pseudo-Voigt distribution. Defaults to 1.0. | 1.0 |
fwhml | float | Full width half maximum of the Lorentzian distribution in the Pseudo-Voigt distribution. Defaults to 1.0. | 1.0 |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Pseudo-Voigt distribution of |
Source code in spectrafit/models.py
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
voigt(x, center=0.0, fwhmv=1.0, gamma=None)
staticmethod
¶
Return a 1-dimensional Voigt distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] |
| required |
center | float | Center of the Voigt distribution. Defaults to 0.0. | 0.0 |
fwhmv | float | Full width at half maximum (FWHM) of the Lorentzian distribution. Defaults to 1.0. | 1.0 |
gamma | float | Scaling factor of the complex part of the Faddeeva Function. Defaults to None. | None |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: Voigt distribution of |
Source code in spectrafit/models.py
112 113 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 |
|
ModelParameters
¶
Bases: AutoPeakDetection
Class to define the model parameters.
Source code in spectrafit/models.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 |
|
return_params: Parameters
property
¶
Return the class
representation of the model parameters.
Returns:
Name | Type | Description |
---|---|---|
Parameters | Parameters | Model parameters class. |
__init__(df, args)
¶
Initialize the model parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | DataFrame containing the input data ( | required |
args | Dict[str, Any] | Nested arguments dictionary for the model based on one or two | required |
About args
for models
The args
dictionary is used to define the model parameters. And the total nested dictionary structure is as follows:
args: Dict[str, Dict[int, Dict[str, Dict[str, Union[str, int, float]]]]]
About the fitting options
In general, there are two option for the fitting possible:
Classic fitting
orlocal fitting
, where the parameters are defined for a 2D spectrum.Global fitting
, where the parameters are defined for a 3D spectrum. Here, the parameters can be automatically defined for each column on the basis of the initial parameters or they can be completley defined by the user. Theglobal fitting
definition starts at1
similiar to the peaks attributes notation.
Source code in spectrafit/models.py
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
|
__perform__()
¶
Perform the model parameter definition.
Raises:
Type | Description |
---|---|
KeyError | Global fitting is combination with automatic peak detection is not implemented yet. |
Source code in spectrafit/models.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
|
__str__()
¶
Return the string
representation of the model parameters.
Returns:
Name | Type | Description |
---|---|---|
str | str | String representation of the model parameters. |
Source code in spectrafit/models.py
971 972 973 974 975 976 977 978 |
|
define_parameters()
¶
Define the input parameters for a params
-dictionary for classic fitting.
Source code in spectrafit/models.py
1157 1158 1159 1160 |
|
define_parameters_auto()
¶
Auto define the model parameters for local fitting.
Source code in spectrafit/models.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
|
define_parameters_global()
¶
Define the input parameters for a params
-dictionary for global fitting.
Source code in spectrafit/models.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 |
|
define_parameters_global_pre()
¶
Define the input parameters for a params
-dictionary for global fitting.
About params
for global fitting
define_parameters_global_pre
requires fully defined params
-dictionary in the json, toml, or yaml file input. This means:
- Number of the spectra must be defined.
- Number of the peaks must be defined.
- Number of the parameters must be defined.
- The parameters must be defined.
Source code in spectrafit/models.py
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 |
|
define_parameters_loop(key_1, value_1)
¶
Loop through the input parameters for a params
-dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_1 | str | The key of the first level of the input dictionary. | required |
value_1 | Dict[str, Any] | The value of the first level of the input dictionary. | required |
Source code in spectrafit/models.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
|
define_parameters_loop_2(key_1, key_2, value_2)
¶
Loop through the input parameters for a params
-dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_1 | str | The key of the first level of the input dictionary. | required |
key_2 | str | The key of the second level of the input dictionary. | required |
value_2 | Dict[str, Any] | The value of the second level of the input dictionary. | required |
Source code in spectrafit/models.py
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
|
define_parameters_loop_3(key_1, key_2, key_3, value_3)
¶
Loop through the input parameters for a params
-dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_1 | str | The key of the first level of the input dictionary. | required |
key_2 | str | The key of the second level of the input dictionary. | required |
key_3 | str | The key of the third level of the input dictionary. | required |
value_3 | Dict[str, Any] | The value of the third level of the input dictionary. | required |
Source code in spectrafit/models.py
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 |
|
df_to_numvalues(df, args)
¶
Transform the dataframe to numeric values of x
and data
.
About the dataframe to numeric values
The transformation is done by the value
property of pandas. The dataframe is separated into the x
and data
columns and the x
column is transformed to the energy values and the data
column is transformed to the intensity values depending on the args
dictionary. In terms of global fitting, the data
contains the intensity values for each column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | DataFrame containing the input data ( | required |
args | Dict[str, Any] | The input file arguments as a dictionary with additional information beyond the command line arguments. | required |
Returns:
Type | Description |
---|---|
Tuple[NDArray[np.float64], NDArray[np.float64]] | Tuple[NDArray[np.float64], NDArray[np.float64]]: Tuple of |
Source code in spectrafit/models.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
|
ReferenceKeys
dataclass
¶
Reference keys for model fitting and peak detection.
Source code in spectrafit/models.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
automodel_check(model)
¶
Check if model is available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | str | Auto Model name (gaussian, lorentzian, voigt, or pseudovoigt). | required |
Raises:
Type | Description |
---|---|
KeyError | If the model is not supported. |
Source code in spectrafit/models.py
536 537 538 539 540 541 542 543 544 545 546 |
|
detection_check(args)
¶
Check if detection is available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args | Dict[str, Any] | The input file arguments as a dictionary with additional information beyond the command line arguments. | required |
Raises:
Type | Description |
---|---|
KeyError | If the key is not parameter of the |
Source code in spectrafit/models.py
548 549 550 551 552 553 554 555 556 557 558 559 |
|
model_check(model)
¶
Check if model is available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | str | Model name. | required |
Raises:
Type | Description |
---|---|
KeyError | If the model is not supported. |
Source code in spectrafit/models.py
524 525 526 527 528 529 530 531 532 533 534 |
|
SolverModels
¶
Bases: ModelParameters
Solving models for 2D and 3D data sets.
Solver Modes
"2D"
: Solve 2D models via the classiclmfit
function."3D"
: Solve 3D models via global git. For theglobal-fitting
procedure, thelmfit
function is used to solve the models with an extended set of parameters. thelmfit
function is used.
Source code in spectrafit/models.py
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 |
|
__call__()
¶
Solve the fitting model.
Returns:
Type | Description |
---|---|
Tuple[Minimizer, Any] | Tuple[Minimizer, Any]: Minimizer class and the fitting results. |
Source code in spectrafit/models.py
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 |
|
__init__(df, args)
¶
Initialize the solver modes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | DataFrame containing the input data ( | required |
args | Dict[str, Any] | The input file arguments as a dictionary with additional information beyond the command line arguments. | required |
Source code in spectrafit/models.py
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
|
solve_global_fitting(params, x, data)
staticmethod
¶
Solving the fitting for global problem.
About implemented models
solve_global_fitting
is the global solution of solve_local_fitting
a wrapper function for the calling the implemented moldels. For the kind of supported models see solve_local_fitting
.
About the global solution
The global solution is a solution for the problem, where the x
-values is the energy, but the y-values are the intensities, which has to be fitted as one unit. For this reason, the residual is calculated as the difference between all the y-values and the global proposed solution. Later the residual has to be flattened to a 1-dimensional array and minimized by the lmfit
-optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params | Dict[str, Parameters] | The best optimized parameters of the fit. | required |
x | NDArray[np.float64] |
| required |
data | NDArray[np.float64] |
| required |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: The best-fitted data based on the proposed model. |
Source code in spectrafit/models.py
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 |
|
solve_local_fitting(params, x, data)
staticmethod
¶
Solving the fitting problem.
About implemented models
solve_local_fitting
is a wrapper function for the calling the implemented moldels. Based on the params
dictionary, the function calls the corresponding models and merge them to the general model with will be optimized by the lmfit
-optimizer. Currently the following models are supported:
- Gaussian
- Lorentzian also known as Cauchy distribution
- Voigt
- Pseudo Voigt
- Exponential
- power (also known as Log-parabola or just power)
- Linear
- Constant
- Error Function
- Arcus Tangens
- Logarithmic
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params | Dict[str, Parameters] | The best optimized parameters of the fit. | required |
x | NDArray[np.float64] |
| required |
data | NDArray[np.float64] |
| required |
Returns:
Type | Description |
---|---|
NDArray[np.float64] | NDArray[np.float64]: The best-fitted data based on the proposed model. |
Source code in spectrafit/models.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
|
calculated_model(params, x, df, global_fit)
¶
Calculate the single contributions of the models and add them to the dataframe.
About calculated models
calculated_model
are also wrapper functions similar to solve_model
. The overall goal is to extract from the best parameters the single contributions in the model. Currently, lmfit
provides only a single model, so the best-fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params | Dict[str, Parameters] | The best optimized parameters of the fit. | required |
x | NDArray[np.float64] |
| required |
df | pd.DataFrame | DataFrame containing the input data ( | required |
global_fit | int | If 1 or 2, the model is calculated for the global fit. | required |
Returns:
Type | Description |
---|---|
pd.DataFrame | pd.DataFrame: Extended dataframe containing the single contributions of the models. |
Source code in spectrafit/models.py
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
|