-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_OCT.py
77 lines (68 loc) · 2.58 KB
/
verify_OCT.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import pandas as pd
import numpy as np
import math
import optparse
## Set Options Parser
parser = optparse.OptionParser()
parser.add_option('-i', '--input', action="store", dest="ipath", default="./OCTess.xlsx", help="Path to raw OCTess output.")
parser.add_option('-o', '--output', action="store", dest="opath", default="./OCTess.xlsx", help="File path to save verified OCTess output file (default settings automatically override raw file)")
options, args = parser.parse_args()
INPUT_FILE = str(options.ipath)
OUTPUT_FILE = str(options.opath)
def flag_numeric(val, pmean, thresh):
try:
val = float(val)
except:
color = '#FFCCCB'
return 'background-color: {}'.format(color)
if (math.isnan(val)):
color = 'yellow'
elif ((val > (pmean+thresh)) | (val < (pmean-thresh))):
color = 'yellow'
else:
return False
return 'background-color: {}'.format(color)
def flag_gender(val):
if val.lower() not in {'male', 'female'}:
color = '#FFCCCB'
else:
return False
return 'background-color: {}'.format(color)
def flag_eye(val):
if val.lower() not in {'od', 'os'}:
color = '#FFCCCB'
else:
return False
return 'background-color: {}'.format(color)
def flag_signal(val):
try:
val = int(val)
except:
color = '#FFCCCB'
return 'background-color: {}'.format(color)
if ((val > 10) | (val < 0)):
color = '#FFCCCB'
else:
return False
return 'background-color: {}'.format(color)
if __name__ == '__main__':
print('Verifying Data...')
df = pd.read_excel(INPUT_FILE, dtype='str')
styler = df.copy().style
styler.applymap(flag_gender, subset='Gender')
styler.applymap(flag_eye, subset='Eye')
styler.applymap(flag_signal, subset='Signal_Strength')
numeric_params = ['Superior', 'Central_Superior', 'Nasal', 'Central_Nasal', 'Inferior',
'Central_Inferior', 'Temporal', 'Central_Temporal', 'Central', 'Volume', 'Avg_Thickness']
for param in numeric_params:
df[param] = pd.to_numeric(df[param], errors='coerce')
# Calculate the mean of the parameter of interest
param_mean = df[param].mean()
# Calculate the standard deviation of the parameter of interest
param_std = df[param].std()
# Calculate the threshold for values that are greater than three standard deviations
threshold = 3 * param_std
styler.applymap(flag_numeric, pmean=param_mean, thresh=threshold, subset=param)
styler.to_excel(OUTPUT_FILE, index=False)
print('Data Verification Complete.')