{ "cells": [ { "cell_type": "code", "metadata": { "tags": [ "plotly-renderer-setup" ] }, "source": [ "# Configure Plotly to render inline figures via CDN so they display\n", "# in the rendered Sphinx output (RTD). Safe to ignore when running\n", "# locally in Jupyter.\n", "import plotly.io as pio\n", "pio.renderers.default = 'notebook_connected'\n" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Example analysis of a PPG/ECG waveform using the vital_sqi package\n", "\n", "The following notebook shows an example of PPG/ECG waveform processing using the vital_sqi package. The aim of the package is to automate signal quality classification for PPG/ECG waveforms. It is achieved by computing various signal quality indices for each signal segment and using them to form a decision. \n", "\n", "## The pipeline can be briefly summarized as follows:\n", "1. Load dataset under analysis\n", "2. Preprocess and segment the dataset\n", "3. Compute SQI for each dataset segment\n", "4. Make decision for each segment" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Global Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import warnings\n", "import os\n", "import pandas as pd \n", "import matplotlib.pyplot as plt\n", "import vital_sqi\n", "from vital_sqi.data.signal_io import ECG_reader,PPG_reader" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Start by importing the signal via the PPG_reader function\n", "\n", "The function expects a .csv or similar data format with named columns. The column names are used to separate between data column, timestamp columns and any additional information columns.\n", "This returns a SignalSQI class that is compatible with other vital_sqi package functions, the main class members of interest are:\n", "* signals: an ndarray of shape (m, n) where m is the number of rows and n is the number of channels of the signal\n", "* sqis: an ndarray of shape (m, n) where m is the number of signal segments, n is the number of SQIs.\n", "* sampling_rate: sampling rate in hertz (Hz)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "from vital_sqi.pipeline.pipeline_highlevel import get_ppg_sqis\n", "\n", "file_in = os.path.abspath('test_data/ppg_smartcare.csv') #FIle input location\n", "sqi_dict = os.path.abspath('test_data/sqi_dict.json') #input dictionary -> which sqi features \n", "segments, signal_obj = get_ppg_sqis(file_in,\n", " signal_idx=['PLETH'], \n", " timestamp_idx=['TIMESTAMP_MS'], \n", " sqi_dict_filename = sqi_dict)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "signal_obj.sqis[0].describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get decision" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "from vital_sqi.pipeline.pipeline_highlevel import get_qualified_ppg\n", "rule_dict_filename = os.path.abspath('test_data/rule_dict_test.json') # location dictionary contain threshold\n", "ruleset_order = {3: 'skewness_1',\n", " 2: 'entropy',\n", " 1: 'perfusion'}\n", "file_in = os.path.abspath('test_data/ppg_smartcare.csv') #FIle input location\n", "sqi_dict = os.path.abspath('test_data/sqi_dict.json') #input dictionary -> which sqi features \n", "signal_obj = get_qualified_ppg(file_in,\n", " signal_idx=['PLETH'], \n", " timestamp_idx=['TIMESTAMP_MS'], \n", " sqi_dict_filename = sqi_dict,\n", " rule_dict_filename = rule_dict_filename,\n", " ruleset_order=ruleset_order,\n", " output_dir=None)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "signal_obj.sqis[0].describe()" ] } ], "metadata": { "kernelspec": { "display_name": "wearables", "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.9.17" }, "metadata": { "interpreter": { "hash": "44a947612cee24806d8552fd18facd5eb37e035fb69274c79904919775bbb337" } } }, "nbformat": 4, "nbformat_minor": 4 }