Add stats features for empatica heartrate

Turn off all empatica compute features
feature/plugin_sentimental
JulioV 2021-02-02 17:34:56 -05:00
parent 3bb0230bac
commit c6dc7e675a
3 changed files with 66 additions and 28 deletions

View File

@ -307,12 +307,12 @@ for provider in config["EMPATICA_HEARTRATE"]["PROVIDERS"].keys():
suffixes = get_zip_suffixes(pid)
files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_unzipped_{suffix}.csv", pid=pid, suffix=suffixes))
files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_raw_{suffix}.csv", pid=pid, suffix=suffixes))
# files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_joined.csv", pid=config["PIDS"]))
# files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_with_datetime.csv", pid=config["PIDS"]))
# files_to_compute.extend(expand("data/interim/{pid}/empatica_heartrate_features/empatica_heartrate_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_HEARTRATE"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower()))
# files_to_compute.extend(expand("data/processed/features/{pid}/empatica_heartrate.csv", pid=config["PIDS"]))
# files_to_compute.extend(expand("data/processed/features/{pid}/all_sensor_features.csv", pid=config["PIDS"]))
# files_to_compute.append("data/processed/features/all_participants/all_sensor_features.csv")
files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_joined.csv", pid=config["PIDS"]))
files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_with_datetime.csv", pid=config["PIDS"]))
files_to_compute.extend(expand("data/interim/{pid}/empatica_heartrate_features/empatica_heartrate_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_HEARTRATE"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower()))
files_to_compute.extend(expand("data/processed/features/{pid}/empatica_heartrate.csv", pid=config["PIDS"]))
files_to_compute.extend(expand("data/processed/features/{pid}/all_sensor_features.csv", pid=config["PIDS"]))
files_to_compute.append("data/processed/features/all_participants/all_sensor_features.csv")
for provider in config["EMPATICA_TEMPERATURE"]["PROVIDERS"].keys():
if config["EMPATICA_TEMPERATURE"]["PROVIDERS"][provider]["COMPUTE"]:

View File

@ -7,7 +7,7 @@ TIMEZONE: &timezone
America/New_York
# See https://www.rapids.science/latest/setup/configuration/#participant-files
PIDS: [e01]
PIDS: [e03]
# See https://www.rapids.science/latest/setup/configuration/#automatic-creation-of-participant-files
CREATE_PARTICIPANT_FILES:
@ -436,8 +436,8 @@ EMPATICA_HEARTRATE:
TABLE: hr
PROVIDERS:
DBDP:
COMPUTE: True
FEATURES: []
COMPUTE: False
FEATURES: ["maxhr", "minhr", "avghr", "medianhr", "modehr", "stdhr", "diffmaxmodehr", "diffminmodehr", "entropyhr"]
SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate
SRC_LANGUAGE: "python"
@ -445,7 +445,7 @@ EMPATICA_TEMPERATURE:
TABLE: temp
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: []
SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate
SRC_LANGUAGE: "python"
@ -454,7 +454,7 @@ EMPATICA_ELECTRODERMAL_ACTIVITY:
TABLE: eda
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: []
SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate
SRC_LANGUAGE: "python"
@ -463,7 +463,7 @@ EMPATICA_BLOOD_VOLUME_PULSE:
TABLE: bvp
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: []
SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate
SRC_LANGUAGE: "python"
@ -472,7 +472,7 @@ EMPATICA_INTER_BEAT_INTERVAL:
TABLE: ibi
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: []
SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate
SRC_LANGUAGE: "python"

View File

@ -1,21 +1,59 @@
import pandas as pd
import numpy as np
from scipy.stats import entropy
def statsFeatures(heartrate_data, features, heartrate_features):
col_name = "heartrate"
if "sumhr" in features:
heartrate_features["sumhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].sum()
if "maxhr" in features:
heartrate_features["maxhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].max()
if "minhr" in features:
heartrate_features["minhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].min()
if "avghr" in features:
heartrate_features["avghr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].mean()
if "medianhr" in features:
heartrate_features["medianhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].median()
if "modehr" in features:
heartrate_features["modehr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].agg(lambda x: pd.Series.mode(x)[0])
if "stdhr" in features:
heartrate_features["stdhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].std()
if "diffmaxmodehr" in features:
heartrate_features["diffmaxmodehr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].max() - heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].agg(lambda x: pd.Series.mode(x)[0])
if "diffminmodehr" in features:
heartrate_features["diffminmodehr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].agg(lambda x: pd.Series.mode(x)[0]) - heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].min()
if "entropyhr" in features:
heartrate_features["entropyhr"] = heartrate_data[["local_segment", col_name]].groupby(["local_segment"])[col_name].agg(entropy)
return heartrate_features
def extractHRFeaturesFromIntradayData(heartrate_intraday_data, features, time_segment, filter_data_by_segment):
heartrate_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
if not heartrate_intraday_data.empty:
heartrate_intraday_data = filter_data_by_segment(heartrate_intraday_data, time_segment)
if not heartrate_intraday_data.empty:
heartrate_intraday_features = pd.DataFrame()
# get stats of heartrate
heartrate_intraday_features = statsFeatures(heartrate_intraday_data, features, heartrate_intraday_features)
heartrate_intraday_features.reset_index(inplace=True)
return heartrate_intraday_features
def dbdp_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs):
sensor_data = pd.read_csv(sensor_data_files["sensor_data"])
requested_features = provider["FEATURES"]
heartrate_intraday_data = pd.read_csv(sensor_data_files["sensor_data"])
requested_intraday_features = provider["FEATURES"]
# name of the features this function can compute
base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"]
base_intraday_features_names = ["maxhr", "minhr", "avghr", "medianhr", "modehr", "stdhr", "diffmaxmodehr", "diffminmodehr", "entropyhr"]
# the subset of requested features this function can compute
features_to_compute = list(set(requested_features) & set(base_features_names))
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
features = pd.DataFrame(columns=["local_segment"] + features_to_compute)
if not sensor_data.empty:
sensor_data = filter_data_by_segment(sensor_data, time_segment)
# extract features from intraday data
heartrate_intraday_features = extractHRFeaturesFromIntradayData(heartrate_intraday_data, intraday_features_to_compute, time_segment, filter_data_by_segment)
if not sensor_data.empty:
features = pd.DataFrame()
return features
return heartrate_intraday_features