PPG analysis

# Automatically reload modules
%load_ext autoreload
%autoreload 2

import os

from paradigma.preprocessing_config import PPGPreprocessingConfig, IMUPreprocessingConfig
from paradigma.ppg_preprocessing import scan_and_sync_segments, preprocess_ppg_data
from paradigma.heart_rate_analysis_config import HeartRateFeatureExtractionConfig
from paradigma.heart_rate_analysis import extract_signal_quality_features
# Cell has the tag 'parameters'
path_to_data =  '../../../tests/data'
path_to_classifier = '../../../src/paradigma/ppg/classifier'

quality_classifier_path = os.path.join(path_to_classifier, "LR_PPG_quality.pkl")
path_to_sensor_data = os.path.join(path_to_data, '1.sensor_data')
path_to_preprocessed_data = os.path.join(path_to_data, '2.preprocessed_data', 'ppg')
path_to_quality_features = os.path.join(path_to_data, '3.extracted_features', 'ppg')
ppg_config = PPGPreprocessingConfig()
imu_config = IMUPreprocessingConfig()
metadatas_ppg, metadatas_imu = scan_and_sync_segments(os.path.join(path_to_sensor_data, 'ppg'),
                                                       os.path.join(path_to_sensor_data, 'imu'))
preprocess_ppg_data(metadatas_ppg[0], metadatas_imu[0],
                    os.path.join(path_to_preprocessed_data, 'ppg'),
                    ppg_config, imu_config)
Shape of the original data: (64775, 2) (72947, 4)
Shape of the overlapping segments: (64775, 2) (64361, 4)
config = HeartRateFeatureExtractionConfig()
extract_signal_quality_features(path_to_preprocessed_data, quality_classifier_path, path_to_quality_features, config)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[4], line 2
      1 config = HeartRateFeatureExtractionConfig()
----> 2 extract_signal_quality_features(path_to_preprocessed_data, quality_classifier_path, path_to_quality_features, config)

File ~/work/paradigma/paradigma/src/paradigma/heart_rate_analysis.py:17, in extract_signal_quality_features(input_path, classifier_path, output_path, config)
     15 def extract_signal_quality_features(input_path: str, classifier_path: str, output_path: str, config: HeartRateFeatureExtractionConfig) -> None:
     16     # load data
---> 17     metadata_time_ppg, metadata_samples_ppg = read_metadata(input_path, "PPG_meta.json", "PPG_time.bin", "PPG_samples.bin")
     18     df_ppg = tsdf.load_dataframe_from_binaries([metadata_time_ppg, metadata_samples_ppg], tsdf.constants.ConcatenationType.columns)
     19     arr_ppg = df_ppg[DataColumns.PPG].to_numpy()

File ~/work/paradigma/paradigma/src/paradigma/util.py:47, in read_metadata(input_path, meta_filename, time_filename, values_filename)
     46 def read_metadata(input_path: str, meta_filename: str, time_filename: str, values_filename: str) -> Tuple[TSDFMetadata, TSDFMetadata]:
---> 47     metadata_dict = tsdf.load_metadata_from_path(os.path.join(input_path, meta_filename))
     48     metadata_time = metadata_dict[time_filename]
     49     metadata_samples = metadata_dict[values_filename]

File ~/.cache/pypoetry/virtualenvs/paradigma-1HID61PK-py3.10/lib/python3.10/site-packages/tsdf/read_tsdf.py:83, in load_metadata_from_path(path)
     75 """
     76 Loads a TSDF metadata file, returns a dictionary
     77 
   (...)
     80 :return: dictionary of TSDFMetadata objects.
     81 """
     82 # The data is isomorphic to a JSON
---> 83 with open(path, "r") as file:
     84     data = json.load(file)
     86 abs_path = os.path.realpath(path)

FileNotFoundError: [Errno 2] No such file or directory: '../../../tests/data/2.preprocessed_data/ppg/PPG_meta.json'