-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fig4.py
219 lines (172 loc) · 9.52 KB
/
Fig4.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 09:19:29 2020
@author: grotheer
"""
#set up the necessary dependencies
import numpy as np
import seaborn as sns
#import afqbrowser as afq
#from afqbrowser import browser
import pandas as pd
import matplotlib.pyplot as plt
from scipy.io import loadmat
from matplotlib.lines import Line2D
import pylab as plot
from numpy.matlib import repmat
from itertools import repeat
#load the data needed for this figure
R1Inter=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/interMeanR1MRI0AcrForPy.mat')
R1InterSe=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/interSeR1MRI0AcrForPy.mat')
R1Slope=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/slopeMeanR1AcrForPy.mat')
R1SlopeSe=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/slopeSeR1AcrForPy.mat')
Tracts=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/tractsAcrForPy.mat')
Nodes=loadmat('/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Data/nodesAcrForPy.mat')
df=pd.DataFrame(R1Inter['meanMRI0R1'])
df.columns=['R1Inter']
df.insert(1,"R1InterSe",R1InterSe['seMRI0R1'])
df.insert(2,"R1Slope",R1Slope['slopeMeanR1'])
df.insert(3,"R1SlopeSe",R1SlopeSe['slopeSeR1'])
df.insert(4,"tractIdx",Tracts['tracts'])
df.insert(5,"Nodes",Nodes['nodes'])
#set up the bundle names and colors
tracts=['ATR', 'ATR', 'CS', 'CS', 'CC', 'CC',
'CH', 'CH', 'FcMa', 'FcMi','IFOF', 'IFOF',
'ILF', 'ILF', 'SLF', 'SLF','UCI', 'UCI',
'AF', 'AF', 'MLF','MLF', 'VOF', 'VOF', 'pAF', 'pAF']
tractPos = {'CS': (0, 0), 'ATR': (0, 1),'VOF': (0, 6), 'pAF': (0, 7),
'SLF': (1, 0), 'CC': (1, 1),'ILF': (1, 2), 'MLF': (1, 3),'IFOF': (1, 4),
'AF': (1, 6), 'UCI': (1, 7),'FcMa': (0,3),'FcMi':(0,4)}
figsize=(22,7)
fig, axes=plt.subplots(2,8,frameon=False,figsize=figsize)
fig.tight_layout
plt.subplots_adjust(left=0.09,bottom=0.1,right=0.90,top=0.95,wspace=0.3,hspace=1)
color_list_all=sns.color_palette("tab20")+sns.color_palette("tab20b")
color_list_chosen=color_list_all[0:6]
color_list_chosen.extend(color_list_all[33:34])
color_list_chosen.extend(color_list_all[35:36])
color_list_chosen.extend(color_list_all[6:14])
color_list_chosen.extend(color_list_all[16:20])
color_list_chosen.extend(color_list_all[24:25])
color_list_chosen.extend(color_list_all[27:28])
color_list_chosen.extend(color_list_all[20:21])
color_list_chosen.extend(color_list_all[23:24])
color_list_chosen.extend(color_list_all[36:37])
color_list_chosen.extend(color_list_all[39:40])
#sns.palplot(color_list_chosen)
#sns.palplot(color_list_chosen)
x_labels=['Node (pos -> ant)', 'Node (pos -> ant)',
'Node (inf -> sup)','Node (inf -> sup)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (lh -> rh)','Node (lh -> rh)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (pos -> ant)', 'Node (pos -> ant)',
'Node (inf -> sup)','Node (inf -> sup)',
'Node (inf -> sup)','Node (inf -> sup)']
params={'legend.fontsize':12,'legend.handlelength':1,'legend.labelspacing':0.25, 'legend.columnspacing':0.25, 'legend.handletextpad':0}
plot.rcParams.update(params)
type=['mean']
hems=['LH']
#create the actual figure
for hem in hems:
if hem=='LH':
foi=[0,2,4,8,9,10,12,14,16,18,20,22,24]
else:
foi=[1,3,5,11,13,15,17,19,21,23,25]
for t in type:
for ct in foi:
if ct==8:
col=ct-1
elif ct==9:
col=ct-4
else:
col=ct
col=col-1
colors=sns.color_palette("tab20")
ax=axes[tractPos[tracts[ct]]]
ax.clear()
ax2=ax.twinx()
ax.set_ylim([0.55,0.6])
ax2.set_ylim([0.0005,0.001])
ax.set_aspect(400)
if t=="mean":
currentTract=df.query("tractIdx == @ct")
g=sns.lineplot(x="Nodes", y="R1Inter",
data=currentTract,hue="tractIdx",
palette=[color_list_chosen[col+1]],
legend=False,ax=ax,style=True,alpha=1,linewidth=3)
g=ax.fill_between(currentTract['Nodes'],currentTract['R1Inter']-currentTract['R1InterSe'],currentTract['R1Inter']+currentTract['R1InterSe'],color=[color_list_chosen[col+2]],alpha=0.5)
g=sns.lineplot(x="Nodes", y="R1Slope",
data=currentTract,hue="tractIdx",
palette=[color_list_chosen[col+1]],
legend=False,ax=ax2,style=True,alpha=1,dashes=[(2,2)],linewidth=3)
g=ax2.fill_between(currentTract['Nodes'],currentTract['R1Slope']-currentTract['R1SlopeSe'],currentTract['R1Slope']+currentTract['R1SlopeSe'],color=[color_list_chosen[col+2]],alpha=0.5)
if ct!=8 and ct!=9:
tr=ct+1
currentTract=df.query("tractIdx == @tr")
g=sns.lineplot(x="Nodes", y="R1Inter",
data=currentTract,hue="tractIdx",
palette=[color_list_chosen[col+1]],
legend=False,ax=ax,style=True,alpha=1,linewidth=3)
g=ax.fill_between(currentTract['Nodes'],currentTract['R1Inter']-currentTract['R1InterSe'],currentTract['R1Inter']+currentTract['R1InterSe'],color=[color_list_chosen[col+2]],alpha=0.5)
g=sns.lineplot(x="Nodes", y="R1Inter",
data=currentTract,hue="tractIdx",
palette=[color_list_chosen[col+1]],
legend=False,ax=ax,style=True,alpha=1,linewidth=3)
g=ax.fill_between(currentTract['Nodes'],currentTract['R1Inter']-currentTract['R1InterSe'],currentTract['R1Inter']+currentTract['R1InterSe'],color=[color_list_chosen[col+2]],alpha=0.5)
g=sns.lineplot(x="Nodes", y="R1Slope",
data=currentTract,hue="tractIdx",
palette=[color_list_chosen[col+1]],
legend=False,ax=ax2,style=True,alpha=1,dashes=[(2,2)],linewidth=3)
g=ax2.fill_between(currentTract['Nodes'],currentTract['R1Slope']-currentTract['R1SlopeSe'],currentTract['R1Slope']+currentTract['R1SlopeSe'],color=[color_list_chosen[col+2]],alpha=0.5)
ax.set_title(tracts[ct],fontsize=25)
ax.set_xlabel(x_labels[ct],fontsize=18)
axes[0, 5].axis("off")
axes[0, 2].axis("off")
axes[1, 5].axis("off")
if ct == 2 or ct==14 or ct==18 or ct==8 or ct==22:
#ax.set_ylabel('R1 in newborns [1/s]',fontsize=18)
ax.set_ylabel(r'R1 in newborns [s$\mathregular{^{-1}}$]',fontsize=18)
ax.set_yticks([0.4,0.5, 0.6])
ax.set_yticklabels([0.4,0.5, 0.6],Fontsize=16)
else:
ax.set_ylabel('',fontsize=14)
ax.set_yticks([0.4,0.5, 0.6])
ax.set_yticklabels([])
ax.spines['left'].set_visible(False)
ax2.spines['left'].set_visible(False)
if ct==10 or ct==0 or ct==9 or ct==24 or ct==16:
#ax2.set_ylabel('R1 Slope [1/s/days]',fontsize=18)
ax2.set_ylabel(r'R1 slope [s$\mathregular{^{-1}}$/days]',fontsize=18)
ax2.set_yticks([0.00001,0.001,0.002])
ax2.set_yticklabels(['', 0.001, 0.002],Fontsize=16)
else:
ax2.set_ylabel('',fontsize=14)
ax2.set_yticks([0.00001,0.001,0.002])
ax2.set_yticklabels([])
ax.spines['right'].set_visible(False)
ax2.spines['right'].set_visible(False)
#plt.locator_params(axis='both', nbins=0.5)
if hem=='RH':
axes[0, 5].axis("off")
axes[0, 2].axis("off")
axes[1, 5].axis("off")
ax.set_xticks([1,50,100])
ax.set_xticklabels([1,50,100],Fontsize=18)
ax.spines['top'].set_visible(True)
ax2.spines['top'].set_visible(True)
ax.tick_params(axis='y',which='both',left=False,right=False)
ax2.tick_params(axis='y',which='both',left=False,right=False)
ax.tick_params(axis='x',which='both',bottom=False,top=False)
ax2.tick_params(axis='x',which='both',bottom=False,top=False)
line1=Line2D([],[],color=color_list_chosen[col+1],linestyle='-')
line2=Line2D([],[],color=color_list_chosen[col+1],linestyle='dashed')
ax.legend([line1,line2],['0m','slope'],loc="upper left",borderpad=0.01,bbox_to_anchor=(-0.05,0.2),ncol=2,framealpha=0.75,frameon=True,edgecolor=[1,1,1],prop={'size':16},fancybox=True,handlelength=1.5)
#save the figure
fig.savefig("/biac2/kgs/projects/babybrains/mri/code/babyDWI/babyWmDev/Output/Fig4.png",format='png',dpi=300)