-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython__R_wavelet_Func.py
More file actions
37 lines (34 loc) · 1.51 KB
/
Python__R_wavelet_Func.py
File metadata and controls
37 lines (34 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
from numpy import *
# import R's "baselineWavelet" package
bW= importr('baselineWavelet')
def baselineWavelet(Spectrum_data):
S=Spectrum_data
# Transform the original data into R language format
rFS=ro.FloatVector(S)
# Creating a R array correspond to the data's dimension
sS=ro.FloatVector(range(1,shape(S)[0]+1))
## Start the wavelet analysis from R's baselineWavelet package
scales=ro.r.seq(1,127,1)
cwtargs={'scales':scales,'wavelet':'mexh'}
# Wavelet coeffecients calculated by cwt
####******************########
wCoefs=ro.r.cwt(rFS,**cwtargs)
####******************########
# Get the ridge of wavelet coeffecients and output it into png file.
localMax=bW.getLocalMaximumCWT(wCoefs)
####******************########
ridgeList=bW.getRidge(localMax, gapTh=3, skip=2)
# Calculating the background contribution
MPargs={'SNR.Th':1,'ridgeLength':10}
# Peak infomation
majorPeakInfo = bW.identifyMajorPeaks(rFS, ridgeList, wCoefs,scales,**MPargs)
peakWidth=bW.widthEstimationCWT(rFS,majorPeakInfo)
bCargs={'lambda':1000,'differences':1}
####******************########
backgr = bW.baselineCorrectionCWT(rFS,peakWidth,**bCargs)
corrected=ro.FloatVector(array(rFS)-array(backgr))
####******************########
#wavelet coeffecients, baseline, baseline-corrected spectrum
return array(wCoefs),array(backgr),array(corrected)