fix: make the emg merger func so it makes one df per session
This commit is contained in:
parent
aa27fb0aa4
commit
3eb838da54
@ -444,10 +444,9 @@ class CSV_handler:
|
||||
return self.data_container_dict
|
||||
|
||||
# Retrieves df via the data_dict in the handler object
|
||||
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 - 1]
|
||||
def get_df_from_data_dict(self, subject_nr, which_arm, session, emg_nr):
|
||||
container:Data_container = self.data_container_dict.get(subject_nr)
|
||||
df = container.dict_list[session - 1].get(which_arm)[emg_nr - 1]
|
||||
return df
|
||||
|
||||
# Loads in data to a CSV_handler. Choose data_type: hard, hardPP, soft og softPP as str.
|
||||
@ -497,38 +496,39 @@ class DL_data_handler:
|
||||
def get_emg_list(self, subject_nr, session_nr) -> list:
|
||||
list_of_emgs = []
|
||||
for emg_nr in range(8):
|
||||
df, _ = self.csv_handler.get_data(self.csv_handler, subject_nr, 'left', session_nr)
|
||||
df, _ = self.csv_handler.get_data(subject_nr, 'left', session_nr, emg_nr+1)
|
||||
list_of_emgs.append(df)
|
||||
for emg_nr in range(8):
|
||||
df, _ = self.csv_handler.get_data(self.csv_handler, subject_nr, 'right', session_nr)
|
||||
df, _ = self.csv_handler.get_data(subject_nr, 'right', session_nr, emg_nr+1)
|
||||
list_of_emgs.append(df)
|
||||
return list_of_emgs
|
||||
|
||||
def make_subj_sample(list_of_emgs):
|
||||
def make_subj_sample(self, list_of_emgs):
|
||||
starting_point:DataFrame = list_of_emgs[0].rename(columns={'emg1':'emg'})
|
||||
print(starting_point)
|
||||
|
||||
tot_session_df:DataFrame = None
|
||||
|
||||
left_nr_remaining = len(list_of_emgs) - 1
|
||||
for i in range(left_nr_remaining):
|
||||
i += 1
|
||||
tot_session_df_list = []
|
||||
for i in range(2, 9):
|
||||
emg_str = get_emg_str(i)
|
||||
list_of_emgs[i].rename(columns={emg_str: 'emg'}, inplace=True)
|
||||
starting_point.append(list_of_emgs[i])
|
||||
df = list_of_emgs[i-1].rename(columns={emg_str: 'emg'})
|
||||
tot_session_df_list.append(df)
|
||||
for i in range(1, 9):
|
||||
emg_str = get_emg_str(i)
|
||||
df = list_of_emgs[7+i].rename(columns={emg_str: 'emg'})
|
||||
tot_session_df_list.append(df)
|
||||
tot_session_df = starting_point.append(tot_session_df_list, ignore_index=True, sort=True)
|
||||
|
||||
return tot_session_df
|
||||
|
||||
def store_samples(self, split_nr) -> None:
|
||||
for subject_nr in range(5):
|
||||
subj_samples = []
|
||||
#session_df_list = []
|
||||
for session_nr in range(4):
|
||||
list_of_emg = self.get_emg_list(self.csv_handler, subject_nr, session_nr)
|
||||
tot_session_df = self.make_subj_sample(list_of_emg)
|
||||
#session_df_list.append(tot_session_df)
|
||||
list_of_emg = self.get_emg_list(subject_nr+1, session_nr+1)
|
||||
tot_session_df, samplerate = self.make_subj_sample(list_of_emg)
|
||||
samples = np.array_split(tot_session_df, split_nr)
|
||||
for array in samples:
|
||||
subj_samples.append(DataFrame(array))
|
||||
df = DataFrame(array)
|
||||
samplerate = get_samplerate(df)
|
||||
subj_samples.append([df, samplerate])
|
||||
|
||||
self.samples_per_subject[subject_nr] = subj_samples
|
||||
|
||||
|
@ -143,9 +143,9 @@ def compare_with_wavelet_filter(data_frame):
|
||||
# Input: CSV_handler
|
||||
# Output: None --> Plot
|
||||
def mfcc_3_plots_1_1_2(csv_handler:CSV_handler):
|
||||
df1, samplerate1 = get_data(csv_handler, 1, 'left', 1, 1)
|
||||
df2, samplerate2 = get_data(csv_handler, 1, 'left', 2, 1)
|
||||
df3, samplerate3 = get_data(csv_handler, 2, 'left', 1, 1)
|
||||
df1, samplerate1 = csv_handler.get_data( 1, 'left', 1, 1)
|
||||
df2, samplerate2 = csv_handler.get_data( 1, 'left', 2, 1)
|
||||
df3, samplerate3 = csv_handler.get_data( 2, 'left', 1, 1)
|
||||
#print(df1.head, samplerate1)
|
||||
#print(df2.head, samplerate2)
|
||||
#print(df3.head, samplerate3)
|
||||
@ -162,9 +162,9 @@ def mfcc_3_plots_1_1_2(csv_handler:CSV_handler):
|
||||
# Input: CSV_handler
|
||||
# Output: None --> Plot
|
||||
def mfcc_3_plots_3_3_4(csv_handler:CSV_handler):
|
||||
df1, samplerate1 = get_data(csv_handler, 3, 'left', 1, 1)
|
||||
df2, samplerate2 = get_data(csv_handler, 3, 'left', 2, 1)
|
||||
df3, samplerate3 = get_data(csv_handler, 4, 'left', 1, 1)
|
||||
df1, samplerate1 = csv_handler.get_data(3, 'left', 1, 1)
|
||||
df2, samplerate2 = csv_handler.get_data(3, 'left', 2, 1)
|
||||
df3, samplerate3 = csv_handler.get_data(4, 'left', 1, 1)
|
||||
#print(df1.head, samplerate1)
|
||||
#print(df2.head, samplerate2)
|
||||
#print(df3.head, samplerate3)
|
||||
@ -178,14 +178,14 @@ def mfcc_3_plots_3_3_4(csv_handler:CSV_handler):
|
||||
plot_3_mfcc(mfcc_feat1, label_1, mfcc_feat2, label_2, mfcc_feat3, label_3)
|
||||
|
||||
def mfcc_all_emg_plots(csv_handler:CSV_handler):
|
||||
df1, samplerate1 = get_data(csv_handler, 1, 'left', 1, 1)
|
||||
df2, samplerate2 = get_data(csv_handler, 1, 'left', 1, 2)
|
||||
df3, samplerate3 = get_data(csv_handler, 1, 'left', 1, 3)
|
||||
df4, samplerate4 = get_data(csv_handler, 1, 'left', 1, 4)
|
||||
df5, samplerate5 = get_data(csv_handler, 1, 'left', 1, 5)
|
||||
df6, samplerate6 = get_data(csv_handler, 1, 'left', 1, 6)
|
||||
df7, samplerate7 = get_data(csv_handler, 1, 'left', 1, 7)
|
||||
df8, samplerate8 = get_data(csv_handler, 1, 'left', 1, 8)
|
||||
df1, samplerate1 = csv_handler.get_data( 1, 'left', 1, 1)
|
||||
df2, samplerate2 = csv_handler.get_data( 1, 'left', 1, 2)
|
||||
df3, samplerate3 = csv_handler.get_data( 1, 'left', 1, 3)
|
||||
df4, samplerate4 = csv_handler.get_data( 1, 'left', 1, 4)
|
||||
df5, samplerate5 = csv_handler.get_data( 1, 'left', 1, 5)
|
||||
df6, samplerate6 = csv_handler.get_data( 1, 'left', 1, 6)
|
||||
df7, samplerate7 = csv_handler.get_data( 1, 'left', 1, 7)
|
||||
df8, samplerate8 = csv_handler.get_data( 1, 'left', 1, 8)
|
||||
N1, mfcc_feat1 = mfcc_custom(df1, samplerate1, mfcc_windowsize, mfcc_stepsize)
|
||||
N2, mfcc_feat2 = mfcc_custom(df2, samplerate2, mfcc_windowsize, mfcc_stepsize)
|
||||
N3, mfcc_feat3 = mfcc_custom(df3, samplerate3, mfcc_windowsize, mfcc_stepsize)
|
||||
@ -212,10 +212,14 @@ def mfcc_all_emg_plots(csv_handler:CSV_handler):
|
||||
def main():
|
||||
|
||||
csv_handler = CSV_handler()
|
||||
load_data(csv_handler, 'soft')
|
||||
csv_handler.load_data('soft')
|
||||
#print(csv_handler.get_data(1, 'left', 1, 1))
|
||||
dl_data_handler = DL_data_handler(csv_handler)
|
||||
dl_data_handler.store_samples(10)
|
||||
print(dl_data_handler.samples_per_subject)
|
||||
#dl_data_handler.store_samples(10)
|
||||
#print(dl_data_handler.samples_per_subject)
|
||||
emg_list = dl_data_handler.get_emg_list(1, 1)
|
||||
df = dl_data_handler.make_subj_sample(emg_list)
|
||||
print(df.head)
|
||||
|
||||
|
||||
main()
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user