Example of 2 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 = "../../data/two_peaks/2/pdata/1"


# Load the data

processor.load_data(filepath)

#Select the region of interest

x_data, y_data = processor.select_region(-630, -540)

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

x_data, y_normalized, y_amp, y_ground = 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
#offset is shared across all peaks and must be in the normalized 0-1 scale
initial_params = [
                  -576.4, 0.12, 40.51, 0.89, 0.0, 
                  -600, 0.12, 40.51, 0.89, 0.0
                  ]

number_of_peaks = 2
# 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

fixed_amp = [False]*number_of_peaks

fixed_width = [False]*number_of_peaks

# fixed_eta controls whether each peak's Gaussian/Lorentzian mixing parameter is fixed
# False means eta is fitted freely (default), True fixes it at its initial_params value
fixed_eta = [False]*number_of_peaks

#alternatively as:

# fixed_x0 = [False, True]


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

#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)
nmrglue: 0.11
numpy: 2.4.6
scipy: 1.17.1
matplotlib: 3.11.1
pandas: 3.0.5

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

Peak 1 (Position: -576.83 ± 0.02):
  Amplitude: 0.996 ± 0.002
  Width (FWHM): 13.97 ± 0.04 ppm
  Width (FWHM): 1838.20 ± 4.97 Hz
  Carrier Frequency: 131.556611854519 MHz
  Eta: 0.22 ± 0.01
  Offset: -0.0028 ± 0.0013
  Gaussian Area: 11.58 ± 0.19
  Lorentzian Area: 4.77 ± 0.28
  Total Area: 16.35 ± 0.34

Peak 2 (Position: -595.46 ± 0.04):
  Amplitude: 0.396 ± 0.002
  Width (FWHM): 15.50 ± 0.09 ppm
  Width (FWHM): 2038.92 ± 12.47 Hz
  Carrier Frequency: 131.556611854519 MHz
  Eta: 0.00 ± 0.03
  Offset: -0.0028 ± 0.0013
  Gaussian Area: 6.53 ± 0.21
  Lorentzian Area: 0.00 ± 0.31
  Total Area: 6.53 ± 0.38
Peak 1 Percentage: 71.44% ± 2.15%
Peak 2 Percentage: 28.56% ± 1.76%
Total: 100.00%

No description has been provided for this image