From d3a3f01f2953cf0c260722327d66ca9af3355a37 Mon Sep 17 00:00:00 2001 From: Primoz Date: Tue, 22 Mar 2022 15:36:52 +0000 Subject: [PATCH] Preparation for the EDA features integration from CF. --- .../cf_tests/calculate_EDA_features_test.py | 80 ++++++++++--------- config.yaml | 4 +- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/calculatingfeatures/cf_tests/calculate_EDA_features_test.py b/calculatingfeatures/cf_tests/calculate_EDA_features_test.py index 7a1ba32c..58c9fc64 100644 --- a/calculatingfeatures/cf_tests/calculate_EDA_features_test.py +++ b/calculatingfeatures/cf_tests/calculate_EDA_features_test.py @@ -9,55 +9,59 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd +pd.set_option('display.max_rows', None) +pd.set_option('display.max_columns', None) -pathToEDACsv = "../example_data/EDA.csv" + +pathToEDACsv = "../example_data/S2_E4_Data/EDA.csv" # get an array of values from EDA empatica file eda_data, startTimeStamp_EDA, sampleRate_EDA = convert1DEmpaticaToArray(pathToEDACsv) +eda_data = eda_data[:int(300000//sampleRate_EDA)] windowLength_EDA = int(sampleRate_EDA*120) # Convert the HRV data into 2D array eda_data_2D = convertInputInto2d(eda_data, windowLength_EDA) -df_EDA = pd.DataFrame() -for row in eda_data_2D: - current_result = {} - current_result.update(gsr.extractGsrFeatures(row, sampleRate=int(sampleRate_EDA),featureNames=gsrFeatureNames)) - df_EDA = df_EDA.append(current_result, ignore_index=True) - -no_interest = 131 -current_row = eda_data_2D[no_interest,] -filtered_EDA = butter_lowpass_filter(current_row, 1.0, int(sampleRate_EDA), 6) - -plt.figure() -plt.plot(current_row, color='blue') -plt.plot(filtered_EDA, color='red') -plt.savefig('output_images/EDA_exa1.png') - -gsr_data = pd.DataFrame(current_row, columns=["EDA"]) -startTime = pd.to_datetime(0, unit="s") -gsr_data.index = pd.date_range(start=startTime, periods=len(gsr_data), freq=str(1000/sampleRate_EDA) + 'L') -gsr_data['filtered_eda'] = filtered_EDA -peakData = calcPeakFeatures(gsr_data, offset=1, thresh=.02, start_WT=4, end_WT=4, sampleRate=int(sampleRate_EDA)) - -peaks = np.where(peakData.peaks == 1.0)[0] -peak_starts = np.where(peakData.peak_start == 1.0)[0] -peak_ends = np.where(peakData.peak_end == 1.0)[0] -print(peaks) -print(peak_starts) -print(peak_ends) - -plt.figure() -plt.plot(filtered_EDA, color='red') -plt.scatter(peaks, filtered_EDA[peaks], color="green") -plt.scatter(peak_starts, filtered_EDA[peak_starts], color="green", marker=">", alpha=0.5) -plt.scatter(peak_ends, filtered_EDA[peak_ends], color="green", marker="s", alpha=0.5) -plt.savefig('output_images/EDA_exa2.png') - -print(df_EDA.loc[no_interest, df_EDA.columns.str.contains('Peak')]) - calculatedFeatures_EDA = calculateFeatures(eda_data_2D, fs=int(sampleRate_EDA), featureNames=gsrFeatureNames) print(calculatedFeatures_EDA) +# df_EDA = pd.DataFrame() +# for row in eda_data_2D: +# current_result = {} +# current_result.update(gsr.extractGsrFeatures(row, sampleRate=int(sampleRate_EDA),featureNames=gsrFeatureNames)) +# df_EDA = df_EDA.append(current_result, ignore_index=True) + +# no_interest = 131 +# current_row = eda_data_2D[no_interest,] +# filtered_EDA = butter_lowpass_filter(current_row, 1.0, int(sampleRate_EDA), 6) + +# plt.figure() +# plt.plot(current_row, color='blue') +# plt.plot(filtered_EDA, color='red') +# plt.savefig('output_images/EDA_exa1.png') + +# gsr_data = pd.DataFrame(current_row, columns=["EDA"]) +# startTime = pd.to_datetime(0, unit="s") +# gsr_data.index = pd.date_range(start=startTime, periods=len(gsr_data), freq=str(1000/sampleRate_EDA) + 'L') +# gsr_data['filtered_eda'] = filtered_EDA +# peakData = calcPeakFeatures(gsr_data, offset=1, thresh=.02, start_WT=4, end_WT=4, sampleRate=int(sampleRate_EDA)) + +# peaks = np.where(peakData.peaks == 1.0)[0] +# peak_starts = np.where(peakData.peak_start == 1.0)[0] +# peak_ends = np.where(peakData.peak_end == 1.0)[0] +# print(peaks) +# print(peak_starts) +# print(peak_ends) + +# plt.figure() +# plt.plot(filtered_EDA, color='red') +# plt.scatter(peaks, filtered_EDA[peaks], color="green") +# plt.scatter(peak_starts, filtered_EDA[peak_starts], color="green", marker=">", alpha=0.5) +# plt.scatter(peak_ends, filtered_EDA[peak_ends], color="green", marker="s", alpha=0.5) +# plt.savefig('output_images/EDA_exa2.png') + +# print(df_EDA.loc[no_interest, df_EDA.columns.str.contains('Peak')]) + diff --git a/config.yaml b/config.yaml index 67aeb299..381e5cb0 100644 --- a/config.yaml +++ b/config.yaml @@ -504,12 +504,12 @@ EMPATICA_ELECTRODERMAL_ACTIVITY: CONTAINER: EDA PROVIDERS: DBDP: - COMPUTE: False + COMPUTE: True FEATURES: ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda", "diffminmodeeda", "entropyeda"] SRC_SCRIPT: src/features/empatica_electrodermal_activity/dbdp/main.py CF: COMPUTE: True - FEATURES: ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda", "diffminmodeeda", "entropyeda"] + FEATURES: ['mean', 'std', 'q25', 'q75', 'qd'] # To-Do add remaining features from CF helper file. SRC_SCRIPT: src/features/empatica_electrodermal_activity/cf/main.py # See https://www.rapids.science/latest/features/empatica-blood-volume-pulse/