From ce503d94e139229a565689ba9601ee06cabdec19 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:50:39 +0100 Subject: [PATCH 01/12] remove valid days and daytime assessment --- src/paradigma/config.py | 3 -- src/paradigma/tremor/tremor_analysis.py | 33 +++++-------------- .../tremor/weekly_tremor.json | 4 +-- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/paradigma/config.py b/src/paradigma/config.py index 3317e59..b5c50e5 100644 --- a/src/paradigma/config.py +++ b/src/paradigma/config.py @@ -361,9 +361,6 @@ class TremorQuantificationConfig(TremorBaseConfig): def __init__(self) -> None: super().__init__() - self.valid_day_threshold_hr: float = 0 # change to 10 later! - self.daytime_hours_lower_bound: float = 8 - self.daytime_hours_upper_bound: float = 22 self.percentile_tremor_power: float = 0.9 self.set_filenames('tremor') diff --git a/src/paradigma/tremor/tremor_analysis.py b/src/paradigma/tremor/tremor_analysis.py index d74502a..2b89627 100644 --- a/src/paradigma/tremor/tremor_analysis.py +++ b/src/paradigma/tremor/tremor_analysis.py @@ -127,29 +127,14 @@ def aggregate_tremor_power(tremor_power: pd.Series, config: TremorQuantification return tremor_power_median, tremor_power_90th_perc, tremor_power_mode -def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig, utc_start_time: str): - - # Create time array in local time zone - utc_start_time = datetime.strptime(utc_start_time, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.UTC) # convert to datetime - local_start_time = utc_start_time.astimezone(pytz.timezone("Europe/Amsterdam")) - time = [local_start_time + timedelta(seconds=x) for x in df.time] - - # determine valid days - daytime_hours = range(config.daytime_hours_lower_bound,config.daytime_hours_upper_bound) - nr_windows_per_day = Counter([dt.date() for dt in time if dt.hour in daytime_hours]) - valid_days = [day for day, count in nr_windows_per_day.items() - if count * config.window_length_s / 3600 >= config.valid_day_threshold_hr] - nr_valid_days = len(valid_days) - - # remove windows during non-valid days, non-daytime hours and non-tremor arm movement - df_filtered = df.loc[[dt.date() in valid_days for dt in time]] - df_filtered = df_filtered.loc[[dt.hour in daytime_hours for dt in time]] - nr_windows_daytime = df_filtered.shape[0] # number of windows during daytime on valid days - df_filtered = df_filtered.loc[df_filtered.low_freq_power <= config.movement_threshold] - nr_windows_daytime_rest = df_filtered.shape[0] # number of windows during daytime on valid days without non-tremor arm movement +def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig): + + # remove windows with detected non-tremor movements + df_filtered = df.loc[df.low_freq_power <= config.movement_threshold] + nr_windows_rest = df_filtered.shape[0] # number of windows without non-tremor arm movement # calculate weekly tremor time - tremor_time= np.sum(df_filtered['pred_tremor_checked']) / df_filtered.shape[0] * 100 + tremor_time= np.sum(df_filtered['pred_tremor_checked']) / nr_windows_rest * 100 # as percentage of total measured time without non-tremor arm movement # calculate weekly tremor power measures tremor_power = df_filtered.loc[df_filtered['pred_tremor_checked'] == 1, 'tremor_power'] @@ -158,9 +143,7 @@ def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig, utc_st # store aggregates in json format d_aggregates = { 'metadata': { - 'nr_valid_days': nr_valid_days, - 'nr_windows_daytime': nr_windows_daytime, - 'nr_windows_daytime_rest': nr_windows_daytime_rest + 'nr_windows_rest': nr_windows_rest }, 'weekly_tremor_measures': { 'tremor_time': tremor_time, @@ -191,7 +174,7 @@ def quantify_tremor_io(path_to_feature_input: Union[str, Path], path_to_predicti df = pd.concat([df_predictions, df_features], axis=1) # Compute weekly aggregated tremor measures - d_aggregates = quantify_tremor(df, config, utc_start_time = metadata_time.start_iso8601) + d_aggregates = quantify_tremor(df, config) # Save output with open(os.path.join(output_path,"weekly_tremor.json"), 'w') as json_file: diff --git a/tests/data/5.quantification/tremor/weekly_tremor.json b/tests/data/5.quantification/tremor/weekly_tremor.json index 73e1cc2..ca7b277 100644 --- a/tests/data/5.quantification/tremor/weekly_tremor.json +++ b/tests/data/5.quantification/tremor/weekly_tremor.json @@ -1,8 +1,6 @@ { "metadata": { - "nr_valid_days": 1, - "nr_windows_daytime": 182, - "nr_windows_daytime_rest": 89 + "nr_windows_rest": 89 }, "weekly_tremor_measures": { "tremor_time": 16.853932584269664, From dec77e701811b71577793550ac0b8bf7e29c3b1a Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:14:34 +0100 Subject: [PATCH 02/12] add notebook without io wrappers --- docs/notebooks/tremor/tremor_analysis.ipynb | 8 +- docs/notebooks/tremor/tremor_analysis2.ipynb | 165 +++++++++++++++++++ src/paradigma/tremor/tremor_analysis.py | 2 - 3 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 docs/notebooks/tremor/tremor_analysis2.ipynb diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index bf60e65..836fc18 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ diff --git a/docs/notebooks/tremor/tremor_analysis2.ipynb b/docs/notebooks/tremor/tremor_analysis2.ipynb new file mode 100644 index 0000000..e7266d8 --- /dev/null +++ b/docs/notebooks/tremor/tremor_analysis2.ipynb @@ -0,0 +1,165 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Tremor analysis" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from paradigma.config import IMUConfig, TremorFeatureExtractionConfig, TremorDetectionConfig, TremorQuantificationConfig\n", + "from paradigma.imu_preprocessing import preprocess_imu_data\n", + "from paradigma.tremor.tremor_analysis import extract_tremor_features, detect_tremor, quantify_tremor" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "df_tremor_week = pd.DataFrame(columns=['low_freq_power','tremor_power','pred_tremor_checked'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load data" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "import tsdf\n", + "from paradigma.util import read_metadata\n", + "\n", + "input_path = 'C:\\\\Users\\\\z835211\\\\Documents\\\\Data\\\\Raw IMU data\\\\WatchData.IMU.Week2\\\\POMU0000775B2E171842'\n", + "segment = 'WatchData.IMU.Week2.raw_segment0010'\n", + "\n", + "# Load data\n", + "metadata_time, metadata_values = read_metadata(str(input_path), str(segment+'_meta.json'),\n", + " str(segment+'_time.bin'), str(segment+'_samples.bin'))\n", + "df = tsdf.load_dataframe_from_binaries([metadata_time, metadata_values], tsdf.constants.ConcatenationType.columns)\n", + "\n", + "# Rename columns\n", + "df = df.rename(columns={f'rotation_{a}': f'gyroscope_{a}' for a in ['x', 'y', 'z']})\n", + "df = df.rename(columns={f'acceleration_{a}': f'accelerometer_{a}' for a in ['x', 'y', 'z']})\n", + "\n", + "config = IMUConfig()\n", + "\n", + "# Apply scale factors \n", + "df[list(config.d_channels_imu.keys())] *= metadata_values.scale_factors\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Preprocess gyroscope data" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "config = IMUConfig()\n", + "df_preprocessed = preprocess_imu_data(df, config, sensor='gyroscope')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extract features" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "config = TremorFeatureExtractionConfig()\n", + "df_features = extract_tremor_features(df_preprocessed, config)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Detect tremor" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "config = TremorDetectionConfig()\n", + "path_to_classifier_input = '../../../tests/data/0.classification/tremor'\n", + "df_tremor_predictions = detect_tremor(df_features, config, path_to_classifier_input)\n", + "\n", + "df_tremor_week = pd.concat([df_tremor_week, df_tremor_predictions[['low_freq_power','tremor_power','pred_tremor_checked']]],ignore_index=True)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Quantify tremor" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "config = TremorQuantificationConfig()\n", + "d_aggregates = quantify_tremor(df_tremor_week, config)\n", + "\n", + "import json\n", + "import os \n", + "\n", + "# Save output\n", + "with open(os.path.join(input_path,\"weekly_tremor.json\"), 'w') as json_file:\n", + " json.dump(d_aggregates, json_file, indent=4)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "paradigma-cfWEGyqZ-py3.11", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/paradigma/tremor/tremor_analysis.py b/src/paradigma/tremor/tremor_analysis.py index 2b89627..736a762 100644 --- a/src/paradigma/tremor/tremor_analysis.py +++ b/src/paradigma/tremor/tremor_analysis.py @@ -7,8 +7,6 @@ from pathlib import Path from typing import Union from sklearn.linear_model import LogisticRegression -from datetime import datetime, timedelta -from collections import Counter from scipy.stats import gaussian_kde from paradigma.constants import DataColumns From 7592f21c34cfa42315a8ccf93f617efaa8b11538 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:22:31 +0100 Subject: [PATCH 03/12] clear output notebook --- docs/notebooks/tremor/tremor_analysis2.ipynb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/notebooks/tremor/tremor_analysis2.ipynb b/docs/notebooks/tremor/tremor_analysis2.ipynb index e7266d8..74488eb 100644 --- a/docs/notebooks/tremor/tremor_analysis2.ipynb +++ b/docs/notebooks/tremor/tremor_analysis2.ipynb @@ -37,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -88,12 +88,13 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "config = TremorFeatureExtractionConfig()\n", - "df_features = extract_tremor_features(df_preprocessed, config)" + "df_features = extract_tremor_features(df_preprocessed, config)\n", + "print(df_features)" ] }, { From ea380d3fcfc0bb61c4e83d0c91ae34c4e48a9d9f Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:28:09 +0100 Subject: [PATCH 04/12] add code for clear output --- docs/notebooks/tremor/tremor_analysis.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index 836fc18..e67c3d1 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -51,6 +51,15 @@ "preprocess_imu_data_io(path_to_sensor_data, path_to_preprocessed_data, config, sensor='gyroscope')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print('hello')" + ] + }, { "cell_type": "markdown", "metadata": {}, From f2f4fca6a0a9b33594673505a506733812439fcf Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:28:50 +0100 Subject: [PATCH 05/12] remove code --- docs/notebooks/tremor/tremor_analysis.ipynb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index e67c3d1..836fc18 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -51,15 +51,6 @@ "preprocess_imu_data_io(path_to_sensor_data, path_to_preprocessed_data, config, sensor='gyroscope')" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('hello')" - ] - }, { "cell_type": "markdown", "metadata": {}, From c780eed9e2e7c3a118da3b2abf29265193c7ae68 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:32:51 +0100 Subject: [PATCH 06/12] add some documentation --- docs/notebooks/tremor/tremor_analysis.ipynb | 9 +++++++++ docs/notebooks/tremor/tremor_analysis2.ipynb | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index 836fc18..d1b3842 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -68,6 +68,15 @@ "extract_tremor_features_io(path_to_preprocessed_data, path_to_extracted_features, config)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print('hello')" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/docs/notebooks/tremor/tremor_analysis2.ipynb b/docs/notebooks/tremor/tremor_analysis2.ipynb index 74488eb..9f23f68 100644 --- a/docs/notebooks/tremor/tremor_analysis2.ipynb +++ b/docs/notebooks/tremor/tremor_analysis2.ipynb @@ -25,7 +25,16 @@ "metadata": {}, "outputs": [], "source": [ - "df_tremor_week = pd.DataFrame(columns=['low_freq_power','tremor_power','pred_tremor_checked'])" + "df_tremor_week = pd.DataFrame(columns=['low_freq_power','tremor_power','pred_tremor_checked']) # create dataframe for concatenation of segments after the tremor detection step" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print('hello')" ] }, { From 14ccae6ba44d804283c34d56efb3ff0e1d7f10e1 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:34:00 +0100 Subject: [PATCH 07/12] remove code --- docs/notebooks/tremor/tremor_analysis.ipynb | 9 --------- docs/notebooks/tremor/tremor_analysis2.ipynb | 9 --------- 2 files changed, 18 deletions(-) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index d1b3842..836fc18 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -68,15 +68,6 @@ "extract_tremor_features_io(path_to_preprocessed_data, path_to_extracted_features, config)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('hello')" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/docs/notebooks/tremor/tremor_analysis2.ipynb b/docs/notebooks/tremor/tremor_analysis2.ipynb index 9f23f68..beeb867 100644 --- a/docs/notebooks/tremor/tremor_analysis2.ipynb +++ b/docs/notebooks/tremor/tremor_analysis2.ipynb @@ -28,15 +28,6 @@ "df_tremor_week = pd.DataFrame(columns=['low_freq_power','tremor_power','pred_tremor_checked']) # create dataframe for concatenation of segments after the tremor detection step" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('hello')" - ] - }, { "cell_type": "markdown", "metadata": {}, From 5b78ff3e0299a17206f67c1ac111db3ca5d2f4f8 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:59:22 +0100 Subject: [PATCH 08/12] delete second notebook (only for testing) --- docs/notebooks/tremor/tremor_analysis2.ipynb | 166 ------------------- 1 file changed, 166 deletions(-) delete mode 100644 docs/notebooks/tremor/tremor_analysis2.ipynb diff --git a/docs/notebooks/tremor/tremor_analysis2.ipynb b/docs/notebooks/tremor/tremor_analysis2.ipynb deleted file mode 100644 index beeb867..0000000 --- a/docs/notebooks/tremor/tremor_analysis2.ipynb +++ /dev/null @@ -1,166 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Tremor analysis" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "from paradigma.config import IMUConfig, TremorFeatureExtractionConfig, TremorDetectionConfig, TremorQuantificationConfig\n", - "from paradigma.imu_preprocessing import preprocess_imu_data\n", - "from paradigma.tremor.tremor_analysis import extract_tremor_features, detect_tremor, quantify_tremor" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "df_tremor_week = pd.DataFrame(columns=['low_freq_power','tremor_power','pred_tremor_checked']) # create dataframe for concatenation of segments after the tremor detection step" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load data" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import tsdf\n", - "from paradigma.util import read_metadata\n", - "\n", - "input_path = 'C:\\\\Users\\\\z835211\\\\Documents\\\\Data\\\\Raw IMU data\\\\WatchData.IMU.Week2\\\\POMU0000775B2E171842'\n", - "segment = 'WatchData.IMU.Week2.raw_segment0010'\n", - "\n", - "# Load data\n", - "metadata_time, metadata_values = read_metadata(str(input_path), str(segment+'_meta.json'),\n", - " str(segment+'_time.bin'), str(segment+'_samples.bin'))\n", - "df = tsdf.load_dataframe_from_binaries([metadata_time, metadata_values], tsdf.constants.ConcatenationType.columns)\n", - "\n", - "# Rename columns\n", - "df = df.rename(columns={f'rotation_{a}': f'gyroscope_{a}' for a in ['x', 'y', 'z']})\n", - "df = df.rename(columns={f'acceleration_{a}': f'accelerometer_{a}' for a in ['x', 'y', 'z']})\n", - "\n", - "config = IMUConfig()\n", - "\n", - "# Apply scale factors \n", - "df[list(config.d_channels_imu.keys())] *= metadata_values.scale_factors\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Preprocess gyroscope data" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "config = IMUConfig()\n", - "df_preprocessed = preprocess_imu_data(df, config, sensor='gyroscope')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extract features" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "config = TremorFeatureExtractionConfig()\n", - "df_features = extract_tremor_features(df_preprocessed, config)\n", - "print(df_features)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Detect tremor" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "config = TremorDetectionConfig()\n", - "path_to_classifier_input = '../../../tests/data/0.classification/tremor'\n", - "df_tremor_predictions = detect_tremor(df_features, config, path_to_classifier_input)\n", - "\n", - "df_tremor_week = pd.concat([df_tremor_week, df_tremor_predictions[['low_freq_power','tremor_power','pred_tremor_checked']]],ignore_index=True)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Quantify tremor" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "config = TremorQuantificationConfig()\n", - "d_aggregates = quantify_tremor(df_tremor_week, config)\n", - "\n", - "import json\n", - "import os \n", - "\n", - "# Save output\n", - "with open(os.path.join(input_path,\"weekly_tremor.json\"), 'w') as json_file:\n", - " json.dump(d_aggregates, json_file, indent=4)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "paradigma-cfWEGyqZ-py3.11", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From 9465193a0ff61e3f3144f6bd38d4591d5bf98098 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:09:18 +0100 Subject: [PATCH 09/12] added suggestions --- docs/notebooks/tremor/tremor_analysis.ipynb | 10 +++++----- src/paradigma/tremor/tremor_analysis.py | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index 836fc18..e678dd3 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ diff --git a/src/paradigma/tremor/tremor_analysis.py b/src/paradigma/tremor/tremor_analysis.py index 736a762..7fcbfca 100644 --- a/src/paradigma/tremor/tremor_analysis.py +++ b/src/paradigma/tremor/tremor_analysis.py @@ -127,7 +127,9 @@ def aggregate_tremor_power(tremor_power: pd.Series, config: TremorQuantification def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig): - # remove windows with detected non-tremor movements + nr_windows_total = df_filtered.shape[0] + + # remove windows with detected non-tremor movements to control for the amount of arm activities performed df_filtered = df.loc[df.low_freq_power <= config.movement_threshold] nr_windows_rest = df_filtered.shape[0] # number of windows without non-tremor arm movement @@ -141,6 +143,7 @@ def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig): # store aggregates in json format d_aggregates = { 'metadata': { + 'nr_windows_total': nr_windows_total, 'nr_windows_rest': nr_windows_rest }, 'weekly_tremor_measures': { From edb7b904cc2e25f119358caf1beb543997b2efb4 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:13:46 +0100 Subject: [PATCH 10/12] fix bug --- src/paradigma/tremor/tremor_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paradigma/tremor/tremor_analysis.py b/src/paradigma/tremor/tremor_analysis.py index 7fcbfca..c5886aa 100644 --- a/src/paradigma/tremor/tremor_analysis.py +++ b/src/paradigma/tremor/tremor_analysis.py @@ -127,7 +127,7 @@ def aggregate_tremor_power(tremor_power: pd.Series, config: TremorQuantification def quantify_tremor(df: pd.DataFrame, config: TremorQuantificationConfig): - nr_windows_total = df_filtered.shape[0] + nr_windows_total = df.shape[0] # remove windows with detected non-tremor movements to control for the amount of arm activities performed df_filtered = df.loc[df.low_freq_power <= config.movement_threshold] From dadace19db8db26df80550d6f006632fdf3edf57 Mon Sep 17 00:00:00 2001 From: nienketimmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:19:55 +0100 Subject: [PATCH 11/12] change test output --- tests/data/5.quantification/tremor/weekly_tremor.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/data/5.quantification/tremor/weekly_tremor.json b/tests/data/5.quantification/tremor/weekly_tremor.json index ca7b277..6a70bb1 100644 --- a/tests/data/5.quantification/tremor/weekly_tremor.json +++ b/tests/data/5.quantification/tremor/weekly_tremor.json @@ -1,5 +1,6 @@ { "metadata": { + "nr_windows_total": 182, "nr_windows_rest": 89 }, "weekly_tremor_measures": { From 9df1e971ca2d4c65a1fd14fdb2fbacbff71ae681 Mon Sep 17 00:00:00 2001 From: Nienke Timmermans <65012819+nienketimmermans@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:21:32 +0100 Subject: [PATCH 12/12] Update tremor_analysis.ipynb --- docs/notebooks/tremor/tremor_analysis.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/notebooks/tremor/tremor_analysis.ipynb b/docs/notebooks/tremor/tremor_analysis.ipynb index e678dd3..bf60e65 100644 --- a/docs/notebooks/tremor/tremor_analysis.ipynb +++ b/docs/notebooks/tremor/tremor_analysis.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [