Skip to content

Commit

Permalink
added optional local baseline correction to integrate peak
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigc committed Nov 26, 2024
1 parent 39e2f43 commit f9f52ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion metabolabpy/nmr/nmrConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self):
self.print_nmr_spectrum_aspect_ratio = 'auto'
self.print_hsqc_peak_aspect_ratio = 1.33
self.print_hsqc_multiplet_aspect_ratio = 1.33
self.local_baseline_correction = False

def make_config(self):
config = configparser.ConfigParser()
Expand All @@ -65,6 +66,7 @@ def make_config(self):
print_stacked_plot_repeat_axes = 'yes' if self.print_stacked_plot_repeat_axes is True else 'no'
print_auto_scale = 'yes' if self.print_auto_scale is True else 'no'
print_label = 'yes' if self.print_label is True else 'no'
local_baseline_correction = 'yes' if self.local_baseline_correction is True else 'no'
config['GUI'] = {'auto_plot': auto_plot,
'keep_zoom': keep_zoom,
'font_size': str(self.font_size),
Expand All @@ -83,7 +85,8 @@ def make_config(self):
'neg_col21': self.neg_col21,
'neg_col22': self.neg_col22,
'plot_legend': plot_legend}
config['System'] = {'current_directory': self.current_directory}
config['System'] = {'current_directory': self.current_directory,
'local_baseline_correction': self.local_baseline_correction}
config['Print'] = {'print_top_axis': print_top_axis,
'print_right_axis': print_right_axis,
'print_left_axis': print_left_axis,
Expand Down Expand Up @@ -130,6 +133,7 @@ def read_config(self):
local_var = local_var.replace("phasereferencecolour", "phase_reference_colour")
local_var = local_var.replace("poscol", "pos_col")
local_var = local_var.replace("negcol", "neg_col")
local_var = local_var.replace("localbaselinecorrection", "local_baseline_correction")
self.set_values(local_var, config[k][l])

def set_auto_plot(self, value):
Expand Down Expand Up @@ -255,6 +259,9 @@ def set_neg_col22(self, value):
def set_mode(self, value):
self.mode = value

def set_local_baseline_correction(self, value):
self.local_baseline_correction = True if value == "True" else False

def set_values(self, key, value):
m_name = "self.set_" + key
eval(m_name)(value)
16 changes: 14 additions & 2 deletions metabolabpy/nmr/nmrData.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from metabolabpy.nmr import procPars
from metabolabpy.nmr import dispPars
from metabolabpy.nmr import splineBaseline
from metabolabpy.nmr import nmrConfig
import os
from scipy.fftpack import fft, ifft, fftshift
from scipy.interpolate import CubicSpline
Expand Down Expand Up @@ -121,6 +122,8 @@ def __init__(self):
self.plot_legend = False
self.legend_label = ''
self.legend_handle = []
self.cf = nmrConfig.NmrConfig()
self.cf.read_config()
if 'pygamma' in sys.modules:
self.has_pg = True
else:
Expand Down Expand Up @@ -228,10 +231,19 @@ def add_peak(self, start_end=np.array([], dtype='float64'), peak_label='', n_pro
npts = len(self.spc[0])
spc = self.spc[0][npts - start_peak_points:npts - end_peak_points].real
max_pos = np.where(spc == np.max(spc))[0][0] + 1
self.peak_max = np.append(self.peak_max, np.max(spc))
self.cf.read_config()
if self.cf.local_baseline_correction:
self.peak_max = np.append(self.peak_max, np.max(spc) - np.mean([spc[0], spc[-1]]))
else:
self.peak_max = np.append(self.peak_max, np.max(spc))

self.peak_max_points = np.append(self.peak_max_points, start_peak_points - max_pos)
self.peak_max_ppm = np.append(self.peak_max_ppm, self.points2ppm(start_peak_points - max_pos))
self.peak_int = np.append(self.peak_int, sum(spc - np.mean([spc[0], spc[-1]])))
if self.cf.local_baseline_correction:
self.peak_int = np.append(self.peak_int, sum(spc - np.mean([spc[0], spc[-1]])))
else:
self.peak_int = np.append(self.peak_int, sum(spc))

sort_idx = np.argsort(self.start_peak)[::-1]
self.start_peak = self.start_peak[sort_idx]
self.end_peak = self.end_peak[sort_idx]
Expand Down

0 comments on commit f9f52ff

Please sign in to comment.