-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproccess_time_general.py
238 lines (194 loc) · 8.05 KB
/
proccess_time_general.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
import os
import numpy as np
import mne
import matplotlib
import sys
#matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from mne.preprocessing import annotate_muscle_zscore
import os.path as op
from mne.preprocessing import ICA
import scipy.io
import seaborn as sns
from init_y import *
xx=2
data_path =r'Y:/cross_modal_project/Across_participants/Time_generalization_wT/'
participant_arr=list(Part_info.keys())[:]
suffics = { 1:'no_max',
2:'max_wo_head',
3:'max_w_head'}
sensor ='meg'
time_add = '_50'
file_name1 = 'scores_move_big_nat_W_P_'
file_name2='_'+suffics[xx]+'_'+ sensor+'_w_T'+time_add
file_name_time = 'times_' +file_name2+'.npy'
path_file = os.path.join(data_path + suffics[xx] + '/matrix/' + file_name_time)
time = np.load(path_file)
scores_all = np.zeros((len(participant_arr),len(['w', 'p']) * len([11, 21, 31]), len(time), len(time)))
path_to_save = data_path + 'results/'
if not os.path.exists(path_to_save):
os.makedirs(path_to_save)
color_v={
0:'blue',
1:'green',
}
mod={
0:'WORDS',
1:'PICTURES',
}
Category = {
11:"move",
12:"still",
21:"big",
22:"small",
31:"nat",
32:"man"
}
for ii, par_name in enumerate(participant_arr):
par=str(Part_info[par_name])
file_name = file_name1 + par + file_name2 +'.npy'
path_file = os.path.join(data_path+suffics[xx] + '/matrix/' + file_name)
scores = np.load(path_file)
scores_all[ii,:,:] = scores
scores_mean = np.mean(scores_all, axis = 0)
scores_std = np.std(scores_all, axis = 0)/np.sqrt(len(participant_arr))
score_mean_std = np.concatenate((scores_mean,scores_std))
score_name_save = '/scores_mean_std_'+suffics[xx]+'_'+sensor+'.npy'
np.save(path_to_save+score_name_save,score_mean_std)
for aa in range(3):
fig,ax=plt.subplots()
im=ax.imshow(score_mean_std[aa,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.45, vmax=0.55)
ax.set_xticks(range(0,375,25))
ax.set_xticklabels(time[range(0,375,25)],rotation=45)
ax.set_yticks(range(0,375,25))
ax.set_yticklabels(time[range(0,375,25)])
ax.set_xlabel('Times Test (ms)' + ' / ' + mod[(aa+3)//3])
ax.set_ylabel('Times Train (ms)' + ' / ' + mod[aa//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2])
plt.colorbar(im)
fig.savefig(path_to_save+Category[(aa%3+1)*10+1]+'_VC_'+Category[(aa%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor+ '_train_' +mod[aa//3], dpi=600)
fig,ax=plt.subplots()
im=ax.imshow(score_mean_std[aa+3,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.45, vmax=0.55)
ax.set_xticks(range(0,375,25))
ax.set_xticklabels(time[range(0,375,25)],rotation=45)
ax.set_yticks(range(0,375,25))
ax.set_yticklabels(time[range(0,375,25)])
ax.set_xlabel('Times Test (ms)' + ' / ' + mod[aa//3])
ax.set_ylabel('Times Train (ms)' + ' / ' + mod[(aa+3)//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2])
plt.colorbar(im)
fig.savefig(path_to_save+Category[((aa+3)%3+1)*10+1]+'_VC_'+Category[((aa+3)%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor + '_train_' +mod[(aa+3)//3], dpi=600)
ind = np.array(range(0,375,5))
sliced_array_shifted = score_mean_std[:, 38:, 38:]
sliced_array = sliced_array_shifted[:,::5,::5]
time_shifted=time+0.024
time_sc=time_shifted[38::25]*1000
time_sc[4]=200
clrst_w=np.load('clst_w.npy')
clrst_p=np.load('clst_p.npy')
#%%
for aa in [1]:#range(3):
fig,ax=plt.subplots()
im=ax.imshow(sliced_array[aa,:,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.40, vmax=0.6)
plt.plot((0, 67), (0, 67), 'k:')
ax.set_xticks(range(0,70,5))
ax.set_xticklabels(time_sc.astype(int),rotation=45)
ax.set_yticks(range(0,70,5))
ax.set_yticklabels(time_sc.astype(int))
ax.set_xlabel('Times Test (s)' + ' / ' + mod[(aa+3)//3])
ax.set_ylabel('Times Train (s)' + ' / ' + mod[aa//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2])
plt.colorbar(im)
plt.contour(clrst_w, 0)
fig.savefig(path_to_save+Category[(aa%3+1)*10+1]+'_VC_'+Category[(aa%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor+ '_train_' +mod[aa//3] + '_sliced', dpi=600)
fig,ax=plt.subplots()
im=ax.imshow(sliced_array[aa+3,:,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.40, vmax=0.6)
plt.plot((0, 67), (0, 67), 'k:')
ax.set_xticks(range(0,70,5))
ax.set_xticklabels(time_sc.astype(int),rotation=45)
ax.set_yticks(range(0,70,5))
ax.set_yticklabels(time_sc.astype(int))
ax.set_xlabel('Times Test (ms)' + ' / ' + mod[aa//3])
ax.set_ylabel('Times Train (ms)' + ' / ' + mod[(aa+3)//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2] )
plt.colorbar(im)
plt.contour(clrst_p, 0)
fig.savefig(path_to_save+Category[((aa+3)%3+1)*10+1]+'_VC_'+Category[((aa+3)%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor + '_train_' +mod[(aa+3)//3]+ '_sliced', dpi=600)
sliced_array_w=sliced_array[1,:,:]
sliced_array_p=sliced_array[4,:,:]
# %%
xx=2
data_path =r'Y:/cross_modal_project/Across_participants/Time_generalization/'
participant_arr=list(Part_info.keys())[:]
suffics = { 1:'no_max',
2:'max_wo_head',
3:'max_w_head'}
sensor ='meg'
time_add = '_50'
file_name1 = 'scores_move_big_nat_W_P_'
file_name2='_'+suffics[xx]+'_'+ sensor
file_name_time = 'times_' +file_name2+'.npy'
path_file = os.path.join(data_path + suffics[xx] + '/matrix/' + file_name_time)
time = np.load(path_file)
scores_all = np.zeros((len(participant_arr),len(['w', 'p']) * len([11, 21, 31]), len(time), len(time)))
path_to_save = data_path + 'results/'
if not os.path.exists(path_to_save):
os.makedirs(path_to_save)
color_v={
0:'blue',
1:'green',
}
mod={
0:'WORDS',
1:'PICTURES',
}
Category = {
11:"move",
12:"still",
21:"big",
22:"small",
31:"nat",
32:"man"
}
for ii, par_name in enumerate(participant_arr):
par=str(Part_info[par_name])
file_name = file_name1 + par + file_name2 +'.npy'
path_file = os.path.join(data_path+suffics[xx] + '/matrix/' + file_name)
scores = np.load(path_file)
scores_all[ii,:,:] = scores
scores_mean = np.mean(scores_all, axis = 0)
scores_std = np.std(scores_all, axis = 0)/np.sqrt(len(participant_arr))
score_mean_std = np.concatenate((scores_mean,scores_std))
score_name_save = '/scores_mean_std_'+suffics[xx]+'_'+sensor+'.npy'
np.save(path_to_save+score_name_save,score_mean_std)
for aa in range(3):
fig,ax=plt.subplots()
im=ax.imshow(score_mean_std[aa,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.45, vmax=0.55)
ax.set_xticks(range(0,375,25))
ax.set_xticklabels(time[range(0,375,25)],rotation=45)
ax.set_yticks(range(0,375,25))
ax.set_yticklabels(time[range(0,375,25)])
ax.set_xlabel('Times Test (ms)' + ' / ' + mod[(aa+3)//3])
ax.set_ylabel('Times Train (ms)' + ' / ' + mod[aa//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2])
plt.colorbar(im)
fig.savefig(path_to_save+Category[(aa%3+1)*10+1]+'_VC_'+Category[(aa%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor+ '_train_' +mod[aa//3], dpi=600)
fig,ax=plt.subplots()
im=ax.imshow(score_mean_std[aa+3,:], interpolation='nearest', origin='lower', cmap='RdBu_r',
vmin=0.45, vmax=0.55)
ax.set_xticks(range(0,375,25))
ax.set_xticklabels(time[range(0,375,25)],rotation=45)
ax.set_yticks(range(0,375,25))
ax.set_yticklabels(time[range(0,375,25)])
ax.set_xlabel('Times Test (ms)' + ' / ' + mod[aa//3])
ax.set_ylabel('Times Train (ms)' + ' / ' + mod[(aa+3)//3])
ax.set_title( Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2])
plt.colorbar(im)
fig.savefig(path_to_save+Category[((aa+3)%3+1)*10+1]+'_VC_'+Category[((aa+3)%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor + '_train_' +mod[(aa+3)//3], dpi=600)
score_all_w=np.mean(scores_all[:,0:3,:,:],axis=1)
score_all_p=np.mean(scores_all[:,3:6,:,:],axis=1)