[422372]: / functions / miscfunc / compmap.m

Download this file

299 lines (272 with data), 9.8 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
% COMPMAP - Plot multiple TOPOPLOT maps of ICA component topographies
% Click on an individual map to view separately.
% Usage:
% >> compmap (winv,'eloc_file',compnos,'title',rowscols,labels,printflag)
%
% Inputs:
% winv - Inverse weight matrix = EEG scalp maps. Each column is a
% map; the rows correspond to the electrode positions
% defined in the eloc_file. Normally, winv = inv(weights*sphere).
% 'eloc_file' - Name of the eloctrode position file in the style defined
% by >> topoplot example {default|0 ->'chan_file'}
% compnos - Vector telling which (order of) component maps to show
% Indices <0 tell compmap to invert a map; = 0 leave blank sbplot
% Example [1 0 -2 3 0 -6] {default|0 -> 1:columns_in_winv}
% 'title' - Title string for each page {default|0 -> 'ICA Component Maps'}
% rowscols - Vector of the form [m,n] where m is total vertical tiles and n
% is horizontal tiles per page. If the number of maps exceeds m*n,
% multiple figures will be produced {def|0 -> one near-square page}.
% labels - Vector of numbers or a matrix of strings to use as labels for
% each map, else ' ' -> no labels {default|0 -> 1:ncolumns_in_winv}
% printflag - 0= screen-plot colors {default}
% 1= printer-plot colors
%
% Note: Map scaling is to +/-max(abs(data); green = 0
%
% Author: Colin Humphries, CNL / Salk Institute, Aug, 1996
%
% See also: TOPOPLOT
% This function calls TOPOPLOT. and CBAR.
% Copyright (C) Colin Humphries & Scott Makeig, CNL / Salk Institute, Aug, 1996
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
% Colin Humphries, CNL / Salk Institute, Aug, 1996
% 03-97 revised -CH
% 11-05-97 revised for Matlab 5.0.0.4064; added negative compnnos option
% improved help msg; added figure offsets -Scott Makeig & CH
% 11-13-97 fixed compnos<0 bug -sm
% 11-18-97 added test for labels=comps -sm
% 12-08-97 added test for COLORBAR_TP -sm
% 12-15-97 added axis('square'), see SQUARE below -sm
% 03-09-98 added test for eloc_file, fixed size checking for labels -sm
% 02-09-00 added test for ' ' for srclabels(1,1) -sm
% 02-23-00 added srclabels==' ' -> no labels -sm
% 03-16-00 added AXCOPY -sm & tpj
% 02-25-01 added test for max(compnos) -sm
% 05-24-01 added HEADPLOT logical flag below -sm
% 01-25-02 reformated help & license -ad
% NOTE:
% There is a minor problem with the Matlab function COLORBAR.
% Use the toolbox CBAR instead.
function compmap(Winv,eloc_file,compnos,titleval,pagesize,srclabels,printlabel,caxis)
DEFAULT_TITLE = 'ICA Component Maps';
DEFAULT_EFILE = 'chan_file';
NUMCONTOUR = 5; % topoplot() style settings
OUTPUT = 'screen'; % default: 'screen' for screen colors,
% 'printer' for printer colors
STYLE = 'both';
INTERPLIMITS = 'head';
MAPLIMITS = 'absmax';
SQUARE = 1; % 1/0 flag making topoplot() asex square -> round heads
ELECTRODES = 'on'; % default: 'on' or 'off'
ELECTRODESIZE = []; % defaults 1-10 set in topoplot text.
HEADPLOT = 0; % 1/0 plot 3-D headplots instead of 2-d topoplots.
if nargin<1
help compmap
return
end
curaxes = gca;
curpos = get(curaxes,'Position');
mapaxes = axes('Position',[curpos(1) curpos(2)+0.09 curpos(3) curpos(4)-0.09],...
'Visible','off');
% leave room for cbar
set(mapaxes,'visible','off');
pos = get(mapaxes,'Position');
% delete(gca);
% ax = axes('Position',pos);
[chans, frames] = size (Winv);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check inputs and set defaults
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin==8
if strcmp(caxis(1,1:2), 'mi') % min/max of data
MAPLIMITS = [min(min(Winv(:,compnos))) max(max(Winv(:,compnos)))];
elseif caxis(1,1:2) == 'ab' % +/-max abs data
absmax = max([abs(min(min(Winv(:,compnos)))) abs(max(max(Winv(:,compnos))))]);
MAPLIMITS = [-absmax absmax];
elseif size(caxis) == [1,2] % given color axis limits
MAPLIMITS = caxis;
end % else default
end
if nargin < 7
printlabel = 0;
end
if printlabel == 0
printlabel = OUTPUT; % default set above
else
printlabel = 'printer';
end
if nargin < 6
srclabels = 0;
end
if nargin < 5
pagesize = 0;
end
if nargin < 4
titleval = 0;
end
if nargin < 3
compnos = 0;
end
if nargin < 2
eloc_file = 0;
end
if srclabels == 0
srclabels = [];
end
if titleval == 0;
titleval = DEFAULT_TITLE;
end
if compnos == 0
compnos = (1:frames);
end
if max(compnos)>frames
fprintf('compmap(): Cannot show comp %d. Only %d components in inverse weights\n',...
max(compnos),frames);
return
end
if pagesize == 0
numsources = length(compnos);
DEFAULT_PAGE_SIZE = ...
[floor(sqrt(numsources)) ceil(numsources/floor(sqrt(numsources)))];
m = DEFAULT_PAGE_SIZE(1);
n = DEFAULT_PAGE_SIZE(2);
elseif length(pagesize) ==1
help compmap
return
else
m = pagesize(1);
n = pagesize(2);
end
if eloc_file == 0
eloc_file = DEFAULT_EFILE;
end
totalsources = length(compnos);
if ~isempty(srclabels)
if ~ischar(srclabels(1,1)) || srclabels(1,1)==' ' % if numbers
if size(srclabels,1) == 1
srclabels = srclabels';
end
end
if size(srclabels,1)==1 && size(srclabels,2)==1 && srclabels==' '
srclabels = repmat(srclabels,totalsources,1);
end
if size(srclabels,1) ~= totalsources,
fprintf('compmap(): numbers of components and component labels do not agree.\n');
return
end
end
pages = ceil(totalsources/(m*n));
if pages > 1
fprintf('compmap(): will create %d figures of %d by %d maps: ',...
pages,m,n);
end
off = [ 25 -25 0 0]; % position offsets for multiple figures
fid = fopen(eloc_file);
if fid<1,
fprintf('compmap()^G: cannot open eloc_file (%s).\n',eloc_file);
return
end
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plot the maps %%%%%%%%%%%%%%%%%%%%%%%
for i = (1:pages)
if i > 1
figure('Position',pos+(i-1)*off); % place figures in right-downward stack
set(gca,'Color','w') %CJH - set background color to white
curaxes = gca;
curpos = get(curaxes,'Position'); % new whole-figure axes
end
if (totalsources > i*m*n)
sbreak = n*m;
else
sbreak = totalsources - (i-1)*m*n; % change page/figure after this many
end
for j = (1:sbreak) % maps on this page/figure
comp = j+(i-1)*m*n; % compno index
if compnos(comp)~=0
if compnos(comp)>0
source_var = Winv(:,compnos(comp))'; % plot map
elseif compnos(comp)<0
source_var = -1*Winv(:,-1*compnos(comp))'; % invert map
end
sbplot(m,n,j,'ax',mapaxes);
if HEADPLOT
headplot(source_var,eloc_file,'electrodes','off'); % 3-d image
else
topoplot(source_var,eloc_file,...
'style',STYLE,...
'electrodes',ELECTRODES,...
'emarkersize',ELECTRODESIZE,...
'numcontour',NUMCONTOUR,...
'interplimits',INTERPLIMITS,...
'maplimits',MAPLIMITS); % draw 2-d scalp map
end
if SQUARE,
axis('square');
end
if isempty(srclabels)
title(int2str(compnos(comp))) ;
else
if ischar(srclabels)
title(srclabels(comp,:));
else
title(num2str(srclabels(comp)));
end
end
drawnow % draw one map at a time
end
end
% ax = axes('Units','Normal','Position',[.5 .06 .32 .05],'Visible','Off');
axes(curaxes);
set(gca,'Visible','off','Units','normalized');
curpos = get(gca,'position');
ax = axes('Units','Normalized','Position',...
[curpos(1)+0.5*curpos(3) curpos(2)+0.01*curpos(4) ...
0.32*curpos(3) 0.05*curpos(4)],'Visible','Off');
if exist('cbar') == 2
cbar(ax); % Slightly altered Matlab colorbar()
% Write authors for further information.
else
colorbar(ax); % Note: there is a minor problem with this call.
end
axval = axis;
Xlim = get(ax,'Xlim');
set(ax,'XTick',(Xlim(2)+Xlim(1))/2);
set(ax,'XTickMode','manual');
set(ax,'XTickLabelMode','manual');
set(ax,'XTickLabel','0');
axes(curaxes);
axis off;
% axbig = axes('Units','Normalized','Position',[0 0 1 1],'Visible','off');
t1 = text(.25,.07,titleval,'HorizontalAlignment','center');
if pages > 1
fprintf('%d ',i);
end
axcopy(gcf); % allow popup window of single map with mouse click
end
if pages > 1
fprintf('\n');
end