Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/franckalbinet/spectfm
https://github.com/franckalbinet/spectfm
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/franckalbinet/spectfm
- Owner: franckalbinet
- License: apache-2.0
- Created: 2025-01-06T14:41:38.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-01-07T16:50:22.000Z (about 1 month ago)
- Last Synced: 2025-01-07T17:59:00.300Z (about 1 month ago)
- Language: Jupyter Notebook
- Size: 3.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SpecTfm
> A Python package providing scikit-learn compatible transforms for
> spectroscopic data preprocessing.It’s designed to work seamlessly with both MIR (Mid-Infrared) and VISNIR
(Visible-Near Infrared) spectral data.**WORK IN PROGRESS**
## Installation
``` bash
pip install spectfm
```## Quick Start
``` python
from spectfm.core import SNV, TakeDerivative, ToAbsorbance
from sklearn.pipeline import Pipeline
```### Loading OSSL dataset
Let’s use OSSL dataset as an example using
[SoilSpecData](https://fr.anckalbi.net/soilspecdata/) package.``` python
from soilspecdata.datasets.ossl import get_ossl
`````` python
ossl = get_ossl()
mir_data = ossl.get_mir(require_valid=True)
```### Preprocessing pipeline
Implemented transforms developed so far include:
- [`SNV`](https://franckalbinet.github.io/spectfm/core.html#snv):
Standard Normal Variate
- [`TakeDerivative`](https://franckalbinet.github.io/spectfm/core.html#takederivative):
Take the first derivative of the spectrum
- [`ToAbsorbance`](https://franckalbinet.github.io/spectfm/core.html#toabsorbance):
Transform the spectrum to absorbance
- More to come…Transforms are fully compatible with
[scikit-learn](https://scikit-learn.org/stable/) and can be used in a
pipeline as follows:``` python
pipe = Pipeline([
('snv', SNV()), # Standard Normal Variate transformation
('deriv', TakeDerivative(window_length=11, polyorder=2, deriv=1)) # First derivative
])X_tfm = pipe.fit_transform(mir_data.spectra)
```### Quick visualization
``` python
from spectfm.visualization import plot_spectra
from matplotlib import pyplot as plt
`````` python
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(15, 7))ax1 = plot_spectra(
mir_data.spectra,
mir_data.wavenumbers,
ax=ax1,
ascending=False,
color='black',
alpha=0.6,
lw=0.5,
xlabel='Wavenumber (cm$^{-1}$)',
title='Raw Spectra'
)ax2 = plot_spectra(
X_tfm,
mir_data.wavenumbers,
ax=ax2,
ascending=False,
color='steelblue',
alpha=0.6,
lw=0.5,
xlabel='Wavenumber (cm$^{-1}$)',
title='SNV + Derivative (1st order) Transformed Spectra'
)plt.tight_layout()
```![](index_files/figure-commonmark/cell-7-output-1.png)
## Dependencies
- fastcore
- numpy
- scipy
- scikit-learn
- matplotlib## Contributing
### Developer guide
If you are new to using `nbdev` here are some useful pointers to get you
started.Install spectfm in Development mode:
``` sh
# make sure spectfm package is installed in development mode
$ pip install -e .# make changes under nbs/ directory
# ...# compile to have changes apply to spectfm
$ nbdev_prepare
```## License
This project is licensed under the Apache2 License - see the LICENSE
file for details.## Support
For questions and support, please [open an
issue](https://github.com/franckalbinet/spectfm/issues) on GitHub.