Eye Drops Analysis for NIRS and Pulse Ox

Writing a new notebook to analyze eye drops only

Initialize and Select ROP Subject Number


In [1]:
from ROPini import *
#Takes a little bit, wait a while.


Baby's ROP Number? 007

Data Collection Start:	2015-06-30 19:02:48
Data Collection Ended:	2015-07-01 13:51:19


ROP Exam Date: 7 1, 2015

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.


  File "<ipython-input-55-8ff6cb557df2>", line 2
    = [int(x) for x in raw_input("Enter times for eye drops here: ").split()]
    ^
SyntaxError: invalid syntax

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)


First Eye Drop Time:	8:30
Second Eye Drop Time:	8:37
Third Eye Drop Time:	8:42

Baseline Average Calculation


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


Baseline Averages
NIRS :	78.0445502693 
PI :	0.903400821741 
SpO2 :	99.8806140134 
PR :	168.554020598

First Eye Drop Avg Every 10 Sec For 5 Minutes


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


                     StO2 1st ED  PI 1st ED  SpO2 1st ED  PR 1st ED
2015-07-01 08:30:00          NaN       0.86        100.0      148.2
2015-07-01 08:30:10          NaN       0.88        100.0      150.6
2015-07-01 08:30:20          NaN       0.80        100.0      146.8
2015-07-01 08:30:30          NaN       0.64        100.0      149.4
2015-07-01 08:30:40          NaN       0.36        100.0      161.8
2015-07-01 08:30:50          NaN       0.44        100.0      166.6
2015-07-01 08:31:00          NaN       0.40         99.6      171.6
2015-07-01 08:31:10          NaN       2.28         99.0      171.2
2015-07-01 08:31:20          NaN       0.74         99.6      163.8
2015-07-01 08:31:30          NaN       0.70        100.0      153.0
2015-07-01 08:31:40          NaN       0.62        100.0      151.2
2015-07-01 08:31:50          NaN       0.64         99.8      155.4
2015-07-01 08:32:00          NaN       0.72        100.0      155.2
2015-07-01 08:32:10          NaN       0.82        100.0      153.0
2015-07-01 08:32:20          NaN       0.92         99.6      151.0
2015-07-01 08:32:30    74.000000       0.92        100.0      152.4
2015-07-01 08:32:40    74.333333       0.94         99.8      156.0
2015-07-01 08:32:50    74.166667       0.86        100.0      153.2
2015-07-01 08:33:00    73.666667       0.80        100.0      155.2
2015-07-01 08:33:10    74.000000       0.80        100.0      154.4
2015-07-01 08:33:20    78.500000       1.44        100.0      156.2
2015-07-01 08:33:30    79.000000       0.44        100.0      163.6
2015-07-01 08:33:40    79.333333       0.80        100.0      159.6
2015-07-01 08:33:50    81.166667       0.82         99.2      154.6
2015-07-01 08:34:00    81.333333       0.80         99.4      155.4
2015-07-01 08:34:10    82.500000       0.86        100.0      154.2
2015-07-01 08:34:20    83.333333       0.82        100.0      151.8
2015-07-01 08:34:30    84.000000       0.76        100.0      152.0
2015-07-01 08:34:40    84.666667       0.74        100.0      150.6
2015-07-01 08:34:50    85.000000       0.76         99.8      149.2

Second Eye Drop Avg Every 10 Sec For 5 Minutes


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


                     StO2 2nd ED  PI 2nd ED  SpO2 2nd ED  PR 2nd ED
2015-07-01 08:37:00    86.000000        NaN          NaN        NaN
2015-07-01 08:37:10    85.833333        NaN          NaN        NaN
2015-07-01 08:37:20    82.166667        NaN          NaN        NaN
2015-07-01 08:37:30    79.000000        NaN          NaN        NaN
2015-07-01 08:37:40    79.166667        NaN          NaN        NaN
2015-07-01 08:37:50    80.000000       0.64        100.0      159.8
2015-07-01 08:38:00    80.000000       0.60        100.0      154.8
2015-07-01 08:38:10    80.000000       0.62        100.0      150.0
2015-07-01 08:38:20    80.000000       0.68        100.0      147.2
2015-07-01 08:38:30    80.000000       0.64        100.0      151.6
2015-07-01 08:38:40    80.333333       0.74        100.0      147.8
2015-07-01 08:38:50    80.000000       0.72        100.0      155.8
2015-07-01 08:39:00    80.000000       1.02        100.0      162.8
2015-07-01 08:39:10    80.666667       0.58        100.0      166.4
2015-07-01 08:39:20    79.500000       1.34        100.0      165.0
2015-07-01 08:39:30    77.333333       1.08        100.0      160.0
2015-07-01 08:39:40    76.500000       0.58         99.8      156.6
2015-07-01 08:39:50    77.333333       0.52         99.8      157.0
2015-07-01 08:40:00    75.666667       0.50        100.0      153.0
2015-07-01 08:40:10    77.500000       0.54        100.0      150.0
2015-07-01 08:40:20    77.666667       0.60        100.0      145.0
2015-07-01 08:40:30    78.166667       0.60        100.0      144.4
2015-07-01 08:40:40    78.500000       0.66        100.0      144.6
2015-07-01 08:40:50    78.000000       0.64        100.0      150.4
2015-07-01 08:41:00    77.500000       0.70        100.0      145.2
2015-07-01 08:41:10    77.166667       0.70        100.0      142.2
2015-07-01 08:41:20    77.500000       0.66        100.0      146.4
2015-07-01 08:41:30    76.333333       0.60        100.0      155.0
2015-07-01 08:41:40    76.000000       0.54        100.0      159.6
2015-07-01 08:41:50    76.000000       0.50        100.0      158.2

Third Eye Drop Avg Every 10 Sec For 5 Minutes


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


                     StO2 3rd ED  PI 3rd ED  SpO2 3rd ED  PR 3rd ED
2015-07-01 08:42:00    76.000000       0.58        100.0      156.8
2015-07-01 08:42:10    75.666667       0.56        100.0      154.4
2015-07-01 08:42:20    76.000000       0.64        100.0      154.0
2015-07-01 08:42:30    76.166667       0.60        100.0      153.2
2015-07-01 08:42:40    77.000000       0.60        100.0      155.0
2015-07-01 08:42:50    77.000000       0.60        100.0      154.4
2015-07-01 08:43:00    76.500000       0.56        100.0      153.2
2015-07-01 08:43:10    76.166667       0.58        100.0      149.2
2015-07-01 08:43:20    77.000000       0.60        100.0      149.8
2015-07-01 08:43:30    77.000000       0.60        100.0      145.2
2015-07-01 08:43:40    77.166667       0.56        100.0      154.8
2015-07-01 08:43:50    77.500000       0.70        100.0      155.8
2015-07-01 08:44:00    77.000000       0.64        100.0      153.8
2015-07-01 08:44:10    77.000000       0.54        100.0      163.6
2015-07-01 08:44:20    77.833333       0.60         99.4      155.6
2015-07-01 08:44:30    78.000000       0.60        100.0      156.2
2015-07-01 08:44:40    78.333333       0.60        100.0      153.4
2015-07-01 08:44:50    78.666667       0.60        100.0      153.8
2015-07-01 08:45:00    78.000000       0.58        100.0      152.2
2015-07-01 08:45:10    77.500000       0.58        100.0      154.6
2015-07-01 08:45:20    77.000000       0.54        100.0      154.4
2015-07-01 08:45:30    77.333333       0.48        100.0      154.0
2015-07-01 08:45:40    77.833333       0.42        100.0      156.4
2015-07-01 08:45:50    77.000000       0.44         99.8      153.0
2015-07-01 08:46:00    77.333333       0.48         99.8      156.6
2015-07-01 08:46:10    76.833333       0.42        100.0      155.4
2015-07-01 08:46:20    76.333333       0.42         99.6      151.6
2015-07-01 08:46:30    76.500000       0.42         99.6      156.2
2015-07-01 08:46:40    76.333333       0.46        100.0      156.2
2015-07-01 08:46:50    77.000000       0.40         99.8      158.6

Export to CSV


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 [ ]: