From 8c726f5d4f7a2273188627d1a511a7c0b2281afd Mon Sep 17 00:00:00 2001 From: JulioV Date: Mon, 14 Dec 2020 20:30:34 -0500 Subject: [PATCH] Start empatica support --- Snakefile | 63 ++++++ config.yaml | 78 +++++++- rules/common.smk | 2 +- rules/features.smk | 184 +++++++++++++++++- rules/preprocessing.smk | 31 +++ src/data/empatica/extract_empatica_data.py | 32 +++ .../empatica_accelerometer/dbdp/main.py | 21 ++ .../empatica_blood_volume_pulse/dbdp/main.py | 21 ++ .../dbdp/main.py | 21 ++ src/features/empatica_heartrate/dbdp/main.py | 21 ++ .../empatica_inter_beat_interval/dbdp/main.py | 21 ++ src/features/empatica_tags/dbdp/main.py | 21 ++ .../empatica_temperature/dbdp/main.py | 21 ++ 13 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 src/data/empatica/extract_empatica_data.py create mode 100644 src/features/empatica_accelerometer/dbdp/main.py create mode 100644 src/features/empatica_blood_volume_pulse/dbdp/main.py create mode 100644 src/features/empatica_electrodermal_activity/dbdp/main.py create mode 100644 src/features/empatica_heartrate/dbdp/main.py create mode 100644 src/features/empatica_inter_beat_interval/dbdp/main.py create mode 100644 src/features/empatica_tags/dbdp/main.py create mode 100644 src/features/empatica_temperature/dbdp/main.py diff --git a/Snakefile b/Snakefile index 91c0679e..bf44d71d 100644 --- a/Snakefile +++ b/Snakefile @@ -288,6 +288,69 @@ for provider in config["FITBIT_STEPS_INTRADAY"]["PROVIDERS"].keys(): # 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_ACCELEROMETER"]["PROVIDERS"].keys(): + if config["EMPATICA_ACCELEROMETER"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_accelerometer_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_accelerometer_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_accelerometer_features/empatica_accelerometer_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_ACCELEROMETER"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_accelerometer.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_HEARTRATE"]["PROVIDERS"].keys(): + if config["EMPATICA_HEARTRATE"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_heartrate_raw.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"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_temperature_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_temperature_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_temperature_features/empatica_temperature_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_TEMPERATURE"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_temperature.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_ELECTRODERMAL_ACTIVITY"]["PROVIDERS"].keys(): + if config["EMPATICA_ELECTRODERMAL_ACTIVITY"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_electrodermal_activity_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_electrodermal_activity_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_electrodermal_activity_features/empatica_electrodermal_activity_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_ELECTRODERMAL_ACTIVITY"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_electrodermal_activity.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_BLOOD_VOLUME_PULSE"]["PROVIDERS"].keys(): + if config["EMPATICA_BLOOD_VOLUME_PULSE"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_blood_volume_pulse_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_blood_volume_pulse_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_blood_volume_pulse_features/empatica_blood_volume_pulse_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_BLOOD_VOLUME_PULSE"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_blood_volume_pulse.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_INTER_BEAT_INTERVAL"]["PROVIDERS"].keys(): + if config["EMPATICA_INTER_BEAT_INTERVAL"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_inter_beat_interval_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_inter_beat_interval_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_inter_beat_interval_features/empatica_inter_beat_interval_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_INTER_BEAT_INTERVAL"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_inter_beat_interval.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_TAGS"]["PROVIDERS"].keys(): + if config["EMPATICA_TAGS"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/empatica_tags_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/empatica_tags_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/empatica_tags_features/empatica_tags_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["EMPATICA_TAGS"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/empatica_tags.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") + # Visualization for Data Exploration if config["HISTOGRAM_PHONE_DATA_YIELD"]["PLOT"]: files_to_compute.append("reports/data_exploration/histogram_phone_data_yield.html") diff --git a/config.yaml b/config.yaml index 9e55fdf5..55317e92 100644 --- a/config.yaml +++ b/config.yaml @@ -7,7 +7,7 @@ TIMEZONE: &timezone America/New_York # See https://www.rapids.science/latest/setup/configuration/#participant-files -PIDS: [test01] +PIDS: [e01] # See https://www.rapids.science/latest/setup/configuration/#automatic-creation-of-participant-files CREATE_PARTICIPANT_FILES: @@ -408,6 +408,82 @@ FITBIT_STEPS_INTRADAY: # FEATURES: [] +######################################################################################################################## +# EMPATICA # +######################################################################################################################## + +EMPATICA_DATA_CONFIGURATION: + SOURCE: + TYPE: FILE + TIMEZONE: + TYPE: SINGLE # Fitbit devices don't support time zones so we read this data in the timezone indicated by VALUE + VALUE: *timezone + +# Sensors ------ + +# See https://www.rapids.science/latest/features/fitbit-heartrate-summary/ +EMPATICA_ACCELEROMETER: + TABLE: acc + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_accelerometer + SRC_LANGUAGE: "python" + +EMPATICA_HEARTRATE: + TABLE: hr + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" + +EMPATICA_TEMPERATURE: + TABLE: temp + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" + +EMPATICA_ELECTRODERMAL_ACTIVITY: + TABLE: temp + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" + +EMPATICA_BLOOD_VOLUME_PULSE: + TABLE: bvp + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" + +EMPATICA_INTER_BEAT_INTERVAL: + TABLE: ibi + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" + +EMPATICA_TAGS: + TABLE: tags + PROVIDERS: + DBDP: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "dbdp" # inside src/features/empatica_heartrate + SRC_LANGUAGE: "python" ######################################################################################################################## # PLOTS # diff --git a/rules/common.smk b/rules/common.smk index a496be7f..53c05122 100644 --- a/rules/common.smk +++ b/rules/common.smk @@ -15,7 +15,7 @@ def optional_steps_sleep_input(wildcards): def input_merge_sensor_features_for_individual_participants(wildcards): feature_files = [] for config_key in config.keys(): - if config_key.startswith(("PHONE", "FITBIT")) and "PROVIDERS" in config[config_key] and isinstance(config[config_key]["PROVIDERS"], dict): + if config_key.startswith(("PHONE", "FITBIT", "EMPATICA")) and "PROVIDERS" in config[config_key] and isinstance(config[config_key]["PROVIDERS"], dict): for provider_key, provider in config[config_key]["PROVIDERS"].items(): if "COMPUTE" in provider.keys() and provider["COMPUTE"]: feature_files.append("data/processed/features/{pid}/" + config_key.lower() + ".csv") diff --git a/rules/features.smk b/rules/features.smk index 33e3ba85..c5f43be4 100644 --- a/rules/features.smk +++ b/rules/features.smk @@ -2,7 +2,7 @@ rule join_features_from_providers: input: sensor_features = find_features_files wildcard_constraints: - sensor_key = '(phone|fitbit).*' + sensor_key = '(phone|fitbit|empatica).*' output: "data/processed/features/{pid}/{sensor_key}.csv" script: @@ -675,3 +675,185 @@ rule merge_sensor_features_for_all_participants: "data/processed/features/all_participants/all_sensor_features.csv" script: "../src/features/utils/merge_sensor_features_for_all_participants.R" + +rule empatica_accelerometer_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_accelerometer_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_ACCELEROMETER"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_accelerometer" + output: + "data/interim/{pid}/empatica_accelerometer_features/empatica_accelerometer_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_accelerometer_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_accelerometer_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_ACCELEROMETER"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_accelerometer" + output: + "data/interim/{pid}/empatica_accelerometer_features/empatica_accelerometer_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_heartrate_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_heartrate_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_HEARTRATE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_heartrate" + output: + "data/interim/{pid}/empatica_heartrate_features/empatica_heartrate_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_heartrate_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_heartrate_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_HEARTRATE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_heartrate" + output: + "data/interim/{pid}/empatica_heartrate_features/empatica_heartrate_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_temperature_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_temperature_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_TEMPERATURE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_temperature" + output: + "data/interim/{pid}/empatica_temperature_features/empatica_temperature_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_temperature_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_temperature_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_TEMPERATURE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_temperature" + output: + "data/interim/{pid}/empatica_temperature_features/empatica_temperature_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_electrodermal_activity_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_electrodermal_activity_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_ELECTRODERMAL_ACTIVITY"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_electrodermal_activity" + output: + "data/interim/{pid}/empatica_electrodermal_activity_features/empatica_electrodermal_activity_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_electrodermal_activity_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_electrodermal_activity_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_ELECTRODERMAL_ACTIVITY"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_electrodermal_activity" + output: + "data/interim/{pid}/empatica_electrodermal_activity_features/empatica_electrodermal_activity_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_blood_volume_pulse_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_blood_volume_pulse_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_BLOOD_VOLUME_PULSE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_blood_volume_pulse" + output: + "data/interim/{pid}/empatica_blood_volume_pulse_features/empatica_blood_volume_pulse_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_blood_volume_pulse_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_blood_volume_pulse_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_BLOOD_VOLUME_PULSE"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_blood_volume_pulse" + output: + "data/interim/{pid}/empatica_blood_volume_pulse_features/empatica_blood_volume_pulse_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_inter_beat_interval_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_inter_beat_interval_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_INTER_BEAT_INTERVAL"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_inter_beat_interval" + output: + "data/interim/{pid}/empatica_inter_beat_interval_features/empatica_inter_beat_interval_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_inter_beat_interval_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_inter_beat_interval_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_INTER_BEAT_INTERVAL"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_inter_beat_interval" + output: + "data/interim/{pid}/empatica_inter_beat_interval_features/empatica_inter_beat_interval_r_{provider_key}.csv" + script: + "../src/features/entry.R" + +rule empatica_tags_python_features: + input: + sensor_data = "data/raw/{pid}/empatica_tags_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_TAGS"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_tags" + output: + "data/interim/{pid}/empatica_tags_features/empatica_tags_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule empatica_tags_r_features: + input: + sensor_data = "data/raw/{pid}/empatica_tags_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["EMPATICA_TAGS"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "empatica_tags" + output: + "data/interim/{pid}/empatica_tags_features/empatica_tags_r_{provider_key}.csv" + script: + "../src/features/entry.R" diff --git a/rules/preprocessing.smk b/rules/preprocessing.smk index e660d13a..33d0fe66 100644 --- a/rules/preprocessing.smk +++ b/rules/preprocessing.smk @@ -242,3 +242,34 @@ rule fitbit_readable_datetime: "data/raw/{pid}/fitbit_{sensor}_{fitbit_data_type}_parsed_with_datetime.csv" script: "../src/data/readable_datetime.R" + +def empatica_input(wildcards): + return expand("data/external/empatica/{{pid}}/{filename}.csv", filename=config["EMPATICA_" + str(wildcards.sensor).upper()]["TABLE"]) + +rule extract_empatica_data: + input: + input_file = empatica_input, + participant_file = "data/external/participant_files/{pid}.yaml" + params: + data_configuration = config["EMPATICA_DATA_CONFIGURATION"], + sensor = "{sensor}", + table = lambda wildcards: config["EMPATICA_" + str(wildcards.sensor).upper()]["TABLE"], + output: + sensor_output = "data/raw/{pid}/empatica_{sensor}_raw.csv" + script: + "../src/data/empatica/extract_empatica_data.py" + + +rule empatica_readable_datetime: + input: + sensor_input = "data/raw/{pid}/empatica_{sensor}_raw.csv", + time_segments = "data/interim/time_segments/{pid}_time_segments.csv" + params: + timezones = config["PHONE_DATA_CONFIGURATION"]["TIMEZONE"]["TYPE"], + fixed_timezone = config["PHONE_DATA_CONFIGURATION"]["TIMEZONE"]["VALUE"], + time_segments_type = config["TIME_SEGMENTS"]["TYPE"], + include_past_periodic_segments = config["TIME_SEGMENTS"]["INCLUDE_PAST_PERIODIC_SEGMENTS"] + output: + "data/raw/{pid}/empatica_{sensor}_with_datetime.csv" + script: + "../src/data/readable_datetime.R" diff --git a/src/data/empatica/extract_empatica_data.py b/src/data/empatica/extract_empatica_data.py new file mode 100644 index 00000000..31baf4ed --- /dev/null +++ b/src/data/empatica/extract_empatica_data.py @@ -0,0 +1,32 @@ +import pandas as pd +from pandas.core import indexing +import yaml + + +def extract_empatica_data(sensor_data_file, output_file, start_date, end_date, timezone, sensor): + print(sensor_data_file) + print(output_file) + print(start_date) + print(end_date) + print(timezone) + print(sensor) + data = pd.read_csv(sensor_data_file) + print(data) + + # extract + print(output_file) + data.to_csv(output_file, index = False) + + +sensor_data_file = snakemake.input[0] +output_file = snakemake.output[0] +with open(snakemake.input[1], "r", encoding="utf-8") as f: + participant_file = yaml.safe_load(f) + +start_date = participant_file["EMPATICA"]["START_DATE"] +end_date = participant_file["EMPATICA"]["END_DATE"] +timezone = snakemake.params["data_configuration"]["TIMEZONE"]["VALUE"] +sensor = snakemake.params["sensor"] + +extract_empatica_data(sensor_data_file, output_file, start_date, end_date, timezone, sensor) + diff --git a/src/features/empatica_accelerometer/dbdp/main.py b/src/features/empatica_accelerometer/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_accelerometer/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_blood_volume_pulse/dbdp/main.py b/src/features/empatica_blood_volume_pulse/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_blood_volume_pulse/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_electrodermal_activity/dbdp/main.py b/src/features/empatica_electrodermal_activity/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_electrodermal_activity/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_heartrate/dbdp/main.py b/src/features/empatica_heartrate/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_heartrate/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_inter_beat_interval/dbdp/main.py b/src/features/empatica_inter_beat_interval/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_inter_beat_interval/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_tags/dbdp/main.py b/src/features/empatica_tags/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_tags/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file diff --git a/src/features/empatica_temperature/dbdp/main.py b/src/features/empatica_temperature/dbdp/main.py new file mode 100644 index 00000000..82da2f3a --- /dev/null +++ b/src/features/empatica_temperature/dbdp/main.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np + +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"] + # name of the features this function can compute + base_features_names = [] # ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_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) + + if not sensor_data.empty: + features = pd.DataFrame() + + + return features \ No newline at end of file