-
Notifications
You must be signed in to change notification settings - Fork 1
/
stat_viz.py
140 lines (98 loc) · 4.83 KB
/
stat_viz.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
import numpy as np
import h5py
import sys
import os
sys.path.append(os.path.expanduser('/home/raid/bayrak/devel/brainsurfacescripts'))
import plotting
import csv
import re
import matplotlib.pyplot as plt
def get_surface(surface_data, hemisphere, surface_type):
"""
surface_data = hdf5 formatted surface data
hemisphere = 'LH', 'RH', or 'full'
surface_type = 'midthickness', 'inflated', or 'very_inflated'
"""
tmp = h5py.File(surface_data, 'r')
indices = np.array( tmp[hemisphere][surface_type]['indices'] )
vertices = np.array( tmp[hemisphere][surface_type]['vertices'] )
triangles = np.array( tmp[hemisphere][surface_type]['triangles'])
return indices, vertices, triangles
surface_data = '/nobackup/kocher1/bayrak/tmp/' + 'data_surface.h5'
surface_type = 'midthickness'
n_lh, vertices_lh, triangles_lh = get_surface(surface_data, 'LH', surface_type)
n_rh, vertices_rh, triangles_rh = get_surface(surface_data, 'RH', surface_type)
path = '/nobackup/kocher1/bayrak/palm_results_SCPTs_NEW/'
fig_path = '/nobackup/kocher1/bayrak/palm_figures_SCPTs_NEW/'
results_list = []
with open(path + 'results_unique.csv', 'rb') as f:
reader = csv.reader(f);
results_list = list(reader);
fig_number = 1;
for result in results_list:
result = str(result)
name_tmp = result[2:-2]
name_tmp = re.sub('01', '04', name_tmp)
nameL1 = re.sub('c1', 'c1', name_tmp)
nameL2 = re.sub('c1', 'c2', nameL1)
nameR1 = re.sub('LH', 'RH', nameL1)
nameR2 = re.sub('LH', 'RH', nameL2)
fig_name = re.sub("LH_", "", nameL1)
print nameL1
print nameL2
print nameR1
print nameR2
# nameL1 = 'LH_01_dpv_ztstat_cfdrp_c3.csv'
L1 = np.loadtxt(os.path.join(path, nameL1), delimiter = ',')
L2 = np.loadtxt(os.path.join(path, nameL2), delimiter = ',')
R1 = np.loadtxt(os.path.join(path, nameR1), delimiter = ',')
R2 = np.loadtxt(os.path.join(path, nameR2), delimiter = ',')
x = np.ones(len(vertices_lh))
index = np.where(L1[n_lh] < 0.05)
index_neg = np.where(L2[n_lh] < 0.05)
if set(index[0]).intersection(index_neg[0]).__len__() != 0:
print "OVERLAP"
x[n_lh[index]] = L1[n_lh[index]]
x[n_lh[index_neg]] = -1 * L2[n_lh[index_neg]]
print np.shape(index)[1], np.shape(index_neg)[1]
if np.shape(index)[1] != 0 and np.shape(index_neg)[1] != 0:
x[np.where(x==1)] = x[n_lh[index]].max() + 0.001
plotting.plot_surf_stat_map(vertices_lh, triangles_lh, fig_number,
'221', stat_map = x, cmap='jet', azim=180,
threshold=x[n_lh[index]].max(),
figsize=(14, 10))
plotting.plot_surf_stat_map(vertices_lh, triangles_lh, fig_number,
'223', stat_map = x, cmap='jet', azim=0,
threshold=x[n_lh[index]].max(),
figsize=(14, 10))
del index, index_neg
y = np.ones(len(vertices_rh))
index = np.where(R1[n_rh] < 0.05)
index_neg = np.where(R2[n_rh] < 0.05)
if set(index[0]).intersection(index_neg[0]).__len__() != 0:
print "OVERLAP"
y[n_rh[index]] = R1[n_rh[index]]
y[n_rh[index_neg]] = -1 * R2[n_rh[index_neg]]
print np.shape(index)[1], np.shape(index_neg)[1]
if np.shape(index)[1] != 0 and np.shape(index_neg)[1] != 0:
y[np.where(y==1)] = y[n_rh[index]].max() + 0.001
plotting.plot_surf_stat_map(vertices_rh, triangles_rh, fig_number,
'222', stat_map = y, cmap='jet', azim=0,
threshold=y[n_rh[index]].max(),
figsize=(14, 10))
plotting.plot_surf_stat_map(vertices_rh, triangles_rh, fig_number,
'224', stat_map = y, cmap='jet', azim=180,
threshold = y[n_rh[index]].max(),
figsize=(14, 10))
plt.suptitle(fig_name)
plt.savefig(fig_path + fig_name[:-4] + '.png')
fig_number += 1
A = get_mean(DATA, subject_list, mode, component=None)
#B = np.array(DATA['100307']['aligned'])
data_L[n_L] = A[0:29696, 3]
data_R[n_R] = A[29696:,3]
plotting.plot_surf_stat_map(verticesR, trianglesR, 3, '222', stat_map=data_R, cmap='jet',azim=0, figsize=(14, 10))
plotting.plot_surf_stat_map(verticesR, trianglesR, 3, '224', stat_map=data_R, cmap='jet',azim=180, figsize=(14, 10))
plotting.plot_surf_stat_map(verticesL, trianglesL, 3, '221', stat_map=data_L, cmap='jet',azim=180, figsize=(14, 10))
plotting.plot_surf_stat_map(verticesL, trianglesL, 3, '223', stat_map=data_L, cmap='jet',azim=0, figsize=(14, 10))
plt.suptitle('subject 1', fontsize=18)