test: test the load and denoise funcs together

This commit is contained in:
Skudalen 2021-06-25 15:28:20 +02:00
parent cb3cca71fb
commit ed35db265a
5 changed files with 18 additions and 9 deletions

View File

@ -447,7 +447,7 @@ class CSV_handler:
def get_df_from_data_dict(self, subject_nr, which_arm, round, emg_nr):
data_type = self.data_type
container = self.data_container_dict.get(subject_nr)
df = container.dict_list[round - 1].get(which_arm)[emg_nr]
df = container.dict_list[round - 1].get(which_arm)[emg_nr - 1]
return df

View File

@ -52,8 +52,8 @@ def sure_threshold_filter(cA, cD):
'''
# soft filtering of wavelet trans with the 40% lowest removed
def soft_threshold_filter(cA, cD):
cA_filt = pywt.threshold(cA, 0.4 * cA.max())
def soft_threshold_filter(cA, cD, threshold):
cA_filt = pywt.threshold(cA, threshold * cA.max())
cD_filt = cD
return cA_filt, cD_filt
@ -71,16 +71,16 @@ def inverse_wavelet(df, cA_filt, cD_filt):
return y_new_values
# Takes in handler and detailes to denoise. Returns arrays and df
def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, round, emg_nr):
def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, round, emg_nr, threshold):
df = handler.get_df_from_data_dict(subject_nr, which_arm, round, emg_nr)
N = get_xory_from_df('x', df)
N_trans, cA, cD = wavelet_db4_denoising(df)
cA_filt, cD_filt = soft_threshold_filter(cA, cD)
cA_filt, cD_filt = soft_threshold_filter(cA, cD, threshold)
y_values = inverse_wavelet(df, cA_filt, cD_filt)
df_new = Handler.make_df_from_xandy(N, y_values, emg_nr)
return N, y_values, df_new
return df_new

View File

@ -1,3 +1,4 @@
from matplotlib import lines
from numpy import load
from Handle_emg_data import *
import matplotlib.pyplot as plt
@ -66,11 +67,19 @@ def test_total_denoising():
# Original df:
df = handler.get_df_from_data_dict(3, 'left', 3, 3)
print(df.head)
plot_df(df)
# Denoised df:
N_trans, y_values, df_denoised = denoice_dataset(handler, 3, 'left', 3, 3)
df_denoised = denoice_dataset(handler, 3, 'left', 3, 3, 0.2)
print(df_denoised.head)
plot_df(df_denoised)
x = get_xory_from_df('x', df)
y1 = get_xory_from_df('y', df)
y2 = get_xory_from_df('y', df_denoised)
figure, axis = plt.subplots(1, 2)
axis[0].plot(x, y1)
axis[1].plot(x, y2)
plt.show()
test_total_denoising()