.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_Analysis/plot_03_peak_linewidth.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_03_peak_linewidth.py: .. _plot_03_peak_linewidth: ============== Peak Linewidth ============== This example demonstrates how to determine the linewidth of peaks in an NMR spectrum. .. GENERATED FROM PYTHON SOURCE LINES 12-15 Load and Process Data --------------------- Let's start with importing a NMR data set and apply some standard processing. Here we use an ODNP-enhanced low-frequency (14.5 MHz) NMR spectrum of 10 mM TEMPONE in toluene. The spectrum can be found in the example data folder of DNPLab. .. GENERATED FROM PYTHON SOURCE LINES 15-33 .. code-block:: Python import numpy as np import dnplab as dnp file_name_path = "../../data/prospa/toluene_10mM_Tempone/40" data = dnp.load(file_name_path) data.attrs["experiment_type"] = "nmr_spectrum" data = dnp.apodize(data, lw=2) data = dnp.fourier_transform(data) data = dnp.phase(data, p0=175) dnp.plt.figure() dnp.fancy_plot(data, xlim=[-20, 20]) dnp.plt.title("ODNP-Enhanced NMR Spectrum of 10 mM TEMPONE in Toluene") dnp.plt.tight_layout() dnp.plt.show() .. image-sg:: /auto_examples/02_Analysis/images/sphx_glr_plot_03_peak_linewidth_001.png :alt: ODNP-Enhanced NMR Spectrum of 10 mM TEMPONE in Toluene :srcset: /auto_examples/02_Analysis/images/sphx_glr_plot_03_peak_linewidth_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-37 Get Peak Linewidth --------------------- Next we apply the DNPLab function *find_peaks* to get a list of all the peaks the algorithm can find in the spectrum and print the list in the terminal. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python peaks = dnp.find_peaks(data) print(peaks.values) .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/local/lib/python3.8/site-packages/scipy/signal/_peak_finding.py:265: ComplexWarning: Casting complex values to real discards the imaginary part value = np.asarray(value, order='C', dtype=np.float64) [[8.19400000e+03 8.30800000e+03] [8.56964530e-02 4.97039427e+00] [2.13823217e+03 4.05198473e+03] [1.16261418e+01 1.23140035e+01] [2.75316253e-01 4.99188285e-01]] .. GENERATED FROM PYTHON SOURCE LINES 42-43 The function returns a dnpdata object with a 3xn arrays of values , with n being the number of peaks found in the spectrum, corresponding to the columns of the array. In this examples, the peak picking function finds two peaks, one for the methyl group and one for all aromatic protons. When printing the values of the dnpdata object the first row corresponds to the index of the peak in the spectrum, the linewidth in Hz is given in the second row, and the relative peak height is given in the third row. The values can be printed in a human readable form using the *peak_info* function .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python dnp.peak_info(peaks) .. rst-class:: sphx-glr-script-out .. code-block:: none Peak #1: Index: 8194, Shift (ppm): 0.09, Height : 2138.23, Width (Hz): 11.63, Width Height: 0.28 Peak #2: Index: 8308, Shift (ppm): 4.97, Height : 4051.98, Width (Hz): 12.31, Width Height: 0.50 -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-50 Setting the Threshold --------------------- By default, *find_peaks* will identify every feature in the spectrum with a amplitude > 5 % of the maximum intensity as a peak. For this, the spectrum is first normalized to a maximum amplitude of 1. This default value can be change as shown in the next line .. GENERATED FROM PYTHON SOURCE LINES 50-54 .. code-block:: Python peaks = dnp.find_peaks(data, height=0.6) dnp.peak_info(peaks) .. rst-class:: sphx-glr-script-out .. code-block:: none Peak #1: Index: 8308, Shift (ppm): 4.97, Height : 4051.98, Width (Hz): 12.31, Width Height: 0.50 -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 55-56 Now, only peaks with a relative intensity > 0.6 are included in the peak list. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.173 seconds) .. _sphx_glr_download_auto_examples_02_Analysis_plot_03_peak_linewidth.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_peak_linewidth.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_peak_linewidth.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_