{ "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, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b42b83a842aa4d338df4f42c4571080b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "rpeaks_2_hrv_pipeline.py: 0%| | 0.00/1.76k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ccc1bab946ad45ee9bb7473e0ecac1e7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "rpeaks2hrv.py: 0%| | 0.00/7.54k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "A new version of the following files was downloaded from https://huggingface.co/hubii-world/rpeaks-to-hrv-pipeline:\n", "- rpeaks2hrv.py\n", ". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n", "A new version of the following files was downloaded from https://huggingface.co/hubii-world/rpeaks-to-hrv-pipeline:\n", "- rpeaks_2_hrv_pipeline.py\n", "- rpeaks2hrv.py\n", ". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c572acc1c2654d9599b1545b1810ff5b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "model.safetensors: 0%| | 0.00/649k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Device set to use cpu\n" ] } ], "source": [ "from transformers import pipeline\n", "\n", "rpeak2hrv_pipeline = pipeline(model = \"hubii-world/rpeaks-to-hrv-pipeline\", trust_remote_code=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Overview: Pipeline parameters\n", "The pipeline provides a variety of different parameters that can be set to adjust the preprocessing behavior. In the following, the different Parameters are explained and usage examples are provided.\n", "\n", "\n", "### Mandatory parameters\n", "In general, the pipeline relies on 2 mandatory parameters the user has to set for every parameter execution:\n", "- `inputs` : str | pd.DataFrame - The input that should be processed by the pipeline. This can either be a path to a file containing the data to process or the data itself\n", "- `sampling_rate` : int - The sampling rate of the continuous cardiac signal in which peaks occur. Default value is 1000\n", "\n", "\n", "### Optional parameters\n", "Besides the mandatory parameter, the pipeline offers multiple optional parameters that may be necessary to set in order to compute correct HRV-features:\n", "- `time_header` : str - The name of the column in the data that contains the timestamp to which the respective values in the same row are recorded. Default setting is 'SystemTime'\n", "- `rri_header` : str - The name of the column in the data that contains the RR-Intervals in msec. Default setting is 'interbeat_interval'\n", "- `windowing_method` : str - The method that should be applied to divide the raw data into windows. Default setting is None, so no windowing is applied\n", "- `window_size` : str - The size of a window in terms of a time frame. Only relevant if windowing should be applied to the data. Default setting is 60 seconds\n", "\n", "\n", "## 3.1 `Inputs`\n", "\n", "The `inputs` parameter represents the data the pipeline should process to HRV-Features. The following input formats are supported:\n", "- str\n", "- pd.Dataframe\n", "\n", "When providing the inputs as string, it has to represent a file path to a file containing the data to process. Supported file formats are .csv, .txt.\n", "\n", "Alternatively, you can also provide the data directly to the pipeline in form of a DataFrame.\n", "\n", "### 3.1.1 Example: Provide input as file path" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | HRV_MeanNN | \n", "HRV_SDNN | \n", "HRV_SDANN1 | \n", "HRV_SDNNI1 | \n", "HRV_SDANN2 | \n", "HRV_SDNNI2 | \n", "HRV_SDANN5 | \n", "HRV_SDNNI5 | \n", "HRV_RMSSD | \n", "HRV_SDSD | \n", "... | \n", "HRV_ULF | \n", "HRV_VLF | \n", "HRV_LF | \n", "HRV_HF | \n", "HRV_VHF | \n", "HRV_TP | \n", "HRV_LFHF | \n", "HRV_LFn | \n", "HRV_HFn | \n", "HRV_LnHF | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "1006.894005 | \n", "159.530641 | \n", "72.830794 | \n", "137.277955 | \n", "56.912177 | \n", "143.4821 | \n", "45.675812 | \n", "152.633402 | \n", "107.280546 | \n", "102.397785 | \n", "... | \n", "0.000497 | \n", "0.010289 | \n", "0.024415 | \n", "0.070705 | \n", "0.026376 | \n", "0.132282 | \n", "0.345306 | \n", "0.184566 | \n", "0.5345 | \n", "-2.649243 | \n", "
1 rows × 35 columns
\n", "| \n", " | window_start | \n", "window_end | \n", "HRV_MeanNN | \n", "HRV_SDNN | \n", "HRV_SDANN1 | \n", "HRV_SDNNI1 | \n", "HRV_SDANN2 | \n", "HRV_SDNNI2 | \n", "HRV_SDANN5 | \n", "HRV_SDNNI5 | \n", "... | \n", "HRV_SampEn | \n", "HRV_ShanEn | \n", "HRV_FuzzyEn | \n", "HRV_MSEn | \n", "HRV_CMSEn | \n", "HRV_RCMSEn | \n", "HRV_CD | \n", "HRV_HFD | \n", "HRV_KFD | \n", "HRV_LZC | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "2025-03-17 16:20:54.760848 | \n", "2025-03-17 16:21:53.596623680 | \n", "1060.358416 | \n", "153.515505 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "1.265666 | \n", "5.657451 | \n", "1.330316 | \n", "0.856145 | \n", "0.9913 | \n", "1.267671 | \n", "1.82538 | \n", "2.016523 | \n", "2.937446 | \n", "1.227977 | \n", "
1 rows × 84 columns
\n", "