DIRAS+ (Dynamic Iterative Reweighted Autoregressive Spectral baseline correction algorithm) is an advanced baseline correction pipeline for Raman spectra that combines the original DIRAS algorithm with machine learning-based parameter optimization.
DIRAS+ extends the original DIRAS algorithm by using a deep learning encoder and XGBoost regressor to automatically predict optimal regularization parameters for each spectrum, eliminating the need for manual parameter tuning.
- Python 3.8 or higher
- pip or conda package manager
# Clone the repository
git clone https://github.com/Aradhye-sys/DIRAS_Plus.git
cd DIRAS_Plus
# Install dependencies
pip install -r requirements.txt# Create conda environment (if environment.yml exists)
conda env create -f environment.yml
conda activate diras-plus
# Or install manually
conda install numpy scipy pandas matplotlib xgboost tensorflow joblibnumpy- Numerical computingscipy- Scientific computing and sparse matricespandas- Data manipulationmatplotlib- Plotting and visualizationxgboost- Gradient boosting for parameter predictiontensorflow>=2.12- Deep learning frameworkjoblib- Model serialization
import numpy as np
import pandas as pd
from src.DIRAS import DIRAS
from src.DIRAS_plus import diras_plus_xgb
# Load your spectral data
# First column: wavenumbers, remaining columns: spectral intensities
df = pd.read_csv("your_spectra.csv")
wavenumbers = df.iloc[:, 0].to_numpy()
spectra = df.iloc[:, 1:].to_numpy()
# Apply DIRAS+ with automatic parameter prediction
lam_pred, baseline, corrected = diras_plus_xgb(
wavenumber=wavenumbers,
spectra=spectra,
diras_fn=DIRAS,
encoder_path="models/encoder.keras",
xgb_path="models/XGBoost.joblib"
)
# Access results
print(f"Predicted lambda values: {lam_pred}")
print(f"Baseline shape: {baseline.shape}")
print(f"Corrected spectra shape: {corrected.shape}")Run the included demo to see DIRAS+ in action:
python demo_run.pyThis will:
- Load synthetic spectral data
- Apply DIRAS with fixed parameters
- Apply DIRAS+ with ML-predicted parameters
- Display comparison plots
DIRAS_Plus/
├── data/
│ └── Synthetic_spectra.csv # Example spectral data
├── models/
│ ├── encoder.keras # Pre-trained encoder model
│ └── XGBoost.joblib # Pre-trained XGBoost model
├── src/
│ ├── DIRAS.py # Original DIRAS algorithm
│ ├── DIRAS_plus.py # DIRAS+ with ML enhancement
│ └── CITATION.cff # Citation information
├── demo_run.py # Demo script
├── requirements.txt # Python dependencies
└── README.md # This file
Original DIRAS baseline correction algorithm.
Parameters:
y: Input signal arraylam: Regularization parameterar_order: Autoregressive model orderomega: Weight for positive residualszeta: Weight for negative residualsratio: Convergence thresholdeps: Numerical stability constant
Returns:
b: Estimated baseline array
DIRAS+ algorithm with ML-based parameter prediction.
Parameters:
wavenumber: Wavenumber axis arrayspectra: Spectral data matrixdiras_fn: DIRAS function referenceencoder_path: Path to encoder modelxgb_path: Path to XGBoost modelpre_lam: Pre-processing lambda valuear_order: Autoregressive model orderomega: Weight parameter for positive residualszeta: Weight parameter for negative residualsspline_s: Spline smoothing parameterpad_len: Padding length for encoder input
Returns:
lam: Predicted lambda valuesbaseline: Estimated baselinescorrected: Baseline-corrected spectra
DIRAS+ typically provides:
- Automatic parameter optimization without manual tuning
- Consistent performance across different spectral types
- Scalable processing for large datasets
We welcome contributions! Please feel free to:
- Report bugs and issues
- Suggest new features
- Submit pull requests
- Improve documentation
If you use this repository, the FC-DIRAS, or DIRAS+ in your research, please cite our work.
Prasad Aradhye, Souparna Mandal, Robert D. Gray, and Colin J. Campbell.
Adaptive Physics-Aware Raman Baseline Correction Using ML-Guided Regularization (DIRAS+)
Analytical Chemistry (2025).
DOI: https://doi.org/10.1021/acs.analchem.5c05185
This repository includes implementations of:
- FC-DIRAS (Frequency-Conditioned DIRAS)
- DIRAS+ (ML-guided adaptive regularization)
If this code, methodology, or the associated publication contributes to your work, please cite the article above.
Citations help support continued development, validation, and dissemination of robust Raman baseline correction methods for the community.
Note: This is research software. Please ensure proper validation for your specific use case.