{
"cells": [
{
"cell_type": "markdown",
"id": "f23a1216-71c4-4158-a77f-ad9bbcb4f30d",
"metadata": {},
"source": [
"# Use Case 3: User interface to research intra-anaesthesisa hypotension\n",
"\n",
"
\n",
"\n",
"This notebook illustrates the usage of the vitabel package 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 **non-waveform data** from an anesthesia chart and add further labels to this data. This notebook in particular demonstrates how `vitabel` can be used outside of resuscitation science, for example to study **intra-operative hypotension** like in this example. In particular, this example illustrates how the interactive plotting functionality can be wrapped and extended which allows building a **user interface to validate** the 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": "5341fa6c-1083-4daa-99a8-fadb30d89b46",
"metadata": {},
"outputs": [],
"source": [
"from vitabel import Vitals, Label\n",
"import numpy as np\n",
"import pandas as pd\n",
"from IPython.display import display, Markdown\n",
"import ipywidgets as widgets\n",
"from matplotlib.collections import PolyCollection\n",
"from datetime import datetime"
]
},
{
"cell_type": "markdown",
"id": "34e111f4-d070-42e9-bbd2-ba9107b13c75",
"metadata": {},
"source": [
"## 1. Loading Data"
]
},
{
"cell_type": "markdown",
"id": "c822de38-334a-4033-88d8-7c1d1358a718",
"metadata": {},
"source": [
"
\n",
"\n",
"A `Vitals` object is initialized and data which was saved previously with vitabel is loaded again.\n",
"\n",
"
\n",
"\n",
"In this project, we're approaching things a little different. Our primary focus is on the mean arterial pressure (MAP) during anaesthesia. To analyze this accurately we need to validate both, the MAP recordings themselves\n",
" and the defined anaesthesia interval.\n",
" \n",
"
\n",
"\n",
"Conceptually `vitabel` devides time-series data into `channels` and `labels`:\n",
" - **channels** contain raw data recorded by a device\n",
" - **labels** provide additional information—either annotated manually or derived from channel data\n",
"\n",
"
\n",
"\n",
"_This distinction can become blurred in cases where the recording device itself generates derived values. For example, if a monitor derives end-tidal COâ‚‚ from a capnography waveform, one could argue whether these values should be considered part of a channel or stored as a label._\n",
"\n",
"
\n",
"\n",
"However in the present use case, to actually remove and add MAP values in an interactive plot we have to **convert** the MAP recordings from the `channel` into a `label`.\n",
"\n",
"
\n",
"\n",
"For the analysis, we are interested in the time span between the _Induction_ and the _End of Anaesthesia_.\n",
"\n",
"We therefore try to extract the time points of interest from the _Events_ channel and generate a **new Label** called _Analsysis_. As we want to manipulate both time points independently from each other, we deliberately use a (normal) `Label` and not an `IntervalLabel`. The time span we are going to analyse will be defined by the extremes of the `time_index` of the label _Analysis_.\n",
"\n",
"
\n",
"\n",
"As in the previous use cases we initialize our plot with `plot_interactive`. We than adapt the figure more extensively by editing the `figure` and its `axes` directly.\n",
"Note that we are plotting the label MAP and on top the channel MAP (where the former is editable via the `Annotate` menu).\n",
"\n",
"
\n",
"\n",
"The `vitabel` package has an integrated function `area_under_threshold` to **quantify hypotension** as area and duration where the signal falls below a specified threshold.\n",
"\n",
"