.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_ImportingData/plot_01_load_1D_NMR_spectrum_Bruker.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_01_ImportingData_plot_01_load_1D_NMR_spectrum_Bruker.py: .. _plot_01_load_1D_NMR_spectrum_Bruker: ====================================== Load 1D NMR spectrum in TopSpin format ====================================== This example demonstrates how to load and process a single 1D NMR spectrum recorded on a Bruker spectrometer acquired using TopSpin. This examples also demonstrates how to access the various components of the data object and generally how to interact with the functions. .. GENERATED FROM PYTHON SOURCE LINES 13-14 First you need to prepare the Python environment by importing DNPLab. .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. code-block:: Python import dnplab as dnp import matplotlib.pylab as plt .. GENERATED FROM PYTHON SOURCE LINES 19-23 Load and Process the NMR Spectrum --------------------------------- In this example we use a 1D NMR spectrum acquired using TopSpin. Example data is located in the data folder. All data enters into the same object structure so this example applies to any NMR format. DNPLab will try to identify the format of the NMR spectrum (e.g. TopSpin, VnmrJ, Kea, etc.). This will work in most cases. If the autodetect fails, the format can be explicitly given using the data_type attribute of the load function (e.g. data_type = "topspin"). Remove digital filter is a boolean. If true, it will remove group delay in the topspin data. .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: Python data = dnp.load("../../data/topspin/1", remove_digital_filter=True) data.attrs["experiment_type"] = "nmr_spectrum" .. GENERATED FROM PYTHON SOURCE LINES 28-29 The spectral data is now stored in the data object. DNPLab uses object oriented programming, therefore, data is not just a variable. It is a dnpData object. Next, we will perform some basic data processing, methods that are pretty standard in NMR spectroscopy. For this just pass the dnpData object from one function to the next. .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. code-block:: Python data = dnp.apodize(data, lw=100) data = dnp.fourier_transform(data) .. GENERATED FROM PYTHON SOURCE LINES 34-37 This procedure removes the DC offset, performs an apodization with a window function (100 Hz linewidth), followed by a Fourier transforms. By default a zero filling of factor two is performed prior to Fourier transforming the spectrum. NMR spectra are typically phase sensitive (complex data) and the final processing step is to phase the spectrum. In DNPLab you can either manually phase correct the spectrum using the 'phase' function and by giving a phase explicitly: .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python data = dnp.phase(data, p0=145, p1=0) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Or by using the autophase function to automatically search for and apply the best phase angle (for reference only) .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python # data = dnp.autophase(data, force_positive=True) .. GENERATED FROM PYTHON SOURCE LINES 45-47 Plot Processed Data ------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-50 DNPLab automatically takes care of the name of the coordinates. For NMR spectra, the dimensions are named "t2" and "t1" for the direct and indirect dimension of a FID, respectively. After the Fourier Transformation these dimensions will be renamed to "f2" and "f1", respectively. Dimensions can be renamed by the user. However, several features in DNPLab take advantage of the dimension name and processing or plotting functions will change their behavior according to the type of the spectrum. .. GENERATED FROM PYTHON SOURCE LINES 52-53 To plot the NMR spectrum simply use the following command. By default, only the real part of the NMR spectrum is shown. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python dnp.fancy_plot(data) dnp.plt.show() .. image-sg:: /auto_examples/01_ImportingData/images/sphx_glr_plot_01_load_1D_NMR_spectrum_Bruker_001.png :alt: plot 01 load 1D NMR spectrum Bruker :srcset: /auto_examples/01_ImportingData/images/sphx_glr_plot_01_load_1D_NMR_spectrum_Bruker_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 Note, that the DNPLab plotting function will automatically reverse the direction of the x axis, as it is custom for NRM spectra and axis labels are automatically generated .. GENERATED FROM PYTHON SOURCE LINES 61-62 The integrated plotting function allows for additional input arguments. For example to only show a portion of the spectrum use the xlim argument. A title can be passed to the function using the title argument. This can also be a variable. For example: .. GENERATED FROM PYTHON SOURCE LINES 62-68 .. code-block:: Python sampleTag = "ODNP Experiment of 10 mM TEMPO in Water" dnp.fancy_plot(data, xlim=[-100, 100], title=sampleTag, showPar=True) dnp.plt.show() .. image-sg:: /auto_examples/01_ImportingData/images/sphx_glr_plot_01_load_1D_NMR_spectrum_Bruker_002.png :alt: ODNP Experiment of 10 mM TEMPO in Water :srcset: /auto_examples/01_ImportingData/images/sphx_glr_plot_01_load_1D_NMR_spectrum_Bruker_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-72 Advanced Usage -------------- The dnpData objects stores many more attributes for the data set, which are loaded automatically when loading the experimental data. For example, the NMR frequency can be easily accessed as follows: .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: Python nmr_frequency = data.attrs["nmr_frequency"] print(nmr_frequency) .. rst-class:: sphx-glr-script-out .. code-block:: none 14831413.270000001 .. GENERATED FROM PYTHON SOURCE LINES 77-79 All variables in DNPLab are stored in SI units. Therefore, the NMR frequency is given in (Hz). If needed, access your processed spectrum as follows: .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python x_axis = data.coords["f2"] # ppm axis spectrum = data.values # spectrum .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.327 seconds) .. _sphx_glr_download_auto_examples_01_ImportingData_plot_01_load_1D_NMR_spectrum_Bruker.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_load_1D_NMR_spectrum_Bruker.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_load_1D_NMR_spectrum_Bruker.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_