Work with spectrum data saved in a csv file¶
The load_csv function lets you work directly with NMR data saved in a csv file.filter
Important thing to know is that this function, unlike the load_data function that works directly with Bruker files, you would have to declare the following parameters alongside the file path:
The CSV file must have the following columns:
# Load data
processor.load_csv(filepath, '17', 'O', 67.8)
# Select region and normalize
x_region, y_region = processor.select_region(160, 850)
x_data, y_normalized = processor.normalize_data(x_region, y_region)
# Define initial parameters for peaks
# Each peak is defined by 5 parameters in order:
# x0 (position), amplitude, width, eta (mixing parameter), offset
initial_params = [
348, 0.16, 81, 0.89, -143.115,
435.5, 0.29, 51, 0.89, -143.115,
560, 0.52, 100, 0.52, -1,
600, 0.61, 82, 0.52, -1,
]
# Fit peaks
# fixed_x0 controls whether peak positions should be fixed during fitting
# False means position can vary, True means position is fixed
fixed_x0 = [False, False, False, True] # Allow all peak positions to vary
# popt: optimized parameters
# metrics: fitting metrics for each peak
# fitted: fitted curve data
popt, metrics, fitted = processor.fit_peaks(x_data, y_normalized, initial_params, fixed_x0)
# Plot and save results
fig, axes, components = processor.plot_results(x_data, y_normalized, fitted, popt)
# Save all results
processor.save_results(filepath, x_data, y_normalized, fitted, metrics,
popt, components)