Skip to content

Commit

Permalink
Merge pull request #49 from AI2MS/45-absolute-creatinine-criterion-do…
Browse files Browse the repository at this point in the history
…es-not-get-calculated-correctly

45 absolute creatinine criterion does not get calculated correctly
  • Loading branch information
aegis301 authored Sep 25, 2023
2 parents 2c4a9e0 + 2fd5662 commit 26251d2
Show file tree
Hide file tree
Showing 21 changed files with 10,119 additions and 4 deletions.
776 changes: 776 additions & 0 deletions generate_tests.ipynb

Large diffs are not rendered by default.

8,584 changes: 8,584 additions & 0 deletions mimic_experiment.ipynb

Large diffs are not rendered by default.

339 changes: 339 additions & 0 deletions prepare_tests_for_physicians.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>stay_id</th>\n",
" <th>charttime</th>\n",
" <th>urineoutput</th>\n",
" <th>urineoutput_stage</th>\n",
" <th>creat</th>\n",
" <th>abs_crea_stage</th>\n",
" <th>rel_crea_stage</th>\n",
" <th>weight</th>\n",
" <th>rrt_status</th>\n",
" <th>rrt_stage</th>\n",
" <th>stage</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30057454.0</td>\n",
" <td>2171-11-07 21:00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>87.2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>NaN</td>\n",
" <td>2171-11-07 22:00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>87.2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>NaN</td>\n",
" <td>2171-11-07 23:00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>87.2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>NaN</td>\n",
" <td>2171-11-08 00:00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>87.2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>NaN</td>\n",
" <td>2171-11-08 01:00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>87.2</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17939</th>\n",
" <td>NaN</td>\n",
" <td>2148-01-08 12:00:00</td>\n",
" <td>100.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17940</th>\n",
" <td>NaN</td>\n",
" <td>2148-01-08 13:00:00</td>\n",
" <td>270.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17941</th>\n",
" <td>NaN</td>\n",
" <td>2148-01-08 14:00:00</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17942</th>\n",
" <td>NaN</td>\n",
" <td>2148-01-08 15:00:00</td>\n",
" <td>125.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17943</th>\n",
" <td>NaN</td>\n",
" <td>2148-01-08 16:00:00</td>\n",
" <td>250.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>120.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>17944 rows × 11 columns</p>\n",
"</div>"
],
"text/plain": [
" stay_id charttime urineoutput urineoutput_stage creat \\\n",
"0 30057454.0 2171-11-07 21:00:00 NaN NaN 2.0 \n",
"1 NaN 2171-11-07 22:00:00 NaN NaN 2.0 \n",
"2 NaN 2171-11-07 23:00:00 NaN NaN 2.0 \n",
"3 NaN 2171-11-08 00:00:00 NaN NaN 2.0 \n",
"4 NaN 2171-11-08 01:00:00 NaN NaN 2.0 \n",
"... ... ... ... ... ... \n",
"17939 NaN 2148-01-08 12:00:00 100.0 NaN NaN \n",
"17940 NaN 2148-01-08 13:00:00 270.0 NaN NaN \n",
"17941 NaN 2148-01-08 14:00:00 120.0 NaN NaN \n",
"17942 NaN 2148-01-08 15:00:00 125.0 NaN NaN \n",
"17943 NaN 2148-01-08 16:00:00 250.0 NaN NaN \n",
"\n",
" abs_crea_stage rel_crea_stage weight rrt_status rrt_stage stage \n",
"0 NaN NaN 87.2 NaN NaN NaN \n",
"1 NaN NaN 87.2 NaN NaN NaN \n",
"2 NaN NaN 87.2 NaN NaN NaN \n",
"3 NaN NaN 87.2 NaN NaN NaN \n",
"4 NaN NaN 87.2 NaN NaN NaN \n",
"... ... ... ... ... ... ... \n",
"17939 NaN NaN 120.0 NaN NaN NaN \n",
"17940 NaN NaN 120.0 NaN NaN NaN \n",
"17941 NaN NaN 120.0 NaN NaN NaN \n",
"17942 NaN NaN 120.0 NaN NaN NaN \n",
"17943 NaN NaN 120.0 NaN NaN NaN \n",
"\n",
"[17944 rows x 11 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.read_excel('tests/experiment/data/test_human_aki.xlsx')\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[37267577.0,\n",
" 39268883.0,\n",
" 38540883.0,\n",
" 34592300.0,\n",
" 35009126.0,\n",
" 32314488.0,\n",
" 34617352.0,\n",
" 39635619.0,\n",
" 32391858.0,\n",
" 32119961.0,\n",
" 38383343.0,\n",
" 35514836.0,\n",
" 30849778.0,\n",
" 33281088.0,\n",
" 35258379.0]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import random\n",
"stay_ids = data.stay_id.unique()\n",
"# select 3 sets of 5 random stays\n",
"random.seed(301)\n",
"random_stay_ids = random.sample(list(stay_ids), 15)\n",
"random_stay_ids"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"([37267577.0, 39268883.0, 38540883.0, 34592300.0, 35009126.0],\n",
" [32314488.0, 34617352.0, 39635619.0, 32391858.0, 32119961.0],\n",
" [38383343.0, 35514836.0, 30849778.0, 33281088.0, 35258379.0])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_1 = random_stay_ids[:5]\n",
"set_2 = random_stay_ids[5:10]\n",
"set_3 = random_stay_ids[10:15]\n",
"set_1, set_2, set_3"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pyakienv",
"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.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions pyAKI/preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
stay_identifier: str = "stay_id",
time_identifier: str = "charttime",
interpolate: bool = True,
threshold: Optional[int] = None,
threshold: Optional[int] = 8,
) -> None:
"""
Initialize a new instance of the UrineOutputPreProcessor class.
Expand Down Expand Up @@ -140,7 +140,7 @@ def __init__(
stay_identifier: str = "stay_id",
time_identifier: str = "charttime",
ffill: bool = True,
threshold: Optional[int] = None,
threshold: Optional[int] = 72,
) -> None:
"""
Initialize a new instance of the CreatininePreProcessor class.
Expand Down
2 changes: 1 addition & 1 deletion pyAKI/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def probe(self, df: pd.DataFrame = None, **kwargs) -> pd.DataFrame:
df = df.copy()
df[self.RESNAME] = 0
df.loc[(df[self._column] - baseline_values) >= 0.3, self.RESNAME] = 1
df.loc[(df[self._column] - baseline_values) >= 4, self.RESNAME] = 3
df.loc[df[self._column] >= 4, self.RESNAME] = 3

df.loc[df[self._column] == 0, self.RESNAME] = None
df[self.RESNAME] = df[self.RESNAME].ffill().fillna(0)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description_file = README.md
long_description_content_type = text/markdown
summary = pyAKI allows calculation of Acute Kidney Injury from urine output and creatinine based on KDIGO criteria.
author = 'Jan Ernsting, Christian Porschen'
author_email = '[email protected], '
author_email = '[email protected], [email protected]'
url = https://github.com/AI2MS/pyAKI
project_urls=
Source Code = https://github.com/AI2MS/pyAKI
Expand Down
20 changes: 20 additions & 0 deletions test_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pyAKI.kdigo
import pandas as pd

if __name__ == "__main__":
# Load the test data
urine_output = pd.read_csv("tests/data/test_machine_urineoutput.csv")
creatinine = pd.read_csv("tests/data/test_machine_creatinine.csv")
crrt = pd.read_csv("tests/data/test_machine_crrt.csv")
patient_data = pd.read_csv("tests/data/test_machine_weights.csv")

ana = pyAKI.kdigo.Analyser(
[
pyAKI.utils.Dataset(pyAKI.utils.DatasetType.URINEOUTPUT, urine_output),
pyAKI.utils.Dataset(pyAKI.utils.DatasetType.CREATININE, creatinine),
pyAKI.utils.Dataset(pyAKI.utils.DatasetType.DEMOGRAPHICS, patient_data),
pyAKI.utils.Dataset(pyAKI.utils.DatasetType.CRRT, crrt),
]
)
ana.process_stays().to_csv("tests/data/test_machine_aki.csv")
ana.process_stays().to_excel("tests/data/test_machine_aki.xlsx")
Loading

0 comments on commit 26251d2

Please sign in to comment.