Models
About implemented models
In principle, every model can be implemented in spectrafit
by extending the module spectrafit.models
by a new functions. It is important to know that the raise
check have to be extend by the new function name in the solver_model
and calculated_model
.
__implemented_models__ = [
"gaussian",
"lorentzian",
"voigt",
"pseudovoigt",
"exponential",
"power",
"linear",
"constant",
"erf",
"atan",
"log",
"heaviside",
"my_new_model",
]
...
for model in params:
model = model.lower()
if model.split("_")[0] not in __implemented_models__:
raise KeyError(f"{model} is not supported")
peak_kwargs[(model.split("_")[-1], model.split("_")[0])][
model.split("_")[1]
] = params[model]
for key, _kwarg in peak_kwargs.items():
if key[1] == "my_new_model":
val += my_new_model(x, **_kwarg)
...
def my_new_model(
x: np.array, amplitude: float = 1.0, center: float = 0.0, fwhmg: float = 1.0
) -> np.array:
r"""Return a 1-dimensional `m`y_new_model` distribution."""
...
lmfit
can be found in this example. So far, the built-in models of lmfit are not supported, yet. Change in notation for the Full Maximum Half Widht (FWHM)
The notation for the Full Maximum Half Widht (FWHM) is adapted due to changes in the **kwargs
-handling in the models; see also API and CHANGELOG. The notation becomes:
Method | Old Notation | New Notation |
---|---|---|
Gaussian-FWHM | fwhm | fwhmg |
Lorentzian-FWHM | fwhm | fwhml |
Pseudo-Voigt | fwhm_g | fwhmg |
Pseudo-Voigt | fwhm_l | fwhml |
Voigt | fwhm | fwhmv |
Implemented models¶
Here is a list of implemented models of spectrafit
:
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
Important constants for the models¶
For calculating the models a few math constants are needed, which are implemented in the constants
module.
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 |
|