diff --git a/config.yaml b/config.yaml index 8a1516de..5d81159b 100644 --- a/config.yaml +++ b/config.yaml @@ -491,7 +491,7 @@ EMPATICA_ACCELEROMETER: "sumOfSquareComponents", "averageVectorLength", "averageVectorLengthPower", "rollAvgLow", "pitchAvgLow", "rollStdDevLow", "pitchStdDevLow", "rollMotionAmountLow", "rollMotionRegularityLow", "manipulationLow", "rollPeaks", "pitchPeaks", "rollPitchCorrelation"] # Acc features WINDOWS: - COMPUTE: False + COMPUTE: True WINDOW_LENGTH: 10 # specify window length in seconds SRC_SCRIPT: src/features/empatica_accelerometer/cr/main.py @@ -521,7 +521,7 @@ EMPATICA_TEMPERATURE: "calcMeanCrossingRateAutocorr", "countAboveMeanAutocorr", "sumPer", "sumSquared", "squareSumOfComponent", "sumOfSquareComponents"] WINDOWS: - COMPUTE: False + COMPUTE: True WINDOW_LENGTH: 90 # specify window length in seconds SRC_SCRIPT: src/features/empatica_temperature/cr/main.py @@ -541,7 +541,7 @@ EMPATICA_ELECTRODERMAL_ACTIVITY: 'avgPeakIncreaseTime', 'avgPeakDecreaseTime', 'avgPeakDuration', 'maxPeakResponseSlopeBefore', 'maxPeakResponseSlopeAfter', 'signalOverallChange', 'changeDuration', 'changeRate', 'significantIncrease', 'significantDecrease'] WINDOWS: - COMPUTE: False + COMPUTE: True WINDOW_LENGTH: 80 # specify window length in seconds SRC_SCRIPT: src/features/empatica_electrodermal_activity/cr/main.py @@ -550,11 +550,11 @@ EMPATICA_BLOOD_VOLUME_PULSE: CONTAINER: BVP PROVIDERS: DBDP: - COMPUTE: True + COMPUTE: False FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"] SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py CR: - COMPUTE: True + COMPUTE: False FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR', # Time features 'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features WINDOWS: @@ -567,17 +567,17 @@ EMPATICA_INTER_BEAT_INTERVAL: CONTAINER: IBI PROVIDERS: DBDP: - COMPUTE: False + COMPUTE: True FEATURES: ["maxibi", "minibi", "avgibi", "medianibi", "modeibi", "stdibi", "diffmaxmodeibi", "diffminmodeibi", "entropyibi"] SRC_SCRIPT: src/features/empatica_inter_beat_interval/dbdp/main.py CR: - COMPUTE: False + COMPUTE: True FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR', # Time features 'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features WINDOWS: COMPUTE: True WINDOW_LENGTH: 4 # specify window length in seconds - SRC_SCRIPT: src/features/inter_beat_interval/cr/main.py + SRC_SCRIPT: src/features/empatica_inter_beat_interval/cr/main.py # See https://www.rapids.science/latest/features/empatica-tags/ EMPATICA_TAGS: diff --git a/src/features/empatica_accelerometer/cr/main.py b/src/features/empatica_accelerometer/cr/main.py index 9618a88c..ca2bf5ee 100644 --- a/src/features/empatica_accelerometer/cr/main.py +++ b/src/features/empatica_accelerometer/cr/main.py @@ -1,24 +1,24 @@ import pandas as pd from scipy.stats import entropy -from CalculatingFeatures.helper_functions import convert3DEmpaticaToArray, convertInputInto2d, accelerometerFeatureNames, frequencyFeatureNames -from CalculatingFeatures.calculate_features import calculateFeatures +from cr_features.helper_functions import convert_to2d, accelerometer_features, frequency_features +from cr_features.calculate_features import calculate_features import sys -def getSampleRate(data): +def get_sample_rate(data): try: timestamps_diff = data['timestamp'].diff().dropna().mean() except: raise Exception("Error occured while trying to get the mean sample rate from the data.") - return 1000/timestamps_diff + return int(1000/timestamps_diff) -def extractAccFeaturesFromIntradayData(acc_intraday_data, features, window_length, time_segment, filter_data_by_segment): +def extract_acc_features_from_intraday_data(acc_intraday_data, features, window_length, time_segment, filter_data_by_segment): acc_intraday_features = pd.DataFrame(columns=["local_segment"] + features) if not acc_intraday_data.empty: - sample_rate = getSampleRate(acc_intraday_data) + sample_rate = get_sample_rate(acc_intraday_data) acc_intraday_data = filter_data_by_segment(acc_intraday_data, time_segment) @@ -29,18 +29,18 @@ def extractAccFeaturesFromIntradayData(acc_intraday_data, features, window_lengt # apply methods from calculate features module if window_length is None: acc_intraday_features = \ - acc_intraday_data.groupby('local_segment').apply(lambda x: calculateFeatures( \ - convertInputInto2d(x['double_values_0'], x.shape[0]), \ - convertInputInto2d(x['double_values_1'], x.shape[0]), \ - convertInputInto2d(x['double_values_2'], x.shape[0]), \ - fs=int(sample_rate), featureNames=features)) + acc_intraday_data.groupby('local_segment').apply(lambda x: calculate_features( \ + convert_to2d(x['double_values_0'], x.shape[0]), \ + convert_to2d(x['double_values_1'], x.shape[0]), \ + convert_to2d(x['double_values_2'], x.shape[0]), \ + fs=sample_rate, feature_names=features)) else: acc_intraday_features = \ - acc_intraday_data.groupby('local_segment').apply(lambda x: calculateFeatures( \ - convertInputInto2d(x['double_values_0'], window_length*int(sample_rate)), \ - convertInputInto2d(x['double_values_1'], window_length*int(sample_rate)), \ - convertInputInto2d(x['double_values_2'], window_length*int(sample_rate)), \ - fs=int(sample_rate), featureNames=features)) + acc_intraday_data.groupby('local_segment').apply(lambda x: calculate_features( \ + convert_to2d(x['double_values_0'], window_length*sample_rate), \ + convert_to2d(x['double_values_1'], window_length*sample_rate), \ + convert_to2d(x['double_values_2'], window_length*sample_rate), \ + fs=sample_rate, feature_names=features)) acc_intraday_features.reset_index(inplace=True) @@ -61,12 +61,12 @@ def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segmen requested_window_length = None # name of the features this function can compute - base_intraday_features_names = accelerometerFeatureNames + frequencyFeatureNames + base_intraday_features_names = accelerometer_features + frequency_features # the subset of requested features this function can compute intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names)) # extract features from intraday data - acc_intraday_features = extractAccFeaturesFromIntradayData(acc_intraday_data, intraday_features_to_compute, + acc_intraday_features = extract_acc_features_from_intraday_data(acc_intraday_data, intraday_features_to_compute, requested_window_length, time_segment, filter_data_by_segment) return acc_intraday_features \ No newline at end of file diff --git a/src/features/empatica_blood_volume_pulse/cr/main.py b/src/features/empatica_blood_volume_pulse/cr/main.py index bdf26f75..daf3a079 100644 --- a/src/features/empatica_blood_volume_pulse/cr/main.py +++ b/src/features/empatica_blood_volume_pulse/cr/main.py @@ -1,13 +1,13 @@ import pandas as pd from scipy.stats import entropy -from CalculatingFeatures.helper_functions import convertInputInto2d, hrvFeatureNames, hrvFreqFeatureNames -from CalculatingFeatures.hrv import extractHrvFeatures, extractHrvFeatures2D, extractHrvFeatures2DWrapper +from cr_features.helper_functions import convert_to2d, hrv_features, hrv_freq_features +from cr_features.hrv import extract_hrv_features_2d_wrapper import sys -def getSampleRate(data): +def get_sample_rate(data): try: timestamps_diff = data['timestamp'].diff().dropna().mean() except: @@ -15,11 +15,11 @@ def getSampleRate(data): return int(1000/timestamps_diff) -def extractBVPFeaturesFromIntradayData(bvp_intraday_data, features, window_length, time_segment, filter_data_by_segment): +def extract_bvp_features_from_intraday_data(bvp_intraday_data, features, window_length, time_segment, filter_data_by_segment): bvp_intraday_features = pd.DataFrame(columns=["local_segment"] + features) if not bvp_intraday_data.empty: - sample_rate = getSampleRate(bvp_intraday_data) + sample_rate = get_sample_rate(bvp_intraday_data) print(bvp_intraday_data.shape) @@ -29,24 +29,25 @@ def extractBVPFeaturesFromIntradayData(bvp_intraday_data, features, window_lengt bvp_intraday_features = pd.DataFrame() + print(features) + # apply methods from calculate features module if window_length is None: bvp_intraday_features = \ bvp_intraday_data.groupby('local_segment').apply(\ lambda x: - extractHrvFeatures2DWrapper( - convertInputInto2d(x['blood_volume_pulse'], x.shape[0]), - sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, featureNames=features)) + extract_hrv_features_2d_wrapper( + convert_to2d(x['blood_volume_pulse'], x.shape[0]), + sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=False, feature_names=features)) else: bvp_intraday_features = \ bvp_intraday_data.groupby('local_segment').apply(\ lambda x: - extractHrvFeatures2DWrapper( - convertInputInto2d(x['blood_volume_pulse'], window_length*sample_rate), - sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, featureNames=features)) - print(sample_rate) - print(bvp_intraday_features) + extract_hrv_features_2d_wrapper( + convert_to2d(x['blood_volume_pulse'], window_length*sample_rate), + sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features)) + bvp_intraday_features.reset_index(inplace=True) return bvp_intraday_features @@ -65,12 +66,12 @@ def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segmen requested_window_length = None # name of the features this function can compute - base_intraday_features_names = hrvFeatureNames + hrvFreqFeatureNames + base_intraday_features_names = hrv_features + hrv_freq_features # the subset of requested features this function can compute intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names)) # extract features from intraday data - bvp_intraday_features = extractBVPFeaturesFromIntradayData(bvp_intraday_data, intraday_features_to_compute, + bvp_intraday_features = extract_bvp_features_from_intraday_data(bvp_intraday_data, intraday_features_to_compute, requested_window_length, time_segment, filter_data_by_segment) return bvp_intraday_features \ No newline at end of file diff --git a/src/features/empatica_electrodermal_activity/cr/main.py b/src/features/empatica_electrodermal_activity/cr/main.py index b621f040..7cb6e5b2 100644 --- a/src/features/empatica_electrodermal_activity/cr/main.py +++ b/src/features/empatica_electrodermal_activity/cr/main.py @@ -1,8 +1,8 @@ import pandas as pd from scipy.stats import entropy -from CalculatingFeatures.helper_functions import convertInputInto2d, gsrFeatureNames -from CalculatingFeatures.calculate_features import calculateFeatures +from cr_features.helper_functions import convert_to2d, gsr_features +from cr_features.calculate_features import calculate_features def getSampleRate(data): @@ -11,9 +11,9 @@ def getSampleRate(data): except: raise Exception("Error occured while trying to get the mean sample rate from the data.") - return 1000/timestamps_diff + return int(1000/timestamps_diff) -def extractEDAFeaturesFromIntradayData(eda_intraday_data, features, window_length, time_segment, filter_data_by_segment): +def extract_eda_features_from_intraday_data(eda_intraday_data, features, window_length, time_segment, filter_data_by_segment): eda_intraday_features = pd.DataFrame(columns=["local_segment"] + features) if not eda_intraday_data.empty: @@ -29,11 +29,11 @@ def extractEDAFeaturesFromIntradayData(eda_intraday_data, features, window_lengt if window_length is None: eda_intraday_features = \ eda_intraday_data.groupby('local_segment').apply(\ - lambda x: calculateFeatures(convertInputInto2d(x['electrodermal_activity'], x.shape[0]), fs=int(sample_rate), featureNames=features)) + lambda x: calculate_features(convert_to2d(x['electrodermal_activity'], x.shape[0]), fs=sample_rate, feature_names=features)) else: eda_intraday_features = \ eda_intraday_data.groupby('local_segment').apply(\ - lambda x: calculateFeatures(convertInputInto2d(x['electrodermal_activity'], window_length*int(sample_rate)), fs=int(sample_rate), featureNames=features)) + lambda x: calculate_features(convert_to2d(x['electrodermal_activity'], window_length*sample_rate), fs=sample_rate, feature_names=features)) eda_intraday_features.reset_index(inplace=True) @@ -54,12 +54,12 @@ def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segmen requested_window_length = None # name of the features this function can compute - base_intraday_features_names = gsrFeatureNames + base_intraday_features_names = gsr_features # the subset of requested features this function can compute intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names)) # extract features from intraday data - eda_intraday_features = extractEDAFeaturesFromIntradayData(eda_intraday_data, intraday_features_to_compute, + eda_intraday_features = extract_eda_features_from_intraday_data(eda_intraday_data, intraday_features_to_compute, requested_window_length, time_segment, filter_data_by_segment) return eda_intraday_features \ No newline at end of file diff --git a/src/features/empatica_inter_beat_interval/cr/main.py b/src/features/empatica_inter_beat_interval/cr/main.py index f8d38b66..39e8f59c 100644 --- a/src/features/empatica_inter_beat_interval/cr/main.py +++ b/src/features/empatica_inter_beat_interval/cr/main.py @@ -1,25 +1,27 @@ import pandas as pd from scipy.stats import entropy -from CalculatingFeatures.helper_functions import convertInputInto2dTime, convert2DEmpaticaToArray hrvFeatureNames, hrvFreqFeatureNames -from CalculatingFeatures.calculate_features import calculateFeatures +from cr_features.helper_functions import convert_ibi_to2d_time, hrv_features, hrv_freq_features +from cr_features.calculate_features import calculate_features import sys +pd.set_option('display.max_rows', 1000) -def getSampleRate(data): + +def get_sample_rate(data): try: timestamps_diff = data['timestamp'].diff().dropna().mean() except: raise Exception("Error occured while trying to get the mean sample rate from the data.") - return 1000/timestamps_diff + return int(1000/timestamps_diff) -def extractIBIFeaturesFromIntradayData(ibi_intraday_data, features, window_length, time_segment, filter_data_by_segment): +def extract_ibi_features_from_intraday_data(ibi_intraday_data, features, window_length, time_segment, filter_data_by_segment): ibi_intraday_features = pd.DataFrame(columns=["local_segment"] + features) if not ibi_intraday_data.empty: - sample_rate = getSampleRate(ibi_intraday_data) + sample_rate = get_sample_rate(ibi_intraday_data) ibi_intraday_data = filter_data_by_segment(ibi_intraday_data, time_segment) @@ -27,15 +29,22 @@ def extractIBIFeaturesFromIntradayData(ibi_intraday_data, features, window_lengt ibi_intraday_features = pd.DataFrame() + print(ibi_intraday_data.head(100)) + sys.exit() + # apply methods from calculate features module - # if window_length is None: - # ibi_intraday_features = \ - # ibi_intraday_data.groupby('local_segment').apply(\ - # lambda x: calculateFeatures(convertInputInto2d(x['blood_volume_pulse'], x.shape[0]), fs=int(sample_rate), featureNames=features)) - # else: - # ibi_intraday_features = \ - # ibi_intraday_data.groupby('local_segment').apply(\ - # lambda x: calculateFeatures(convertInputInto2d(x['blood_volume_pulse'], window_length*int(sample_rate)), fs=int(sample_rate), featureNames=features)) + if window_length is None: + ibi_intraday_features = \ + ibi_intraday_data.groupby('local_segment').apply(\ + extract_hrv_features_2d_wrapper( + convert_to2d(x['inter_beat_interval'], window_length*sample_rate), + sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features)) + else: + ibi_intraday_features = \ + ibi_intraday_data.groupby('local_segment').apply(\ + extract_hrv_features_2d_wrapper( + convert_to2d(x['blood_volume_pulse'], window_length*sample_rate), + sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features)) ibi_intraday_features.reset_index(inplace=True) @@ -55,12 +64,12 @@ def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segmen requested_window_length = None # name of the features this function can compute - base_intraday_features_names = hrvFeatureNames + hrvFreqFeatureNames + base_intraday_features_names = hrv_features + hrv_freq_features # the subset of requested features this function can compute intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names)) # extract features from intraday data - ibi_intraday_features = extractBVPFeaturesFromIntradayData(ibi_intraday_data, intraday_features_to_compute, + ibi_intraday_features = extract_ibi_features_from_intraday_data(ibi_intraday_data, intraday_features_to_compute, requested_window_length, time_segment, filter_data_by_segment) return ibi_intraday_features \ No newline at end of file diff --git a/src/features/empatica_temperature/cr/main.py b/src/features/empatica_temperature/cr/main.py index 20a8af85..78eaa952 100644 --- a/src/features/empatica_temperature/cr/main.py +++ b/src/features/empatica_temperature/cr/main.py @@ -1,24 +1,24 @@ import pandas as pd from scipy.stats import entropy -from CalculatingFeatures.helper_functions import convert1DEmpaticaToArray, convertInputInto2d, genericFeatureNames -from CalculatingFeatures.calculate_features import calculateFeatures +from cr_features.helper_functions import convert_to2d, generic_features +from cr_features.calculate_features import calculate_features import sys -def getSampleRate(data): +def get_sample_rate(data): try: timestamps_diff = data['timestamp'].diff().dropna().mean() except: raise Exception("Error occured while trying to get the mean sample rate from the data.") - return 1000/timestamps_diff + return int(1000/timestamps_diff) -def extractTempFeaturesFromIntradayData(temperature_intraday_data, features, window_length, time_segment, filter_data_by_segment): +def extract_temp_features_from_intraday_data(temperature_intraday_data, features, window_length, time_segment, filter_data_by_segment): temperature_intraday_features = pd.DataFrame(columns=["local_segment"] + features) if not temperature_intraday_data.empty: - sample_rate = getSampleRate(temperature_intraday_data) + sample_rate = get_sample_rate(temperature_intraday_data) temperature_intraday_data = filter_data_by_segment(temperature_intraday_data, time_segment) @@ -30,11 +30,11 @@ def extractTempFeaturesFromIntradayData(temperature_intraday_data, features, win if window_length is None: temperature_intraday_features = \ temperature_intraday_data.groupby('local_segment').apply(\ - lambda x: calculateFeatures(convertInputInto2d(x['temperature'], x.shape[0]), fs=int(sample_rate), featureNames=features)) + lambda x: calculate_features(convert_to2d(x['temperature'], x.shape[0]), fs=sample_rate, feature_names=features)) else: temperature_intraday_features = \ temperature_intraday_data.groupby('local_segment').apply(\ - lambda x: calculateFeatures(convertInputInto2d(x['temperature'], window_length*int(sample_rate)), fs=int(sample_rate), featureNames=features)) + lambda x: calculate_features(convert_to2d(x['temperature'], window_length*sample_rate), fs=sample_rate, feature_names=features)) temperature_intraday_features.reset_index(inplace=True) @@ -54,11 +54,11 @@ def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segmen requested_window_length = None # name of the features this function can compute - base_intraday_features_names = genericFeatureNames + base_intraday_features_names = generic_features # the subset of requested features this function can compute intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names)) # extract features from intraday data - temperature_intraday_features = extractTempFeaturesFromIntradayData(temperature_intraday_data, intraday_features_to_compute, + temperature_intraday_features = extract_temp_features_from_intraday_data(temperature_intraday_data, intraday_features_to_compute, requested_window_length, time_segment, filter_data_by_segment) return temperature_intraday_features \ No newline at end of file