Created
September 13, 2019 09:27
-
-
Save DeastinY/36d6f7d29e7144126cdeda60fc69659c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculate_horowitz(df): | |
"""calculates the Horowitz index, defined as PaO2/FIO2. | |
300-450: all fine (depending on age) | |
200-300: moderately severe lung damage | |
<200: severe lung damage""" | |
paO2 = df["paO2"] | |
if len(paO2) == 0: | |
return [np.nan] * len(df) | |
fiO2 = df["FiO2"] | |
if len(fiO2) == 0: | |
return [np.nan] * len(df) | |
# Fi02s have to be between 21-100%. Everything else is unphysiological (maybe 02 flow in litres) | |
horowitz = [] | |
last_fiO2 = None | |
last_paO2 = None | |
for i in paO2.index: | |
if not np.isnan(fiO2.loc[i]): | |
last_fiO2 = i | |
if not np.isnan(paO2.loc[i]): | |
last_paO2 = i | |
if last_paO2 is not None and last_fiO2 is not None: | |
horowitz.append(paO2.loc[last_paO2]*100/fiO2.loc[last_fiO2]) | |
else: | |
horowitz.append(np.NaN) | |
if len(horowitz) <= 0: | |
raise Exception() | |
horowitz = horowitz if len(horowitz)>0 else [pd.NaN]*df.shape[0] | |
return horowitz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment