-
Notifications
You must be signed in to change notification settings - Fork 0
/
chGeometricLayoutAcute32_64.m
184 lines (161 loc) · 6.76 KB
/
chGeometricLayoutAcute32_64.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
function [correctedCh, correctedChAbs, conf, nChan] = chGeometricLayoutAcute32_64(probe, adaptorFlip, headstage)
% This function maps headstage channels onto recording site coordinates and
% outputs channel geometric correction order for 32-channel acute probes
% connected to 64-channel headstages.
% Inputs: probe - probe name, e.g., 'A32-A1x32-Edge-5mm-20-177'.
% adaptorFlip - true if the adaptor was flipped upside-down during
% the recording.
% headtsage - which headstage was used. At this stage presumes it
% was RHD2164, thus the value should be 'top' if the
% 32ch probe was recorded using RHD2164's top bank, or
% 'bottom' otherwise
% HEADSTAGE TO ADAPTOR
% Arrange headstage pins to correspond to headstage channels 17 to 48
if strcmp(headstage, 'top')
[headstageMap, ~, headstageConf] = RHD2164_headstageTopMap_ind2ch;
elseif strcmp(headstage, 'bottom')
[headstageMap, ~, headstageConf] = RHD2164_headstageBottomMap_ind2ch;
else
error('Wrong input')
end
headstageCh = num2cell(sort(cell2mat(values(headstageMap))));
if strcmp(headstage, 'top')
headstageMap = RHD2164_headstageTopMap_ch2ind;
elseif strcmp(headstage, 'bottom')
headstageMap = RHD2164_headstageBottomMap_ch2ind;
end
headstagePins = cell2mat(values(headstageMap, headstageCh));
% Adaptor channels viewed from the headstage
if ~adaptorFlip
if strcmp(headstage, 'top')
[~, adaptorOutCh, adaptorOutConf] = adaptorTopOutMap_ch2ind(adaptorFlip);
elseif strcmp(headstage, 'bottom')
[~, adaptorOutCh, adaptorOutConf] = adaptorBottomOutMap_ch2ind(adaptorFlip);
end
else
if strcmp(headstage, 'top')
[~, adaptorOutCh, adaptorOutConf] = adaptorBottomOutMap_ch2ind(adaptorFlip);
elseif strcmp(headstage, 'bottom')
[~, adaptorOutCh, adaptorOutConf] = adaptorTopOutMap_ch2ind(adaptorFlip);
end
end
adaptorOutCh = fliplr(adaptorOutCh);
% Transformation
headstage2adaptor = num2cell(adaptorOutCh(headstagePins));
% HEADSTAGE TO PROBE
% Arrange adaptor pins to correspond to headstage channels
if ~adaptorFlip
if strcmp(headstage, 'top')
[adaptorInMap, ~, adaptorInConf] = adaptorProbeInMap_ch2ind;
elseif strcmp(headstage, 'bottom')
[adaptorInMap, ~, adaptorInConf] = adaptorHeadInMap_ch2ind;
end
else
if strcmp(headstage, 'top')
[adaptorInMap, ~, adaptorInConf] = adaptorHeadInMap_ch2ind;
elseif strcmp(headstage, 'bottom')
[adaptorInMap, ~, adaptorInConf] = adaptorProbeInMap_ch2ind;
end
end
adaptorInPins = cell2mat(values(adaptorInMap,headstage2adaptor));
% Probe channels viewed from the adaptor
if strcmp(probe, 'A16-CambridgeNeuroTech')
[~, probeCh, probeOutConf] = probeAcute16Map_ch2ind;
else
[~, probeCh, probeOutConf] = probeAcute32Map_ch2ind;
end
probeCh = fliplr(probeCh);
% Transformation
headstage2probe = num2cell(probeCh(adaptorInPins));
redundantChans = ismember(cell2mat(headstage2probe),0);
if ~isempty(redundantChans)
realChans = ~redundantChans;
else
realChans = true(size(headstage2probe));
end
% HEADSTAGE TO COORDINATES
if strcmp(probe, 'A32-A1x32-Edge-5mm-20-177')
[channelMap, ~, probeInConf] = A32_A1x32_Edge_5mm_20_177_probeMap();
elseif strcmp(probe, 'A32-A1x32-5mm-25-177')
[channelMap, ~, probeInConf] = A32_A1x32_5mm_25_177_probeMap();
elseif strcmp(probe, 'A32-Buzsaki32-5mm-BUZ-200-160')
[channelMap, ~, probeInConf] = A32_Buzsaki32_5mm_BUZ_200_160_probeMap();
elseif strcmp(probe, 'A32-A1x32-Poly3-5mm-25s-177')
[channelMap, ~, probeInConf] = CM32_A32_Poly3_5mm_25s_177_probeMap();
probeInConf.probe = 'A32-A1x32-Poly3-5mm-25s-177';
elseif strcmp(probe, 'A32-A1x32-Poly3-10mm-50-177')
[channelMap, ~, probeInConf] = A32_A1x32_Poly3_10mm_50_177_probeMap();
elseif strcmp(probe, 'A16-CambridgeNeuroTech')
[channelMap, ~, probeInConf] = A16_CambridgeNeuroTech_probeMap();
end
chCoords = cell2mat(values(channelMap,headstage2probe(realChans)));
% CORRECTED HEADSTAGE CHANNEL ORDER
if strcmp(probe, 'A32-Buzsaki32-5mm-BUZ-200-160')
chCoords = [chCoords(1:2:length(chCoords))' chCoords(2:2:length(chCoords))'];
[~, sortedInd] = sort(chCoords(:,1),'ascend');
chCoords = chCoords(sortedInd,:);
chCoordsSh1 = chCoords(1:8,:);
sortedIndSh1 = sortedInd(1:8,:);
chCoordsSh2 = chCoords(9:16,:);
sortedIndSh2 = sortedInd(9:16,:);
chCoordsSh3 = chCoords(17:24,:);
sortedIndSh3 = sortedInd(17:24,:);
chCoordsSh4 = chCoords(25:32,:);
sortedIndSh4 = sortedInd(25:32,:);
[~, sortedInd] = sort(chCoordsSh1(:,2),'ascend');
chCoordsSh1 = chCoordsSh1(sortedInd,:);
sortedIndSh1 = sortedIndSh1(sortedInd);
[~, sortedInd] = sort(chCoordsSh2(:,2),'ascend');
chCoordsSh2 = chCoordsSh2(sortedInd,:);
sortedIndSh2 = sortedIndSh2(sortedInd);
[~, sortedInd] = sort(chCoordsSh3(:,2),'ascend');
chCoordsSh3 = chCoordsSh3(sortedInd,:);
sortedIndSh3 = sortedIndSh3(sortedInd);
[~, sortedInd] = sort(chCoordsSh4(:,2),'ascend');
chCoordsSh4 = chCoordsSh4(sortedInd,:);
sortedIndSh4 = sortedIndSh4(sortedInd);
sortedInd = [sortedIndSh1; sortedIndSh2; sortedIndSh3; sortedIndSh4];
chCoords = [chCoordsSh1; chCoordsSh2; chCoordsSh3; chCoordsSh4];
elseif strcmp(probe, 'A32-A1x32-Poly3-5mm-25s-177') || strcmp(probe, 'A32-A1x32-Poly3-10mm-50-177') ||...
strcmp(probe, 'A16-CambridgeNeuroTech')
chCoords = [chCoords(1:2:length(chCoords))' chCoords(2:2:length(chCoords))'];
[~, sortedInd1] = sort(chCoords(:,1),'ascend');
chCoords = chCoords(sortedInd1,:);
[~, sortedInd2] = sort(chCoords(:,2),'ascend');
sortedInd = sortedInd1(sortedInd2);
chCoords = chCoords(sortedInd2,:);
else
[~, sortedInd] = sort(chCoords,'ascend');
chCoords = chCoords(sortedInd)';
end
headstageCh = cell2mat(headstageCh(realChans));
correctedCh = headstageCh(sortedInd);
correctedChAbs = 1:numel(headstageCh);
correctedChAbs = correctedChAbs(sortedInd);
nChan = numel(correctedChAbs);
% CONFIGURATION
conf.headstageConf = headstageConf;
conf.adaptorConf = adaptorOutConf;
if ~adaptorFlip
if strcmp(headstage, 'top')
conf.adaptorConf.probeEndIn = adaptorInConf.probeEndIn;
elseif strcmp(headstage, 'bottom')
conf.adaptorConf.headstageEndIn = adaptorInConf.headstageEndIn;
end
else
if strcmp(headstage, 'top')
conf.adaptorConf.headstageEndIn = adaptorInConf.headstageEndIn;
elseif strcmp(headstage, 'bottom')
conf.adaptorConf.probeEndIn = adaptorInConf.probeEndIn;
end
end
conf.probeConf = probeInConf;
conf.probeConf.out = probeOutConf.out;
if size(chCoords,2) == 2
conf.probeConf.xcoords = torow(chCoords(:,1));
conf.probeConf.ycoords = torow(chCoords(:,2));
elseif size(chCoords,2) == 1
conf.probeConf.ycoords = torow(chCoords);
else
error('Erroneous probe recording site coordinates');
end