Home > vbmeg > functions > job > trial_rejection > vb_plot_bad_channels2.m

vb_plot_bad_channels2

PURPOSE ^

Candidate channels for rejection are plotted for confirmation by human visual

SYNOPSIS ^

function ch_bad = vb_plot_bad_channels2(data,ix_ch,flg, varargin)

DESCRIPTION ^

 Candidate channels for rejection are plotted for confirmation by human visual
 inspection.

 2014/09/19 Okito Yamashita 

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function    ch_bad = vb_plot_bad_channels2(data,ix_ch,flg, varargin)
0002 % Candidate channels for rejection are plotted for confirmation by human visual
0003 % inspection.
0004 %
0005 % 2014/09/19 Okito Yamashita
0006 %
0007 % Copyright (C) 2011, ATR All Rights Reserved.
0008 % License : New BSD License(see VBMEG_LICENSE.txt)
0009 
0010 %------------------------
0011 % Figure properties
0012 %------------------------
0013 PARM = finputcheck(varargin, ...
0014     { 
0015     'BACKCOLOR'         'real'   []      [0 0 0]; ...
0016     'CUIBUTTONCOLOR'    'real'   []    [.8 .8 .8]; ...
0017     'FIGSIZE'           'real'   []   get(0,'monitorpositions')*0.95;...
0018     'TSTEP'             'integer' []     5;....
0019     'label'             'integer' []     [1:size(data,3)];...
0020     'ylimits'            'real'   []     []});
0021 if ischar(PARM)
0022     error(PARM);
0023 end
0024 
0025 BACKCOLOR = PARM.BACKCOLOR;
0026 GUIBUTTONCOLOR   = PARM.CUIBUTTONCOLOR;
0027 FIGSIZE = PARM.FIGSIZE;
0028 TSTEP = PARM.TSTEP;
0029 label = PARM.label;
0030 ylimits = PARM.ylimits;
0031 if isempty(ylimits), ylimits = [-max(abs(data(:))) max(abs(data(:)))]; end
0032 
0033 %----------------------------
0034 % Data of rejection channels
0035 %----------------------------
0036 flgsum=sum(flg(ix_ch,:),2);
0037 [flgsumsort,jx_ch_sort]=sort(flgsum(:),1,'descend');
0038 ix_ch_sort = ix_ch(jx_ch_sort);
0039 
0040 y = data(ix_ch_sort,:,:);
0041 nch = length(ix_ch);
0042 pannel_rej = [];
0043 
0044 %------------------
0045 % set up the figure
0046 % -----------------
0047 column =ceil(sqrt( nch ))+1;
0048 rows = ceil(nch/column);
0049 
0050 hfig = figure('name', [ 'Channel Rejection'], 'tag', 'main', ...
0051     'numbertitle', 'off', 'color', BACKCOLOR, 'windowstyle', 'modal', 'position', FIGSIZE);
0052 set(hfig,'MenuBar', 'none');
0053 incx = 120;
0054 incy = 110;
0055 sizewx = 100/column;
0056 if rows > 2
0057     sizewy = 90/rows;
0058 else
0059     sizewy = 80/rows;
0060 end;
0061 pos = get(gca,'position'); % plot relative to current axes
0062 q = [pos(1) pos(2) 0 0];
0063 s = [pos(3) pos(4) pos(3) pos(4)]./100;
0064 axis off;
0065 
0066 % figure rows and columns
0067 % -----------------------
0068 count = 1;
0069 for ch = 1 : nch
0070     % compute coordinates
0071     X = mod(count-1, column)/column * incx-10;
0072     Y = (rows-floor((count-1)/column))/rows * incy - sizewy*1.3;
0073 
0074     if ~strcmp(get(gcf, 'tag'), 'main');
0075         disp('Aborting plot');
0076         return;
0077     end;
0078 
0079     % Plot channel timeseries
0080     % ---------------------------
0081     haxes(ch) = axes('Units','Normalized', 'Position',[X Y sizewx sizewy].*s+q);
0082     plot([1:TSTEP:size(y,2)],squeeze(y(ch,1:TSTEP:end,:)))
0083     set_axis
0084     axis([-inf inf ylimits]);
0085     axis on
0086 
0087 
0088     % set buttondownfcn on the axis
0089     %-----------------------------------
0090     set(haxes(ch),'buttondownfcn', @rej_callback_axisbuttondwn,...
0091         'color', get(hfig,'color'),'xcolor','w','ycolor','w');
0092 %     if ch ~= nch
0093 %         set(haxes(ch),'xtick',[],'xticklabel', [], 'ytick',[],'yticklabel', []);
0094 %     end
0095     % inactivate hittest for children of the axis
0096     % this makes it possible to detect mouse click on any places on the axis
0097     hc = get(haxes(ch),'children');
0098     for cc = 1 : length(hc), set(hc(cc),'Hittest', 'off'); end
0099 
0100 
0101     % plot the button
0102     % change axis color for possibly rejected trials
0103     %-----------------------------------------------
0104     hcheck(ch) = uicontrol(hfig, 'Style', 'checkbox', 'Units','Normalized', 'Position',...
0105         [X Y+sizewy sizewx sizewy*0.25].*s+q, 'value', 1, 'String', ['Ch' num2str(label(ix_ch_sort(ch)))], 'callback', @rej_callback_checkbox);
0106 
0107     drawnow;
0108     count = count +1;
0109 end;
0110 
0111 % draw the bottom button
0112 % ----------------------
0113 hcancel = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'Cancel', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0114         'Position',[50 -10  15 sizewy*0.25].*s+q, 'callback', 'close(gcf); fprintf(''Operation cancelled\n'')' );
0115 
0116 hok = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'OK', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0117         'Position',[90 -10  15 sizewy*0.25].*s+q, 'callback',  @rej_callback_mainokbutton);
0118 
0119 hall = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'ALL OFF', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0120         'Position',[70 -10  15 sizewy*0.25].*s+q, 'callback', @rej_callback_allbutton);
0121 
0122 fprintf('press any keys \n');
0123 pause
0124 
0125 ch_bad = ix_ch_sort(pannel_rej);
0126 
0127 
0128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0129 % Nested function
0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131     % After clicking checkbox
0132     function rej_callback_checkbox(hObject,eventdata)
0133        
0134     end
0135     % After pushing 'All off' button
0136     function rej_callback_allbutton(hObject,eventdata)
0137         for ii = 1 : length(hcheck)
0138             set(hcheck(ii),'value',0);
0139         end
0140     end
0141     % After pushing OK, this function returns indicies of checked axis.
0142     function rej_callback_mainokbutton(hObject,eventdata)      
0143         % value of checkbox --> index rejected
0144         pannel_rej = [];
0145         for ii = 1 : length(hcheck)
0146             val = get(hcheck(ii),'value');
0147             if val == 1
0148                 pannel_rej = [pannel_rej ii];
0149             end
0150         end
0151         close(hfig);
0152         figures = findobj('Tag', 'vb_plot_bad_channels2_detail');
0153         for k=1:length(figures)
0154             h_detail = figures(k);
0155             if ishandle(h_detail) ~= -1
0156                 close(h_detail);
0157             end
0158         end
0159     end
0160 
0161     % After clicking axis.
0162     function rej_callback_axisbuttondwn(hObject,eventdata)
0163     
0164         hcurraxes = hObject;
0165         pannel_ind = find(haxes == hcurraxes);
0166         ytmp = squeeze(y(pannel_ind,:,:)); % Nt*Ntrial
0167         
0168         h = figure;
0169         set(h, 'Tag', 'vb_plot_bad_channels2_detail');
0170         plot(ytmp(:));
0171         title(['Ch= ' num2str(label(ix_ch_sort(pannel_ind)))])
0172         xlabel('time points')
0173         ylabel('amplitude')
0174     end
0175 
0176 
0177 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005