Preparation for the EDA features integration from CF.

sociality-task
Primoz 2022-03-22 15:36:52 +00:00
parent 2da0911d4c
commit d3a3f01f29
2 changed files with 44 additions and 40 deletions

View File

@ -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')])

View File

@ -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/