-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_data_collapse.py
248 lines (223 loc) · 7.43 KB
/
plot_data_collapse.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 11 13:55:21 2019
@author: Artur Donaldson
"""
from setup import im_directory,bp_directory,areas_directory
import numpy as np
import matplotlib.pyplot as plt
from voron_eye import plot_linear_distribution
from generalized_analysis import generalized_ad_test,generalized_ks_test
from scipy.stats import gamma,lognorm
from scipy.stats import ks_2samp
from estimate_area_errors import estimate_errs,plot_ci,plot_errorbar
# =============================================================================
# FORMATTING PARAMETERS
# =============================================================================
plt.rcParams['font.size'] = 14
formatting={"marker":"+","s":30} #Formatting for scatter plot for retina
xmin = 0
xmax = 5
ymin = 0
ymax = 1
n_formatting = dict(formatting)
n_formatting["color"]="#411900"
dr_formatting = dict(formatting)
dr_formatting["color"]="#ff0000"
pdr_formatting = dict(formatting)
pdr_formatting["marker"]="o"
h_formatting = dict(formatting)
h_formatting["color"]="#00ff00"
g_formatting = dict(formatting)
g_formatting["color"]="#0000ff"
# =============================================================================
# PARAMETERS
# =============================================================================
database = "HRF"
phi_N = 500
lat_N = 500
#Calculated parameters from author's thesis
c_params = {
"Healthy":[3.504,0,0.285,0.012,0.85], #H
"Glaucomatous":[3.321,0,0.301,0.018,0.23], #G
"NPDR":[3.235,0,0.309,0.024,0.26], #NPDR
"PDR":[1.363,0,0.734,0.036,0.36] #PDR
}
# =============================================================================
# LOAD DATA
# =============================================================================
if database == "HRF":
HRF = True
DRIVE = False
elif database=="DRIVE":
HRF = False
DRIVE = True
if HRF:
R_im = int(.5*3190) #Radius of region of retina visible on image
im_directory = im_directory+"HRF\\"
dr_names =["{:02d}_dr".format(n) for n in range(1,16)]
npdr_names =["{:02d}_dr".format(n) for n in [1,2,3,4,5,7,8,9,10,11,13,15]]
pdr_names = ["{:02d}_dr".format(n) for n in [6,12,14]]
g_names = ["{:02d}_g".format(n) for n in range(1,16)]
h_names = ["{:02d}_h".format(n) for n in range(1,16)]
names = h_names+dr_names+g_names
if DRIVE:
im_directory = im_directory+"DRIVE\\"
dr_names = [3,8,14,17,25,26,32] #Subjects with DR
#according to researchers https://drive.grand-challenge.org/
names = list(range(1,41))
h_names = list(names)
for n in dr_names:
h_names.remove(n)
#Directory containing branchpoint data and general info
areas_directory = areas_directory+database+"\\"
fa_sep = dict()
ca_sep = dict()
for name in names:
print(name)
if HRF:
f = open(areas_directory+"curved_core_cell_areas_"+name+"_phiN={}latN={}.txt".format(phi_N,lat_N),"r")
if DRIVE:
f = open(areas_directory+"curved_core_cell_areas_{}_phiN={}latN={}.txt".format(name,phi_N,lat_N),"r")
areas = list()
i = 0
for line in f.readlines():
if i > 1:
areas = [float(x) for x in line.rsplit(",")[0:-1]]
i+=1
areas = np.array(areas)
#Remove zero areas
nonzero_areas = areas[areas.nonzero()]
#Normalize
ca_sep[name]=nonzero_areas/nonzero_areas.mean()
if HRF:
f = open(areas_directory+"flat_core_cell_areas_{}.txt".format(name),"r")
if DRIVE:
f = open(areas_directory+"flat_core_cell_areas_{}.txt".format(name),"r")
areas = list()
i = 0
for line in f.readlines():
if i > 1:
areas = np.array([float(x) for x in line.rstrip().rsplit(",")[0:-1]])
i+=1
fa_sep[name]=areas/areas.mean()
#%%
# =============================================================================
# JOIN TOGETHER DISTRIBUTIONS
# =============================================================================
fa_h=list()
fa_dr=list()
fa_npdr=list()
fa_pdr=list()
fa_g=list()
ca_h=list()
ca_dr=list()
ca_npdr=list()
ca_pdr=list()
ca_g=list()
for n in h_names:
fa_h.extend(fa_sep[n])
ca_h.extend(ca_sep[n])
for n in dr_names:
fa_dr.extend(fa_sep[n])
ca_dr.extend(ca_sep[n])
if not DRIVE:
for n in npdr_names:
fa_npdr.extend(fa_sep[n])
ca_npdr.extend(ca_sep[n])
for n in pdr_names:
fa_pdr.extend(fa_sep[n])
ca_pdr.extend(ca_sep[n])
for n in g_names:
fa_g.extend(fa_sep[n])
ca_g.extend(ca_sep[n])
#%%
# =============================================================================
# PLOT
# =============================================================================
plt.close("all")
x = np.linspace(xmin,xmax,1000)
fig=plt.figure()
ax=plt.subplot(111)
for condition in ["NPDR","PDR"]:#,"Glaucomatous"]:
marker="+"
if condition=="Healthy":
indices = h_names
fmt="g-"
elif condition=="DR":
indices = dr_names
fmt="r--"
elif condition=="NPDR":
indices = npdr_names
fmt="m-"
marker="P"
elif condition=="PDR":
indices = pdr_names
fmt="r-"
marker="o"
elif condition=="Glaucomatous":
indices = g_names
fmt="b-"
else:
print("DONT KNOW THIS CONDITION")
params = c_params[condition][:3]
for name in indices:
print(name)
if len(ca_sep[name])>20:
fig,ax = plot_linear_distribution(ca_sep[name],name="{}".format(name),n="auto",density=True,fig=fig,ax=ax,formatting={'marker':marker})
else:
print("Can't plot",name,"has",len(ca_sep[name]))
#plot fit
fit=gamma.pdf(x,*params)
ax.plot(x,fit,fmt,label=condition)
ax.legend(ncol=2)
# =============================================================================
# FORMATTING
# =============================================================================
fig.suptitle("{} {} Core Cell Areas".format(database,condition))
ax.set_ylabel(r'Probability density')
ax.set_xlabel(r"$ A/\langle A \rangle$")
ax.set_xlim(xmin,xmax)
ax.set_ylim(ymin,ymax)
for condition in ["Healthy","Glaucomatous"]:
marker="+"
fig=plt.figure()
ax=fig.add_subplot(111)
if condition=="Healthy":
indices = h_names
fmt="g-"
elif condition=="DR":
indices = dr_names
fmt="r--"
elif condition=="NPDR":
indices = npdr_names
fmt="m-"
marker="P"
elif condition=="PDR":
indices = pdr_names
fmt="r-"
marker="o"
elif condition=="Glaucomatous":
indices = g_names
fmt="b-"
else:
print("DONT KNOW THIS CONDITION")
params = c_params[condition][:3]
for name in indices:
print(name)
if len(ca_sep[name])>20:
fig,ax = plot_linear_distribution(ca_sep[name],name="{}".format(name),n="auto",density=True,fig=fig,ax=ax,formatting={'marker':marker})
else:
print("Can't plot",name,"has",len(ca_sep[name]))
#plot fit
fit=gamma.pdf(x,*params)
ax.plot(x,fit,fmt,label=condition)
ax.legend(ncol=2)
# =============================================================================
# FORMATTING
# =============================================================================
fig.suptitle("{} {} Core Cell Areas".format(database,condition))
ax.set_ylabel(r'Probability density')
ax.set_xlabel(r"$ A/\langle A \rangle$")
ax.set_xlim(xmin,xmax)
ax.set_ylim(ymin,ymax)