-
Notifications
You must be signed in to change notification settings - Fork 19
/
sc_updateclusterimages.m
141 lines (87 loc) · 4.02 KB
/
sc_updateclusterimages.m
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
function features=sc_updateclusterimages(features,mua,s_opt);
% first, update the ISI plots
for i=1:features.Nclusters
% precompute ISI hist.
features.isioptions(1).tmax = max(.5,features.isioptions(1).tmax);
l=linspace(0,features.isioptions(1).tmax,features.isioptions(1).nbins);
thisclust=find(features.clusters==i);
if numel(thisclust)>1
dt= diff(features.ts(thisclust).*1000);
dt(dt==0)=[];
psize=0.65;
h=histc(dt,l);
h=(h./max(h)).*psize.*.95;
features.isiplots{i}=h;
else
features.isiplots{i}=zeros(0,features.isioptions(1).nbins);
end;
end;
% now update actual cluster images
if size(features.clusterimages,3) < 12
features.clusterimages=zeros(features.imagesize,features.imagesize,12);
end;
usefastmethod =1;
% first, if usefastmethod, interpolate up all waveforms so they look nicer
if usefastmethod
if ~isfield(features,'waveforms_hi') % this takes up time in the first pass
x=size(mua.waveforms,2);
L_im=linspace(1,x,features.imagesize);
sfact = features.imagesize/x;
features.waveforms_hi=zeros(size(mua.waveforms,1),round(x*sfact));
ii_intp=round(L_im);
for i=1:size( mua.waveforms,1)
if mod(i,10000)==0
clf; hold on;
fill([-2 -2 5 5],[-2 2 2 -2],'k','FaceColor',[.95 .95 .95]);
plot(linspace(1,3,numel(features.waveforms_hi(i-1,:))) , 0.9*features.waveforms_hi(i-1,:)/max(features.waveforms_hi(i-1,:)) ,'k','LineWidth',22,'color',.93.*[1 1 1])
xx=linspace(0,2*pi*(i/size( mua.waveforms,1)),100);
plot(sin(xx).*.4,cos(xx).*.4,'k','LineWidth',22,'color',[.85 .85 .85])
text(0,0,['interpolating waveforms']);
xlim([-1.3, 3.3]); ylim([-1.3, 1.2]);
daspect([1 1 1]);set(gca,'XTick',[]); set(gca,'YTick',[]);
drawnow;
end;
%features.waveforms_hi(i,:) = interp1(1:x,mua.waveforms(i,:),L_im, 'nearest'); % use 'linear' for speed or even 'nearest'
features.waveforms_hi(i,:) = mua.waveforms(i,ii_intp);
end;
end;
end;
%npoints=numel(mua.ts_spike);
npoints=size(mua.waveforms,2);
ll=(linspace(-.1,.1,features.imagesize).*4.8)./features.waveformscale;
% if the last manipulation was a +,-,or *, then the only clusters that are
% affected are NULl and the slected cluster, so we can restrict the image
% upates to these two clusters and save a LOT of time:
if ~exist('features.last_op_was_from_any')
features.last_op_was_from_any=1;
end;
if features.last_op_was_from_any
clusters_to_update = 1:features.Nclusters;
else
clusters_to_update =[1 features.editedcluster];
end;
for i=clusters_to_update
features.clusterimages(:,:,i)=zeros(features.imagesize,features.imagesize);
inthiscluster=find(features.clusters==i);
% if numel(inthiscluster)==1
% g=g';
% end;
% only use some of the waveforms for very large clusters, tweak the
% numbers, its just a guess for now
if numel(inthiscluster) > 50000
ds_factor = s_opt.skipevery_wf_display;
elseif numel(inthiscluster) > 5000
ds_factor = ceil(s_opt.skipevery_wf_display/2);
else
ds_factor = 1;
end;
for k=1:features.imagesize % go trough image instead of waveform points, for speed and image quality
x = k;
%features.clusterimages(:,x,i) = histc( features.waveforms_hi(inthiscluster, round(sc_remap(k,1,features.imagesize,1,size(mua.waveforms,2))) ) , ll*6 );
if numel(inthiscluster) >0
features.clusterimages(:,x,i) = histc( features.waveforms_hi(inthiscluster(1:ds_factor:end), k ) , ll ) ;
else
features.clusterimages(:,x,i) = 1;
end;
end;
end;