-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_chans_evolution.py
166 lines (155 loc) · 5.78 KB
/
script_chans_evolution.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
import brain_state_calculate as bsc
import numpy as np
import matplotlib.pyplot as plt
from collections import Counter
#some graph about the neuron evolution over day
# how many neurons lost ?
# how many neurons gain ?
# how many neurons modulate ?
# how much the fire rate is modulated ?
from cpp_file_tools import cpp_file_tools
base_dir = '../RT_classifier/BMIOutputs/BMISCIOutputs/'
files = {'r31':
{'03': range(1, 25)+range(52, 58),
'04': range(1, 45),
'06': range(78, 113),
'07': range(27, 51),
'10': range(6, 31),
'11': range(1, 16),
'12': range(1, 27),
'13': range(63, 89),
'14': range(1, 23)},
'r32':
{'03': range(25, 52),
'04': range(45, 83),
'06': range(42, 78),
'07': range(51, 82),
'10': range(31, 69),
'11': range(1, 36),
'12': range(27, 54),
'13': range(32, 63)},
'r34':
{'06': range(1, 42),
'07': range(1, 27),
'10': range(1, 6),
'11': range(1, 31),
'12': range(54, 87),
'13': range(1, 32),
'14': range(23, 48)}
}
number_of_chan = 128
group_chan_by = 1
my_cft = cpp_file_tools(number_of_chan, group_chan_by)
#number of chan after grouping
number_of_chan /=group_chan_by
f = open('chan_evo_result.txt', 'w')
n = 0
all_chan_means = {}
all_chan_stds = {}
all_new_neuron = {}
all_lost_neuron = {}
all_mod_neuron = {}
all_chan_mod_count = {}
all_chan_mod = []
perc_modulation = []
for rat in files.keys():
all_chan_means[rat] = []
all_chan_stds[rat] = []
all_new_neuron[rat] = []
all_lost_neuron[rat] = []
all_mod_neuron[rat] = []
all_chan_mod_count[rat] = [0]*number_of_chan
for date in files[rat].keys():
file_date = '12'+date
dir_name = base_dir+'Dec'+date+'/'+rat+'/'
l_res, tmp_obs = my_cft.convert_cpp_file(dir_name, file_date, files[rat][date], False, 'SCIOutput_')
l_obs = np.array(tmp_obs)
all_chan_means[rat].append(l_obs.mean(0))
all_chan_stds[rat].append(l_obs.std(0))
all_chan_means[rat] = np.array(all_chan_means[rat])
all_chan_stds[rat] = np.array(all_chan_stds[rat])
for i in range(all_chan_means[rat].shape[1]):
plt.plot(all_chan_means[rat][:, i], 'b-')
plt.plot(all_chan_means[rat][:, i]+all_chan_stds[rat][:, i], 'b--')
plt.plot(all_chan_means[rat][:, i]-all_chan_stds[rat][:, i], 'b--')
plt.savefig('tmp_fig/chan_evol_'+str(n) +'.png', bbox_inches='tight')
plt.close()
n += 1
for d in range(1, all_chan_means[rat].shape[0]):
new_neuron = 0
lost_neuron = 0
mod_neuron = 0
for c in range(all_chan_means[rat].shape[1]):
if all_chan_means[rat][d-1, c] == 0 and all_chan_means[rat][d, c] != 0:
new_neuron += 1
if all_chan_means[rat][d-1, c] != 0 and all_chan_means[rat][d, c] == 0:
lost_neuron += 1
if all_chan_means[rat][d, c] != 0:
all_chan_mod_count[rat][c] += 1
mod_neuron += 1
#we count only modulation for chan that are modulate at least one time during the day
for c in range(all_chan_means[rat].shape[1]):
all_chan_mod.append(all_chan_means[rat][d-1, c]-all_chan_means[rat][d, c])
#divided by number_of_chan/100 cause we want %
all_new_neuron[rat].append(new_neuron/(number_of_chan/100))
all_lost_neuron[rat].append(lost_neuron/(number_of_chan/100))
all_mod_neuron[rat].append(mod_neuron/(number_of_chan/100))
print all_chan_means[rat].shape[0], Counter(all_chan_mod_count[rat])
tmp = Counter(all_chan_mod_count[rat])
for k in tmp.keys():
perc_modulation += [k/float(all_chan_means[rat].shape[0]-1)*100]*tmp[k]
plt.plot(all_new_neuron[rat], 'g-', label="new")
plt.plot(all_lost_neuron[rat], 'r-', label="lost")
plt.plot(all_mod_neuron[rat], 'b-', label="modulate")
plt.legend(loc='upper right')
plt.ylabel('% of neurons')
plt.xlabel('day')
plt.savefig('tmp_fig/neuron_evo_'+rat+'.png')
plt.close()
boxplot_new_neuron = []
boxplot_lost_neuron = []
boxplot_mod_neuron = []
for rat in files.keys():
boxplot_new_neuron += all_new_neuron[rat]
boxplot_lost_neuron += all_lost_neuron[rat]
boxplot_mod_neuron += all_mod_neuron[rat]
plt.boxplot([boxplot_new_neuron, boxplot_lost_neuron, boxplot_mod_neuron])
plt.xticks([1, 2, 3], ['new', 'lost', 'modulate'])
plt.ylabel('% of neuron')
plt.savefig('tmp_fig/neuron_evo_boxplot.png')
f.write('\n mean new: ')
f.write(str(np.array(boxplot_new_neuron).mean()))
f.write('\n std new: ')
f.write(str(np.array(boxplot_new_neuron).std()))
f.write('\n mean lost: ')
f.write(str(np.array(boxplot_lost_neuron).mean()))
f.write('\n std lost: ')
f.write(str(np.array(boxplot_lost_neuron).std()))
f.write('\n mean mod: ')
f.write(str(np.array(boxplot_mod_neuron).mean()))
f.write('\n std mod: ')
f.write(str(np.array(boxplot_mod_neuron).std()))
plt.close()
all_chan_mod=np.array(all_chan_mod)
plt.boxplot(all_chan_mod[all_chan_mod != 0])
plt.xticks([1], ['mean fire modulation between day'])
plt.savefig('tmp_fig/neuron_mod_over_d_boxplot.png')
plt.close()
f.write('\nmean var: ')
f.write(str(all_chan_mod[all_chan_mod != 0].mean()))
f.write('\nstds var: ')
f.write(str(all_chan_mod[all_chan_mod != 0].std()))
bins = np.linspace(0, 100, 6)
hist, bins = np.histogram(perc_modulation, bins)
hist /= 3.84
widths = np.diff(bins)
plt.bar(bins[:-1], hist, widths)
plt.ylabel('% of neuron')
plt.xlabel('% of day modulate')
plt.savefig('tmp_fig/modulation_hist.png')
plt.close()
#number of lost neurons between day
#number of new neurons
f.close()
print('###############')
print('#### END ####')