In [1]:
from ROPini import *
#Takes a little bit, wait a while.
In [55]:
Hour1, Minute1, Hour2, Minute2, Hour3,
Minute3 = [int(x) for x in raw_input("Enter times for eye drops here: ").split()]
#Syntax should be "HH MM HH MM HH MM" First time, second time, third time all in one line.
#No commas or colons.
In [37]:
W1 = datetime(Year, Month, Day, Hour1, Minute1)
W2 = datetime(Year, Month, Day, Hour2, Minute2)
W3 = datetime(Year, Month, Day, Hour3, Minute3)
In [48]:
print "First Eye Drop Time:\t" + str(Hour1) + ":" +str(Minute1)
print "Second Eye Drop Time:\t" + str(Hour2) + ":" +str(Minute2)
print "Third Eye Drop Time:\t" + str(Hour3) + ":" +str(Minute3)
In [49]:
avg0NIRS = df.StO2[Y:W1].mean()
avg0PI = df.PI[Y:W1].mean()
avg0O2 = df.SpO2[Y:W1].mean()
avg0PR = df.PR[Y:W1].mean()
print 'Baseline Averages\n', 'NIRS :\t', avg0NIRS, '\nPI :\t',avg0PI, '\nSpO2 :\t',avg0O2,'\nPR :\t',avg0PR,
#df.std() for standard deviation
In [50]:
def perdeltadrop1(start, end, delta):
rdrop1 = []
curr = start
while curr < end:
rdrop1.append(curr)
curr += delta
return rdrop1
dfdrop1NI = df.StO2[W1:W1+timedelta(minutes=5)]
dfdrop1PI = df.PI[W1:W1+timedelta(minutes=5)]
dfdrop1O2 = df.SpO2[W1:W1+timedelta(minutes=5)]
dfdrop1PR = df.PR[W1:W1+timedelta(minutes=5)]
windrop1 = timedelta(seconds=10)
rdrop1 = perdeltadrop1(W1, W1+timedelta(minutes=5), windrop1)
avgdrop1NI = Series(index = rdrop1, name = 'StO2 1st ED')
avgdrop1PI = Series(index = rdrop1, name = 'PI 1st ED')
avgdrop1O2 = Series(index = rdrop1, name = 'SpO2 1st ED')
avgdrop1PR = Series(index = rdrop1, name = 'PR 1st ED')
for i in rdrop1:
avgdrop1NI[i] = dfdrop1NI[i:(i+windrop1)].mean()
avgdrop1PI[i] = dfdrop1PI[i:(i+windrop1)].mean()
avgdrop1O2[i] = dfdrop1O2[i:(i+windrop1)].mean()
avgdrop1PR[i] = dfdrop1PR[i:(i+windrop1)].mean()
resultdrops1 = concat([avgdrop1NI, avgdrop1PI, avgdrop1O2, avgdrop1PR], axis=1, join='inner')
print resultdrops1
In [51]:
def perdeltadrop2(start, end, delta):
rdrop2 = []
curr = start
while curr < end:
rdrop2.append(curr)
curr += delta
return rdrop2
dfdrop2NI = df.StO2[W2:W2+timedelta(minutes=5)]
dfdrop2PI = df.PI[W2:W2+timedelta(minutes=5)]
dfdrop2O2 = df.SpO2[W2:W2+timedelta(minutes=5)]
dfdrop2PR = df.PR[W2:W2+timedelta(minutes=5)]
windrop2 = timedelta(seconds=10)
rdrop2 = perdeltadrop2(W2, W2+timedelta(minutes=5), windrop2)
avgdrop2NI = Series(index = rdrop2, name = 'StO2 2nd ED')
avgdrop2PI = Series(index = rdrop2, name = 'PI 2nd ED')
avgdrop2O2 = Series(index = rdrop2, name = 'SpO2 2nd ED')
avgdrop2PR = Series(index = rdrop2, name = 'PR 2nd ED')
for i in rdrop2:
avgdrop2NI[i] = dfdrop2NI[i:(i+windrop2)].mean()
avgdrop2PI[i] = dfdrop2PI[i:(i+windrop2)].mean()
avgdrop2O2[i] = dfdrop2O2[i:(i+windrop2)].mean()
avgdrop2PR[i] = dfdrop2PR[i:(i+windrop2)].mean()
resultdrops2 = concat([avgdrop2NI, avgdrop2PI, avgdrop2O2, avgdrop2PR], axis=1, join='inner')
print resultdrops2
In [52]:
def perdeltadrop3(start, end, delta):
rdrop3 = []
curr = start
while curr < end:
rdrop3.append(curr)
curr += delta
return rdrop3
dfdrop3NI = df.StO2[W3:W3+timedelta(minutes=5)]
dfdrop3PI = df.PI[W3:W3+timedelta(minutes=5)]
dfdrop3O2 = df.SpO2[W3:W3+timedelta(minutes=5)]
dfdrop3PR = df.PR[W3:W3+timedelta(minutes=5)]
windrop3 = timedelta(seconds=10)
rdrop3 = perdeltadrop3(W3, W3+timedelta(minutes=5), windrop3)
avgdrop3NI = Series(index = rdrop3, name = 'StO2 3rd ED')
avgdrop3PI = Series(index = rdrop3, name = 'PI 3rd ED')
avgdrop3O2 = Series(index = rdrop3, name = 'SpO2 3rd ED')
avgdrop3PR = Series(index = rdrop3, name = 'PR 3rd ED')
for i in rdrop3:
avgdrop3NI[i] = dfdrop3NI[i:(i+windrop3)].mean()
avgdrop3PI[i] = dfdrop3PI[i:(i+windrop3)].mean()
avgdrop3O2[i] = dfdrop3O2[i:(i+windrop3)].mean()
avgdrop3PR[i] = dfdrop3PR[i:(i+windrop3)].mean()
resultdrops3 = concat([avgdrop3NI, avgdrop3PI, avgdrop3O2, avgdrop3PR], axis=1, join='inner')
print resultdrops3
In [53]:
import csv
import os
#we change the directory that python looks at to the new place.
os.chdir("/Users/John/Dropbox/LLU/ROP/Python Output Files")
#csv properties
class excel_tab(csv.excel):
delimiter = '\t'
csv.register_dialect("excel_tab", excel_tab)
#CSV file
with open('ROP'+BabyNumber+'EyeDrops.csv', 'w') as f:
writer = csv.writer(f, dialect=excel_tab)
writer.writerow([avg0NIRS, ',NIRS Start']) #NIRS data
for i in rdrop1:
writer.writerow([avgdrop1NI[i]])
for i in rdrop2:
writer.writerow([avgdrop2NI[i]])
for i in rdrop3:
writer.writerow([avgdrop3NI[i]])
writer.writerow([avg0PI, ',PI Start']) #PI data
for i in rdrop1:
writer.writerow([avgdrop1PI[i]])
for i in rdrop2:
writer.writerow([avgdrop2PI[i]])
for i in rdrop3:
writer.writerow([avgdrop3PI[i]])
writer.writerow([avg0O2, ',SpO2 Start']) #SpO2 data
for i in rdrop1:
writer.writerow([avgdrop1O2[i]])
for i in rdrop2:
writer.writerow([avgdrop2O2[i]])
for i in rdrop3:
writer.writerow([avgdrop3O2[i]])
writer.writerow([avg0PR, ',PR Start']) #PR Data
for i in rdrop1:
writer.writerow([avgdrop1PR[i]])
for i in rdrop2:
writer.writerow([avgdrop2PR[i]])
for i in rdrop3:
writer.writerow([avgdrop3PR[i]])
In [ ]: