chore: moved load and get func to emg_handler file

This commit is contained in:
Skudalen 2021-06-30 16:02:34 +02:00
parent 40773560ce
commit aa27fb0aa4
4 changed files with 28 additions and 25 deletions

View File

@ -2,7 +2,7 @@ import pandas as pd
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
from pandas.core.frame import DataFrame from pandas.core.frame import DataFrame
from Present_data import get_data #from Present_data import get_data
class Data_container: class Data_container:
@ -450,6 +450,28 @@ class CSV_handler:
df = container.dict_list[round - 1].get(which_arm)[emg_nr - 1] df = container.dict_list[round - 1].get(which_arm)[emg_nr - 1]
return df return df
# Loads in data to a CSV_handler. Choose data_type: hard, hardPP, soft og softPP as str.
# Returns None.
def load_data(self, data_type):
if data_type == 'hard':
self.load_hard_original_emg_data()
elif data_type == 'hardPP':
self.load_hard_PP_emg_data()
elif data_type == 'soft':
self.load_soft_original_emg_data()
elif data_type == 'softPP':
self.load_soft_PP_emg_data()
else:
raise Exception('Wrong input')
# Retrieved data. Send in loaded csv_handler and data detailes you want.
# Returns DataFrame and samplerate
def get_data(self, subject_nr, which_arm, session, emg_nr):
data_frame = self.get_df_from_data_dict(subject_nr, which_arm, session, emg_nr)
samplerate = get_samplerate(data_frame)
return data_frame, samplerate
''' '''
def get_keyboard_data(self, filename:str, pres_or_release:str='pressed'): def get_keyboard_data(self, filename:str, pres_or_release:str='pressed'):
filepath = self.working_dir + str(filename) filepath = self.working_dir + str(filename)
@ -469,14 +491,16 @@ class DL_data_handler:
4: [], 4: [],
5: [] 5: []
} }
def get_samples_dict(self):
return self.samples_per_subject
def get_emg_list(self, subject_nr, session_nr) -> list: def get_emg_list(self, subject_nr, session_nr) -> list:
list_of_emgs = [] list_of_emgs = []
for emg_nr in range(8): for emg_nr in range(8):
df, _ = get_data(self.csv_handler, subject_nr, 'left', session_nr) df, _ = self.csv_handler.get_data(self.csv_handler, subject_nr, 'left', session_nr)
list_of_emgs.append(df) list_of_emgs.append(df)
for emg_nr in range(8): for emg_nr in range(8):
df, _ = get_data(self.csv_handler, subject_nr, 'right', session_nr) df, _ = self.csv_handler.get_data(self.csv_handler, subject_nr, 'right', session_nr)
list_of_emgs.append(df) list_of_emgs.append(df)
return list_of_emgs return list_of_emgs

View File

@ -104,27 +104,6 @@ def plot_all_emg_mfcc(data_list:list, label_list:list):
# The CSV_handler takes in data_type, but only for visuals. # The CSV_handler takes in data_type, but only for visuals.
# E.g. handler = CSV_handler('soft') # E.g. handler = CSV_handler('soft')
# Loads in data to a CSV_handler. Choose data_type: hard, hardPP, soft og softPP as str.
# Returns None.
def load_data(csv_handler:CSV_handler, data_type):
if data_type == 'hard':
csv_handler.load_hard_original_emg_data()
elif data_type == 'hardPP':
csv_handler.load_hard_PP_emg_data()
elif data_type == 'soft':
csv_handler.load_soft_original_emg_data()
elif data_type == 'softPP':
csv_handler.load_soft_PP_emg_data()
else:
raise Exception('Wrong input')
# Retrieved data. Send in loaded csv_handler and data detailes you want.
# Returns DataFrame and samplerate
def get_data(csv_handler:CSV_handler, subject_nr, which_arm, session, emg_nr):
data_frame = csv_handler.get_df_from_data_dict(subject_nr, which_arm, session, emg_nr)
samplerate = get_samplerate(data_frame)
return data_frame, samplerate
# Takes in handler and detailes to denoise. # Takes in handler and detailes to denoise.
# Returns arrays and df # Returns arrays and df

Binary file not shown.