forked from brendonw1/KilosortWrapper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
createChannelMapFile_KSW.m
169 lines (157 loc) · 5.45 KB
/
createChannelMapFile_KSW.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
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
function createChannelMapFile_Local(basepath,basename,electrode_type)
% Original function by Brendon and Sam
% electrode_type: Two options at this point: 'staggered' or 'neurogrid'
% create a channel map file
if ~exist('basepath','var')
basepath = cd;
end
if ~exist('basename','var')
[~,basename] = fileparts(basepath);
end
[par,rxml] = LoadXml(fullfile(basepath,[basename,'.xml']));
xml_electrode_type = rxml.child(1).child(4).value;
switch(xml_electrode_type)
case 'staggered'
electrode_type = 'staggered';
case 'neurogrid'
electrode_type = 'neurogrid';
case 'grid'
electrode_type = 'neurogrid';
case 'poly3'
electrode_type = 'poly3';
case 'poly5'
electrode_type = 'poly5';
case 'twohundred'
electrode_type = 'twohundred';
end
%%Default
if ~exist('electrode_type')
electrode_type = 'staggered';
end
%%
xcoords = [];%eventual output arrays
ycoords = [];
ngroups = length(par.AnatGrps);
for g = 1:ngroups
groups{g} = par.AnatGrps(g).Channels;
end
switch(electrode_type)
case 'staggered'
for a= 1:ngroups %being super lazy and making this map with loops
x = [];
y = [];
tchannels = groups{a};
for i =1:length(tchannels)
x(i) = 20;%length(tchannels)-i;
y(i) = -i*20;
if mod(i,2)
x(i) = -x(i);
end
end
x = x+a*200;
xcoords = cat(1,xcoords,x(:));
ycoords = cat(1,ycoords,y(:));
end
case 'poly3'
disp('poly3 probe layout')
for a= 1:ngroups %being super lazy and making this map with loops
tchannels = groups{a};
x = nan(1,length(tchannels));
y = nan(1,length(tchannels));
extrachannels = mod(length(tchannels),3);
polyline = mod([1:length(tchannels)-extrachannels],3);
x(find(polyline==1)+extrachannels) = -18;
x(find(polyline==2)+extrachannels) = 0;
x(find(polyline==0)+extrachannels) = 18;
x(1:extrachannels) = 0;
y(find(x == 18)) = [1:length(find(x == 18))]*-20;
y(find(x == 0)) = [1:length(find(x == 0))]*-20-10+extrachannels*20;
y(find(x == -18)) = [1:length(find(x == -18))]*-20;
x = x+a*200;
xcoords = cat(1,xcoords,x(:));
ycoords = cat(1,ycoords,y(:));
end
case 'poly5'
disp('poly5 probe layout')
for a= 1:ngroups %being super lazy and making this map with loops
tchannels = groups{a};
x = nan(1,length(tchannels));
y = nan(1,length(tchannels));
extrachannels = mod(length(tchannels),5);
polyline = mod([1:length(tchannels)-extrachannels],5);
x(find(polyline==1)+extrachannels) = -2*18;
x(find(polyline==2)+extrachannels) = -18;
x(find(polyline==3)+extrachannels) = 0;
x(find(polyline==4)+extrachannels) = 18;
x(find(polyline==0)+extrachannels) = 2*18;
x(1:extrachannels) = 18*(-1).^[1:extrachannels];
y(find(x == 2*18)) = [1:length(find(x == 2*18))]*-28;
y(find(x == 18)) = [1:length(find(x == 18))]*-28-14;
y(find(x == 0)) = [1:length(find(x == 0))]*-28;
y(find(x == -18)) = [1:length(find(x == -18))]*-28-14;
y(find(x == 2*-18)) = [1:length(find(x == 2*-18))]*-28;
x = x+a*200;
xcoords = cat(1,xcoords,x(:));
ycoords = cat(1,ycoords,y(:));
end
case 'neurogrid'
for a= 1:ngroups %being super lazy and making this map with loops
x = [];
y = [];
tchannels = groups{a};
for i =1:length(tchannels)
x(i) = length(tchannels)-i;
y(i) = -i*50;
end
x = x+a*50;
xcoords = cat(1,xcoords,x(:));
ycoords = cat(1,ycoords,y(:));
end
case 'twohundred'
for a= 1:ngroups
x = [];
y = [];
tchannels = groups{a};
for i =1:length(tchannels)
x(i) = 0;%length(tchannels)-i;
if mod(i,2)
y(i) = 0;%odds
else
y(i) = 200;%evens
end
end
x = x+(a-1)*200;
xcoords = cat(1,xcoords,x(:));
ycoords = cat(1,ycoords,y(:));
end
end
Nchannels = length(xcoords);
kcoords = zeros(1,Nchannels);
switch(electrode_type)
case 'neurogrid'
for a= 1:ngroups
kcoords(groups{a}+1) = floor((a-1)/4)+1;
end
otherwise
for a= 1:ngroups
kcoords(groups{a}+1) = a;
end
end
connected = true(Nchannels, 1);
% just use AnatGrps
% % Removing dead channels by the skip parameter in the xml
% % order = [par.AnatGrps.Channels];
% % skip = find([par.AnatGrps.Skip]);
% % connected(order(skip)+1) = false;
order = [par.AnatGrps.Channels];
if isfield(par,'SpkGrps')
skip2 = find(~ismember([par.AnatGrps.Channels], [par.SpkGrps.Channels])); % finds the indices of the channels that are not part of SpkGrps
connected(order(skip2)+1) = false;
end
chanMap = 1:Nchannels;
chanMap0ind = chanMap - 1;
[~,I] = sort(horzcat(groups{:}));
xcoords = xcoords(I)';
ycoords = ycoords(I)';
save(fullfile(basepath,'chanMap.mat'), ...
'chanMap','connected', 'xcoords', 'ycoords', 'kcoords', 'chanMap0ind')