Gold-standard Raman and FTIR spectroscopy toolkit for food science.
Project description
FoodSpec
"Food decides the nature of your mind… Mind is born of the food you take."
— Sri Sathya Sai Baba, Effect of Food on the Mind, Summer Showers 1993 – Indian Culture and Spirituality (29 May 1993)
Production-ready Python toolkit for Raman/FTIR/NIR spectroscopy in food science. FoodSpec provides reproducible workflows for preprocessing, feature extraction, statistics, and machine learning, with built-in support for protocol-driven analysis, model management, and automated reporting.
Version: 1.0.0 | Status: Production Ready | Tests: 685 passing (79% coverage)
What problems does FoodSpec solve?
- Fragmented workflows: Vendor-specific formats, ad hoc preprocessing, irreproducible scripts.
- Lack of standards: No consistent data model across labs or instruments.
- Manual documentation: Time-consuming figure and report generation.
- Reproducibility challenges: Difficulty sharing, versioning, and archiving analyses.
What does FoodSpec provide?
Data & Import
- Unified data model for Raman, FTIR, and NIR spectroscopy
- CSV/TXT/JCAMP loaders; optional vendor support (SPC, OPUS)
- HDF5 spectral libraries for reference materials and calibration
Preprocessing
- Baseline correction (6 methods: ALS, rubberband, polynomial, airPLS, modified polynomial, rolling ball)
- Smoothing (Savitzky-Golay, moving average), normalization (vector, SNV, MSC)
- Derivatives, cropping, cosmic-ray removal
- ATR/atmospheric correction for FTIR
Feature Extraction & Interpretation
- Peak, band, and ratio detection with library-based chemical interpretation
- Ratiometric Questions (RQ) engine for reproducible ratio computation
- PCA/PLS scores, fingerprint similarity, VIP scores
- Feature importance summaries with visualization
Statistics & Quality Control
- Parametric and nonparametric hypothesis tests (t-test, ANOVA, MANOVA, Kruskal-Wallis)
- Bootstrap and permutation-based robustness
- Classification and regression metrics with confidence intervals
- Batch QC, novelty detection, drift monitoring, replicate consistency
Machine Learning
- Classification: Logistic, SVM, Random Forest, Gradient Boosting, PLS-DA
- Regression: Linear, Partial Least Squares, Random Forest
- XGBoost, LightGBM integration
- Optional Conv1D and MLP deep learning
- Model registry, versioning, and lifecycle tracking
Domain Workflows
- Oil authentication and quality assessment
- Heating/oxidation trajectory analysis
- Mixture composition estimation (NNLS, MCR-ALS)
- Hyperspectral imaging and spatial mapping
- Calibration transfer between instruments (Direct Standardization, PDS)
Reproducibility & Reporting
- Protocol-driven execution (YAML configuration)
- Automated narrative reports with metrics, tables, and figures
- Run metadata capture and artifact versioning
- Prediction confidence guards and quality gates
- Full provenance tracking
Supported modalities
| Modality | Input | Preprocessing | Workflows |
|---|---|---|---|
| Raman | Vendor/CSV/HDF5 | Baseline, smoothing, cosmic-ray removal | Authentication, heating, mixtures, QC |
| FTIR | Vendor/CSV/HDF5 | Baseline, normalization, cropping | Authentication, heating, QC |
| NIR | CSV/HDF5 | Smoothing, derivatives, SNV | Calibration, regression, quality |
| Hyperspectral | HDF5 | Per-pixel preprocessing | Mapping, segmentation, classification |
Installation
Requires Python 3.10 or 3.11
pip install foodspec
# Optional extras
pip install 'foodspec[ml]' # XGBoost, LightGBM
pip install 'foodspec[deep]' # Conv1D, MLP deep learning
pip install 'foodspec[dev]' # Documentation, tests, linting
See the [inAPI (5 minutes)
from foodspec import load_library
from foodspec.apps.oils import run_oil_authentication_workflow
# Load example dataset
fs = load_library("oils_demo.h5")
# Run complete authentication workflow
result = run_oil_authentication_workflow(fs, label_column="oil_type")
# Access results
print(f"Balanced Accuracy: {result.balanced_accuracy:.3f}")
print(f"Confusion Matrix:\n{result.confusion_matrix}")
CLI (5 minutes)
# Convert CSV to HDF5 library
foodspec csv-to-library raw_spectra.csv library.h5 \
--wavenumber-col wavenumber --sample-id-col sample_id
# Run oil authentication workflow
foodspec oil-auth library.h5 \
--label oil_type --output results/
📚 **[Full Documentation](https://chandrasekarnarayana.github.io/foodspec/)** | 150+ pages of guides, tutorials, and API reference
### Quick Links
- **Getting Started**
- [Installation Guide](https://chandrasekarnarayana.github.io/foodspec/01-getting-started/installation/)
- [Python Quickstart](https://chandrasekarnarayana.github.io/foodspec/01-getting-started/quickstart_python/)
- [CLI Quickstart](https://chandrasekarnarayana.github.io/foodspec/01-getting-started/quickstart_cli/)
- [15-Minute Tutorial](https://chandrasekarnarayana.github.io/foodspec/01-getting-started/quickstart_15min/)
- **User Guides**
- [Data Libraries](https://chandrasekarnarayana.github.io/foodspec/04-user-guide/libraries/)
- [CSV Import](https://chandrasekarnarayana.github.io/foodspec/04-user-guide/csv_to_library/)
- [CLI Reference](https://chandrasekarnarayana.github.io/foodspec/04-user-guide/cli/)
-Package Statistics
- **21,500+ lines** of production code
- **685 tests** with 79% coverage
- **150+ documentation pages** with examples
- **16 example scripts** + 3 Jupyter notebooks
- **10+ vendor formats** supported
- **6 baseline methods**, 4 normalization methods
- **10+ ML algorithms** with nested cross-validation
- **Protocol-driven workflows** for reproducibility
:
```bibtex
@software{foodspec2025,
title = {FoodSpec: Pyt! Please:
- Read the [Contributing Guide](https://chandrasekarnarayana.github.io/foodspec/06-developer-guide/contributing/)
- Follow the [Documentation Guidelines](https://chandrasekarnarayana.github.io/foodspec/06-developer-guide/documentation_guidelines/)
- Write clear code with docstrings and type hints
- Add tests for new features (pytest)
- Ensure all checks pass: `pytest`, `ruff check`, `mkdocs build`
Open issues and pull requests with clear, concise descriptions. We appreciate bug reports, feature requests, and documentation improvement
See [CITATION.cff](CITATION.cff) for machine-readable citation metadata
## Development & Testing
```bash
# Run tests with coverage
pytest --cov=src/foodspec tests/ --cov-report=html
# Lint code
ruff check src/ tests/
# Build documentation
mkdocs build
# Run example scripts
python examples/phase1_quickstart.py
All tests passing ✅ | Coverage: 79% ✅ | Documentation builds ✅
-
Advanced Topics
-
Developer Resources
For more examples and tutorials, see the documentation.
Documentation
- Getting started: Installation
- Quickstart guides: Python • CLI • Protocols
- Data & IO: CSV import • Vendor formats • Libraries
- Preprocessing: Complete guide
- Features & Analysis: Feature extraction • Interpretation
- Workflows: Oil authentication • Heating analysis • Mixtures • Calibration
- ML & Statistics: Methods • Metrics
- Advanced: Protocols & automation • Registry & plugins • Deployment
- Reference: Glossary • API • Troubleshooting
Testing
pytest --cov # Run tests with coverage report
ruff check # Lint checks
mkdocs build # Build documentation locally
Citation
If you use FoodSpec in your research, please cite the software. See CITATION.cff for full details.
Contributing
We welcome contributions. Before submitting, please:
- Follow guidelines in docs/contributing.md
- Write clear code with docstrings and examples
- Add tests for new features
- Ensure
pytest,ruff, andmkdocs buildpass
Open issues and pull requests with concise, clear descriptions.
Collaborators
- Dr. Jhinuk Gupta, Department of Food and Nutritional Sciences, Sri Sathya Sai Institute of Higher Learning (SSSIHL), Andhra Pradesh, India — LinkedIn
- Dr. Sai Muthukumar V, Department of Physics, SSSIHL, Andhra Pradesh, India — LinkedIn
- Ms. Amrita Shaw, Department of Food and Nutritional Sciences, SSSIHL, Andhra Pradesh, India — LinkedIn
- Deepak L. N. Kallepalli, Cognievolve AI Inc., Canada & HCL Technologies Ltd., Bangalore, India — LinkedIn
Author
- Chandrasekar SUBRAMANI NARAYANA, Aix-Marseille University, Marseille, France — LinkedIn
FoodSpec aligns spectroscopy, chemometrics, and ML into reproducible, well-documented pipelines for food science. Dive into the documentation for detailed theory, examples, and workflow guidance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file foodspec-1.0.0.tar.gz.
File metadata
- Download URL: foodspec-1.0.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832aaad12a64cd074549785f3079dd1a67b9da91ccdbd0f2ffa7491cf760d898
|
|
| MD5 |
b2a5252cc0c28b89db7b5dbacf74cd48
|
|
| BLAKE2b-256 |
f7af9d60b18c781bbd6c3263f201b5c8faea4caad075f28ba797b128c99e43b1
|
Provenance
The following attestation bundles were made for foodspec-1.0.0.tar.gz:
Publisher:
publish.yml on chandrasekarnarayana/foodspec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
foodspec-1.0.0.tar.gz -
Subject digest:
832aaad12a64cd074549785f3079dd1a67b9da91ccdbd0f2ffa7491cf760d898 - Sigstore transparency entry: 779589711
- Sigstore integration time:
-
Permalink:
chandrasekarnarayana/foodspec@131da3a8c3efdf07966aa436a4c03b95bd69ecac -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/chandrasekarnarayana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@131da3a8c3efdf07966aa436a4c03b95bd69ecac -
Trigger Event:
release
-
Statement type:
File details
Details for the file foodspec-1.0.0-py3-none-any.whl.
File metadata
- Download URL: foodspec-1.0.0-py3-none-any.whl
- Upload date:
- Size: 345.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e991b3638f0b3bf0e3ccc3ea4ce3d6bfc9bd74ab0f857cb521d6e6a3b382a7d6
|
|
| MD5 |
2885cf03fb19475c4042a5a3ee8eca0a
|
|
| BLAKE2b-256 |
1a192d78a2e04b93d3ec25c105e4336c2c7b7d29984f0274aa8fdd1ed8559533
|
Provenance
The following attestation bundles were made for foodspec-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on chandrasekarnarayana/foodspec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
foodspec-1.0.0-py3-none-any.whl -
Subject digest:
e991b3638f0b3bf0e3ccc3ea4ce3d6bfc9bd74ab0f857cb521d6e6a3b382a7d6 - Sigstore transparency entry: 779589713
- Sigstore integration time:
-
Permalink:
chandrasekarnarayana/foodspec@131da3a8c3efdf07966aa436a4c03b95bd69ecac -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/chandrasekarnarayana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@131da3a8c3efdf07966aa436a4c03b95bd69ecac -
Trigger Event:
release
-
Statement type: