Skip to content

Commit

Permalink
started wavewat
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigc committed Sep 19, 2023
1 parent c44d858 commit cf34193
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
28 changes: 19 additions & 9 deletions metabolabpy/nmr/nmrData.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from pybaselines.polynomial import poly, modpoly, imodpoly, penalized_poly, loess, quant_reg, goldindec
from pybaselines import Baseline
from metabolabpy.nmr.phase3 import phase3
import pywt

try:
import pygamma as pg
Expand Down Expand Up @@ -1271,9 +1272,9 @@ def proc_spc1d(self, reset_spline=False):
max_iter=self.proc.autobaseline_max_iter, alpha=self.proc.autobaseline_alpha,
beta=self.proc.autobaseline_beta, gamma=self.proc.autobaseline_gamma,
beta_mult=self.proc.autobaseline_beta_mult, gamma_mult=self.proc.autobaseline_gamma_mult,
half_window=self.proc.autobaseline_half_window, quantile=self.autobaseline_quantile,
poly_order=self.autobaseline_poly_order, smooth_half_window=self.autobaseline_smooth_half_window,
add_ext=self.autobaseline_add_ext)
half_window=self.proc.autobaseline_half_window, quantile=self.proc.autobaseline_quantile,
poly_order=self.proc.autobaseline_poly_order, smooth_half_window=self.proc.autobaseline_smooth_half_window,
add_ext=self.proc.autobaseline_add_ext)
# end proc_spc1d

def proc_spc2d(self, test_quad_2d=False, no_abs=False):
Expand Down Expand Up @@ -2289,12 +2290,21 @@ def water_supp(self, fid):
# end water_supp

def wavewat(self, fid):
x = np.linspace(0, len(fid) - 1, len(fid))
f0 = np.copy(fid)
fid = np.roll(fid, math.floor(-self.acq.group_delay))
pp = np.polyfit(x, fid, self.proc.poly_order)
fid = fid - np.polyval(pp, x)
fid = np.roll(fid, math.ceil(self.acq.group_delay))
gd = int(self.acq.group_delay)
fid = np.copy(self.fid[0])
fid -= fid[-1]
npts = len(fid)
npts2 = self.proc.ww_zf * npts
fida = np.zeros(2*npts2, dtype='complex128')
fida[npts2:npts2 + npts - gd] = fid[gd:]
fida[npts2 - npts +gd:npts2] = np.flip(fid[gd:])
fid2 = pywt.mra(data=fida, wavelet=self.proc.ww_wavelet, transform='dwt')
fid3 = np.zeros(2*npts2, dtype='complex128')
n_mra = len(fid2)
for k in range(self.proc.ww_start, n_mra):
fid3 += fid2[k]

fid[gd:] = np.copy(fid3[npts2:npts2 + npts - gd])
return fid
# end wavewat

Expand Down
3 changes: 3 additions & 0 deletions metabolabpy/nmr/procPars.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def __init__(self):
self.autobaseline_poly_order = 4
self.autobaseline_smooth_half_window = 32
self.autobaseline_add_ext = 2
self.ww_start = 9
self.ww_zf = 16
self.ww_wavelet = 'rbio6.8'
# end __init__

def __str__(self): # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ xlsxwriter
multiprocess
pybaselines
darkdetect
pywavelets
#on arm: then install with : pip3 install metabolabpy --no-deps
#pygamma # needs python 3.9
pygamma # needs python 3.9

0 comments on commit cf34193

Please sign in to comment.