Integrate a baseline-corrected IR band

This example shows how to baseline-correct a spectral region and compare trapezoidal and Simpson integration on a sequence of IR spectra.

import spectrochempy as scp

Load a stacked IR dataset and restrict the analysis to the band of interest.

dataset = scp.read_omnic("irdata/nh4y-activation.spg")
band = dataset[:20, 1250.0:1800.0]
band.y -= band.y[0]
band.y.ito("min")
band.y.title = "acquisition time"

prefs = scp.preferences
prefs.figure.figsize = (7, 3.5)
prefs.colormap = "Dark2"
prefs.colorbar = True
_ = band.plot()
plot peak integration

Fit a polynomial baseline on three reference regions.

blc = scp.Baseline(model="polynomial", order=3)
blc.ranges = (
    [1740.0, 1800.0],
    [1550.0, 1570.0],
    [1250.0, 1300.0],
)
blc.fit(band)

corrected = blc.corrected
_ = corrected.plot()
plot peak integration

Integrate each spectrum over the full selected region.

trapz_area = corrected.trapezoid(dim="x")
simpson_area = corrected.simpson(dim="x")

scp.plot_multiple(
    method="scatter",
    ms=5,
    datasets=[trapz_area, simpson_area],
    labels=["trapezoidal rule", "Simpson's rule"],
    legend="best",
)
plot peak integration
<Axes: xlabel='acquisition time $\\mathrm{/\\ \\mathrm{min}}$', ylabel='area $\\mathrm{/\\ \\mathrm{a.u.} \\cdot \\mathrm{cm}^{-1}}$'>

For this dataset both numerical methods are very close.

plot peak integration

This ends the example. Uncomment the next line to display the figures when running the script directly with Python.

# scp.show()

Total running time of the script: (0 minutes 0.987 seconds)