-
Notifications
You must be signed in to change notification settings - Fork 0
/
230701_addActiveReelFrames.py
41 lines (36 loc) · 1.58 KB
/
230701_addActiveReelFrames.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pandas as pd
import numpy as np
from tqdm import tqdm
'''
def findFirstNonZeroIndex(thisReel):
for eachIndex in range(len(thisReel)):
if thisReel[eachIndex] != 0:
return(eachIndex)
return 380
dataDF = pd.read_csv('Data/Fe_def_outcome_cleanedAndStratified_YN.csv', index_col='mrn')
listOfMRNs = dataDF.index.to_list()
for eachMRN in tqdm(listOfMRNs):
if dataDF.loc[eachMRN].loc['blacklist'] == False:
thisReelPath = 'Data/lab_data_patientReels/' + str(eachMRN) + '.npy'
thisReel = np.load(thisReelPath)
thisReel = np.sum(thisReel, axis=0)
#startNonZero = str(findFirstNonZeroIndex(thisReel))
dataDF.at[eachMRN,'startNonZero'] = findFirstNonZeroIndex(thisReel)
if dataDF.loc[eachMRN].loc['IDA'] == True:
if (dataDF.loc[eachMRN].loc['reelFrame']-24-dataDF.loc[eachMRN].loc['startNonZero'])>0:
dataDF.at[eachMRN, 'blacklist2'] = 'False'
else:
dataDF.at[eachMRN, 'blacklist2'] = 'notEnoughHistoricLabs'
else:
if (338-dataDF.loc[eachMRN].loc['startNonZero'])>0:
dataDF.at[eachMRN, 'blacklist2'] = 'False'
else:
dataDF.at[eachMRN, 'blacklist2'] = 'notEnoughHistoricLabs'
else:
dataDF.at[eachMRN, 'blacklist2'] = 'noLabsRecorded'
dataDF.to_csv('Data/Fe_def_outcome_cleanedAndStratified_YN_230701.csv')
'''
dataDF = pd.read_csv('Data/Fe_def_outcome_cleanedAndStratified_YN_230701.csv', index_col='mrn')
dataDF = dataDF[dataDF['blacklist2']=='False']
dataDF = dataDF[dataDF['IDA']==False]
print(len(dataDF))