You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
6 years ago
|
from models import Model
|
||
|
|
||
6 years ago
|
import utils
|
||
7 years ago
|
from scipy import signal
|
||
|
import numpy as np
|
||
6 years ago
|
|
||
7 years ago
|
|
||
6 years ago
|
class PeaksModel(Model):
|
||
|
|
||
7 years ago
|
def __init__(self):
|
||
6 years ago
|
super()
|
||
7 years ago
|
|
||
6 years ago
|
async def fit(self, dataset, contamination=0.005):
|
||
7 years ago
|
pass
|
||
|
|
||
6 years ago
|
async def predict(self, dataframe):
|
||
7 years ago
|
array = dataframe['value'].as_matrix()
|
||
|
window_size = 20
|
||
|
# window = np.ones(101)
|
||
|
# mean_filtered = signal.fftconvolve(
|
||
|
# np.concatenate([np.zeros(window_size), array, np.zeros(window_size)]),
|
||
|
# window,
|
||
|
# mode='valid'
|
||
|
# )
|
||
|
# filtered = np.divide(array, mean_filtered / 101)
|
||
|
|
||
|
window = signal.general_gaussian(2 * window_size + 1, p=0.5, sig=5)
|
||
|
#print(window)
|
||
|
filtered = signal.fftconvolve(array, window, mode='valid')
|
||
|
|
||
|
# filtered = np.concatenate([
|
||
|
# np.zeros(window_size),
|
||
|
# filtered,
|
||
|
# np.zeros(window_size)
|
||
|
# ])
|
||
|
filtered = filtered / np.sum(window)
|
||
|
array = array[window_size:-window_size]
|
||
|
filtered = np.subtract(array, filtered)
|
||
|
|
||
|
# filtered = np.convolve(array, step, mode='valid')
|
||
|
# print(len(array))
|
||
|
# print(len(filtered))
|
||
|
|
||
|
# step = np.hstack((np.ones(window_size), 0, -1*np.ones(window_size)))
|
||
|
#
|
||
|
# conv = np.convolve(array, step, mode='valid')
|
||
|
#
|
||
|
# conv = np.concatenate([
|
||
|
# np.zeros(window_size),
|
||
|
# conv,
|
||
|
# np.zeros(window_size)])
|
||
|
|
||
|
#data = step_detect.t_scan(array, window=window_size)
|
||
|
data = filtered
|
||
|
data /= data.max()
|
||
|
|
||
6 years ago
|
result = utils.find_steps(data, 0.1)
|
||
7 years ago
|
return [(dataframe.index[x], dataframe.index[x + window_size]) for x in result]
|