Time domain baseline correction (NMR)
Here we show how to baseline correct dataset in the time domain before applying FFT.
The example spectra were downloaded from this page where you can find some explanations on this kind of process.
[1]:
import spectrochempy as scp
[2]:
# This example uses Bruker NMR data.
#
# Requires the official ``spectrochempy-nmr`` plugin.
# Install with: ``pip install spectrochempy[nmr]``.
[3]:
path = scp.preferences.datadir / "nmrdata" / "bruker" / "tests" / "nmr" / "h3po4"
fid = scp.nmr.read_topspin(path, expno=4)
prefs = scp.preferences
prefs.figure.figsize = (7, 3)
_ = fid.plot(show_complex=True)
WARNING | (UserWarning) No module named 'spectrochempy_hypercomplex'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[3], line 5
1 path = scp.preferences.datadir / "nmrdata" / "bruker" / "tests" / "nmr" / "h3po4"
2 fid = scp.nmr.read_topspin(path, expno=4)
3 prefs = scp.preferences
4 prefs.figure.figsize = (7, 3)
----> 5 _ = fid.plot(show_complex=True)
AttributeError: 'NoneType' object has no attribute 'plot'
[4]:
spec = scp.fft(fid)
_ = spec.plot(xlim=(5, -5))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 spec = scp.fft(fid)
2 _ = spec.plot(xlim=(5, -5))
File ~/work/spectrochempy/spectrochempy/.venv/lib/python3.13/site-packages/spectrochempy/processing/fft/fft.py:166, in fft(dataset, size, sizeff, inv, **kwargs)
118 def fft(dataset, size=None, sizeff=None, inv=False, **kwargs):
119 """
120 Apply a complex fast fourier transform.
121
(...) 164
165 """
--> 166 is_ir = dataset.meta.interferogram
168 # On which axis do we want to apply transform (get axis from arguments)
169 dim = kwargs.pop("dim", kwargs.pop("axis", -1))
AttributeError: 'NoneType' object has no attribute 'meta'
We can see that in the middle of the spectrum there are an artifact (a transmitter spike) due to different DC offset between imaginary.
In SpectroChemPy, for now, we provide a simple kind of dc correction using the dccommand.
[5]:
dc_corrected_fid = fid.dc()
spec = scp.fft(dc_corrected_fid)
_ = spec.plot(xlim=(5, -5))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 dc_corrected_fid = fid.dc()
2 spec = scp.fft(dc_corrected_fid)
3 _ = spec.plot(xlim=(5, -5))
AttributeError: 'NoneType' object has no attribute 'dc'
[6]:
path = scp.preferences.datadir / "nmrdata" / "bruker" / "tests" / "nmr" / "cadmium"
fid2 = scp.nmr.read_topspin(path, expno=100)
_ = fid2.plot(show_complex=True)
WARNING | (UserWarning) (956,)cannot be shaped into(1024,)
WARNING | (UserWarning) No module named 'spectrochempy_hypercomplex'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[6], line 3
1 path = scp.preferences.datadir / "nmrdata" / "bruker" / "tests" / "nmr" / "cadmium"
2 fid2 = scp.nmr.read_topspin(path, expno=100)
----> 3 _ = fid2.plot(show_complex=True)
AttributeError: 'NoneType' object has no attribute 'plot'
[7]:
spec2 = scp.fft(fid2)
_ = spec2.plot()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 spec2 = scp.fft(fid2)
2 _ = spec2.plot()
File ~/work/spectrochempy/spectrochempy/.venv/lib/python3.13/site-packages/spectrochempy/processing/fft/fft.py:166, in fft(dataset, size, sizeff, inv, **kwargs)
118 def fft(dataset, size=None, sizeff=None, inv=False, **kwargs):
119 """
120 Apply a complex fast fourier transform.
121
(...) 164
165 """
--> 166 is_ir = dataset.meta.interferogram
168 # On which axis do we want to apply transform (get axis from arguments)
169 dim = kwargs.pop("dim", kwargs.pop("axis", -1))
AttributeError: 'NoneType' object has no attribute 'meta'
[8]:
dc_corrected_fid2 = fid2.dc()
spec2 = scp.fft(dc_corrected_fid2)
_ = spec2.plot()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[8], line 1
----> 1 dc_corrected_fid2 = fid2.dc()
2 spec2 = scp.fft(dc_corrected_fid2)
3 _ = spec2.plot()
AttributeError: 'NoneType' object has no attribute 'dc'