A PyQt6-based GUI application for applying baseline corrections and noise reduction to spectroscopy data.
-
Multiple Baseline Correction Algorithms: Access to 50+ baseline correction algorithms from the
pybaselineslibrary, with library's original categories:- Polynomial (poly, modpoly, imodpoly, etc.)
- Whittaker (asls, iasls, airpls, etc.)
- Morphological (mor, imor, rolling_ball, etc.)
- Spline (mixture_model, pspline variants, etc.)
- Smoothing (snip, swima, ipsa, etc.)
- Classification (dietrich, golotvin, fastchrom, etc.)
- Miscellaneous (beads, custom_bc, etc.)
-
Noise Reduction: Savitzky-Golay filter with configurable parameters
-
Real-time Visualization: Interactive plot
-
Flexible Data Input:
- Load NumPy binary files (*.npy)
- Optionally, load xrflab related files (*.atx, *.pck)
- Generate synthetic spectra for testing
-
Dynamic Parameter Adjustment: All algorithm parameters are automatically generated from function signatures with appropriate input widgets
- Python 3.12 or higher
- poetry package manager (pip if poetry was not available)
poetry installIf poetry was not available:
pip install .If the user has access to xrflab library, installing it would give the user more
options for opening spectra files.
poetry add xrflab_urlpython GUI.py-
Load or Generate Data
- A synthetic spectrum is generated when the app is loaded
- Click "Open Spectrum" to load existing data files
- Click "Generate Random Spectrum" to generate random spectrum
-
Configure Baseline Correction
- Enable/disable baseline correction with the checkbox
- Select a category from the dropdown
- Choose a specific algorithm
- Adjust algorithm parameters as needed
-
Configure Noise Reduction (Optional)
- Enable noise reduction with the checkbox
- Adjust Savitzky-Golay filter parameters:
- Window length (number of points)
- Polynomial order
- Derivative order
- Extension mode
-
View Results
- The plot updates automatically as you adjust parameters
- Blue line: Original spectrum
- Green line: Computed baseline
- Orange line: Corrected spectrum
| Extension | Description |
|---|---|
.npy |
NumPy Binary Array |
If xrflab is available, the below extensions are also supported:
| Extension | Description |
|---|---|
.atx |
Antique'X Spectrum |
.pck |
Antique'X Packet Spectrum |
The application is organized into modular components:
MainWindow: Main application window and UI orchestrationSpectrumGenerator: Generates synthetic test spectra with Gaussian peaksBaselineProcessor: Manages baseline correction algorithms and parametersNoiseReducer: Applies Savitzky-Golay filteringPlotManager: Handles plot visualization and updatesFileManager: Manages file I/O operationsParameterWidgetFactory: Creates appropriate widgets for algorithm parametersConditionDialog: Dialog for selecting spectrum conditions from multi-condition files
Best for simple, smooth baselines. Uses polynomial fitting with various robustness improvements.
Recommended starting points:
modpoly: Modified polynomial, good general-purpose algorithmimodpoly: Improved modpoly with better peak handling
Penalized least squares approaches. Excellent for complex baselines.
Recommended starting points:
asls: Asymmetric least squares, very populararpls: Adaptive reweighted penalized least squares
Based on mathematical morphology operations. Good for uneven baselines.
Recommended starting points:
mor: Basic morphological methodrolling_ball: Simulates rolling a ball under the spectrum
Use spline interpolation for smooth baseline estimation.
Recommended starting points:
mixture_model: Statistical mixture model approachpspline_asls: P-spline version of ASLS
Apply smoothing operations to estimate baseline.
Recommended starting points:
snip: Statistics-sensitive non-linear iterative peak-clippingnoise_median: Median-based smoothing
Use signal classification to identify baseline regions.
Recommended starting points:
dietrich: Simple and fast classification methodstd_distribution: Standard deviation-based classification
-
Start Simple: Begin with polynomial methods like
modpolybefore trying more complex algorithms -
Adjust Lambda/Alpha: For Whittaker methods, the smoothing parameter (usually
lam) controls baseline smoothness:- Smaller values (1e3 - 1e5): More flexible baseline
- Larger values (1e6 - 1e8): Smoother baseline
-
Peak Sensitivity: For spectra with sharp peaks, use methods with asymmetric weighting (asls, arpls, etc.)
-
Iterative Refinement: Some algorithms (imodpoly, iasls) iterate to improve results. Adjust iteration parameters if needed.
-
Window Length: Should be odd and larger than polynomial order
- Smaller windows: Preserve peak shape but less smoothing
- Larger windows: More smoothing but can distort peaks
-
Polynomial Order:
- Order 2-3: Good for most spectra
- Higher orders: Can introduce artifacts
- Parameter changes are debounced (300ms delay) to prevent excessive recalculation
- For large datasets, start with fast algorithms (polynomial, morphological)
- Disable real-time updates if working with very large spectra
Error: "Algorithm 'xxx' not found"
- Ensure
pybaselinesis properly installed - Some algorithms may require specific dependencies
Error: "window_length must be less than or equal to the size of x"
- Reduce the window length parameter in noise reduction
- Ensure your spectrum has enough data points
Error: "polyorder must be less than window_length"
- Reduce polynomial order or increase window length
Plot shows error message
- Check parameter values are appropriate for your data
- Try a different algorithm
- Verify input data is valid (no NaN or infinite values)
If you encounter issues:
- Check parameter values are within reasonable ranges
- Try the default synthetic spectrum to isolate data vs. algorithm issues
- Consult the pybaselines documentation for algorithm-specific guidance
This project uses the following open-source libraries:
- PyQt6: GPL v3
- pybaselines: BSD 3-Clause License
- pyqtgraph: MIT License
- NumPy, SciPy: BSD License
Please ensure compliance with respective licenses for distribution.
Contributions are welcome! Areas for improvement:
- Additional baseline correction methods
- Export functionality for corrected spectra
- Batch processing capabilities
- Parameter presets/profiles
- Undo/redo functionality
- Additional visualization options (residuals, difference plots)
- pybaselines: Official Documentation
- Savitzky-Golay filter: SciPy.savgol_filter
Author: [Bahador Rousta Jorshary]
Last Updated: January 2026