feat: complete a denoise func for part of the dataset

This commit is contained in:
Skudalen 2021-06-25 13:41:57 +02:00
parent 9634a63d31
commit 8f34ff6abf
2 changed files with 29 additions and 2 deletions

View File

@ -13,12 +13,18 @@ class Data_container:
self.data_dict_round2 = {'left': [None]*8, 'right': [None]*8}
self.data_dict_round3 = {'left': [None]*8, 'right': [None]*8}
self.data_dict_round4 = {'left': [None]*8, 'right': [None]*8}
self.dict_list = [self.data_dict_round1,
self.data_dict_round2,
self.data_dict_round3,
self.data_dict_round4
]
class CSV_handler:
def __init__(self):
self.working_dir = str(Path.cwd())
self.data_container_dict = {} # Dict with keys equal subject numbers and values equal the relvant datacontainer
self.data_type = ''
# Makes dataframe from the csv files in the working directory
def make_df(self, filename):
@ -158,6 +164,7 @@ class CSV_handler:
self.store_df_in_container(filename, emg_nr, 'right', data_container, round+1)
# Links the stored data in the data_container to the Handler
self.link_container_to_handler(data_container)
self.data_type = 'hardPP'
return self.data_container_dict
def load_soft_PP_emg_data(self):
@ -249,6 +256,7 @@ class CSV_handler:
self.store_df_in_container(filename, emg_nr, 'right', data_container, round+1)
# Links the stored data in the data_container to the Handler
self.link_container_to_handler(data_container)
self.data_type = 'softPP'
return self.data_container_dict
def load_hard_original_emg_data(self):
@ -340,7 +348,7 @@ class CSV_handler:
self.store_df_in_container(filename, emg_nr, 'right', data_container, round+1)
# Links the stored data in the data_container to the Handler
self.link_container_to_handler(data_container)
self.data_type = 'hard'
return self.data_container_dict
def load_soft_original_emg_data(self):
@ -432,6 +440,7 @@ class CSV_handler:
self.store_df_in_container(filename, emg_nr, 'right', data_container, round+1)
# Links the stored data in the data_container to the Handler
self.link_container_to_handler(data_container)
self.data_type = 'soft'
return self.data_container_dict
# Help: gets the str from emg nr

View File

@ -1,5 +1,6 @@
import numpy as np
import matplotlib.pyplot as plt
import pandas
from pandas.core.frame import DataFrame
from scipy.fft import fft, fftfreq
import pywt
@ -69,6 +70,23 @@ def inverse_wavelet(df, cA_filt, cD_filt):
old_len = len(get_xory_from_df('y', df))
return y_new_values
def denoice_dataset(handler:Handler.CSV_handler, subject_nr, which_arm, emg_nr, round):
data_type = handler.data_type
container = handler.data_container_dict.get(subject_nr)
df = container.dict_list[round - 1].get(which_arm)[emg_nr]
print(df.head)
N = get_xory_from_df('x', df)
N_trans, cA, cD = wavelet_db4_denoising(df)
cA_filt, cD_filt = soft_threshold_filter(cA, cD)
y_values = inverse_wavelet(df, cA_filt, cD_filt)
return pandas.DataFrame([N_trans, y_values])
# MOVE TO Present_data.py
# Plots DataFrame objects
def plot_df(df:DataFrame):
lines = df.plot.line(x='timestamp')