Modifications, mostly imports, after changes in cr-features module.
parent
075c64d1e5
commit
8c8fe1fec7
16
config.yaml
16
config.yaml
|
@ -491,7 +491,7 @@ EMPATICA_ACCELEROMETER:
|
||||||
"sumOfSquareComponents", "averageVectorLength", "averageVectorLengthPower", "rollAvgLow", "pitchAvgLow", "rollStdDevLow",
|
"sumOfSquareComponents", "averageVectorLength", "averageVectorLengthPower", "rollAvgLow", "pitchAvgLow", "rollStdDevLow",
|
||||||
"pitchStdDevLow", "rollMotionAmountLow", "rollMotionRegularityLow", "manipulationLow", "rollPeaks", "pitchPeaks", "rollPitchCorrelation"] # Acc features
|
"pitchStdDevLow", "rollMotionAmountLow", "rollMotionRegularityLow", "manipulationLow", "rollPeaks", "pitchPeaks", "rollPitchCorrelation"] # Acc features
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
COMPUTE: False
|
COMPUTE: True
|
||||||
WINDOW_LENGTH: 10 # specify window length in seconds
|
WINDOW_LENGTH: 10 # specify window length in seconds
|
||||||
SRC_SCRIPT: src/features/empatica_accelerometer/cr/main.py
|
SRC_SCRIPT: src/features/empatica_accelerometer/cr/main.py
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ EMPATICA_TEMPERATURE:
|
||||||
"calcMeanCrossingRateAutocorr", "countAboveMeanAutocorr", "sumPer", "sumSquared", "squareSumOfComponent",
|
"calcMeanCrossingRateAutocorr", "countAboveMeanAutocorr", "sumPer", "sumSquared", "squareSumOfComponent",
|
||||||
"sumOfSquareComponents"]
|
"sumOfSquareComponents"]
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
COMPUTE: False
|
COMPUTE: True
|
||||||
WINDOW_LENGTH: 90 # specify window length in seconds
|
WINDOW_LENGTH: 90 # specify window length in seconds
|
||||||
SRC_SCRIPT: src/features/empatica_temperature/cr/main.py
|
SRC_SCRIPT: src/features/empatica_temperature/cr/main.py
|
||||||
|
|
||||||
|
@ -541,7 +541,7 @@ EMPATICA_ELECTRODERMAL_ACTIVITY:
|
||||||
'avgPeakIncreaseTime', 'avgPeakDecreaseTime', 'avgPeakDuration', 'maxPeakResponseSlopeBefore', 'maxPeakResponseSlopeAfter',
|
'avgPeakIncreaseTime', 'avgPeakDecreaseTime', 'avgPeakDuration', 'maxPeakResponseSlopeBefore', 'maxPeakResponseSlopeAfter',
|
||||||
'signalOverallChange', 'changeDuration', 'changeRate', 'significantIncrease', 'significantDecrease']
|
'signalOverallChange', 'changeDuration', 'changeRate', 'significantIncrease', 'significantDecrease']
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
COMPUTE: False
|
COMPUTE: True
|
||||||
WINDOW_LENGTH: 80 # specify window length in seconds
|
WINDOW_LENGTH: 80 # specify window length in seconds
|
||||||
SRC_SCRIPT: src/features/empatica_electrodermal_activity/cr/main.py
|
SRC_SCRIPT: src/features/empatica_electrodermal_activity/cr/main.py
|
||||||
|
|
||||||
|
@ -550,11 +550,11 @@ EMPATICA_BLOOD_VOLUME_PULSE:
|
||||||
CONTAINER: BVP
|
CONTAINER: BVP
|
||||||
PROVIDERS:
|
PROVIDERS:
|
||||||
DBDP:
|
DBDP:
|
||||||
COMPUTE: True
|
COMPUTE: False
|
||||||
FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"]
|
FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"]
|
||||||
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py
|
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py
|
||||||
CR:
|
CR:
|
||||||
COMPUTE: True
|
COMPUTE: False
|
||||||
FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR', # Time features
|
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
|
'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
|
@ -567,17 +567,17 @@ EMPATICA_INTER_BEAT_INTERVAL:
|
||||||
CONTAINER: IBI
|
CONTAINER: IBI
|
||||||
PROVIDERS:
|
PROVIDERS:
|
||||||
DBDP:
|
DBDP:
|
||||||
COMPUTE: False
|
COMPUTE: True
|
||||||
FEATURES: ["maxibi", "minibi", "avgibi", "medianibi", "modeibi", "stdibi", "diffmaxmodeibi", "diffminmodeibi", "entropyibi"]
|
FEATURES: ["maxibi", "minibi", "avgibi", "medianibi", "modeibi", "stdibi", "diffmaxmodeibi", "diffminmodeibi", "entropyibi"]
|
||||||
SRC_SCRIPT: src/features/empatica_inter_beat_interval/dbdp/main.py
|
SRC_SCRIPT: src/features/empatica_inter_beat_interval/dbdp/main.py
|
||||||
CR:
|
CR:
|
||||||
COMPUTE: False
|
COMPUTE: True
|
||||||
FEATURES: ['meanHr', 'ibi', 'sdnn', 'sdsd', 'rmssd', 'pnn20', 'pnn50', 'sd', 'sd2', 'sd1/sd2', 'numRR', # Time features
|
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
|
'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
COMPUTE: True
|
COMPUTE: True
|
||||||
WINDOW_LENGTH: 4 # specify window length in seconds
|
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/
|
# See https://www.rapids.science/latest/features/empatica-tags/
|
||||||
EMPATICA_TAGS:
|
EMPATICA_TAGS:
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
from scipy.stats import entropy
|
||||||
|
|
||||||
from CalculatingFeatures.helper_functions import convert3DEmpaticaToArray, convertInputInto2d, accelerometerFeatureNames, frequencyFeatureNames
|
from cr_features.helper_functions import convert_to2d, accelerometer_features, frequency_features
|
||||||
from CalculatingFeatures.calculate_features import calculateFeatures
|
from cr_features.calculate_features import calculate_features
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def getSampleRate(data):
|
def get_sample_rate(data):
|
||||||
try:
|
try:
|
||||||
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
||||||
except:
|
except:
|
||||||
raise Exception("Error occured while trying to get the mean sample rate from the data.")
|
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)
|
acc_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
|
||||||
|
|
||||||
if not acc_intraday_data.empty:
|
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)
|
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
|
# apply methods from calculate features module
|
||||||
if window_length is None:
|
if window_length is None:
|
||||||
acc_intraday_features = \
|
acc_intraday_features = \
|
||||||
acc_intraday_data.groupby('local_segment').apply(lambda x: calculateFeatures( \
|
acc_intraday_data.groupby('local_segment').apply(lambda x: calculate_features( \
|
||||||
convertInputInto2d(x['double_values_0'], x.shape[0]), \
|
convert_to2d(x['double_values_0'], x.shape[0]), \
|
||||||
convertInputInto2d(x['double_values_1'], x.shape[0]), \
|
convert_to2d(x['double_values_1'], x.shape[0]), \
|
||||||
convertInputInto2d(x['double_values_2'], x.shape[0]), \
|
convert_to2d(x['double_values_2'], x.shape[0]), \
|
||||||
fs=int(sample_rate), featureNames=features))
|
fs=sample_rate, feature_names=features))
|
||||||
else:
|
else:
|
||||||
acc_intraday_features = \
|
acc_intraday_features = \
|
||||||
acc_intraday_data.groupby('local_segment').apply(lambda x: calculateFeatures( \
|
acc_intraday_data.groupby('local_segment').apply(lambda x: calculate_features( \
|
||||||
convertInputInto2d(x['double_values_0'], window_length*int(sample_rate)), \
|
convert_to2d(x['double_values_0'], window_length*sample_rate), \
|
||||||
convertInputInto2d(x['double_values_1'], window_length*int(sample_rate)), \
|
convert_to2d(x['double_values_1'], window_length*sample_rate), \
|
||||||
convertInputInto2d(x['double_values_2'], window_length*int(sample_rate)), \
|
convert_to2d(x['double_values_2'], window_length*sample_rate), \
|
||||||
fs=int(sample_rate), featureNames=features))
|
fs=sample_rate, feature_names=features))
|
||||||
|
|
||||||
acc_intraday_features.reset_index(inplace=True)
|
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
|
requested_window_length = None
|
||||||
|
|
||||||
# name of the features this function can compute
|
# 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
|
# the subset of requested features this function can compute
|
||||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||||
|
|
||||||
# extract features from intraday data
|
# 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)
|
requested_window_length, time_segment, filter_data_by_segment)
|
||||||
|
|
||||||
return acc_intraday_features
|
return acc_intraday_features
|
|
@ -1,13 +1,13 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
from scipy.stats import entropy
|
||||||
|
|
||||||
from CalculatingFeatures.helper_functions import convertInputInto2d, hrvFeatureNames, hrvFreqFeatureNames
|
from cr_features.helper_functions import convert_to2d, hrv_features, hrv_freq_features
|
||||||
from CalculatingFeatures.hrv import extractHrvFeatures, extractHrvFeatures2D, extractHrvFeatures2DWrapper
|
from cr_features.hrv import extract_hrv_features_2d_wrapper
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def getSampleRate(data):
|
def get_sample_rate(data):
|
||||||
try:
|
try:
|
||||||
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
||||||
except:
|
except:
|
||||||
|
@ -15,11 +15,11 @@ def getSampleRate(data):
|
||||||
|
|
||||||
return int(1000/timestamps_diff)
|
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)
|
bvp_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
|
||||||
|
|
||||||
if not bvp_intraday_data.empty:
|
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)
|
print(bvp_intraday_data.shape)
|
||||||
|
|
||||||
|
@ -29,24 +29,25 @@ def extractBVPFeaturesFromIntradayData(bvp_intraday_data, features, window_lengt
|
||||||
|
|
||||||
bvp_intraday_features = pd.DataFrame()
|
bvp_intraday_features = pd.DataFrame()
|
||||||
|
|
||||||
|
print(features)
|
||||||
|
|
||||||
# apply methods from calculate features module
|
# apply methods from calculate features module
|
||||||
if window_length is None:
|
if window_length is None:
|
||||||
bvp_intraday_features = \
|
bvp_intraday_features = \
|
||||||
bvp_intraday_data.groupby('local_segment').apply(\
|
bvp_intraday_data.groupby('local_segment').apply(\
|
||||||
lambda x:
|
lambda x:
|
||||||
extractHrvFeatures2DWrapper(
|
extract_hrv_features_2d_wrapper(
|
||||||
convertInputInto2d(x['blood_volume_pulse'], x.shape[0]),
|
convert_to2d(x['blood_volume_pulse'], x.shape[0]),
|
||||||
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, featureNames=features))
|
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=False, feature_names=features))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
bvp_intraday_features = \
|
bvp_intraday_features = \
|
||||||
bvp_intraday_data.groupby('local_segment').apply(\
|
bvp_intraday_data.groupby('local_segment').apply(\
|
||||||
lambda x:
|
lambda x:
|
||||||
extractHrvFeatures2DWrapper(
|
extract_hrv_features_2d_wrapper(
|
||||||
convertInputInto2d(x['blood_volume_pulse'], window_length*sample_rate),
|
convert_to2d(x['blood_volume_pulse'], window_length*sample_rate),
|
||||||
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, featureNames=features))
|
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
||||||
print(sample_rate)
|
|
||||||
print(bvp_intraday_features)
|
|
||||||
bvp_intraday_features.reset_index(inplace=True)
|
bvp_intraday_features.reset_index(inplace=True)
|
||||||
|
|
||||||
return bvp_intraday_features
|
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
|
requested_window_length = None
|
||||||
|
|
||||||
# name of the features this function can compute
|
# 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
|
# the subset of requested features this function can compute
|
||||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||||
|
|
||||||
# extract features from intraday data
|
# 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)
|
requested_window_length, time_segment, filter_data_by_segment)
|
||||||
|
|
||||||
return bvp_intraday_features
|
return bvp_intraday_features
|
|
@ -1,8 +1,8 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
from scipy.stats import entropy
|
||||||
|
|
||||||
from CalculatingFeatures.helper_functions import convertInputInto2d, gsrFeatureNames
|
from cr_features.helper_functions import convert_to2d, gsr_features
|
||||||
from CalculatingFeatures.calculate_features import calculateFeatures
|
from cr_features.calculate_features import calculate_features
|
||||||
|
|
||||||
|
|
||||||
def getSampleRate(data):
|
def getSampleRate(data):
|
||||||
|
@ -11,9 +11,9 @@ def getSampleRate(data):
|
||||||
except:
|
except:
|
||||||
raise Exception("Error occured while trying to get the mean sample rate from the data.")
|
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)
|
eda_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
|
||||||
|
|
||||||
if not eda_intraday_data.empty:
|
if not eda_intraday_data.empty:
|
||||||
|
@ -29,11 +29,11 @@ def extractEDAFeaturesFromIntradayData(eda_intraday_data, features, window_lengt
|
||||||
if window_length is None:
|
if window_length is None:
|
||||||
eda_intraday_features = \
|
eda_intraday_features = \
|
||||||
eda_intraday_data.groupby('local_segment').apply(\
|
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:
|
else:
|
||||||
eda_intraday_features = \
|
eda_intraday_features = \
|
||||||
eda_intraday_data.groupby('local_segment').apply(\
|
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)
|
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
|
requested_window_length = None
|
||||||
|
|
||||||
# name of the features this function can compute
|
# 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
|
# the subset of requested features this function can compute
|
||||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||||
|
|
||||||
# extract features from intraday data
|
# 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)
|
requested_window_length, time_segment, filter_data_by_segment)
|
||||||
|
|
||||||
return eda_intraday_features
|
return eda_intraday_features
|
|
@ -1,25 +1,27 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
from scipy.stats import entropy
|
||||||
|
|
||||||
from CalculatingFeatures.helper_functions import convertInputInto2dTime, convert2DEmpaticaToArray hrvFeatureNames, hrvFreqFeatureNames
|
from cr_features.helper_functions import convert_ibi_to2d_time, hrv_features, hrv_freq_features
|
||||||
from CalculatingFeatures.calculate_features import calculateFeatures
|
from cr_features.calculate_features import calculate_features
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
pd.set_option('display.max_rows', 1000)
|
||||||
|
|
||||||
def getSampleRate(data):
|
|
||||||
|
def get_sample_rate(data):
|
||||||
try:
|
try:
|
||||||
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
||||||
except:
|
except:
|
||||||
raise Exception("Error occured while trying to get the mean sample rate from the data.")
|
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)
|
ibi_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
|
||||||
|
|
||||||
if not ibi_intraday_data.empty:
|
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)
|
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()
|
ibi_intraday_features = pd.DataFrame()
|
||||||
|
|
||||||
|
print(ibi_intraday_data.head(100))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# apply methods from calculate features module
|
# apply methods from calculate features module
|
||||||
# if window_length is None:
|
if window_length is None:
|
||||||
# ibi_intraday_features = \
|
ibi_intraday_features = \
|
||||||
# ibi_intraday_data.groupby('local_segment').apply(\
|
ibi_intraday_data.groupby('local_segment').apply(\
|
||||||
# lambda x: calculateFeatures(convertInputInto2d(x['blood_volume_pulse'], x.shape[0]), fs=int(sample_rate), featureNames=features))
|
extract_hrv_features_2d_wrapper(
|
||||||
# else:
|
convert_to2d(x['inter_beat_interval'], window_length*sample_rate),
|
||||||
# ibi_intraday_features = \
|
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
||||||
# ibi_intraday_data.groupby('local_segment').apply(\
|
else:
|
||||||
# lambda x: calculateFeatures(convertInputInto2d(x['blood_volume_pulse'], window_length*int(sample_rate)), fs=int(sample_rate), featureNames=features))
|
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)
|
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
|
requested_window_length = None
|
||||||
|
|
||||||
# name of the features this function can compute
|
# 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
|
# the subset of requested features this function can compute
|
||||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||||
|
|
||||||
# extract features from intraday data
|
# 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)
|
requested_window_length, time_segment, filter_data_by_segment)
|
||||||
|
|
||||||
return ibi_intraday_features
|
return ibi_intraday_features
|
|
@ -1,24 +1,24 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
from scipy.stats import entropy
|
||||||
|
|
||||||
from CalculatingFeatures.helper_functions import convert1DEmpaticaToArray, convertInputInto2d, genericFeatureNames
|
from cr_features.helper_functions import convert_to2d, generic_features
|
||||||
from CalculatingFeatures.calculate_features import calculateFeatures
|
from cr_features.calculate_features import calculate_features
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def getSampleRate(data):
|
def get_sample_rate(data):
|
||||||
try:
|
try:
|
||||||
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
timestamps_diff = data['timestamp'].diff().dropna().mean()
|
||||||
except:
|
except:
|
||||||
raise Exception("Error occured while trying to get the mean sample rate from the data.")
|
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)
|
temperature_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
|
||||||
|
|
||||||
if not temperature_intraday_data.empty:
|
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)
|
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:
|
if window_length is None:
|
||||||
temperature_intraday_features = \
|
temperature_intraday_features = \
|
||||||
temperature_intraday_data.groupby('local_segment').apply(\
|
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:
|
else:
|
||||||
temperature_intraday_features = \
|
temperature_intraday_features = \
|
||||||
temperature_intraday_data.groupby('local_segment').apply(\
|
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)
|
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
|
requested_window_length = None
|
||||||
|
|
||||||
# name of the features this function can compute
|
# 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
|
# the subset of requested features this function can compute
|
||||||
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
|
||||||
|
|
||||||
# extract features from intraday data
|
# 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)
|
requested_window_length, time_segment, filter_data_by_segment)
|
||||||
return temperature_intraday_features
|
return temperature_intraday_features
|
Loading…
Reference in New Issue