33 lines
971 B
Python
33 lines
971 B
Python
import matplotlib.pyplot as plt
|
|
import matplotlib
|
|
import pandas as pd
|
|
import numpy as np
|
|
from scipy.signal import savgol_filter
|
|
import scipy.signal as signal
|
|
import sys
|
|
df = pd.read_csv(sys.argv[1],delimiter="\t")
|
|
target = sys.argv[2]
|
|
time_size = 5
|
|
window = time_size * 30 + 1
|
|
|
|
def reject_outliers(data,indicies, m = 2.):
|
|
d = np.abs(data - np.median(data))
|
|
mdev = np.median(d)
|
|
s = d/mdev if mdev else 0.
|
|
return (data[s<m],indicies[s<m])
|
|
|
|
xhat = savgol_filter(df[target].array.to_numpy(),window,3)
|
|
indexs = np.arange(len(xhat))
|
|
xhat,xs = reject_outliers(xhat,indexs,m=1.5)
|
|
indicies = signal.argrelextrema(xhat, np.less,order=int(window/2))[0]
|
|
|
|
plt.plot(df[target])
|
|
plt.plot(xs,xhat,color="green")
|
|
plt.plot(xs[indicies],xhat[indicies],marker="o", ls="", ms=3 )
|
|
|
|
value1 = np.median(xhat)
|
|
print(np.median(xhat))
|
|
# value2 = np.percentile(xhat, 75)
|
|
plt.plot([0,len(df[target])],[value1,value1],color="purple")
|
|
#plt.plot([0,len(xhat)],[value2,value2])
|
|
plt.show() |