{
"cells": [
{
"cell_type": "markdown",
"id": "9602592c-49af-4f2c-99bb-c13b8832d9bd",
"metadata": {},
"source": [
"# Use Case 1: Defibrillator data from out-of-hospital cardiac arrest case\n",
"\n",
"
\n",
"\n",
"This notebook illustrates the usage of the `vitabel` module to visualize, annotate and process time-series data from the medical field. Please find the detailed, searchable documentation here: \n",
"[](https://vitabel.readthedocs.io/en/latest/?badge=latest)\n",
"\n",
"In this case we analyze data recorded by a defibrillator during a real-world out-of-hospital cardiac arrest case.\n",
"This notebook in particular demonstrates the capabilities of `vitabel` to **display** and **annote** data.\n",
"\n",
"
\n",
"\n",
"If you have never worked with _Jupyter Notebooks_ before, you may find this guide helpful: **[Beginners Guide to Jupyter Notebooks](https://mybinder.org/v2/gh/jupyter/notebook/HEAD?urlpath=%2Fdoc%2Ftree%2Fdocs%2Fsource%2Fexamples%2FNotebook%2FRunning+Code.ipynb)**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8865d157-3791-4855-a97f-54350306fd38",
"metadata": {},
"outputs": [],
"source": [
"from vitabel import Vitals, Label\n",
"\n",
"import bz2\n",
"from pathlib import Path\n",
"import tempfile\n",
"import shutil\n",
"from datetime import datetime\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"id": "71ab307b-df58-4187-ac0e-e92cfdc54834",
"metadata": {},
"source": [
"## 1. Loading Data\n",
"\n",
"
\n",
"\n",
"An empty Vitabel object called `case` is initiated and all channels from a defibrillator recording (in this case a ZOLL X-Series case, stored in a compressed file) are loaded and added to the case.\n",
"\n",
"
\n",
"\n",
"Every Vitabel object as well as every channel and label holds a `metadata` dictionary. In the following we add the usage of the case in this notebook to the metadata.\n",
"\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02d8aad2",
"metadata": {},
"outputs": [],
"source": [
"usage_metadata = {\n",
" \"vitabel publication\": {\n",
" \"user\": \"ENTER YOUR NAME HERE\",\n",
" \"purpose\": \"highlighting capabilities to display and annotate defibrillator data\",\n",
" \"remarks\": [\n",
" \"a useful tool for researchers\",\n",
" \"handling data of devices by other manufacturers should be integrated better in the future\"\n",
" ],\n",
" }\n",
"}\n",
"case.metadata.update({\"usage\": usage_metadata})\n",
"\n",
"print(\"Current case metadata:\")\n",
"case.metadata"
]
},
{
"cell_type": "markdown",
"id": "61d0fe0a-0a5b-41bf-9cf5-eb9d6a7a97a8",
"metadata": {},
"source": [
"
\n",
"\n",
"We get an overview over all loaded channels by calling `case.info()`\n",
"\n",
"
\n",
"\n",
"We use integrated algorithms to extract **etCO₂** values and detect **ventilations** from the capnography signal.\n",
"Additionally, we analyze the accelerometer data from the CPR feedback device and the ECG signal from the defibrillation pads to estimate the **probability of spontaneous circulation**.\n",
"\n",
"
\n",
"\n",
"We aim to manually **annotate** occurrences of **Return of Spontaneous Circulation (ROSC)**. To do so, we create an empty label and add it to the case. With `metadata` we can store miscellaneous data in the label inside a dictionary (`{}`). Furthermore, we can define the `plotstyle` by passing parameters in another dictionary.\n",
"\n",
"The argument `plot_type` determines how label data is depicted in the plot. As the type is also dynamically adapted to the available data,\n",
"we can explore the different types by adding labels with different data in the later generated plot.\n",
"\n",
"More details on labels can be found [in our documentation](https://vitabel.readthedocs.io/en/latest/autoapi/vitabel/timeseries/index.html#vitabel.timeseries.Label).\n",
"\n",
"
\n",
"\n",
"We provide a setup for the interactive plot.\n",
"\n",
"The `channels` to be plottted are defined as lists in a list (`[[],[]]`). Each of the inner lists define a new subplot.\n",
"The `labels` to be plotted on top are defined by another lists in a list.\n",
"\n",
"Subplots below the already defined ones are defined by `channel_overviews`. These subplots serve a special purpose by displaying the entire recording interval and highlighting the depicted subsegement in the upper subplots.\n",
"\n",
"Above the plot a menu is given to `Annotate`, `Align Timelines`, and deffines `Settings` of the plot.\n",
"\n",
"Try to annotate the ROSCs by clicking with the right mouse button where you assume a ROSC.\n",
"Also try to toggle the checkboxes in various combinations in oder to add different data to the label.\n",
"\n",
"
\n",
"\n",
"The data that has been added to the *ROSC* label can be retrieved by calling the `get_data` method. The result is returned in a `DataSlice` object.\n",
"\n",
"