-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproccess_time_cat.py
187 lines (156 loc) · 6.44 KB
/
proccess_time_cat.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
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=1
aaa= 'no_ica'
data_path =r'Y:/cross_modal_project/Across_participants/Category_w_time/'
participant_arr=list(Part_info.keys())
suffics = { 1:'no_max',
2:'max_wo_head',
3:'max_w_head'}
sensor ='meg'
file_name1 = 'scores_move_big_nat_W_P_'
file_name2='_'+suffics[xx]+'_'+ sensor+'_'+aaa+'_50'
file_name_time = 'times' +file_name2+'.npy'
path_file = os.path.join(data_path + suffics[xx]+'/' + aaa + '/' + file_name_time)
time = np.load(path_file)
scores_all = scores_all = np.zeros((len(participant_arr),len(['w', 'p']) * len([11, 21, 31]), 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]+ '/' +aaa +'/'+ file_name)
scores = np.load(path_file)
scores_all[ii,:,:] = scores
#start_ind = np.where(time==0.430)
#end_ind = np.where(time==0.500)
#total_sum = np.mean(scores_all[:,:,int(start_ind[0]):int(end_ind[0])],axis=2)
#from scipy import stats
#stats.ttest_1samp(total_sum[:,4],0.5,axis=0)
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+'_'+aaa+'.npy'
np.save(path_to_save+score_name_save,score_mean_std)
# %%
for aa in range(3):
fig=plt.figure(aa)
plt.plot(time,scores_mean[aa,:],color=color_v[aa//3], label='Words')
plt.fill_between(time, scores_mean[aa,:]-scores_std[aa,:], scores_mean[aa,:]+scores_std[aa,:], color=color_v[aa//3], alpha=0.2)
plt.plot(time,scores_mean[aa+3,:],color=color_v[(aa+3)//3], label='Pictures')
plt.fill_between(time, scores_mean[aa+3,:]-scores_std[aa+3,:], scores_mean[aa+3,:]+scores_std[aa+3,:], color=color_v[(aa+3)//3], alpha=0.2)
plt.axvline(.0, color='k', linestyle='-')
plt.axvline(.6, color='k', linestyle='-')
plt.axhline(.5, color='k', linestyle='--', label='chance')
plt.xlabel('Times')
plt.ylabel('AUC/scores')
plt.title(Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2]+'/ '+suffics[xx]+' / '+str(len(participant_arr))+' averaged / '+sensor)
plt.ylim(0.35,0.7)
plt.legend(loc='lower right')
fig.savefig(path_to_save+Category[(aa%3+1)*10+1]+'_VC_'+Category[(aa%3+1)*10+2]+'_'+suffics[xx]+'_'+sensor+'_'+aaa, dpi=600)
# %%
y_data_p = np.mean(scores_mean[3:6,:],axis = 0)
y_data_w = np.mean(scores_mean[0:2,:],axis = 0)
fig = plt.figure(1)
plt.plot(time,y_data_p,color=color_v[0], label='Pictures')
plt.plot(time,y_data_w,color=color_v[1], label='Words')
#plt.fill_between(time, scores_mean[aa+3,:]-scores_std[aa+3,:], scores_mean[aa+3,:]+scores_std[aa+3,:], color=color_v[(aa+3)//3], alpha=0.2)
plt.axvline(.0, color='k', linestyle='-')
plt.axvline(.6, color='k', linestyle='-')
plt.axhline(.5, color='k', linestyle='--', label='chance')
plt.xlabel('Times')
plt.ylabel('AUC/scores')
plt.title('Category classification '+'/ '+suffics[xx]+' / '+str(len(participant_arr))+' averaged / '+sensor)
plt.ylim(0.45,0.7)
plt.legend(loc='upper left')
fig.savefig(path_to_save+'all categories'+'_'+suffics[xx]+'_'+sensor+'_'+aaa, dpi=600)
# %%
#aa=0
sensor='meg'
color_x={1:'m-',
2:'b-',
3:'k-'}
clr={1:'m',2:'b',3:'k'}
fig=plt.figure()
for xxx in [1,2,3]:
score_name = 'scores_mean_std_'+suffics[xxx]+'_'+sensor+'_'+aaa+'.npy'
path_file = os.path.join(path_to_save, score_name)
scores_mean = np.load(path_file)
plt.plot(time,np.mean(scores_mean[3:6,:],axis=0),color_x[xxx], label=suffics[xxx])
#plt.fill_between(time, scores_mean[aa+3,:]-scores_mean[aa+9,:], scores_mean[aa+3,:]+scores_mean[aa+9,:], color=clr[xxx], alpha=0.2)
plt.axvline(.0, color='k', linestyle='-')
plt.axvline(.6, color='k', linestyle='-')
plt.axhline(.5, color='k', linestyle='--', label='chance')
plt.xlabel('Times')
plt.ylabel('AUC/scores')
plt.title('Pic_'+'all categories '+' / '+str(len(participant_arr))+' averaged / '+sensor)
plt.ylim(0.45,0.65)
plt.legend(loc='upper right')
fig.savefig(path_to_save+'Pic_'+'all_categories_'+'_'+sensor+'_lines', dpi=600)
# %%
#aa=0
xxx=3
color_x={0:'k-',
1:'r-',
2:'g-'}
clr={0:'k',1:'r',2:'g'}
fig=plt.figure()
for ii,sensor in enumerate(['meg','grad','mag']):
score_name = 'scores_mean_std_'+suffics[xxx]+'_'+sensor+'.npy'
path_file = os.path.join(path_to_save, score_name)
scores_mean = np.load(path_file)
plt.plot(time,np.mean(scores_mean[3:6,:],axis=0),color_x[ii], label=sensor)
#plt.fill_between(time, scores_mean[aa,:]-scores_mean[aa+9,:], scores_mean[aa,:]+scores_mean[aa+6,:], color=clr[ii], alpha=0.2)
plt.axvline(.0, color='k', linestyle='-')
plt.axvline(.6, color='k', linestyle='-')
plt.axhline(.5, color='k', linestyle='--', label='chance')
plt.xlabel('Times')
plt.ylabel('AUC/scores')
plt.title('Pic/ '+'all categories '+' / '+str(len(participant_arr))+' averaged / '+suffics[xxx])
plt.ylim(0.45,0.65)
plt.legend(loc='upper right')
fig.savefig(path_to_save+'Pic_'+'all categories'+'_'+suffics[xxx]+aaa, dpi=600)
#for aa in range(6):
# fig=plt.figure(aa)
# plt.plot(time,scores_mean[aa,:],color=color_v[aa//3])
#
# plt.fill_between(time, scores_mean[aa,:]-scores_std[aa,:], scores_mean[aa,:]+scores_std[aa,:], color=color_v[aa//3], alpha=0.2)
#
# plt.axvline(.0, color='k', linestyle='-')
# plt.axvline(.6, color='k', linestyle='-')
# plt.axhline(.5, color='k', linestyle='--', label='chance')
#
# plt.xlabel('Times')
# plt.ylabel('AUC/scores')
# plt.title(mod[aa//3]+'/ '+Category[(aa%3+1)*10+1]+' VC '+Category[(aa%3+1)*10+2]+'/ '+str(delta_T)+'ms'+' / '+str(len(par_arr))+' averaged')
# plt.ylim(0.35,0.7)
# fig.savefig(path_to_save+mod[aa//3]+'_'+Category[(aa%3+1)*10+1]+'_VC_'+Category[(aa%3+1)*10+2]+'_'+str(delta_T)+'_time.png', dpi=600)