Processing Relaxation measurement

Processing NMR spectra taken for relaxation measurements

Requires the official spectrochempy-nmr plugin. Install with: pip install spectrochempy[nmr].

Import API

import spectrochempy as scp

# short version of the unit registry
U = scp.ur

Importing a pseudo 2D NMR spectra

Define the folder where are the spectra

datadir = scp.preferences.datadir
nmrdir = datadir / "nmrdata" / "bruker" / "tests" / "nmr"

dataset = scp.nmr.read(nmrdir / "relax" / "100" / "ser", use_list="vdlist")

Analysing the data

Print dataset summary

NDDataset [relax expno:100 procno:1 (SER)] — complex128, shape: (y:9, x:1982), count
name
:
relax expno:100 procno:1 (SER)
author
:
runner@runnervmmklqx
created
:
2026-06-28 17:38:39+00:00
history
:
2026-06-28 17:38:39+00:00> Imported from TopSpin dataset
Data
title
:
intensity
values
:
R[[ 0.5522 2.137 ... -1.437 -0.02603]
[ 1.099 3.404 ... -0.6497 -0.0129]
...
[ 1.603 5.99 ... 4.959 0.09235]
[ 1.61 6.14 ... -0.7725 -0.01501]] countI[[ -1.513 -2.733 ... 4.471 0.08437]
[ -2.496 -4.623 ... -6.003 -0.1152]
...
[ -4.25 -7.726 ... 4.695 0.08693]
[ -4.302 -7.69 ... 0.222 0.004867]] count
shape
:
(y:9, x:1982(complex))
Dimension `x`
size
:
1982
title
:
F2 acquisition time
coordinates
:
[ 0 6.4 ... 1.267e+04 1.268e+04] µs
Dimension `y`
size
:
9
title
:
time
coordinates
:
[ 1 2 ... 20 50] s


Plot the dataset

ds = dataset.em(lb=15 * U.Hz)
ds = ds.fft()
ds = ds.pk(phc0=-10 * U.deg, phc1=0 * U.deg)
_ = ds.plot(xlim=(-60, -140))
plot processing nmr relax

Integrate a region

dsint = ds[:, -90.0:-115.0].simpson()
_ = dsint.plot(marker="^", ls=":")
dsint.real
plot processing nmr relax
NDDataset [relax expno:100 procno:1 (SER)] — float64, size: 9, count⋅ppm
name
:
relax expno:100 procno:1 (SER)
author
:
runner@runnervmmklqx
created
:
2026-06-28 17:38:39+00:00
description
:
Integration of NDDataset 'relax expno:100 procno:1 (SER)' along dim: 'x'.
history
:
2026-06-28 17:38:39+00:00> Dataset resulting from application of `simpson` method
Data
title
:
area
values
:
[ 1507 2543 ... 4173 4300] count⋅ppm
size
:
9
Dimension `y`
size
:
9
title
:
time
coordinates
:
[ 1 2 ... 20 50] s


Fit a model

create an Optimize object using a simple leastsq method

fitter = scp.Optimize(log_level="INFO", method="leastsq")

Define the model to fit

def T1_model(t, I0, T1):  # no underscore in parameters names.
    # T1 relaxation model
    import numpy as np

    I = I0 * (1 - np.exp(-t / T1))
    return I

Add the model to the fitter usermodels as it it not a built-in model

fitter.usermodels = {"T1_model": T1_model}

Define the parameter variables using a script (parameter: value, low_bound, high_bound) no underscore in parameters names.

fitter.script = """
MODEL: T1
shape: T1_model
  $ I0:  1000.0, 1, none
  $ T1:  2.0,    0.1, none
"""

Performs the fit


NDDataset [relax expno:100 procno:1 (SER)_Optimize.inverse_transform] — float64, shape: (u:1, y:9), count⋅ppm
name
:
relax expno:100 procno:1 (SER)_Optimize.inverse_transform
author
:
runner@runnervmmklqx
created
:
2026-06-28 17:38:39+00:00
history
:
2026-06-28 17:38:39+00:00> Created using method Optimize.inverse_transform
Data
title
:
area
values
:
[[ 1506 2470 ... 4185 4185]] count⋅ppm
shape
:
(u:1, y:9)
Dimension `u`
title
:
coordinates
:
Undefined
Dimension `y`
size
:
9
title
:
time
coordinates
:
[ 1 2 ... 20 50] s


_ = fitter.plotmerit(dsint, som, method="scatter", title="T1 relaxation fitting")
T1 relaxation fitting

This ends the example ! The following line can be removed or commented when the example is run as a notebook (ipynb).

# scp.show()

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