Skip to content

Commit

Permalink
Merge pull request #94 from biomarkersParkinson/arm-swing-quantification
Browse files Browse the repository at this point in the history
Arm swing quantification
  • Loading branch information
nienketimmermans authored Jan 9, 2025
2 parents e11a17f + 2e34ec7 commit 6137c24
Show file tree
Hide file tree
Showing 32 changed files with 1,084 additions and 875 deletions.
114 changes: 104 additions & 10 deletions docs/notebooks/gait/gait_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"outputs": [],
"source": [
"import os\n",
"from paradigma.gait.gait_analysis import extract_gait_features_io, detect_gait_io, extract_arm_activity_features_io, filter_gait_io\n",
"from paradigma.config import IMUConfig, GaitFeatureExtractionConfig, GaitDetectionConfig, ArmActivityFeatureExtractionConfig, FilteringGaitConfig\n",
"\n",
"from paradigma.config import IMUConfig, GaitFeatureExtractionConfig, GaitDetectionConfig, \\\n",
" ArmActivityFeatureExtractionConfig, FilteringGaitConfig, ArmSwingQuantificationConfig\n",
"from paradigma.gait.gait_analysis import extract_gait_features_io, detect_gait_io, \\\n",
" extract_arm_activity_features_io, filter_gait_io, quantify_arm_swing_io, aggregate_quantification_dict_io\n",
"from paradigma.preprocessing import preprocess_imu_data_io"
]
},
Expand All @@ -32,13 +35,30 @@
"branch = 'gait'\n",
"sensor = 'imu'\n",
"\n",
"gait_detection_classifier_filename = 'gait_detection_classifier.pkl'\n",
"gait_detection_scaler_filename = 'gait_detection_scaler_params.json'\n",
"gait_detection_threshold_filename = 'gait_detection_threshold.txt'\n",
"\n",
"gait_filtering_classifier_filename = 'gait_filtering_classifier.pkl'\n",
"gait_filtering_scaler_filename = 'gait_filtering_scaler_params.json'\n",
"gait_filtering_threshold_filename = 'gait_filtering_threshold.txt'\n",
"\n",
"path_to_data = '../../../tests/data'\n",
"path_to_classifiers = os.path.join(path_to_data, '0.classification', branch)\n",
"\n",
"path_to_classifier_input = os.path.join(path_to_data, '0.classification', branch)\n",
"path_to_classifiers = os.path.join(path_to_classifier_input, 'classifiers')\n",
"path_to_scalers = os.path.join(path_to_classifier_input, 'scalers')\n",
"path_to_thresholds = os.path.join(path_to_classifier_input, 'thresholds')\n",
"\n",
"path_to_sensor_data = os.path.join(path_to_data, '1.prepared_data', sensor)\n",
"path_to_preprocessed_data = os.path.join(path_to_data, '2.preprocessed_data', sensor)\n",
"path_to_extracted_features = os.path.join(path_to_data, '3.extracted_features', branch)\n",
"path_to_predictions = os.path.join(path_to_data, '4.predictions', branch)\n",
"path_to_quantification = os.path.join(path_to_data, '5.quantification', branch)\n",
"path_to_aggregation = os.path.join(path_to_data, '6.aggregation', branch)\n",
"\n",
"quantification_filename = 'arm_swing_quantification.json'\n",
"aggregation_filename = 'arm_swing_aggregates.json'\n",
"\n",
"# Cell has the tag 'parameters', so it won't overwrite the parameters when running the notebook in tests"
]
Expand All @@ -57,7 +77,13 @@
"outputs": [],
"source": [
"config = IMUConfig()\n",
"preprocess_imu_data_io(path_to_sensor_data, path_to_preprocessed_data, config, sensor='both')"
"\n",
"preprocess_imu_data_io(\n",
" path_to_input=path_to_sensor_data, \n",
" path_to_output=path_to_preprocessed_data, \n",
" config=config, \n",
" sensor='both'\n",
")"
]
},
{
Expand All @@ -74,7 +100,12 @@
"outputs": [],
"source": [
"config = GaitFeatureExtractionConfig()\n",
"extract_gait_features_io(path_to_preprocessed_data, path_to_extracted_features, config)"
"\n",
"extract_gait_features_io(\n",
" config=config,\n",
" path_to_input=path_to_preprocessed_data, \n",
" path_to_output=path_to_extracted_features, \n",
" )"
]
},
{
Expand All @@ -91,7 +122,17 @@
"outputs": [],
"source": [
"config = GaitDetectionConfig()\n",
"detect_gait_io(path_to_extracted_features, path_to_predictions, path_to_classifiers, config)"
"\n",
"full_path_to_classifier = os.path.join(path_to_classifiers, gait_detection_classifier_filename)\n",
"full_path_to_scaler = os.path.join(path_to_scalers, gait_detection_scaler_filename)\n",
"\n",
"detect_gait_io(\n",
" config=config, \n",
" path_to_input=path_to_extracted_features, \n",
" path_to_output=path_to_predictions, \n",
" full_path_to_classifier=full_path_to_classifier, \n",
" full_path_to_scaler=full_path_to_scaler\n",
")"
]
},
{
Expand All @@ -108,7 +149,15 @@
"outputs": [],
"source": [
"config = ArmActivityFeatureExtractionConfig()\n",
"extract_arm_activity_features_io(path_to_preprocessed_data, path_to_predictions, path_to_classifiers, path_to_extracted_features, config)"
"full_path_to_threshold = os.path.join(path_to_thresholds, gait_detection_threshold_filename)\n",
"\n",
"extract_arm_activity_features_io(\n",
" config=config,\n",
" path_to_timestamp_input=path_to_preprocessed_data, \n",
" path_to_prediction_input=path_to_predictions, \n",
" path_to_output=path_to_extracted_features,\n",
" full_path_to_threshold=full_path_to_threshold\n",
" )"
]
},
{
Expand All @@ -125,7 +174,16 @@
"outputs": [],
"source": [
"config = FilteringGaitConfig()\n",
"filter_gait_io(path_to_extracted_features, path_to_classifiers, path_to_predictions, config)"
"full_path_to_classifier = os.path.join(path_to_classifiers, gait_filtering_classifier_filename)\n",
"full_path_to_scaler = os.path.join(path_to_scalers, gait_filtering_scaler_filename)\n",
"\n",
"filter_gait_io(\n",
" config=config,\n",
" path_to_input=path_to_extracted_features, \n",
" path_to_output=path_to_predictions,\n",
" full_path_to_classifier=full_path_to_classifier, \n",
" full_path_to_scaler=full_path_to_scaler\n",
")"
]
},
{
Expand All @@ -141,8 +199,44 @@
"metadata": {},
"outputs": [],
"source": [
"# config = ArmSwingQuantificationConfig()\n",
"# quantify_arm_swing_io(path_to_extracted_features, path_to_predictions, path_to_classifiers, path_to_quantification, config)"
"asq_config = ArmSwingQuantificationConfig()\n",
"imu_config = IMUConfig()\n",
"\n",
"imu_config.set_sensor('gyroscope')\n",
"\n",
"full_path_to_output = os.path.join(path_to_quantification, quantification_filename)\n",
"\n",
"quantify_arm_swing_io(\n",
" imu_config=imu_config,\n",
" asq_config=asq_config,\n",
" path_to_timestamp_input=path_to_preprocessed_data, \n",
" path_to_prediction_input=path_to_predictions, \n",
" full_path_to_output=full_path_to_output, \n",
" full_path_to_threshold=full_path_to_threshold, \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aggregate quantification"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"full_path_to_input = os.path.join(path_to_quantification, quantification_filename)\n",
"full_path_to_output = os.path.join(path_to_aggregation, aggregation_filename)\n",
"\n",
"aggregate_quantification_dict_io(\n",
" full_path_to_input=full_path_to_input,\n",
" full_path_to_output=full_path_to_output,\n",
" aggregates=['median', '95p']\n",
")"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/ppg/ppg_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "paradigma-8ps1bg0Z-py3.12",
"display_name": "paradigma-Fn6RLG4_-py3.11",
"language": "python",
"name": "python3"
},
Expand All @@ -131,7 +131,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
5 changes: 5 additions & 0 deletions docs/tutorials/data_preparation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
"\n",
"watch_side = 'right'\n",
"\n",
"df_imu[DataColumns.ACCELEROMETER_Y] *= -1\n",
"df_imu[DataColumns.ACCELEROMETER_Z] *= -1\n",
"df_imu[DataColumns.GYROSCOPE_Y] *= -1\n",
"df_imu[DataColumns.GYROSCOPE_Z] *= -1\n",
"\n",
"df_imu = invert_watch_side(df_imu, watch_side)\n",
"df_imu.head(5)"
]
Expand Down
Loading

0 comments on commit 6137c24

Please sign in to comment.