# SoilSpecTfm
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
> Spectral Processing Tools for Soil Spectroscopy
By translating specialized soil spectroscopy methods into the
[`scikit-learn`](https://scikit-learn.org/stable/) framework,
`SoilSpecTfm` and
[`SoilSpecData`](https://fr.anckalbi.net/soilspecdata/) connect this
niche domain with Python’s vast machine learning ecosystem, making
advanced ML/DL tools accessible to soil scientists.
Implemented transforms developed so far include:
- **Baseline corrections**:
- [x]
[`SNV`](https://franckalbinet.github.io/soilspectfm/core.html#snv):
Standard Normal Variate
- [x]
[`MSC`](https://franckalbinet.github.io/soilspectfm/core.html#msc):
Multiplicative Scatter Correction
- [ ] `Detrend`: Detrend the spectrum (planned)
- [ ] `ALS`: Asymmetric Least Squares detrend the spectrum (planned)
- **Derivatives**:
- [x]
[`TakeDerivative`](https://franckalbinet.github.io/soilspectfm/core.html#takederivative):
Take derivative (1st, 2nd, etc.) of the spectrum and apply
Savitzky-Golay smoothing
- [ ] `GapSegmentDerivative`: (planned)
- **Smoothing**:
- [x]
[`WaveletDenoise`](https://franckalbinet.github.io/soilspectfm/core.html#waveletdenoise):
Wavelet denoising
- [x]
[`SavGolSmooth`](https://franckalbinet.github.io/soilspectfm/core.html#savgolsmooth):
Savitzky-Golay smoothing
- **Other transformations**:
- [x]
[`ToAbsorbance`](https://franckalbinet.github.io/soilspectfm/core.html#toabsorbance):
Transform the spectrum to absorbance
- [x]
[`Resample`](https://franckalbinet.github.io/soilspectfm/core.html#resample):
Resample the spectrum to a new wavenumber range
- [x]
[`Trim`](https://franckalbinet.github.io/soilspectfm/core.html#trim):
Trim the spectrum to a specific wavenumber range
**Key Features**:
- Seamless integration with scikit-learn’s machine learning ecosystem
- Complement with [SoilSpecData](https://fr.anckalbi.net/soilspecdata/)
package for soil spectroscopy workflows
- Pipeline-ready transformers with consistent API
All transformers follow scikit-learn conventions:
- Implement fit/transform interface
- Support get_params/set_params for GridSearchCV
- Provide detailed documentation and examples
## Installation
``` bash
pip install soilspectfm
```
## Quick Start
``` python
from soilspectfm.core import (SNV,
TakeDerivative,
ToAbsorbance,
Resample,
WaveletDenoise)
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()
```
### Preprocessing pipeline
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
('denoise', WaveletDenoise()), # Wavelet denoising
('deriv', TakeDerivative(window_length=11, polyorder=2, deriv=1)) # First derivative
])
X_tfm = pipe.fit_transform(mir_data.spectra)
```
### Quick visualization
``` python
from soilspectfm.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
## Further references
- https://orange-spectroscopy.readthedocs.io/en/latest/widgets/preprocess-spectra.html
## 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/franckalbinet/soilspectfm",
"name": "soilspectfm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "nbdev jupyter notebook python",
"author": "Franck Albinet",
"author_email": "franckalbinet@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/eb/62/000120914769e7972550d321429627341be145735dee46aa3f54568f0f25/soilspectfm-0.0.5.tar.gz",
"platform": null,
"description": "# SoilSpecTfm\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n> Spectral Processing Tools for Soil Spectroscopy\n\nBy translating specialized soil spectroscopy methods into the\n[`scikit-learn`](https://scikit-learn.org/stable/) framework,\n`SoilSpecTfm` and\n[`SoilSpecData`](https://fr.anckalbi.net/soilspecdata/) connect this\nniche domain with Python\u2019s vast machine learning ecosystem, making\nadvanced ML/DL tools accessible to soil scientists.\n\nImplemented transforms developed so far include:\n\n- **Baseline corrections**:\n\n - [x]\n [`SNV`](https://franckalbinet.github.io/soilspectfm/core.html#snv):\n Standard Normal Variate\n - [x]\n [`MSC`](https://franckalbinet.github.io/soilspectfm/core.html#msc):\n Multiplicative Scatter Correction\n - [ ] `Detrend`: Detrend the spectrum (planned)\n - [ ] `ALS`: Asymmetric Least Squares detrend the spectrum (planned)\n\n- **Derivatives**:\n\n - [x]\n [`TakeDerivative`](https://franckalbinet.github.io/soilspectfm/core.html#takederivative):\n Take derivative (1st, 2nd, etc.) of the spectrum and apply\n Savitzky-Golay smoothing\n - [ ] `GapSegmentDerivative`: (planned)\n\n- **Smoothing**:\n\n - [x]\n [`WaveletDenoise`](https://franckalbinet.github.io/soilspectfm/core.html#waveletdenoise):\n Wavelet denoising\n - [x]\n [`SavGolSmooth`](https://franckalbinet.github.io/soilspectfm/core.html#savgolsmooth):\n Savitzky-Golay smoothing\n\n- **Other transformations**:\n\n - [x]\n [`ToAbsorbance`](https://franckalbinet.github.io/soilspectfm/core.html#toabsorbance):\n Transform the spectrum to absorbance\n - [x]\n [`Resample`](https://franckalbinet.github.io/soilspectfm/core.html#resample):\n Resample the spectrum to a new wavenumber range\n - [x]\n [`Trim`](https://franckalbinet.github.io/soilspectfm/core.html#trim):\n Trim the spectrum to a specific wavenumber range\n\n**Key Features**:\n\n- Seamless integration with scikit-learn\u2019s machine learning ecosystem\n- Complement with [SoilSpecData](https://fr.anckalbi.net/soilspecdata/)\n package for soil spectroscopy workflows\n- Pipeline-ready transformers with consistent API\n\nAll transformers follow scikit-learn conventions:\n\n- Implement fit/transform interface\n- Support get_params/set_params for GridSearchCV\n- Provide detailed documentation and examples\n\n## Installation\n\n``` bash\npip install soilspectfm\n```\n\n## Quick Start\n\n``` python\nfrom soilspectfm.core import (SNV, \n TakeDerivative, \n ToAbsorbance, \n Resample, \n WaveletDenoise)\n\nfrom sklearn.pipeline import Pipeline\n```\n\n### Loading OSSL dataset\n\nLet\u2019s use OSSL dataset as an example using\n[SoilSpecData](https://fr.anckalbi.net/soilspecdata/) package.\n\n``` python\nfrom soilspecdata.datasets.ossl import get_ossl\n```\n\n``` python\nossl = get_ossl()\nmir_data = ossl.get_mir()\n```\n\n### Preprocessing pipeline\n\nTransforms are fully compatible with\n[scikit-learn](https://scikit-learn.org/stable/) and can be used in a\npipeline as follows:\n\n``` python\npipe = Pipeline([\n ('snv', SNV()), # Standard Normal Variate transformation\n ('denoise', WaveletDenoise()), # Wavelet denoising\n ('deriv', TakeDerivative(window_length=11, polyorder=2, deriv=1)) # First derivative\n])\n\nX_tfm = pipe.fit_transform(mir_data.spectra)\n```\n\n### Quick visualization\n\n``` python\nfrom soilspectfm.visualization import plot_spectra\nfrom matplotlib import pyplot as plt\n```\n\n``` python\nfig, (ax1, ax2) = plt.subplots(2, 1, figsize=(15, 7))\n\nax1 = plot_spectra(\n mir_data.spectra, \n mir_data.wavenumbers,\n ax=ax1,\n ascending=False,\n color='black',\n alpha=0.6,\n lw=0.5,\n xlabel='Wavenumber (cm$^{-1}$)',\n title='Raw Spectra'\n)\n\nax2 = plot_spectra(\n X_tfm,\n mir_data.wavenumbers,\n ax=ax2,\n ascending=False,\n color='steelblue',\n alpha=0.6,\n lw=0.5,\n xlabel='Wavenumber (cm$^{-1}$)',\n title='SNV + Derivative (1st order) Transformed Spectra'\n)\n\nplt.tight_layout()\n```\n\n![](index_files/figure-commonmark/cell-7-output-1.png)\n\n## Dependencies\n\n- fastcore\n- numpy\n- scipy\n- scikit-learn\n- matplotlib\n\n## Further references\n\n- https://orange-spectroscopy.readthedocs.io/en/latest/widgets/preprocess-spectra.html\n\n## Contributing\n\n### Developer guide\n\nIf you are new to using `nbdev` here are some useful pointers to get you\nstarted.\n\nInstall spectfm in Development mode:\n\n``` sh\n# make sure spectfm package is installed in development mode\n$ pip install -e .\n\n# make changes under nbs/ directory\n# ...\n\n# compile to have changes apply to spectfm\n$ nbdev_prepare\n```\n\n## License\n\nThis project is licensed under the Apache2 License - see the LICENSE\nfile for details.\n\n## Support\n\nFor questions and support, please [open an\nissue](https://github.com/franckalbinet/spectfm/issues) on GitHub.\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Soil infrared spectra preprocessing utilities",
"version": "0.0.5",
"project_urls": {
"Homepage": "https://github.com/franckalbinet/soilspectfm"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6502358e9816ca08fdfc796f33bcbb982ad844f575ba4f37bb9f74e90b7a56c0",
"md5": "28ac228e64af531b27cd3a2ed159bff8",
"sha256": "2402c1848e908aaeba8b5190f34d15edc7270268cb2f528bbbd5b18dc0ab414c"
},
"downloads": -1,
"filename": "soilspectfm-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "28ac228e64af531b27cd3a2ed159bff8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 14303,
"upload_time": "2025-01-24T09:55:36",
"upload_time_iso_8601": "2025-01-24T09:55:36.120464Z",
"url": "https://files.pythonhosted.org/packages/65/02/358e9816ca08fdfc796f33bcbb982ad844f575ba4f37bb9f74e90b7a56c0/soilspectfm-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "eb62000120914769e7972550d321429627341be145735dee46aa3f54568f0f25",
"md5": "56ee54bd9c3514aeee092759ce752923",
"sha256": "3aceb7ad25a961309292295b5a5ab2b78637e99b2cfff7a861325e9c1f63c8dc"
},
"downloads": -1,
"filename": "soilspectfm-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "56ee54bd9c3514aeee092759ce752923",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16245,
"upload_time": "2025-01-24T09:55:38",
"upload_time_iso_8601": "2025-01-24T09:55:38.425898Z",
"url": "https://files.pythonhosted.org/packages/eb/62/000120914769e7972550d321429627341be145735dee46aa3f54568f0f25/soilspectfm-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-24 09:55:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "franckalbinet",
"github_project": "soilspectfm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "soilspectfm"
}