Example of 6 peaks

import sys
import matplotlib.pyplot as plt
sys.path.append("../../src")
from nmrlineshapeanalyser.core import NMRProcessor

#create NMRProcessor object

processor = NMRProcessor()

#Load filepath
filepath = r"..\..\data\six_peaks\5\pdata\1\\"


# Load the data

processor.load_data(filepath)

#Select the region of interest

x_data, y_data = processor.select_region(200, 800)

#Normalize the data and return normalised y_axis and the corresponding x_axis

x_data, y_normalized = processor.normalize_data(x_data, y_data)

#define initial parameters for the fitting
#this example is for a single peak
#format of the parameters is [x0, amplitude, width, eta, offset]
# x0 (position), amplitude, width, eta (mixing parameter), offset
#x0 has to be close to the peak position
initial_params = [
                  334, 0.12, 40.51, 0.89, -143.115, 
                  430, 0.12, 40.51, 0.89, -143.115,
                  497, 0.219, 55.43, 0.52, -143.115,
                  562, 0.12, 40.51, 0.89, -143.115,
                  581, 0.219, 55.43, 0.52, -143.155,
                  623, 0.12, 40.51, 0.89, -143.115
                  ]

number_of_peaks = 6
# fixed_x0 controls whether peak positions should be fixed during fitting
# False means position can vary, True means position is fixed
fixed_x0 = [False]*number_of_peaks

#FIt the data
popt, metrics, fitted = processor.fit_peaks(x_data, y_normalized, initial_params, fixed_x0)

#popt is the optimized parameters
#metrics is the metrics of the fitting
#fitted is the fitted curve data

#Plot and examine the results of the fitting
fig, axes, components = processor.plot_results(x_data, y_normalized, fitted, popt)

#Save the figure as an png file and the results as a csv file
processor.save_results(filepath, x_data, y_normalized, fitted, metrics, popt, components)

Peak Fitting Results:
===================

Peak 1 (Position: 335.07 ± 0.19):
Amplitude: 0.060 ± 0.001
Width: 47.42 ± 0.55 in ppm
Width: 3215.12 ± 36.98 in Hz
Eta: 0.00 ± 0.06
Offset: -965.720 ± 13452.906
Gaussian Area: 3.04 ± 0.19
Lorentzian Area: 0.00 ± 0.27
Total Area: 3.04 ± 0.33
--------------------------------------------------

Peak 2 (Position: 431.23 ± 0.19):
Amplitude: 0.225 ± 0.004
Width: 57.32 ± 0.60 in ppm
Width: 3886.79 ± 40.92 in Hz
Eta: 0.48 ± 0.02
Offset: -178.649 ± 2760.662
Gaussian Area: 7.08 ± 0.34
Lorentzian Area: 9.80 ± 0.50
Total Area: 16.88 ± 0.61
--------------------------------------------------

Peak 3 (Position: 497.39 ± 0.25):
Amplitude: 0.135 ± 0.017
Width: 38.41 ± 1.91 in ppm
Width: 2604.37 ± 129.64 in Hz
Eta: 0.35 ± 0.08
Offset: 1880.891 ± 3039.696
Gaussian Area: 3.61 ± 0.67
Lorentzian Area: 2.83 ± 0.78
Total Area: 6.44 ± 1.03
--------------------------------------------------

Peak 4 (Position: 580.16 ± 0.46):
Amplitude: 0.095 ± 0.020
Width: 31.00 ± 2.67 in ppm
Width: 2101.75 ± 180.90 in Hz
Eta: 0.36 ± 0.19
Offset: -327.977 ± 3039.696
Gaussian Area: 2.02 ± 0.75
Lorentzian Area: 1.65 ± 0.95
Total Area: 3.67 ± 1.21
--------------------------------------------------

Peak 5 (Position: 553.29 ± 1.75):
Amplitude: 0.642 ± 0.026
Width: 72.26 ± 2.27 in ppm
Width: 4899.37 ± 153.92 in Hz
Eta: 0.00 ± 0.13
Offset: -333.249 ± 3039.696
Gaussian Area: 49.40 ± 6.84
Lorentzian Area: 0.00 ± 9.37
Total Area: 49.40 ± 11.60
--------------------------------------------------

Peak 6 (Position: 614.38 ± 1.31):
Amplitude: 0.724 ± 0.019
Width: 83.87 ± 1.04 in ppm
Width: 5686.87 ± 70.58 in Hz
Eta: 0.00 ± 0.03
Offset: -75.293 ± 3039.697
Gaussian Area: 64.62 ± 2.86
Lorentzian Area: 0.05 ± 3.18
Total Area: 64.67 ± 4.27
--------------------------------------------------
Peak 1 Percentage is 2.11% ± 0.29%
Peak 2 Percentage is 11.71% ± 1.10%
Peak 3 Percentage is 4.47% ± 0.81%
Peak 4 Percentage is 2.54% ± 0.87%
Peak 5 Percentage is 34.29% ± 8.58%
Peak 6 Percentage is 44.88% ± 4.89%
Overall Percentage is 100.00% ± 10.01%

No description has been provided for this image