.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_ImportingData/plot_04_create_dnpdata_object_from_individual_files.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_04_create_dnpdata_object_from_individual_files.py: .. _plot_04_create_dnpdata_object_from_individual_files: ========================================================= Create a 2D dnpdata object from set of individual spectra ========================================================= This example demonstrates how to import a list of DNP-NMR spectra and create a 2D dnpdata object. Depending on how you record a set of DNP-NMR experiments, you will either end up with a single file corresponding to a 2D array of spectra (in which case you can skip to the next example ...) or with a set of individual files recorded for example at different microwave power levels. A common example is recording the NMR signal at different levels of microwave power to determine the enhancement at maximum power. Processing each spectrum individually is tedious and time-consuming. To make processing more convenient, the individual NMR spectra can be concatenated in a single dnpdata object for easy processing and analyzing of the data. .. GENERATED FROM PYTHON SOURCE LINES 14-17 Load NMR Spectra ---------------- For this example a set of 41 individual 1D NMR spectra are imported. Each spectrum is recorded using a different microwave power. The import function of DNPLab can handle a list of spectra and will automatically create the dnpdata object. To load multiple spectra first create a list of paths to the individual spectra (alternatively, you can loop over the folder index, however, for educational purposes we keep this example simple for now). .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. code-block:: Python import dnplab as dnp import numpy as np filepath_prefix = "../../data/prospa/toluene_10mM_Tempone/" filenames = [filepath_prefix + "%d/data.1d" % i for i in range(1, 42)] .. GENERATED FROM PYTHON SOURCE LINES 26-27 In addition, create an array with the power levels. In this example we use numpy to create the array. The length of this array should match the number of spectra. The Python list "filenames" and the array of power levels will become input arguments to the load function. Here, the dimension is called "Power" and the values stored in "powers" serves as the "coord" input argument. When importing the spectra DNPLab will automatically create a 2D object with a new dimension named "Power" and the data is concatenated into a single 2D dnpdata object. In this example the power is given in units of dBm. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python powers = np.linspace(0, 40, 41) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Now load the data and assign the power array to coord, .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python data = dnp.load(filenames, dim="Power", coord=powers) .. GENERATED FROM PYTHON SOURCE LINES 36-39 Process and Save the NMR Spectra -------------------------------- Once the 2D data set is created, NMR processing is straightforward. Here, we apply a line-broadening of 10 Hz, perform a Fourier Transformation, and zero-filling of the data set to twice the number of points (default of the Fourier transform function). .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: Python # dnp.dnpNMR.remove_offset(ws) data = dnp.apodize(data, lw=10) data = dnp.fourier_transform(data) .. GENERATED FROM PYTHON SOURCE LINES 46-47 Once the raw data are processed it is time to plot the 1D spectra. .. GENERATED FROM PYTHON SOURCE LINES 47-56 .. code-block:: Python sampleTag = "10 mM TEMPO in Toluene" dnp.plt.figure() dnp.fancy_plot(data, xlim=[-10, 20]) dnp.plt.title(sampleTag) dnp.plt.show() dnp.plt.tight_layout() .. image-sg:: /auto_examples/01_ImportingData/images/sphx_glr_plot_04_create_dnpdata_object_from_individual_files_001.png :alt: 10 mM TEMPO in Toluene :srcset: /auto_examples/01_ImportingData/images/sphx_glr_plot_04_create_dnpdata_object_from_individual_files_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-60 Saving the Processed Data ------------------------- DNPLab can save large data sets in a single file, so the processed data can be used at a later stage for further processing or analysis. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python file_name_path = "../../data/h5/PowerBuildUp.h5" dnp.save(data, file_name_path, overwrite=True) .. GENERATED FROM PYTHON SOURCE LINES 65-66 DNPLab saves the 2D dnpdata object in the hdf5 file format. We will use this data in the next example (:ref:`plot_01_load_2D_calculate_DNP_enhancements`) for further processing. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.356 seconds) .. _sphx_glr_download_auto_examples_01_ImportingData_plot_04_create_dnpdata_object_from_individual_files.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_create_dnpdata_object_from_individual_files.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_create_dnpdata_object_from_individual_files.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_