NDDataset baseline correction

In this example, we perform a baseline correction of a 2D NDDataset interactively, using the multivariate method and a pchip interpolation.

As usual we start by importing the useful library, and at least the spectrochempy library.

import spectrochempy as scp

Load data:

datadir = scp.preferences.datadir
nd = scp.NDDataset.read_omnic(datadir / "irdata" / "nh4y-activation.spg")

Do some slicing to keep only the interesting region:

ndp = (nd - nd[-1])[:, 1291.0:5999.0]
# Important:  notice that we use floating point number
# integer would mean points, not wavenumbers!

Define the BaselineCorrection object:

Launch the interactive view, using the BaselineCorrection.run method:

ranges = [
    [1556.30, 1568.26],
    [1795.00, 1956.75],
    [3766.03, 3915.81],
    [4574.26, 4616.04],
    [4980.10, 4998.01],
    [5437.52, 5994.70],
]  # predefined ranges
span = ibc.run(
    *ranges, method="multivariate", interpolation="pchip", npc=5, zoompreview=3
)
INTERACTIVE BASELINE CORRECTION, Click on left button & Span to set regions. Click on right button on a region to remove it., Baseline corrected dataset preview

Print the corrected dataset:

plot baseline correction
NDDataset: [float64] a.u. (shape: (y:55, x:4883))

This ends the example ! The following line can be uncommented if no plot shows when running the .py script

scp.show()

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

Gallery generated by Sphinx-Gallery