Added CF for HRV and shortened test data

sociality-task
Primoz 2022-03-30 15:01:24 +00:00
parent 470993eeb0
commit a357138f6e
3 changed files with 61 additions and 2 deletions

View File

@ -541,9 +541,14 @@ EMPATICA_BLOOD_VOLUME_PULSE:
CONTAINER: BVP CONTAINER: BVP
PROVIDERS: PROVIDERS:
DBDP: DBDP:
COMPUTE: False COMPUTE: True
FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"] FEATURES: ["fqHighestPeakFreqs", "fqHighestPeaks", "fqEnergyFeat", "fqEntropyFeat", "fqHistogramBins","fqAbsMean", "fqSkewness", "fqKurtosis", "fqInterquart", # Freq features
"maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"] # HRV features
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py
CF:
COMPUTE: True
FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR']
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/cf/main.py
# See https://www.rapids.science/latest/features/empatica-inter-beat-interval/ # See https://www.rapids.science/latest/features/empatica-inter-beat-interval/
EMPATICA_INTER_BEAT_INTERVAL: EMPATICA_INTER_BEAT_INTERVAL:

Binary file not shown.

View File

@ -0,0 +1,54 @@
import pandas as pd
from scipy.stats import entropy
from CalculatingFeatures.helper_functions import convertInputInto2d, hrvFeatureNames, frequencyFeatureNames
from CalculatingFeatures.calculate_features import calculateFeatures
import sys
def getSampleRate(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
def extractBVPFeaturesFromIntradayData(bvp_intraday_data, features, 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)
bvp_intraday_data = filter_data_by_segment(bvp_intraday_data, time_segment)
if not bvp_intraday_data.empty:
bvp_intraday_features = pd.DataFrame()
# apply methods from calculate features module
bvp_intraday_features = \
bvp_intraday_data.groupby('local_segment').apply(\
lambda x: calculateFeatures(convertInputInto2d(x['blood_volume_pulse'], x.shape[0]), fs=int(sample_rate), featureNames=features))
bvp_intraday_features.reset_index(inplace=True)
return bvp_intraday_features
def cf_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs):
bvp_intraday_data = pd.read_csv(sensor_data_files["sensor_data"])
requested_intraday_features = provider["FEATURES"]
# name of the features this function can compute
base_intraday_features_names = hrvFeatureNames + frequencyFeatureNames
# 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, time_segment,
filter_data_by_segment)
return bvp_intraday_features