.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_Analysis/plot_02_analyze_inversion_recovery_experiments.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_02_Analysis_plot_02_analyze_inversion_recovery_experiments.py: .. _plot_02_analyse_inversion_recovery_experiments: ========================================= Analyze T1 Inversion-Recovery Experiments ========================================= This example demonstrates how to import TopSpin data from an inversion recovery NMR experiment and determine the T1 relaxation rate through a fit. .. GENERATED FROM PYTHON SOURCE LINES 12-15 Load Inversion Recovery Spectra ------------------------------- Start with importing data and creating the DNPLab workspace. Note that the data are added to the workspace as 'raw' then copied to the processing buffer 'proc' to preserve the raw data during processing. .. GENERATED FROM PYTHON SOURCE LINES 15-23 .. code-block:: Python import numpy as np import dnplab as dnp file_name_path = "../../data/topspin/304" data = dnp.load(file_name_path, assign_vdlist="t1", remove_digital_filter=True) data.attrs["experiment_type"] = "nmr_spectrum" .. GENERATED FROM PYTHON SOURCE LINES 24-25 Next, the FID has to be processed. Here, first a background correction is applied to remove any DC offsets, followed by windowing and FFT to get the frequency domain NMR spectrum. .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python data = dnp.remove_background(data) data = dnp.apodize(data, lw=100) data = dnp.fourier_transform(data) data = dnp.phase(data, p0=65) dnp.fancy_plot(data, xlim=[-50, 80], title="Inversion Recovery") dnp.plt.show() .. image-sg:: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_001.png :alt: Inversion Recovery :srcset: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-40 Align Inversion Recovery Spectra -------------------------------- The spectra shown here are the individual NMR spectra for different T1 recovery times. Note how these spectra are not perfectly aligned? This can be fixed using the aligning function. A more detailed description of the aligning routine of DNPLab is given in the tutorial :ref:`plot_01_align_nmr_spectra`. .. GENERATED FROM PYTHON SOURCE LINES 40-47 .. code-block:: Python data = dnp.ndalign(data) dnp.fancy_plot(data, xlim=[-50, 80], title="Inversion Recovery, aligned") dnp.plt.show() .. image-sg:: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_002.png :alt: Inversion Recovery, aligned :srcset: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-51 Integrate Spectra ----------------- To determine the T1 relaxation time, we first have to integrate the peak intensity across the entire spectrum. After integration the workspace will have a new dnpdata object called "integrals" where the integral values and indirect axis are kept. To use ``fancy_plot`` the attribute experiment_type has to be changed to "inversion_recovery". .. GENERATED FROM PYTHON SOURCE LINES 51-66 .. code-block:: Python integrals = dnp.integrate(data) integrals.attrs["experiment_type"] = "inversion_recovery" dnp.fancy_plot(integrals) dnp.plt.show() # Depending on the quality of the data it is sometimes better to not integrate over the entire spectrum but to pick a peak region and only integrate over this region. To integrate over a region from 0 to 20 ppm us the following command: integrals = dnp.integrate(data, regions=[(0, 20)]) integrals.attrs["experiment_type"] = "inversion_recovery" dnp.fancy_plot(integrals) dnp.plt.show() .. image-sg:: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_003.png :alt: Inversion Recovery :srcset: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-70 Fit Data -------- To get the T1 value an inversion recovery function is fitted to the data sets. The fit requires an initial guess. .. GENERATED FROM PYTHON SOURCE LINES 70-89 .. code-block:: Python initial_guess = (2.0, -4000, 4000) # initial guess for: T1, M_0, M_inf out = dnp.fit(dnp.math.relaxation.t1, integrals, dim="t1", p0=initial_guess) fit = out["fit"] popt = out["popt"] err = out["err"] dnp.fancy_plot(integrals, title="Inversion Recovery") dnp.plot(fit, "-") dnp.plt.show() T1 = popt["popt", 0] M_0 = popt["popt", 1] M_inf = popt["popt", 2] print(T1.values) print(M_0.values) print(M_inf.values) .. image-sg:: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_004.png :alt: Inversion Recovery :srcset: /auto_examples/02_Analysis/images/sphx_glr_plot_02_analyze_inversion_recovery_experiments_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/local/lib/python3.8/site-packages/numpy/lib/function_base.py:626: ComplexWarning: Casting complex values to real discards the imaginary part a = asarray(a, dtype=dtype, order=order) [[2.23229459]] [[9969941.79596873]] [[-12485648.5952709]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.488 seconds) .. _sphx_glr_download_auto_examples_02_Analysis_plot_02_analyze_inversion_recovery_experiments.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_analyze_inversion_recovery_experiments.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_analyze_inversion_recovery_experiments.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_