|
|
@ -47,20 +47,25 @@ class JumpModel(Model): |
|
|
|
confidences.append(0.20 * (segment_max - segment_min)) |
|
|
|
confidences.append(0.20 * (segment_max - segment_min)) |
|
|
|
flat_segment = segment_data.rolling(window = 5).mean() |
|
|
|
flat_segment = segment_data.rolling(window = 5).mean() |
|
|
|
flat_segment_dropna = flat_segment.dropna() |
|
|
|
flat_segment_dropna = flat_segment.dropna() |
|
|
|
|
|
|
|
min_jump = min(flat_segment_dropna) |
|
|
|
|
|
|
|
max_jump = max(flat_segment_dropna) |
|
|
|
pdf = gaussian_kde(flat_segment_dropna) |
|
|
|
pdf = gaussian_kde(flat_segment_dropna) |
|
|
|
x = np.linspace(flat_segment_dropna.min() - 1, flat_segment_dropna.max() + 1, len(flat_segment_dropna)) |
|
|
|
x = np.linspace(flat_segment_dropna.min() - 1, flat_segment_dropna.max() + 1, len(flat_segment_dropna)) |
|
|
|
y = pdf(x) |
|
|
|
y = pdf(x) |
|
|
|
ax_list = [] |
|
|
|
ax_list = list(zip(x, y)) |
|
|
|
for i in range(len(x)): |
|
|
|
|
|
|
|
ax_list.append([x[i], y[i]]) |
|
|
|
|
|
|
|
ax_list = np.array(ax_list, np.float32) |
|
|
|
ax_list = np.array(ax_list, np.float32) |
|
|
|
antipeaks_kde = argrelextrema(np.array(ax_list), np.less)[0] |
|
|
|
antipeaks_kde = argrelextrema(np.array(ax_list), np.less)[0] |
|
|
|
peaks_kde = argrelextrema(np.array(ax_list), np.greater)[0] |
|
|
|
peaks_kde = argrelextrema(np.array(ax_list), np.greater)[0] |
|
|
|
|
|
|
|
try: |
|
|
|
min_peak_index = peaks_kde[0] |
|
|
|
min_peak_index = peaks_kde[0] |
|
|
|
max_peak_index = peaks_kde[1] |
|
|
|
|
|
|
|
segment_median = ax_list[antipeaks_kde[0], 0] |
|
|
|
|
|
|
|
segment_min_line = ax_list[min_peak_index, 0] |
|
|
|
segment_min_line = ax_list[min_peak_index, 0] |
|
|
|
|
|
|
|
max_peak_index = peaks_kde[1] |
|
|
|
segment_max_line = ax_list[max_peak_index, 0] |
|
|
|
segment_max_line = ax_list[max_peak_index, 0] |
|
|
|
|
|
|
|
segment_median = ax_list[antipeaks_kde[0], 0] |
|
|
|
|
|
|
|
except IndexError: |
|
|
|
|
|
|
|
segment_max_line = max_jump |
|
|
|
|
|
|
|
segment_min_line = min_jump |
|
|
|
|
|
|
|
segment_median = (max_jump - min_jump) / 2 + min_jump |
|
|
|
jump_height = 0.95 * (segment_max_line - segment_min_line) |
|
|
|
jump_height = 0.95 * (segment_max_line - segment_min_line) |
|
|
|
jump_height_list.append(jump_height) |
|
|
|
jump_height_list.append(jump_height) |
|
|
|
jump_length = utils.find_jump_length(segment_data, segment_min_line, segment_max_line) |
|
|
|
jump_length = utils.find_jump_length(segment_data, segment_min_line, segment_max_line) |
|
|
@ -95,9 +100,7 @@ class JumpModel(Model): |
|
|
|
pdf = gaussian_kde(flat_segment_dropna) |
|
|
|
pdf = gaussian_kde(flat_segment_dropna) |
|
|
|
x = np.linspace(flat_segment_dropna.min() - 1, flat_segment_dropna.max() + 1, len(flat_segment_dropna)) |
|
|
|
x = np.linspace(flat_segment_dropna.min() - 1, flat_segment_dropna.max() + 1, len(flat_segment_dropna)) |
|
|
|
y = pdf(x) |
|
|
|
y = pdf(x) |
|
|
|
ax_list = [] |
|
|
|
ax_list = list(zip(x, y)) |
|
|
|
for i in range(len(x)): |
|
|
|
|
|
|
|
ax_list.append([x[i], y[i]]) |
|
|
|
|
|
|
|
ax_list = np.array(ax_list, np.float32) |
|
|
|
ax_list = np.array(ax_list, np.float32) |
|
|
|
antipeaks_kde = argrelextrema(np.array(ax_list), np.less)[0] |
|
|
|
antipeaks_kde = argrelextrema(np.array(ax_list), np.less)[0] |
|
|
|
segment_median = ax_list[antipeaks_kde[0], 0] |
|
|
|
segment_median = ax_list[antipeaks_kde[0], 0] |
|
|
@ -125,7 +128,7 @@ class JumpModel(Model): |
|
|
|
self.state['convolve_min'] = self.state['WINDOW_SIZE'] |
|
|
|
self.state['convolve_min'] = self.state['WINDOW_SIZE'] |
|
|
|
|
|
|
|
|
|
|
|
if len(jump_height_list) > 0: |
|
|
|
if len(jump_height_list) > 0: |
|
|
|
self.state['JUMP_HEIGHT'] = int(min(jump_height_list)) |
|
|
|
self.state['JUMP_HEIGHT'] = float(min(jump_height_list)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.state['JUMP_HEIGHT'] = 1 |
|
|
|
self.state['JUMP_HEIGHT'] = 1 |
|
|
|
|
|
|
|
|
|
|
@ -167,13 +170,20 @@ class JumpModel(Model): |
|
|
|
|
|
|
|
|
|
|
|
delete_list = [] |
|
|
|
delete_list = [] |
|
|
|
pattern_data = self.model_jump |
|
|
|
pattern_data = self.model_jump |
|
|
|
|
|
|
|
upper_bound = self.state['convolve_max'] * 1.2 |
|
|
|
|
|
|
|
lower_bound = self.state['convolve_min'] * 0.8 |
|
|
|
|
|
|
|
delete_up_bound = self.state['conv_del_max'] * 1.02 |
|
|
|
|
|
|
|
delete_low_bound = self.state['conv_del_min'] * 0.98 |
|
|
|
for segment in segments: |
|
|
|
for segment in segments: |
|
|
|
if segment > self.state['WINDOW_SIZE'] and segment < (len(data) - self.state['WINDOW_SIZE']): |
|
|
|
if segment > self.state['WINDOW_SIZE'] and segment < (len(data) - self.state['WINDOW_SIZE']): |
|
|
|
convol_data = data[segment - self.state['WINDOW_SIZE'] : segment + self.state['WINDOW_SIZE'] + 1] |
|
|
|
convol_data = data[segment - self.state['WINDOW_SIZE'] : segment + self.state['WINDOW_SIZE'] + 1] |
|
|
|
conv = scipy.signal.fftconvolve(convol_data, pattern_data) |
|
|
|
conv = scipy.signal.fftconvolve(convol_data, pattern_data) |
|
|
|
if max(conv) > self.state['convolve_max'] * 1.2 or max(conv) < self.state['convolve_min'] * 0.8: |
|
|
|
try: |
|
|
|
|
|
|
|
if max(conv) > upper_bound or max(conv) < lower_bound: |
|
|
|
|
|
|
|
delete_list.append(segment) |
|
|
|
|
|
|
|
elif max(conv) < delete_up_bound and max(conv) > delete_low_bound: |
|
|
|
delete_list.append(segment) |
|
|
|
delete_list.append(segment) |
|
|
|
elif max(conv) < self.state['conv_del_max'] * 1.02 and max(conv) > self.state['conv_del_min'] * 0.98: |
|
|
|
except ValueError: |
|
|
|
delete_list.append(segment) |
|
|
|
delete_list.append(segment) |
|
|
|
else: |
|
|
|
else: |
|
|
|
delete_list.append(segment) |
|
|
|
delete_list.append(segment) |
|
|
|