2017-06-09 167 views
2

私のデータファイルは、次のリンクで共有されています。Pythonプロットのピークを検出する

このデータは、次のスクリプトを使用してプロットすることができます。

import matplotlib as mpl 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.cbook as cbook 

def read_datafile(file_name): 

    data = np.loadtxt(file_name, delimiter=',') 
    return data 

data = read_datafile('mah_data.csv') 


fig = plt.figure() 

ax1 = fig.add_subplot(111) 

ax1.set_title("Data")  
ax1.set_xlabel('t') 
ax1.set_ylabel('s') 

ax1.plot(x,y, c='r', label='My data') 

leg = ax1.legend() 

plt.show() 

私たちはどのようにしてピークを検出できますか?私はPythonで適切なピーク検出アルゴリズムを見つけることができません。

+0

私がGoogleドライブにアクセスできませんでした、問題のサンプルデータセットを追加してください。 – Ding

+0

'x'と' y'は何ですか?おそらく、それらは 'data'配列に基づいていますが、これまでに投稿したコードでは定義しません。 – bnaecker

答えて

2

peakutil(http://pythonhosted.org/PeakUtils/)を使用してみてください。ここで私の解決策はあなたの質問にpeakutilを使用しています。

import pandas as pd 
import peakutils 
data = pd.read_csv("mah_data.csv", header=None) 
ts = data[0:10000][1] # Get the second column in the csv file 
print(ts[0:10]) # Print the first 10 rows, for quick testing 
# check peakutils for all the parameters. 
# indices are the index of the points where peaks appear 
indices = peakutils.indexes(ts, thres=0.4, min_dist=1000) 
print(indices) 

はまた、scipyのダウンロードチェックアウトピークの発見は(https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks_cwt.html

+0

データをプロットしてピークを特定する例については、https://plot.ly/python/peak-finding/をチェックアウトすることができます。 – zenravs

0

あなたはアレイの局所極大又は極小のインデックスを返すことscipy.signalargrelextrema関数を使用することができなければなりません。これは、軸を指定することによって、多次元配列に対しても機能します。

from scipy.signal import argrelextrema 

ind_max = argrelextrema(z, np.greater) # indices of the local maxima 
ind_min = argrelextrema(z, np.lesser) # indices of the local minima 

maxvals = z[ind_max] 
minvals = z[ind_min] 

具体的には、一つは地元の極大値またはローカルminimasを見つけるために argrelmin argrelmaxまたはを使用することができます。これは、axis引数を使用する多次元配列に対しても機能します。詳細については

from scipy.signal import argrelmax, argrelmin 

ind_max = argrelmax(z, np.greater) # indices of the local maxima 
ind_min = argrelmin(z, np.lesser) # indices of the local minima 

maxvals = z[ind_max] 
minvals = z[ind_min] 

、1は、このリンクを参照することができます:https://docs.scipy.org/doc/scipy/reference/signal.html#peak-finding

関連する問題