
# ATR-FTIR Baseline Correction Pipeline for Bituminous Materials

## Overview

This repository contains a complete processing pipeline for **ATR-FTIR spectra of bituminous materials**, with a focus on:

* Physics-based ATR correction
* Baseline correction
* Spectral normalization
* Quantitative peak integration
* Comparative visualization

The correction approach is based on **refractive index–dependent ATR penetration depth** and characteristic **aliphatic band vibrations**, allowing improved comparison between spectra and more physically meaningful interpretation of band areas.

The pipeline is designed to process raw FTIR spectra in a predefined CSV format and automatically generate corrected datasets and publication-ready plots.

---

## Scientific Background

ATR-FTIR measurements of bituminous materials are strongly influenced by:

* Wavenumber-dependent penetration depth
* Refractive index mismatch
* Baseline distortions
* Band intensity scaling effects

This script applies:

1. **ATR correction based on refractive index assumptions**
2. **Baseline correction**
3. **Spectral normalization**
4. **Quantitative integration of key functional group regions**

Special attention is given to **aliphatic CH stretching and rocking vibrations**, which are used as internal references in the correction workflow.

---

## Pipeline Structure

The main pipeline performs the following steps:

### 1. Extraction and Normalization

* Reads raw CSV spectra
* Averages replicates (if present)
* Stores extracted spectra
* Generates normalized spectra

### 2. ATR + Baseline Correction

* Applies ATR correction based on penetration depth
* Applies baseline correction
* Generates corrected and normalized corrected spectra

### 3. Spectral Parameter Extraction

Integrates characteristic peak regions:

| Functional Group        | Wavenumber Range (cm⁻¹) |
| ----------------------- | ----------------------- |
| Aliphatic CH stretching | 2800–3000               |
| Carbonyl (C=O)          | 1650–1750               |
| Aromatic C=C            | 1520–1650               |
| Sulfoxides (S=O)        | 980–1070                |
| Aromatic bending        | 735–910                 |
| Aliphatic CH rocking    | 710–735                 |

Areas are extracted for:

* Raw spectra
* Raw ATR-corrected spectra
* Normalized raw spectra
* Normalized ATR-corrected spectra

### 4. Visualization

The script automatically generates:

* Raw vs corrected spectra plots
* Difference spectra
* Aliphatic rocking vs stretching comparison plots
* Bar plots of integrated peak areas (dual y-axis comparison)
* Fitted ATR parameter visualization

All figures are saved to disk for further analysis.

---

## Input Requirements

### Raw Data Format

The script expects raw spectra as CSV files with:

* Column containing **wavenumber (cm⁻¹)**
* Column(s) containing **absorbance values**
* Wavenumber axis in descending or ascending order (consistent format)
* Uniform spacing across spectra

Improper formatting will prevent correct parsing.

It is recommended that:

* All spectra share the same spectral range
* Units are in cm⁻¹ and absorbance

---

## Output

The pipeline generates:

* Extracted spectra JSON files
* Normalized spectra JSON files
* ATR-corrected spectra JSON files
* Integrated spectral parameter JSON file
* PNG figures for:

  * Spectra comparison
  * Difference spectra
  * Peak area barplots
  * ATR fitting diagnostics

---

## Goal of the Project

The purpose of this project is to provide a **reproducible and physically informed correction workflow for ATR-FTIR spectra of bituminous materials**, enabling:

* Reliable comparison between samples
* Reduction of ATR-induced distortions
* Quantitative analysis of ageing and oxidation markers
* Improved interpretation of aliphatic band behaviour

The pipeline is intended for research applications in:

* Bitumen ageing studies
* Oxidation monitoring
* Chemical fingerprint analysis
* Material comparison studies

---

## Running the Pipeline

```bash
python main.py --raw data/raw --extracted data/extracted --corrected data/corrected --plots data/spectra_plots
```

Default directories are provided but can be modified via CLI arguments.

---

## Notes

* The ATR correction relies on assumed refractive index behaviour.
* Results should be interpreted within the limits of the physical model.
* The script is designed specifically for bituminous materials and may require adaptation for other material systems.

---

