HRV: changed wrapper calcFeat method with specialized one.
parent
3c058e4463
commit
075c64d1e5
28
config.yaml
28
config.yaml
|
@ -510,18 +510,18 @@ EMPATICA_TEMPERATURE:
|
|||
CONTAINER: TEMP
|
||||
PROVIDERS:
|
||||
DBDP:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
FEATURES: ["maxtemp", "mintemp", "avgtemp", "mediantemp", "modetemp", "stdtemp", "diffmaxmodetemp", "diffminmodetemp", "entropytemp"]
|
||||
SRC_SCRIPT: src/features/empatica_temperature/dbdp/main.py
|
||||
CR:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
FEATURES: ["autocorrelations", "countAboveMean", "countBelowMean", "maximum", "minimum", "meanAbsChange", "longestStrikeAboveMean",
|
||||
"longestStrikeBelowMean", "stdDev", "median", "meanChange", "numberOfZeroCrossings", "absEnergy", "linearTrendSlope",
|
||||
"ratioBeyondRSigma", "binnedEntropy", "numOfPeaksAutocorr", "numberOfZeroCrossingsAutocorr", "areaAutocorr",
|
||||
"calcMeanCrossingRateAutocorr", "countAboveMeanAutocorr", "sumPer", "sumSquared", "squareSumOfComponent",
|
||||
"sumOfSquareComponents"]
|
||||
WINDOWS:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
WINDOW_LENGTH: 90 # specify window length in seconds
|
||||
SRC_SCRIPT: src/features/empatica_temperature/cr/main.py
|
||||
|
||||
|
@ -530,18 +530,18 @@ EMPATICA_ELECTRODERMAL_ACTIVITY:
|
|||
CONTAINER: EDA
|
||||
PROVIDERS:
|
||||
DBDP:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
FEATURES: ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda", "diffminmodeeda", "entropyeda"]
|
||||
SRC_SCRIPT: src/features/empatica_electrodermal_activity/dbdp/main.py
|
||||
CR:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
FEATURES: ['mean', 'std', 'q25', 'q75', 'qd', 'deriv', 'power', 'numPeaks', 'ratePeaks', 'powerPeaks', 'sumPosDeriv', 'propPosDeriv', 'derivTonic',
|
||||
'sigTonicDifference', 'freqFeats','maxPeakAmplitudeChangeBefore', 'maxPeakAmplitudeChangeAfter', 'avgPeakAmplitudeChangeBefore',
|
||||
'avgPeakAmplitudeChangeAfter', 'avgPeakChangeRatio', 'maxPeakIncreaseTime', 'maxPeakDecreaseTime', 'maxPeakDuration', 'maxPeakChangeRatio',
|
||||
'avgPeakIncreaseTime', 'avgPeakDecreaseTime', 'avgPeakDuration', 'maxPeakResponseSlopeBefore', 'maxPeakResponseSlopeAfter',
|
||||
'signalOverallChange', 'changeDuration', 'changeRate', 'significantIncrease', 'significantDecrease']
|
||||
WINDOWS:
|
||||
COMPUTE: True
|
||||
COMPUTE: False
|
||||
WINDOW_LENGTH: 80 # specify window length in seconds
|
||||
SRC_SCRIPT: src/features/empatica_electrodermal_activity/cr/main.py
|
||||
|
||||
|
@ -551,15 +551,15 @@ EMPATICA_BLOOD_VOLUME_PULSE:
|
|||
PROVIDERS:
|
||||
DBDP:
|
||||
COMPUTE: True
|
||||
FEATURES: ["fqHighestPeakFreqs", "fqHighestPeaks", "fqEnergyFeat", "fqEntropyFeat", "fqHistogramBins","fqAbsMean", "fqSkewness", "fqKurtosis", "fqInterquart", # Freq features
|
||||
"maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"] # HRV features
|
||||
FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"]
|
||||
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py
|
||||
CR:
|
||||
COMPUTE: True
|
||||
FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR']
|
||||
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
|
||||
WINDOW_LENGTH: 10 # specify window length in seconds
|
||||
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/cr/main.py
|
||||
|
||||
# See https://www.rapids.science/latest/features/empatica-inter-beat-interval/
|
||||
|
@ -570,6 +570,14 @@ EMPATICA_INTER_BEAT_INTERVAL:
|
|||
COMPUTE: False
|
||||
FEATURES: ["maxibi", "minibi", "avgibi", "medianibi", "modeibi", "stdibi", "diffmaxmodeibi", "diffminmodeibi", "entropyibi"]
|
||||
SRC_SCRIPT: src/features/empatica_inter_beat_interval/dbdp/main.py
|
||||
CR:
|
||||
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:
|
||||
COMPUTE: True
|
||||
WINDOW_LENGTH: 4 # specify window length in seconds
|
||||
SRC_SCRIPT: src/features/inter_beat_interval/cr/main.py
|
||||
|
||||
# See https://www.rapids.science/latest/features/empatica-tags/
|
||||
EMPATICA_TAGS:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import pandas as pd
|
||||
from scipy.stats import entropy
|
||||
|
||||
from CalculatingFeatures.helper_functions import convertInputInto2d, hrvFeatureNames, frequencyFeatureNames
|
||||
from CalculatingFeatures.calculate_features import calculateFeatures
|
||||
from CalculatingFeatures.helper_functions import convertInputInto2d, hrvFeatureNames, hrvFreqFeatureNames
|
||||
from CalculatingFeatures.hrv import extractHrvFeatures, extractHrvFeatures2D, extractHrvFeatures2DWrapper
|
||||
|
||||
import sys
|
||||
|
||||
|
@ -13,13 +13,15 @@ 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 extractBVPFeaturesFromIntradayData(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)
|
||||
if not bvp_intraday_data.empty:
|
||||
sample_rate = getSampleRate(bvp_intraday_data)
|
||||
|
||||
print(bvp_intraday_data.shape)
|
||||
|
||||
bvp_intraday_data = filter_data_by_segment(bvp_intraday_data, time_segment)
|
||||
|
||||
|
@ -31,12 +33,20 @@ def extractBVPFeaturesFromIntradayData(bvp_intraday_data, features, window_lengt
|
|||
if window_length is None:
|
||||
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))
|
||||
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))
|
||||
|
||||
else:
|
||||
bvp_intraday_features = \
|
||||
bvp_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))
|
||||
|
||||
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)
|
||||
bvp_intraday_features.reset_index(inplace=True)
|
||||
|
||||
return bvp_intraday_features
|
||||
|
@ -55,7 +65,7 @@ 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 + frequencyFeatureNames
|
||||
base_intraday_features_names = hrvFeatureNames + hrvFreqFeatureNames
|
||||
# the subset of requested features this function can compute
|
||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
import pandas as pd
|
||||
from scipy.stats import entropy
|
||||
|
||||
from CalculatingFeatures.helper_functions import convertInputInto2dTime, convert2DEmpaticaToArray hrvFeatureNames, hrvFreqFeatureNames
|
||||
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 extractIBIFeaturesFromIntradayData(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)
|
||||
|
||||
ibi_intraday_data = filter_data_by_segment(ibi_intraday_data, time_segment)
|
||||
|
||||
if not ibi_intraday_data.empty:
|
||||
|
||||
ibi_intraday_features = pd.DataFrame()
|
||||
|
||||
# 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))
|
||||
|
||||
ibi_intraday_features.reset_index(inplace=True)
|
||||
|
||||
return ibi_intraday_features
|
||||
|
||||
|
||||
def cr_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs):
|
||||
ibi_intraday_data = pd.read_csv(sensor_data_files["sensor_data"])
|
||||
|
||||
requested_intraday_features = provider["FEATURES"]
|
||||
|
||||
calc_windows = kwargs.get('calc_windows', False)
|
||||
|
||||
if provider["WINDOWS"]["COMPUTE"] and calc_windows:
|
||||
requested_window_length = provider["WINDOWS"]["WINDOW_LENGTH"]
|
||||
else:
|
||||
requested_window_length = None
|
||||
|
||||
# name of the features this function can compute
|
||||
base_intraday_features_names = hrvFeatureNames + hrvFreqFeatureNames
|
||||
# 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,
|
||||
requested_window_length, time_segment, filter_data_by_segment)
|
||||
|
||||
return ibi_intraday_features
|
|
@ -27,7 +27,7 @@ else:
|
|||
if calc_windows:
|
||||
sensor_features.to_csv(snakemake.output[1], index=False)
|
||||
sensor_features = fetch_provider_features(provider, provider_key, sensor_key, sensor_data_files, time_segments_file, calc_windows=False)
|
||||
elif "empatica" in sensor_key and provider_key == "dbdp":
|
||||
elif "empatica" in sensor_key:
|
||||
pd.DataFrame().to_csv(snakemake.output[1], index=False)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue