Refactor light features: replace "metrics" with "features"

Co-authored-by: Meng Li <AnnieLM1996@gmail.com>
pull/95/head
Mingze Cao 2020-04-08 13:02:53 -05:00
parent f46e8c0666
commit 0809001dfa
5 changed files with 26 additions and 26 deletions

View File

@ -94,7 +94,7 @@ SCREEN:
LIGHT: LIGHT:
DAY_SEGMENTS: *day_segments DAY_SEGMENTS: *day_segments
METRICS: ["count", "maxlux", "minlux", "avglux", "medianlux", "stdlux"] FEATURES: ["count", "maxlux", "minlux", "avglux", "medianlux", "stdlux"]
ACCELEROMETER: ACCELEROMETER:
DAY_SEGMENTS: *day_segments DAY_SEGMENTS: *day_segments

View File

@ -703,7 +703,7 @@ See `Light Config Code`_
.. - Apply readable dateime to Sensor dataset: ``expand("data/raw/{pid}/{sensor}_with_datetime.csv", pid=config["PIDS"], sensor=config["SENSORS"]),`` .. - Apply readable dateime to Sensor dataset: ``expand("data/raw/{pid}/{sensor}_with_datetime.csv", pid=config["PIDS"], sensor=config["SENSORS"]),``
- Extract Light Metrics: - Extract Light Features:
| ``expand("data/processed/{pid}/light_{day_segment}.csv",`` | ``expand("data/processed/{pid}/light_{day_segment}.csv",``
| ``pid=config["PIDS"],`` | ``pid=config["PIDS"],``
@ -719,9 +719,9 @@ See `Light Config Code`_
- **Script:** ``src/data/readable_datetime.R`` - See the readable_datetime.R_ script. - **Script:** ``src/data/readable_datetime.R`` - See the readable_datetime.R_ script.
- **Rule:** ``rules/features.snakefile/light_metrics`` - See the light_metrics_ rule. - **Rule:** ``rules/features.snakefile/light_features`` - See the light_features_ rule.
- **Script:** ``src/features/light_metrics.py`` - See the light_metrics.py_ script. - **Script:** ``src/features/light_features.py`` - See the light_features.py_ script.
.. _light-parameters: .. _light-parameters:
@ -731,14 +731,14 @@ See `Light Config Code`_
Name Description Name Description
============ =================== ============ ===================
day_segment The particular ``day_segments`` that will be analyzed. The available options are ``daily``, ``morning``, ``afternoon``, ``evening``, ``night`` day_segment The particular ``day_segments`` that will be analyzed. The available options are ``daily``, ``morning``, ``afternoon``, ``evening``, ``night``
metrics The different measures that can be retrieved from the Light dataset. See :ref:`Available Light Metrics <light-available-metrics>` Table below features The different measures that can be retrieved from the Light dataset. See :ref:`Available Light Metrics <light-available-features>` Table below
============ =================== ============ ===================
.. _light-available-metrics: .. _light-available-features:
**Available Light Metrics** **Available Light Features**
The following table shows a list of the available metrics for the Light dataset. The following table shows a list of the available features for the Light dataset.
=========== ========= ============= =========== ========= =============
Name Units Description Name Units Description
@ -1175,8 +1175,8 @@ stddurationactivebout minutes Std duration active bout: The standard
.. _activity_metrics: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L74 .. _activity_metrics: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L74
.. _google_activity_recognition.py: https://github.com/carissalow/rapids/blob/master/src/features/google_activity_recognition.py .. _google_activity_recognition.py: https://github.com/carissalow/rapids/blob/master/src/features/google_activity_recognition.py
.. _`Light Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L94 .. _`Light Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L94
.. _light_metrics: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L113 .. _light_features: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L113
.. _light_metrics.py: https://github.com/carissalow/rapids/blob/master/src/features/light_metrics.py .. _light_features.py: https://github.com/carissalow/rapids/blob/master/src/features/light_features.py
.. _`Location (Barnetts) Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L70 .. _`Location (Barnetts) Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L70
.. _phone_sensed_bins: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/preprocessing.snakefile#L46 .. _phone_sensed_bins: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/preprocessing.snakefile#L46
.. _phone_sensed_bins.R: https://github.com/carissalow/rapids/blob/master/src/data/phone_sensed_bins.R .. _phone_sensed_bins.R: https://github.com/carissalow/rapids/blob/master/src/data/phone_sensed_bins.R

View File

@ -111,16 +111,16 @@ rule screen_features:
script: script:
"../src/features/screen_features.py" "../src/features/screen_features.py"
rule light_metrics: rule light_features:
input: input:
"data/raw/{pid}/light_with_datetime.csv", "data/raw/{pid}/light_with_datetime.csv",
params: params:
day_segment = "{day_segment}", day_segment = "{day_segment}",
metrics = config["LIGHT"]["METRICS"], features = config["LIGHT"]["FEATURES"],
output: output:
"data/processed/{pid}/light_{day_segment}.csv" "data/processed/{pid}/light_{day_segment}.csv"
script: script:
"../src/features/light_metrics.py" "../src/features/light_features.py"
rule accelerometer_features: rule accelerometer_features:
input: input:

View File

@ -0,0 +1,13 @@
import pandas as pd
from light.light_base import base_light_features
light_data = pd.read_csv(snakemake.input[0], parse_dates=["local_date_time", "local_date"])
day_segment = snakemake.params["day_segment"]
requested_features = snakemake.params["features"]
light_features = pd.DataFrame(columns=["local_date"])
light_features = light_features.merge(base_light_features(light_data, day_segment, requested_features), on="local_date", how="outer")
assert len(requested_features) + 1 == light_features.shape[1], "The number of features in the output dataframe (=" + str(light_features.shape[1]) + ") does not match the expected value (=" + str(len(requested_features)) + " + 1). Verify your light feature extraction functions"
light_features.to_csv(snakemake.output[0], index=False)

View File

@ -1,13 +0,0 @@
import pandas as pd
from light.light_base import base_light_features
light_data = pd.read_csv(snakemake.input[0], parse_dates=["local_date_time", "local_date"])
day_segment = snakemake.params["day_segment"]
metrics = snakemake.params["metrics"]
light_features = pd.DataFrame(columns=["local_date"])
light_features = light_features.merge(base_light_features(light_data, day_segment, metrics), on="local_date", how="outer")
assert len(metrics) + 1 == light_features.shape[1], "The number of features in the output dataframe (=" + str(light_features.shape[1]) + ") does not match the expected value (=" + str(len(metrics)) + " + 1). Verify your light feature extraction functions"
light_features.to_csv(snakemake.output[0], index=False)