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

vb_plot_bad_trials2

PURPOSE ^

Candidate trials for rejection are plotted for confirmation by human visual

SYNOPSIS ^

function tr_bad = vb_plot_bad_trials2(data,ix_tr,flg, varargin)

DESCRIPTION ^

 Candidate trials 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    tr_bad = vb_plot_bad_trials2(data,ix_tr,flg, varargin)
0002 % Candidate trials 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_tr),1);
0037 [flgsumsort,jx_tr_sort]=sort(flgsum(:),1,'descend');
0038 ix_tr_sort = ix_tr(jx_tr_sort);
0039 
0040 y = data(:,:,ix_tr_sort);
0041 ntr = length(ix_tr);
0042 pannel_rej = [];
0043 
0044 %------------------
0045 % set up the figure
0046 % -----------------
0047 column =ceil(sqrt( ntr ))+1;
0048 rows = ceil(ntr/column);
0049 
0050 hfig = figure('name', [ 'Trial 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 tr = 1 : ntr
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(tr) = axes('Units','Normalized', 'Position',[X Y sizewx sizewy].*s+q);
0082     plot([1:TSTEP:size(y,2)],squeeze(y(:,1:TSTEP:end,tr)'))
0083     set_axis
0084     axis([-inf inf ylimits]);
0085     axis on
0086 
0087 
0088     % set buttondownfcn on the axis
0089     %-----------------------------------
0090     set(haxes(tr),'buttondownfcn', @rej_callback_axisbuttondwn,...
0091         'color', get(hfig,'color'),'xcolor','w','ycolor','w');
0092 %     if tr ~= ntr
0093 %         set(haxes(tr),'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(tr),'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(tr) = uicontrol(hfig, 'Style', 'checkbox', 'Units','Normalized', 'Position',...
0105         [X Y+sizewy sizewx sizewy*0.25].*s+q, 'value', 1, 'String', ['Trial' num2str(label(ix_tr_sort(tr)))], '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''); pannel_rej = [];' );
0115 hok = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'OK', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0116         'Position',[90 -10  15 sizewy*0.25].*s+q, 'callback',  @rej_callback_mainokbutton);
0117 hall = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'ALL OFF', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0118         'Position',[70 -10  15 sizewy*0.25].*s+q, 'callback', @rej_callback_allbutton);
0119     
0120 fprintf('press any keys \n');
0121 pause
0122 
0123 tr_bad = ix_tr_sort(pannel_rej);
0124 
0125 
0126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0127 % Nested function
0128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0129     % After clicking checkbox
0130     function rej_callback_checkbox(hObject,eventdata)
0131        
0132     end
0133     % After pushing 'All off' button
0134     function rej_callback_allbutton(hObject,eventdata)
0135          for ii = 1 : length(hcheck)
0136             set(hcheck(ii),'value',0);
0137          end
0138     end
0139     % After pushing OK, this function returns indicies of checked axis.
0140     function rej_callback_mainokbutton(hObject,eventdata)      
0141         % value of checkbox --> index rejected
0142         pannel_rej = [];
0143         for ii = 1 : length(hcheck)
0144             val = get(hcheck(ii),'value');
0145             if val == 1
0146                 pannel_rej = [pannel_rej ii];
0147             end
0148         end
0149         close(hfig);
0150         figures = findobj('Tag', 'vb_plot_bad_trials2_detail');
0151         for k=1:length(figures)
0152             h_detail = figures(k);
0153             if ishandle(h_detail) ~= -1
0154                 close(h_detail);
0155             end
0156         end
0157     end
0158 
0159     % After clicking axis.
0160     function rej_callback_axisbuttondwn(hObject,eventdata)
0161     
0162         hcurraxes = hObject;
0163         pannel_ind = find(haxes == hcurraxes);
0164         ytmp = squeeze(y(:,:,pannel_ind)); % Nch*Nt
0165         
0166         h = figure;
0167         set(h, 'Tag', 'vb_plot_bad_trials2_detail');
0168 
0169         plot(ytmp');
0170         title(['Trial= ' num2str(label(ix_tr_sort(pannel_ind)))])
0171         xlabel('time points')
0172         ylabel('amplitude')
0173     end
0174 
0175 
0176 end

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