Contrib — Optional Backends¶
Optional backends that wrap third-party libraries for advanced functionality.
pybaselines Backend¶
Note
Requires pybaselines: pip install pyspectrakit[baselines]
spectrakit.contrib._pybaselines.pybaselines_method ¶
Apply any pybaselines method through a unified interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
method
|
str
|
Name of the pybaselines method (e.g., |
required |
**kwargs
|
Any
|
Keyword arguments forwarded to the pybaselines method. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Estimated baseline, same shape as intensities. |
Raises:
| Type | Description |
|---|---|
DependencyError
|
If pybaselines is not installed. |
ValueError
|
If the method name is not recognized. |
Source code in src/spectrakit/contrib/_pybaselines.py
spectrakit.contrib._pybaselines.list_pybaselines_methods ¶
Return a dictionary of available pybaselines methods by category.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dict mapping category names to lists of method names. |
Source code in src/spectrakit/contrib/_pybaselines.py
lmfit Backend¶
Note
Requires lmfit: pip install pyspectrakit[fitting]
spectrakit.contrib._lmfit.fit_peaks ¶
fit_peaks(
intensities: ndarray,
wavenumbers: ndarray,
peak_positions: list[float],
model: str = "gaussian",
**kwargs: Any,
) -> FitResult
Fit spectral peaks using lmfit models.
Creates a composite model of multiple peaks and fits them to the data. Each peak is initialized near the specified position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
wavenumbers
|
ndarray
|
Wavenumber axis, shape |
required |
peak_positions
|
list[float]
|
Approximate peak center positions in wavenumber units. |
required |
model
|
str
|
Peak shape model. One of |
'gaussian'
|
**kwargs
|
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
FitResult
|
|
FitResult
|
parameters, and residual. |
Raises:
| Type | Description |
|---|---|
DependencyError
|
If lmfit is not installed. |
ValueError
|
If the model name is not supported. |
Source code in src/spectrakit/contrib/_lmfit.py
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 | |
spectrakit.contrib._lmfit.FitResult
dataclass
¶
Container for peak fitting results.
Attributes:
| Name | Type | Description |
|---|---|---|
best_fit |
ndarray
|
Fitted curve, shape |
components |
list[ndarray]
|
Individual peak components, list of arrays. |
parameters |
list[dict[str, float]]
|
Fitted parameter values per peak. |
residual |
ndarray
|
Residual (data - fit), shape |
success |
bool
|
Whether the fit converged. |
Source code in src/spectrakit/contrib/_lmfit.py
spectrakit.contrib._lmfit.SUPPORTED_MODELS
module-attribute
¶
SUPPORTED_MODELS = {
"gaussian": "GaussianModel",
"lorentzian": "LorentzianModel",
"voigt": "VoigtModel",
"pseudo_voigt": "PseudoVoigtModel",
}