-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Any | ||
|
||
import numpy as np | ||
from pybaselines import Baseline | ||
|
||
__all__ = [ | ||
"baseline", | ||
] | ||
|
||
|
||
def baseline(spectra: np.ndarray, method: str = "arpls", **params: Any) -> np.ndarray: | ||
""" | ||
Calculate the baseline of [many] spectra using pybaselines. | ||
Parameters | ||
---------- | ||
spectra : array-like ([N], wns) | ||
The spectra to calculate the baseline of. | ||
method : str, default: "arpls" | ||
The pybaselines method name. | ||
**params: | ||
Passed to pybaselines | ||
Returns | ||
------- | ||
baseline : np.ndarray ([N], wns) | ||
The calculated baselines | ||
""" | ||
baseliner = Baseline(np.arange(1340)) | ||
baseline_func = getattr(baseliner, method) | ||
|
||
spectra = np.atleast_2d(spectra) | ||
if np.issubdtype(spectra.dtype, np.integer): | ||
spectra = spectra.astype(np.float32) | ||
|
||
baselines = np.zeros_like(spectra) | ||
|
||
for i, spec in enumerate(spectra): | ||
baselines[i], w = baseline_func(spec, **params) | ||
return baselines.squeeze() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters