Skip to content

Commit

Permalink
Tutorial ppg (#106)
Browse files Browse the repository at this point in the history
* Start heart rate estimation including tfd

* stash updates

* update based on merge conflicts

* update hr main function

* update minor stuff matlab files

* change tfd parameters to dict

* First steps to refactoring to numpy

* Finalizing heart rate pipeline plus renaming preprocessing to acc instead of imu

* setting execution count to null

* fix output types

* fixing pytype due to old configs

* fix min_hr_samples pytype error

* remove irrelevant config

* resolved comments PR reviewer

* remove data type since it causes pytype error

* clear execution count

* import heart_rate_estimation

* merge updates

* update ppg_analysis

* replace df to numpy arrays

* fix notebook

* adding accelerometer feature

* fix type error list vs float

* implement accelerometer feature

* update matlab file based on refactoring

* fixing types, docstrings and readibility

* adding documentation acc feature

* add documentation of autocorrelation

* Made requested changes

* fix config

* adding aggregation heart rate

* update aggregates

* remove config

* add start tutorial

* aggregation implementation with dictionary

* add lines for consistency

* moved windoweddataextractor to segmenting

* resolve merge conflict

* update loading + preprocessing with seperate functionality

* update tutorial notebook and corresponding notebook

* Update test to io function

* update tutorial and notebook with simplified loading of the data

* Reset execution counts in notebook cells

* update execution_counts and output

* Updates from PR feedback

* fix type error

* made final feedback

---------

Co-authored-by: Erikpostt <erik_post_6@hotmail.com>
Co-authored-by: Erik Post <57133568+Erikpostt@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 14, 2025
1 parent 34396ae commit 3eafaf7
Show file tree
Hide file tree
Showing 5 changed files with 1,397 additions and 49 deletions.
58 changes: 44 additions & 14 deletions docs/notebooks/ppg/ppg_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import importlib.resources\n",
"import pickle\n",
"from pathlib import Path\n",
"\n",
"from paradigma.config import PPGConfig, IMUConfig, SignalQualityFeatureExtractionConfig, SignalQualityFeatureExtractionAccConfig, SignalQualityClassificationConfig, HeartRateExtractionConfig\n",
"from paradigma.preprocessing import scan_and_sync_segments, preprocess_ppg_data\n",
"from paradigma.heart_rate.heart_rate_analysis import extract_signal_quality_features, signal_quality_classification, estimate_heart_rate, aggregate_heart_rate"
"from paradigma.preprocessing import preprocess_ppg_data\n",
"from paradigma.heart_rate.heart_rate_analysis import extract_signal_quality_features, signal_quality_classification, estimate_heart_rate, aggregate_heart_rate\n",
"from paradigma.util import load_tsdf_dataframe"
]
},
{
Expand All @@ -33,18 +37,42 @@
"branch = 'heart_rate'\n",
"sensor = 'ppg'\n",
"\n",
"path_to_data = '../../../tests/data'\n",
"path_to_classifier = os.path.join(path_to_data, '0.classification', sensor)\n",
"path_to_sensor_data = os.path.join(path_to_data, '1.prepared_data')\n",
"path_to_preprocessed_data = os.path.join(path_to_data, '2.preprocessed_data', sensor)\n",
"path_to_quality_features = os.path.join(path_to_data, '3.extracted_features', branch)\n",
"path_to_signal_quality = os.path.join(path_to_data, '4.predictions', branch)\n",
"path_to_hr_estimate = os.path.join(path_to_data, '5.quantification', branch)\n",
"path_to_hr_aggregation = os.path.join(path_to_data, '6.aggregation', branch)\n",
"ppg_prefix = 'PPG'\n",
"imu_prefix = 'IMU'\n",
"\n",
"ppg_classifier_package_filename = 'ppg_quality_classifier.pkl'\n",
"\n",
"path_to_data = Path('../../../tests/data')\n",
"path_to_assets = Path('../../../src/paradigma/assets')\n",
"\n",
"path_to_classifier = path_to_data / '0.Classification' / sensor\n",
"path_to_prepared_data = path_to_data / '1.prepared_data'\n",
"path_to_preprocessed_data = path_to_data / '2.preprocessed_data' / sensor\n",
"path_to_extracted_features = path_to_data / '3.extracted_features' / branch\n",
"path_to_predictions = path_to_data / '4.predictions' / branch\n",
"path_to_quantification = path_to_data / '5.quantification' / branch\n",
"path_to_aggregation = path_to_data / '6.aggregation' / branch\n",
"\n",
"aggregation_filename = 'heart_rate_aggregates.json'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_ppg, _, _ = load_tsdf_dataframe(path_to_prepared_data / ppg_prefix, prefix = ppg_prefix)\n",
"df_imu, _, _ = load_tsdf_dataframe(path_to_prepared_data / imu_prefix, prefix = imu_prefix)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -61,8 +89,7 @@
"ppg_config = PPGConfig()\n",
"imu_config = IMUConfig()\n",
"\n",
"metadatas_ppg, metadatas_imu = scan_and_sync_segments(os.path.join(path_to_sensor_data, sensor), os.path.join(path_to_sensor_data, 'imu'))\n",
"df_ppg_proc, df_acc_proc = preprocess_ppg_data(metadatas_ppg[0], metadatas_imu[0], path_to_preprocessed_data, ppg_config, imu_config)"
"df_ppg_proc, df_acc_proc = preprocess_ppg_data(df_ppg, df_imu, ppg_config, imu_config)"
]
},
{
Expand Down Expand Up @@ -96,8 +123,11 @@
"metadata": {},
"outputs": [],
"source": [
"full_path_to_classifier_package = path_to_assets / ppg_classifier_package_filename\n",
"with importlib.resources.files('paradigma.assets').joinpath(ppg_classifier_package_filename).open('rb') as f:\n",
" clf_package = pickle.load(f)\n",
"config = SignalQualityClassificationConfig()\n",
"df_sqa = signal_quality_classification(df_features, config, path_to_classifier)"
"df_sqa = signal_quality_classification(df_features, config, clf_package)"
]
},
{
Expand Down
Loading

0 comments on commit 3eafaf7

Please sign in to comment.