-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratePlots.py
More file actions
98 lines (78 loc) · 3.62 KB
/
Copy pathGeneratePlots.py
File metadata and controls
98 lines (78 loc) · 3.62 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import csv
import sys
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from PatientRecord import *
import numpy as np
if (len(sys.argv) < 2):
print 'Usage: ', sys.argv[0], '<input CSV file>'
sys.exit(-1)
###################################################################
# Script entry point
###################################################################
rows = []
with open(sys.argv[1], 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in reader:
rows.append(row)
patientRecords = PatientRecordList(rows)
arrayNames = ['Age',
'Weight',
'CrossSectionalArea_TVC',
'CrossSectionalArea_Subglottis',
'CrossSectionalArea_MidTrachea',
'CrossSectionalArea_Ratio',
'CrossSectionalArea_AtlasScore',
'CrossSectionalArea_RatioScore',
'HydraulicDiameter_TVC',
'HydraulicDiameter_Subglottis',
'HydraulicDiameter_MidTrachea',
'HydraulicDiameter_Ratio',
'HydraulicDiameter_AtlasScore',
'HydraulicDiameter_RatioScore']
controlCases = patientRecords.Filter( [('PatientID', '<', 2000)] )
print controlCases.GetNumberOfRecords(), "controls"
controlArrays = controlCases.GetArraysOfMembers(arrayNames);
surgeryCases = patientRecords.Filter( [('SurgeryChosen', '==', 'Y'),
('PatientID', '>=', 2000)] )
print surgeryCases.GetNumberOfRecords(), "surgery cases"
surgeryArrays = surgeryCases.GetArraysOfMembers(arrayNames);
noSurgeryCases = patientRecords.Filter( [('SurgeryChosen', '==', 'N'),
('PatientID', '>=', 2000)] )
print noSurgeryCases.GetNumberOfRecords(), "no surgery cases"
noSurgeryArrays = noSurgeryCases.GetArraysOfMembers(arrayNames);
for abcissaName in ['Age', 'Weight']:
for ordinateName in arrayNames[2:]:
fig = Figure()
canvas = FigureCanvas(fig)
axes = fig.add_subplot(111)
xLabel = abcissaName
xLabel = xLabel.replace('Age', 'Age (months)')
xLabel = xLabel.replace('Weight', 'Weight (kg)')
axes.set_xlabel(xLabel)
yLabel = ordinateName.replace('_', ' - ')
yLabel = yLabel.replace('CrossSectionalArea', 'Cross-Sectional Area')
yLabel = yLabel.replace('HydraulicDiameter', 'Hydraulic Diameter')
yLabel = yLabel.replace('Mid', 'Mid-')
yLabel = yLabel.replace('AtlasScore', 'Atlas Score')
yLabel = yLabel.replace('RatioScore', 'Ratio Score')
axes.set_ylabel(yLabel)
title = '{0} vs. {1}'.format(yLabel, abcissaName)
axes.set_title(title)
axes.hold('on')
axes.plot(controlArrays[abcissaName],
controlArrays[ordinateName], 'gx', label='Control')
axes.plot(surgeryArrays[abcissaName],
surgeryArrays[ordinateName], color='yellow', marker='^',
linestyle='None', label='SGS - Surgery')
axes.plot(noSurgeryArrays[abcissaName],
noSurgeryArrays[ordinateName], 'bo', label='SGS - No Surgery')
#surgeryPatientIDs = surgeryCases.GetArraysOfMembers(['PatientID']);
#for (pid, x, y ) in zip(surgeryPatientIDs['PatientID'],
# surgeryArrays[abcissaName],
# surgeryArrays[ordinateName]):
# axes.annotate(pid, xy=(x, y))
axes.legend(numpoints=1)
axes.hold('off')
fig.savefig('images/{0}-vs-{1}.png'.format(ordinateName, abcissaName))