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 and prepare the dataset

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

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

Compare integration methods

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

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.822 seconds)