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 pd.set_option('display.max_rows', None) pd.set_option('display.max_columns', None) 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) 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')])