Add folder structure for CF testing and EDA test.

sociality-task
Primoz 2022-03-21 10:40:18 +00:00
parent a80f7c0cc4
commit d1c59de2e9
5 changed files with 73 additions and 3 deletions

0
__init__.py 100644
View File

View File

@ -219,3 +219,6 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Output images
cf_tests/output_images/

View File

@ -0,0 +1,63 @@
import sys
sys.path.append("..")
from CalculatingFeatures.helper_functions import convert1DEmpaticaToArray, convertInputInto2d, gsrFeatureNames
from CalculatingFeatures.calculate_features import calculateFeatures
from CalculatingFeatures import gsr
from eda_explorer.load_files import butter_lowpass_filter
from eda_explorer.EDA_Peak_Detection_Script import calcPeakFeatures
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pathToEDACsv = "../example_data/EDA.csv"
# get an array of values from EDA empatica file
eda_data, startTimeStamp_EDA, sampleRate_EDA = convert1DEmpaticaToArray(pathToEDACsv)
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)

View File

@ -1,8 +1,12 @@
from calculatingfeatures.CalculatingFeatures.helper_functions import convert1DEmpaticaToArray, convertInputInto2d, frequencyFeatureNames, hrvFeatureNames
from calculatingfeatures.CalculatingFeatures.calculate_features import calculateFeatures
import sys
sys.path.append("..")
from CalculatingFeatures.helper_functions import convert1DEmpaticaToArray, convertInputInto2d, frequencyFeatureNames, hrvFeatureNames
from CalculatingFeatures.calculate_features import calculateFeatures
import pandas as pd
pathToHrvCsv = "calculatingfeatures/example_data/S2_E4_Data/BVP.csv"
pathToHrvCsv = "../example_data/S2_E4_Data/BVP.csv"
windowLength = 500
# get an array of values from HRV empatica file