{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# (Optional but recommeded) Set up Virtual Environment\n", "\n", "TODO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Install pipeline dependencies\n", "In order to use the pipeline, you need to install some dependencies the pipeline relies on. Run the following command to install the dependencies defined in requirements.txt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install -r requirements.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Instantiate pipeline" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5e6901339e274840a9447cffdba845e6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "config.json: 0%| | 0.00/829 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
HRV_MeanNNHRV_SDNNHRV_SDANN1HRV_SDNNI1HRV_SDANN2HRV_SDNNI2HRV_SDANN5HRV_SDNNI5HRV_RMSSDHRV_SDSD...HRV_ULFHRV_VLFHRV_LFHRV_HFHRV_VHFHRV_TPHRV_LFHFHRV_LFnHRV_HFnHRV_LnHF
01006.894005159.53064172.830794137.27795556.912177143.482145.675812152.633402107.280546102.397785...0.0004970.0102890.0244150.0707050.0263760.1322820.3453060.1845660.5345-2.649243
\n", "

1 rows × 35 columns

\n", "" ], "text/plain": [ " HRV_MeanNN HRV_SDNN HRV_SDANN1 HRV_SDNNI1 HRV_SDANN2 HRV_SDNNI2 \\\n", "0 1006.894005 159.530641 72.830794 137.277955 56.912177 143.4821 \n", "\n", " HRV_SDANN5 HRV_SDNNI5 HRV_RMSSD HRV_SDSD ... HRV_ULF HRV_VLF \\\n", "0 45.675812 152.633402 107.280546 102.397785 ... 0.000497 0.010289 \n", "\n", " HRV_LF HRV_HF HRV_VHF HRV_TP HRV_LFHF HRV_LFn HRV_HFn \\\n", "0 0.024415 0.070705 0.026376 0.132282 0.345306 0.184566 0.5345 \n", "\n", " HRV_LnHF \n", "0 -2.649243 \n", "\n", "[1 rows x 35 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "file_path = \"./Data/hr_rr_Elias-Rec_1703_162053.csv\"\n", "result = rpeak2hrv_pipeline(inputs=file_path, feature_domains=['time', 'freq'], sampling_rate=1000)\n", "result.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.2 `sampling_rate`\n", "The sampling_rate (Hz) represents the rate with which the sensor sampled data from the patient. It has to be provided as integer. In the example above, you can see a configuration where the sampling_rate is set to 2000.\n", "\n", "The default rate is 1000 Hz, meaning that the sensor sampled 1000 values per second." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.3 `time_header` & `rri_header`\n", "time_header and rri_header are important settings to define the structure of the data the pipeline has to process. In general, the pipeline supports two possible data formats:\n", "- R Peak Flags\n", "- RR-Intervals with timestamps\n", "\n", "### 3.3.1 R Peak Flags\n", "The first format option is defined by a Dataframe with one column named `'ECG_R_Peaks'`. The column values are simple binary flags indicating whether a R peak occured or not. \n", "\n", "This is the standard data format used by neurokit to represent R peaks. If you use this data format, you do not need to specify `time_header` and `rri_header`.\n", "\n", "__Important__: Make sure that the column has the correct name and that you specify the correct sampling rate, as these are indispensable information to compute the correct HRV-Features.\n", "\n", "#### Example: R Peak Flags\n", "\n", "TODO\n", "\n", "### 3.3.2 RR-Intervals with timestamps\n", "The second format option is defined by a DataFrame with two columns containing the RR-Intervals in milliseconds and the corresponding timestamps at which the RR-intervals have been recorded by the sensor. Here, `time_header` speficies the column name containing the timestamps and `rri_header` speficies the column containing the RR-intervals.\n", "The default column names are `'SystemTime'` and `'interbeat_intervals'`.\n", "#### Example: RR-Intervals with timestamps\n", "\n", "TODO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.4 `windowing_method`\n", "The windowing_method defines the method to be used to divide the raw data into windows. The supported settings are:\n", "- 'rolling' - Creates a window rolling over the data. For more information see [pandas.DataFrame.rolling()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rolling.html)\n", "- 'first_interval' - Keeps the data values that are recorded within the first timeframe defined by window_size and omits the rest\n", "- 'last_interval'- Keeps the data values that are recorded within the last timeframe defined by window_size and omits the rest\n", "\n", "\n", "# 3.4.1 Example: Use 'first_interval'-windowing\n", "The following code snipped shows an exemplary usage of first_interval windowing. In this example, only the values recorded within the first 60s of the data collection are used to compute HRV-Features" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\georg\\Desktop\\HIWI\\ECG2HRV\\.venv\\Lib\\site-packages\\neurokit2\\hrv\\hrv_nonlinear.py:268: NeuroKitWarning: Missing interbeat intervals have been detected. Note that missing intervals can distort some HRV features, in particular nonlinear indices.\n", " warn(\n", "c:\\Users\\georg\\Desktop\\HIWI\\ECG2HRV\\.venv\\Lib\\site-packages\\neurokit2\\hrv\\hrv_nonlinear.py:529: NeuroKitWarning: DFA_alpha2 related indices will not be calculated. The maximum duration of the windows provided for the long-term correlation is smaller than the minimum duration of windows. Refer to the `scale` argument in `nk.fractal_dfa()` for more information.\n", " warn(\n", "C:\\Users\\georg\\.cache\\huggingface\\modules\\transformers_modules\\willergeorg\\rpeaks-to-hrv-pipeline\\354dfd60f24b9b5900052952ca632b87456e4701\\rpeaks2hrv.py:24: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n", " hrv_values = pd.concat([hrv_values, hrv_time], ignore_index=True)\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
window_startwindow_endHRV_MeanNNHRV_SDNNHRV_SDANN1HRV_SDNNI1HRV_SDANN2HRV_SDNNI2HRV_SDANN5HRV_SDNNI5...HRV_SampEnHRV_ShanEnHRV_FuzzyEnHRV_MSEnHRV_CMSEnHRV_RCMSEnHRV_CDHRV_HFDHRV_KFDHRV_LZC
02025-03-17 16:20:54.7608482025-03-17 16:21:53.5966236801060.358416153.515505NaNNaNNaNNaNNaNNaN...1.2656665.6574511.3303160.8561450.99131.2676711.825382.0165232.9374461.227977
\n", "

1 rows × 84 columns

\n", "
" ], "text/plain": [ " window_start window_end HRV_MeanNN \\\n", "0 2025-03-17 16:20:54.760848 2025-03-17 16:21:53.596623680 1060.358416 \n", "\n", " HRV_SDNN HRV_SDANN1 HRV_SDNNI1 HRV_SDANN2 HRV_SDNNI2 HRV_SDANN5 \\\n", "0 153.515505 NaN NaN NaN NaN NaN \n", "\n", " HRV_SDNNI5 ... HRV_SampEn HRV_ShanEn HRV_FuzzyEn HRV_MSEn HRV_CMSEn \\\n", "0 NaN ... 1.265666 5.657451 1.330316 0.856145 0.9913 \n", "\n", " HRV_RCMSEn HRV_CD HRV_HFD HRV_KFD HRV_LZC \n", "0 1.267671 1.82538 2.016523 2.937446 1.227977 \n", "\n", "[1 rows x 84 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "file_path = \"./Data/hr_rr_Elias-Rec_1703_162053.csv\"\n", "result = rpeak2hrv_pipeline(inputs=file_path, windowing_method=\"first_interval\", window_size=\"60s\", sampling_rate=1000)\n", "result.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.5 `window_size`\n", "The window_size defines the size of the windows the data should be divided in. In general, the definition follows this pattern: '{any positive integer}{t}', where t is an element of {'d', 'h', 'm', 's'}.\n", "\n", "For example: the setting '20m' represents a window size of 20 minutes.\n", "\n", "The default setting is '60s' corresponding to a window size of a minute.\n", "\n", "Setting this parameter is only necessary, if you want to apply windowing." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example: Window size\n", "\n", "TODO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. Supported file formats\n", "\n", "TODO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.6" } }, "nbformat": 4, "nbformat_minor": 2 }