-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_simulation.m
More file actions
230 lines (214 loc) · 7.27 KB
/
plot_simulation.m
File metadata and controls
230 lines (214 loc) · 7.27 KB
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
function plot_simulation(Nsim, initdata, ConData, savename_input, varargin)
% Loads the results of simulations, and plots
% INPUT:
% * initdata: structure with initial settings, in '-filename--_initialsettings.mat';
% * ConData: structure with connectivity data, in '-filename--_ConData.mat'
% * Nsim: # simulations to plot
% * 'simvec' (optional): vector with which simulations to use
% exaple use:
% * plot_simulation(10, initdata, ConData) plots the first 10 simulations
% * plot_simulation(10, initdata, ConData, )
f = filesep;
%% Plot example
if ~exist('Nsim','var')
Nsim = input('Which simulation(s) do you want to plot? (give array)');
end
simvec = 1:Nsim;
% Look for 'varargin' inputs
len = length(varargin);
% check "len" for even number
if mod(len,2) > 0
error('Wrong arguments: must be name-value pairs.');
end
for i = 1:2:len
switch lower(varargin{i})
case 'simvec'
simvec=varargin{i+1};
Nsim = length(simvec);
otherwise
% neglect invalid option
disp(['Ignoring invalid input ' varargin{i}])
end
end
whiskers = ones(1,Nsim);
for nt = 1:Nsim
disp(['Loading simulation ' num2str(simvec(nt)) ' for plotting'])
try
if initdata.Vthresdyn
thresholdname = 'dynthreshold_set';
else
thresholdname = 'fixthreshold_set';
end
load([ConData.savefolder ConData.FnametoSave '_Simcolumn_' thresholdname '_' initdata.setVthres.type '_simulation_' num2str(simvec(nt)) ]);
load([ConData.savefolder savename_input '_Thalamic_Spike_Trains.mat' ]);
catch
if nt>1
keyboard
end
savefolder = input('What is the folder where the simulations were saved?', 's');
if ~strcmp(savefolder(end), f)
savefolder(end+1) = f ;
end
animal = input('What was the animal name?','s');
savename = input('What were the file names?', 's');
thresholdtype = input('What kind of threshold was used? (d/f)', 's');
if strcmp(thresholdtype, 'd')
thresholdname = 'dynthreshold_set';
else
thresholdname = 'fixthreshold_set';
end
thresholdset = input('How were the thresholds set? (d/t/i)','s');
if strcmp(thresholdset, 'd')
thresholdsetname = 'distribution';
elseif strcmp(thresholdset, 't')
thresholdsetname = 'pertype';
else
thresholdsetname = 'individual';
end
try
if ~isempty(animal)
ConData.savefolder = savefolder;
ConData.FnametoSave = [savename '_' animal];
initdata.setVthres.type = thresholdsetname;
load([ConData.savefolder ConData.FnametoSave '_Simcolumn_' thresholdname '_' initdata.setVthres.type '_simulation_' num2str(simvec(nt)) ]);
load([ConData.savefolder ConData.FnametoSave '_Thalamic_Spike_Trains.mat' ], 'WhiskerTrace');
else
ConData.savefolder = savefolder;
ConData.FnametoSave = savename;
initdata.setVthres.type = thresholdsetname;
load([ConData.savefolder ConData.FnametoSave '_Simcolumn_' thresholdname '_' initdata.setVthres.type '_simulation_' num2str(simvec(nt)) ]);
load([ConData.savefolder ConData.FnametoSave '_Thalamic_Spike_Trains.mat' ], 'WhiskerTrace');
end
catch
load([savefolder savename num2str(simvec(nt)) '.mat' ]);
savenameth = input('What were the file names for the thalamic spike trains?', 's');
load([savefolder savenameth], 'WhiskerTrace');
end
end
[barrelnr, ind_barrel] = sort(cellinfo_all(:,5)); % sort by barrel
celltypevec = cellinfo_all(ind_barrel,4);
Nbarrel = max(barrelnr);
Nall = length(modelsc);
neuronlist = randi(Nall, [1,4]);
% neuronlist = [5138,672,676,6720];
disp(['Plotting simulation ' num2str(simvec(nt)) ])
figure
for nn = 1:4
time = (1:length(V(ind_barrel(neuronlist(nn)),:)))*simdata.timestep;
subplot(2,2,nn)
plot(time, V(ind_barrel(neuronlist(nn)),:))
hold all
try
plot(time,U(ind_barrel(neuronlist(nn)),:))
catch
disp('Parameter U not saved')
end
if initdata.Vthresdyn
try
plot(time, VT(ind_barrel(neuronlist(nn)),:))
catch
disp('Parameter V_T not saved')
end
legend('V', 'u','V_T')
else
legend('V', 'u')
end
ylim([-80, 20])
grid on
box on
title(['Neuron ',num2str(ind_barrel(neuronlist(nn)))])
end
figure
if whiskers(nt)==1
for na=1:2
subplot(6,1,na)
plot((1:length(WhiskerTrace.Recording{na,simvec(nt)}))*WhiskerTrace.binsize, WhiskerTrace.Recording{na,simvec(nt)}, 'k', 'LineWidth',2)
xlim([1, length(WhiskerTrace.Recording{na,simvec(nt)})*WhiskerTrace.binsize])
if na==1
title('Whisker Angle')
else
title('Whisker Curvature')
end
set(gca, 'XGrid','on')
end
end
[Nneuronth, ~] = size(inputspikes);
subplot(3,1,2)
mint = 1;
maxt = 0;
for nn = 1:Nneuronth
hold all
plot(inputspikes(nn,:), nn*ones(size(inputspikes(nn,:))), '.k')
u = unique(inputspikes(nn,:)); % remove 0
if length(u)>1
if u(2)<mint
mint = u(2);
end
end
if max(inputspikes(nn,:))>maxt
maxt = max(inputspikes(nn,:));
end
end
NCB = 0;
[barrelnrth, ~] = sort(cellinfo_input(:,5)); % sort by barrel
for nb = 1:Nbarrel
% solid lines between barrels
NCB = NCB+sum(barrelnrth==nb);
try
plot([mint maxt],[NCB,NCB], '-b')
catch
plot([0 maxt],[NCB,NCB], '-b')
end
end
ylim([1 Nneuronth])
title('Thalamic input spikes')
box on
subplot(3,1,3)
[Nneuron, ~] = size(modelspt);
for nn = 1:Nneuron
hold all
plot(modelspt(ind_barrel(nn),:), nn*ones(size(modelspt(ind_barrel(nn),:))), '.k')
u = unique(modelspt(ind_barrel(nn),:)); % remove 0
if length(u)>1
if u(2)<mint
mint = u(2);
end
end
if max(modelspt(ind_barrel(nn),:))>maxt
maxt = max(modelspt(ind_barrel(nn),:));
end
end
NCB = 0;
NCB_old = 0;
for nb = 1:Nbarrel
% solid lines between barrels
NCB = NCB+sum(barrelnr==nb);
try
plot([mint maxt],[NCB,NCB], '-b')
catch
plot([0 maxt],[NCB,NCB], '-b')
end
% dotted lines between cell-types
NCT = NCB_old;
for celltype = 1:15
NCT = NCT+sum(celltypevec(NCB_old+1:NCB)==celltype);
try
plot([mint maxt],[NCT,NCT], '--r')
catch
plot([0 maxt],[NCT,NCT], '--r')
end
end
NCB_old = NCB;
end
ylim([1 Nneuron])
title('Model spikes')
for na=2:3
subplot(3,1,na)
xlim([mint, maxt])
xlabel('time (ms)')
ylabel('Neuron number')
set(gca, 'XGrid','on')
box on
end
end
end