Scipy.signal find_peaks数组尺寸错误

时间:2019-03-25 20:17:26

标签: python scipy

我正在浏览数百个数据文件,以寻找信号中的峰值。我将数据存储在numpy数组中,并尝试使用scipy中的find_peaks方法。但是,无论我尝试什么,我都会得到:

  

ValueError:x必须具有一维尺寸

代码如下:

#Load electron signal data from file
data = np.loadtxt("C3tsss00001.txt", delimiter=" ", skiprows=5, dtype=float)

time, volts = np.hsplit(data, 2)

voltssmth = savgol_filter(volts, 5, 2, mode='nearest')

print(volts)
print(voltssmth)

#Invert negative detected signals into positive ones
volts = volts * -1
voltssmth = voltssmth * -1


#find peak due to detected electrons
peaks, _ =find_peaks(volts, height = .005)

这是完整的错误回溯     追溯(最近一次通话):

  File "<ipython-input-1-950424021ed6>", line 1, in <module>
    runfile('//phypcs/smith.10851$/Roaming Profile/Desktop/03.22.19    /MCPtest.py')

  File "C:\Users\smith.10851\AppData\Local\Continuum\anaconda3\lib\site-    packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "C:\Users\smith.10851\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "//phypcs/smith.10851$/Roaming Profile/Desktop/03.22.19/MCPtest.py", line 32, in <module>
peaks, _ =find_peaks(volts, height = .005)

File "C:\Users\smith.10851\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\_peak_finding.py", line 875, in find_peaks
raise ValueError('`x` must have exactly one dimension')

ValueError:x必须具有一维尺寸

这是给出问题的一小部分数据:

LECROYWP725Zi 0 Waveform
Segments 1 SegmentSize 10002
Segment TrigTime TimeSinceSegment1
#1 22-Mar-2019 18:12:19 0                 
Time Ampl
-5.4942647e-011 0.000339844
4.5057353e-011 0.000337891
1.4505735e-010 0.000330078
2.4505735e-010 0.000310547
3.4505735e-010 0.000289062
4.4505735e-010 0.000285156
5.4505735e-010 0.000210938
6.4505735e-010 0.000166016
7.4505735e-010 0.000115234
8.4505735e-010 0.000113281
9.4505735e-010 0.000111328
1.0450574e-009 9.57031e-005
1.1450574e-009 6.83594e-005
1.2450574e-009 3.90625e-005
1.3450574e-009 4.49219e-005
1.4450574e-009 3.125e-005
1.5450574e-009 -2.34375e-005
1.6450574e-009 -5.66406e-005
1.7450574e-009 -0.000101563
1.8450574e-009 -0.000103516
1.9450574e-009 -9.375e-005
2.0450574e-009 -0.000111328
2.1450574e-009 -8.98437e-005
2.2450574e-009 -0.000121094
2.3450574e-009 -0.000130859
2.4450574e-009 -0.000119141
2.5450574e-009 -0.000136719
2.6450574e-009 -0.000138672

0 个答案:

没有答案