0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 function sig_topo(GND_GRP_specGND_or_fname,test_id,varargin)
0083
0084 p=inputParser;
0085 p.addRequired('GND_GRP_specGND_or_fname',@(x) ischar(x) || isstruct(x));
0086 p.addRequired('test_id',@(x) isnumeric(x) && (length(x)==1));
0087 p.addParamValue('units','t',@ischar);
0088 p.addParamValue('fig_id',[],@(x) isnumeric(x) && (length(x)==1));
0089 p.addParamValue('title_on',1,@(x) isnumeric(x) && (length(x)==1));
0090 p.addParamValue('one_scale',[],@(x) isnumeric(x) && (length(x)==1));
0091 p.addParamValue('verblevel',[],@(x) isnumeric(x) && (length(x)==1));
0092 p.addParamValue('scale_limits',[],@(x) isnumeric(x) && (length(x)==2));
0093
0094 p.parse(GND_GRP_specGND_or_fname,test_id,varargin{:});
0095
0096
0097 if isempty(p.Results.verblevel),
0098 VERBLEVEL=2;
0099 else
0100 VERBLEVEL=p.Results.verblevel;
0101 end
0102
0103 if ~(strcmpi(p.Results.units,'t') || strcmpi(p.Results.units,'uV') || strcmpi(p.Results.units,'dB'))
0104 error('Value of optional input ''units'' must be ''t'', ''uV'', or ''dB''.');
0105 end
0106
0107
0108 if ischar(GND_GRP_specGND_or_fname),
0109 fprintf('Loading GND, GRP, or specGND struct variable from file %s.\n',GND_GRP_specGND_or_fname);
0110 load(GND_GRP_specGND_or_fname,'-MAT');
0111 if ~exist('GND','var') && ~exist('GRP','var') && ~exist('specGND','var')
0112 error('File %s does not contain a GND, GRP, or specGND variable.',GND_GRP_specGND_or_fname);
0113 end
0114 if exist('GRP','var'),
0115 GND=GRP;
0116 clear GRP;
0117 elseif exist('specGND','var'),
0118 GND=specGND;
0119 clear specGND;
0120 end
0121 VerbReport(sprintf('Experiment: %s',GND.exp_desc),2,VERBLEVEL);
0122 else
0123 GND=GND_GRP_specGND_or_fname;
0124 clear GND_GRP_specGND_or_fname;
0125 end
0126
0127 n_test=length(GND.t_tests);
0128 if test_id>n_test,
0129 error('There are only %d t-tests stored with these data, but you requested Test #%d',n_test,test_id);
0130 end
0131
0132 if isfield(GND.t_tests(1),'freq_band')
0133
0134
0135 GND.t_tests(test_id).time_wind=GND.t_tests(test_id).freq_band;
0136 GND.t_tests(test_id).mean_wind=GND.t_tests(test_id).mean_band;
0137 GND.t_tests(test_id).used_tpt_ids=GND.t_tests(test_id).used_freq_ids;
0138 GND.grands_t=GND.grands_pow_dB_t;
0139 GND.grands=GND.grands_pow_dB;
0140 freq_step=GND.freqs(2)-GND.freqs(1);
0141 freq_ord=orderofmag(freq_step);
0142 ord_pow=log10(freq_ord);
0143 if ord_pow>=0,
0144 n_dig_past_dot=0;
0145 else
0146 n_dig_past_dot=-ord_pow;
0147 end
0148 GND.time_pts=rnd_orderofmag(GND.freqs);
0149 freq_domain=1;
0150 if strcmpi(p.Results.units,'uV'),
0151 watchit('You can''t plot spectral power topographies in units of microvolts. They will be plot in decibels (i.e., 10*log10((uV^2)/Hz))) instead.');
0152 end
0153 else
0154 freq_domain=0;
0155 if strcmpi(p.Results.units,'dB'),
0156 watchit('You can''t plot ERP topographies in units of decibels. They will be plot in microvolts instead.');
0157 end
0158 end
0159
0160 if ~strcmpi(GND.t_tests(test_id).mean_wind,'yes'),
0161 error('sig_topo.m only works for significance tests applied to data averaged across multiple time points.');
0162 end
0163
0164 n_topos=length(GND.t_tests(test_id).used_tpt_ids);
0165 wdth=floor(sqrt(n_topos));
0166 ht=ceil(n_topos/wdth);
0167
0168 bin=GND.t_tests(test_id).bin;
0169 chans=GND.t_tests(test_id).used_chan_ids;
0170 if length(chans)<3,
0171 watchit('sig_topo.m cannot plot scalp topographies with less than 3 electrodes.');
0172 return
0173 end
0174 if isempty(p.Results.fig_id)
0175 fig_h=figure;
0176 else
0177 fig_h=figure(p.Results.fig_id); clf;
0178 end
0179 if isfield(GND,'bin_info'),
0180 set(fig_h,'name',['Bin ' int2str(bin) ' [' GND.bin_info(bin).bindesc ']'],'paperpositionmode','auto');
0181 else
0182 set(fig_h,'name',['Bin ' int2str(bin) ' [' GND.bindesc{bin} ']'],'paperpositionmode','auto');
0183 end
0184
0185
0186
0187
0188 if strcmpi(p.Results.units,'uV') || strcmpi(p.Results.units,'dB') ,
0189 if freq_domain,
0190 units='dB';
0191 else
0192 units='\muV';
0193 end
0194
0195 mns=zeros(length(chans),n_topos);
0196 for w=1:n_topos,
0197 mns(:,w)=mean(GND.grands(chans,GND.t_tests(test_id).used_tpt_ids{w},bin),2);
0198 end
0199 if ~isempty(p.Results.scale_limits)
0200 one_scale=1;
0201 maplimits=p.Results.scale_limits;
0202 VerbReport(sprintf('Using color scale limits of: %f to %f',maplimits(1),maplimits(2)),2,VERBLEVEL);
0203 VerbReport(sprintf('All topographies will have the same color scale.'),2,VERBLEVEL);
0204 elseif isempty(p.Results.one_scale) || (p.Results.one_scale<=0),
0205 one_scale=0;
0206 maplimits='absmax';
0207 else
0208 one_scale=1;
0209 mx=max(max(abs(mns)));
0210 maplimits=[-1 1]*mx;
0211 end
0212 else
0213 units='t';
0214 if ~isempty(p.Results.scale_limits)
0215 one_scale=1;
0216 maplimits=p.Results.scale_limits;
0217 VerbReport(sprintf('Using color scale limits of: %f to %f',maplimits(1),maplimits(2)),2,VERBLEVEL);
0218 VerbReport(sprintf('All topographies will have the same color scale.'),2,VERBLEVEL);
0219 elseif isempty(p.Results.one_scale) || (p.Results.one_scale>0),
0220 one_scale=1;
0221 mx=max(max(abs(GND.t_tests(test_id).data_t)));
0222 maplimits=[-1 1]*mx;
0223 else
0224 one_scale=0;
0225 maplimits='absmax';
0226 end
0227 end
0228
0229 if VERBLEVEL,
0230 if isnan(GND.t_tests(test_id).n_perm),
0231 fprintf('q level of critical t-scores: %f., FDR method: %s\n', ...
0232 GND.t_tests(test_id).desired_alphaORq,GND.t_tests(test_id).mult_comp_method);
0233 else
0234 fprintf('Estimated alpha level of critical t-scores: %f.\n', ...
0235 GND.t_tests(test_id).estimated_alpha);
0236 end
0237 end
0238
0239 for a=1:n_topos,
0240 subplot(ht,wdth,a);
0241 time_wind=GND.t_tests(test_id).time_wind(a,:);
0242 if strcmpi(p.Results.units,'uV') || strcmpi(p.Results.units,'dB') ,
0243 mn=mns(:,a);
0244 else
0245 mn=GND.t_tests(test_id).data_t(:,a);
0246 end
0247
0248 if isnan(GND.t_tests(test_id).n_perm),
0249 sig_chans=find(GND.t_tests(test_id).fdr_rej(:,a));
0250 else
0251 sig_chans=find(GND.t_tests(test_id).adj_pval(:,a)<GND.t_tests(test_id).estimated_alpha);
0252 end
0253 topoplotMK(mn,GND.chanlocs(chans),'emarker2',{sig_chans,'o',[1 1 1],4}, ...
0254 'maplimits',maplimits);
0255 if freq_domain,
0256 lab_form=['%.' int2str(n_dig_past_dot) 'f-%.' int2str(n_dig_past_dot) 'f Hz'];
0257 else
0258 lab_form='%d-%d ms';
0259 end
0260
0261 hh=title(sprintf(lab_form,time_wind(1),time_wind(2)));
0262 if ~one_scale,
0263 hcb=colorbar;
0264 hy=ylabel(hcb,units);
0265 set(hy,'rotation',0,'verticalalignment','middle','position',[4.9+n_topos*.2 0.03 1.0001]);
0266 end
0267 end
0268
0269 if one_scale,
0270 hcb=cbar_nudge('vert',0,maplimits);
0271 hy=ylabel(hcb,units);
0272 set(hy,'rotation',0,'verticalalignment','middle');
0273 end
0274
0275
0276 if p.Results.title_on,
0277 if isfield(GND,'bin_info'),
0278 h=textsc(['Bin ' int2str(bin) ': ' GND.bin_info(bin).bindesc],'title');
0279 else
0280 h=textsc(['Bin ' int2str(bin) ': ' GND.bindesc{bin}],'title');
0281 end
0282 set(h,'fontsize',14,'fontweight','bold');
0283 if ~verLessThan('matlab','8')
0284 set(h,'position',[.5 .975 0]);
0285 end
0286 end
0287
0288
0289
0290
0291
0292
0293 function [handle]=cbar_nudge(arg,colors,minmax, grad)
0294
0295 if nargin < 2
0296 colors = 0;
0297 end
0298 posscale = 'off';
0299 if nargin < 1
0300 arg = 'vert';
0301 ax = [];
0302 else
0303 if isempty(arg)
0304 arg = 0;
0305 end
0306 if arg(1) == 0
0307 ax = [];
0308 arg = 'vert';
0309 elseif strcmpi(arg, 'pos')
0310 ax = [];
0311 arg = 'vert';
0312 posscale = 'on';
0313 else
0314 if isstr(arg)
0315 ax = [];
0316 else
0317 ax = arg;
0318 arg = [];
0319 end
0320 end
0321 end
0322
0323 if nargin>2
0324 if size(minmax,1) ~= 1 | size(minmax,2) ~= 2
0325 help cbar
0326 fprintf('cbar() : minmax arg must be [min,max]\n');
0327 return
0328 end
0329 end
0330 if nargin < 4
0331 grad = 5;
0332 end;
0333
0334
0335
0336
0337
0338
0339 if (length(colors) == 1) & (colors == 0)
0340 t = caxis;
0341 else
0342 t = [0 1];
0343 end
0344 if ~isempty(arg)
0345 if strcmp(arg,'vert')
0346 cax = gca;
0347 pos = get(cax,'Position');
0348 stripe = 0.04;
0349 edge = 0.01;
0350 space = -.02;
0351
0352 set(cax,'Position',[pos(1) pos(2) pos(3) pos(4)])
0353 rect = [pos(1)+pos(3)+space pos(2) stripe*pos(3) pos(4)];
0354 ax = axes('Position', rect);
0355 elseif strcmp(arg,'horiz')
0356 cax = gca;
0357 pos = get(cax,'Position');
0358 stripe = 0.075;
0359 space = .1;
0360 set(cax,'Position',...
0361 [pos(1) pos(2)+(stripe+space)*pos(4) pos(3) (1-stripe-space)*pos(4)])
0362 rect = [pos(1) pos(2) pos(3) stripe*pos(4)];
0363 ax = axes('Position', rect);
0364 end
0365 else
0366 pos = get(ax,'Position');
0367 if pos(3) > pos(4)
0368 arg = 'horiz';
0369 else
0370 arg = 'vert';
0371 end
0372 end
0373
0374
0375
0376
0377
0378 map = colormap;
0379 n = size(map,1);
0380
0381 if length(colors) == 1
0382 if strcmp(arg,'vert')
0383 if strcmpi(posscale, 'on')
0384 image([0 1],[0 t(2)],[ceil(n/2):n-colors]');
0385 else
0386 image([0 1],t,[1:n-colors]');
0387 end;
0388 set(ax,'xticklabelmode','manual')
0389 set(ax,'xticklabel',[],'YAxisLocation','right')
0390
0391 else
0392 image(t,[0 1],[1:n-colors]);
0393 set(ax,'yticklabelmode','manual')
0394 set(ax,'yticklabel',[],'YAxisLocation','right')
0395 end
0396 set(ax,'Ydir','normal','YAxisLocation','right')
0397
0398 else
0399
0400 if max(colors) > n
0401 error('Color vector excedes size of colormap')
0402 end
0403 if strcmp(arg,'vert')
0404 image([0 1],t,[colors]');
0405 set(ax,'xticklabelmode','manual')
0406 set(ax,'xticklabel',[])
0407 else
0408 image([0 1],t,[colors]);
0409 set(ax,'yticklabelmode','manual')
0410 set(ax,'yticklabel',[],'YAxisLocation','right')
0411 end
0412 set(ax,'Ydir','normal','YAxisLocation','right')
0413 end
0414
0415
0416
0417
0418
0419 if nargin > 2
0420 if strcmp(arg,'vert')
0421 Cax = get(ax,'Ylim');
0422 else
0423 Cax = get(ax,'Xlim');
0424 end;
0425 CBTicks = [Cax(1):(Cax(2)-Cax(1))/(grad-1):Cax(2)];
0426 CBLabels = [minmax(1):(minmax(2)-minmax(1))/(grad-1):minmax(2)];
0427
0428 dec = floor(log10(max(abs(minmax))));
0429 CBLabels = ([minmax]* [ linspace(1,0, grad);linspace(0, 1, grad)]);
0430 if dec<1
0431 CBLabels = round(CBLabels*10^(1-dec))*10^(dec-1);
0432 elseif dec == 1
0433 CBLabels = round(CBLabels*10^(2-dec))*10^(dec-2);
0434 else
0435 CBLabels = round(CBLabels);
0436 end
0437
0438 if strcmp(arg,'vert')
0439 set(ax,'Ytick',CBTicks);
0440 set(ax,'Yticklabel',CBLabels);
0441 else
0442 set(ax,'Xtick',CBTicks);
0443 set(ax,'Xticklabel',CBLabels);
0444 end
0445 end
0446 handle = ax;
0447
0448
0449
0450
0451
0452 set(ax,'tag','cbar')