Home > matlabmk > set_ic_ftr_thresh.m

set_ic_ftr_thresh

PURPOSE ^

set_ic_ftr_thresh() - Generates GUI for objectively rejecting ICs

SYNOPSIS ^

function set_ic_ftr_thresh(command_str)

DESCRIPTION ^

 set_ic_ftr_thresh() - Generates GUI for objectively rejecting ICs 
                       according to various features. Run GUI and click on
                       "Help" button for further info.
              
 Usage:
  >> set_ic_ftr_thresh(command_str)

 Optional Input:
   command_str - One of the following possible strings:
                    'initialize': Creates the GUI {default}
                    'refresh': Updates GUI using whatever is currently 
                         stored in global EEG variable
                    'load data': Loads set file from disk
                    'new feature': Updates the GUI when a new feature has
                         been selected
                    'new threshold': Updates the GUI when the rejection 
                         threshold is changed
                    'save changes': Saves the EEG variable to disk 
                    'disable': Disable feature and threshold elements of
                         the GUI (e.g., when there's an error loading a file).


 IC Features:
                                 **TOPOGRAPHY FEATURES**
               1. Blink Topo: Absolute cosine similarity to prototypical 
                  blink topography. Takes a value between 0 and 1 with 1 being 
                  identical to the blink topography prototype.
               2. Horz EOG Topo: Absolute cosine similarity to prototypical
                  horizontal eye movement topography: Takes a value between 0   
                  and 1, with 1 being identical to the horizontal eye movement 
                  topography prototype.
               3. Heart Topo: Absolute cosine similarity to prototypical 
                  heart artifact topography: Takes a value between 0 and 1  
                  with 1 being identical to the heart artifact topography 
                  prototype.
               4. Extrm Topo Wt: The proportion of a topography's length
                  accounted for by a single channel. This feature takes a
                  value between 1/n and 1, where n is the number of
                  channels. A value of 1 means that the IC's topography is
                  zero at all electrodes save one. This feature tends to
                  be large for ICs that correspond to a bad channel (e.g.,
                  an electrode that changed impedence during the
                  experiment) or EMG ICs.
                                                

                                 **ACTIVATION SPECTRUM FEATURES**
               5. EMG Spectra: Mean spectral power between 25-55 Hz minus
                  mean spectral power between 0-17 Hz. This feature is
                  large for ICs composed primarily of EMG. Spectral power
                  is first transformed to t-scores to normalize this
                  feature across participants.
               6. EOG Spectra: Mean spectral power between 0-6 Hz minus
                  mean spectral power between 8-18 Hz. This feature is           
                  large for ICs composed primarily of EOG. Spectral power 
                  is first transformed to t-scores to normalize this 
                  feature across participants.

                                 **ACTIVATION MAGNITUDE FEATURE**
               7. Act Std Dev: Mean standard deviation at each time point ("mn_std"):
                  This feature is large for ICs characterized by highly
                  variable activations (typically due to blinks, eye
                  movements, or extreme EMG).  Only computable for epoched
                  data.


 Author: 
 David Groppe
 Kutaslab, 12/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function set_ic_ftr_thresh(command_str)
0002 % set_ic_ftr_thresh() - Generates GUI for objectively rejecting ICs
0003 %                       according to various features. Run GUI and click on
0004 %                       "Help" button for further info.
0005 %
0006 % Usage:
0007 %  >> set_ic_ftr_thresh(command_str)
0008 %
0009 % Optional Input:
0010 %   command_str - One of the following possible strings:
0011 %                    'initialize': Creates the GUI {default}
0012 %                    'refresh': Updates GUI using whatever is currently
0013 %                         stored in global EEG variable
0014 %                    'load data': Loads set file from disk
0015 %                    'new feature': Updates the GUI when a new feature has
0016 %                         been selected
0017 %                    'new threshold': Updates the GUI when the rejection
0018 %                         threshold is changed
0019 %                    'save changes': Saves the EEG variable to disk
0020 %                    'disable': Disable feature and threshold elements of
0021 %                         the GUI (e.g., when there's an error loading a file).
0022 %
0023 %
0024 % IC Features:
0025 %                                 **TOPOGRAPHY FEATURES**
0026 %               1. Blink Topo: Absolute cosine similarity to prototypical
0027 %                  blink topography. Takes a value between 0 and 1 with 1 being
0028 %                  identical to the blink topography prototype.
0029 %               2. Horz EOG Topo: Absolute cosine similarity to prototypical
0030 %                  horizontal eye movement topography: Takes a value between 0
0031 %                  and 1, with 1 being identical to the horizontal eye movement
0032 %                  topography prototype.
0033 %               3. Heart Topo: Absolute cosine similarity to prototypical
0034 %                  heart artifact topography: Takes a value between 0 and 1
0035 %                  with 1 being identical to the heart artifact topography
0036 %                  prototype.
0037 %               4. Extrm Topo Wt: The proportion of a topography's length
0038 %                  accounted for by a single channel. This feature takes a
0039 %                  value between 1/n and 1, where n is the number of
0040 %                  channels. A value of 1 means that the IC's topography is
0041 %                  zero at all electrodes save one. This feature tends to
0042 %                  be large for ICs that correspond to a bad channel (e.g.,
0043 %                  an electrode that changed impedence during the
0044 %                  experiment) or EMG ICs.
0045 %
0046 %
0047 %                                 **ACTIVATION SPECTRUM FEATURES**
0048 %               5. EMG Spectra: Mean spectral power between 25-55 Hz minus
0049 %                  mean spectral power between 0-17 Hz. This feature is
0050 %                  large for ICs composed primarily of EMG. Spectral power
0051 %                  is first transformed to t-scores to normalize this
0052 %                  feature across participants.
0053 %               6. EOG Spectra: Mean spectral power between 0-6 Hz minus
0054 %                  mean spectral power between 8-18 Hz. This feature is
0055 %                  large for ICs composed primarily of EOG. Spectral power
0056 %                  is first transformed to t-scores to normalize this
0057 %                  feature across participants.
0058 %
0059 %                                 **ACTIVATION MAGNITUDE FEATURE**
0060 %               7. Act Std Dev: Mean standard deviation at each time point ("mn_std"):
0061 %                  This feature is large for ICs characterized by highly
0062 %                  variable activations (typically due to blinks, eye
0063 %                  movements, or extreme EMG).  Only computable for epoched
0064 %                  data.
0065 %
0066 %
0067 % Author:
0068 % David Groppe
0069 % Kutaslab, 12/2009
0070 %
0071 
0072 
0073 %%%%%%%%%%%%%%%% FUTURE ADDITIONS %%%%%%%%%%%%%%%%%
0074 %
0075 % -When you mouse over an IC's data point, display the number of the IC,
0076 % the IC's label, and the IC's value for that feature
0077 
0078 global EEG;
0079 global VERBLEVEL;
0080 
0081 if nargin == 0
0082     command_str = 'initialize';
0083 end
0084 
0085 %% I. Find GUI if already created
0086 if ~strcmpi(command_str,'initialize')
0087     h_fig = gcf;
0088     if ~strcmp(get(h_fig,'tag'),'set_ic_ftr_thresh')
0089         % If the current figure does not have the right
0090         % tag, find the one that does.
0091         h_figs = get(0,'children');
0092         h_fig = findobj(h_figs,'flat',...
0093             'tag','set_ic_ftr_thresh');
0094         if isempty(h_fig)
0095             % If set_ic_ftr_thresh does not exist
0096             % initialize it. Then run the command string
0097             % that was originally requested.
0098             set_ic_ftr_thresh('initialize');
0099             set_ic_ftr_thresh(command_str);
0100             return;
0101         end
0102     end
0103     
0104     % At this point we know that h_fig is the handle
0105     % to the figure containing the GUI of interest to
0106     % this function.
0107    
0108 end
0109 
0110 %% II. Create GUI if not created
0111 if strcmp(command_str,'initialize')
0112     % Make sure that the GUI has not been already
0113     % initialized in another existing figure.
0114     % NOTE THAT THIS GUI INSTANCE CHECK
0115     % INSURES THAT ONLY ONE INSTANCE OF THE GUI IS CREATED
0116     h_figs = get(0,'children');
0117     h_fig = findobj(h_figs,'flat',...
0118         'tag','set_ic_ftr_thresh');
0119     if ~isempty(h_fig)
0120         figure(h_fig(1));
0121         return
0122     end
0123     
0124     h_fig = figure('name','set_ic_ftr_thresh GUI','tag','set_ic_ftr_thresh', ...
0125         'MenuBar','none');
0126     pos=get(h_fig,'position');
0127     %set(h_fig,'position',[pos(1:2) 660 520]);
0128     
0129     clear dat_tmp;
0130 
0131     
0132     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133     %%% II.a Top part of GUI: INPUT FILE %%%
0134     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0135     % Frame
0136     h_frame_top = uicontrol(h_fig,...
0137         'Units','normalized', ...
0138         'Position',[ 0 0.9 1 0.3 ],...
0139         'Style','frame');
0140     frm_col=get(h_frame_top,'backgroundcolor');
0141     
0142     % Create input filename browse button
0143     h_in_fnameB=uicontrol(h_fig,...
0144         'CallBack',['h_in_fname=findobj(gcf,''tag'',''in_fname'');' ...
0145         '[in_fname, in_pathname]=uigetfile(''*.set'',''Select EEGLAB .set data file'');' ...
0146         'if in_fname, ', ...
0147         '  set(h_in_fname,''string'',[in_pathname in_fname]);' ...
0148         '  set_ic_ftr_thresh(''load data''); end;'], ...
0149         'Units','normalized', ...
0150         'Position',[ 0.03 0.92 0.15 0.06 ],...
0151         'String','Input File',...
0152         'ToolTipString','Click to find *.eim file containing EEG and sorting variables', ...
0153         'Style','pushbutton');
0154     
0155     % Create input filename menu
0156     h_in_fname=uicontrol(h_fig,...
0157         'CallBack','set_ic_ftr_thresh(''load data'');',...
0158         'Units','normalized', ...
0159         'Position',[ 0.18 0.92 0.8 0.06 ], ...
0160         'String','None', ...
0161         'Style','edit', ...
0162         'Enable','on', ...
0163         'BackGroundColor','w', ...
0164         'Tag','in_fname');
0165     align([h_in_fnameB h_in_fname],'VerticalAlignment','center');
0166     
0167     
0168     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0169     %%% II.b Left part of GUI: IC features      %%%
0170     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0171     % Frame
0172     h_frame_top = uicontrol(h_fig,...
0173         'Units','normalized', ...
0174         'Position',[ 0 0 .25 0.9 ],...
0175         'Style','frame');
0176     frm_col=get(h_frame_top,'backgroundcolor');
0177     
0178 
0179     % Title
0180     uicontrol(h_fig,...
0181         'Units','normalized', ...
0182         'Position',[ 0.04 0.82 0.18 0.07 ],...
0183         'String','IC Features',...
0184         'FontWeight','bold', ...
0185         'FontSize',14, ...
0186         'HorizontalAlignment','center', ...
0187         'tag','static', ...
0188         'ToolTipString',['Features useful for identifying independent components (ICs) corresponding to artifacts. ', ...
0189         10 'Computed by cmpt_ic_art_ftrs.m.'], ...
0190         'Style','text');
0191     
0192     % Blink topography
0193     h_blink_topo=uicontrol(h_fig,...
0194         'Units','normalized', ...
0195         'CallBack',['tmp=get(gcf,''userdata''); ',...
0196         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0197         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0198         ' set(tmp.h_mn_std,''value'',0); ', ...
0199         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0200         ' set(tmp.h_heart_topo,''value'',0); ', ...
0201         ' set(tmp.h_he_topo,''value'',0); ', ...
0202         ' set(tmp.h_blink_topo,''value'',1); ', ...
0203         ' set_ic_ftr_thresh(''new feature'');'], ...
0204         'Position',[ 0.01 0.78 0.24 0.06 ], ...
0205         'String','Blink Topo', ...
0206         'Style','radiobutton', ...
0207         'Value',0, ...
0208         'FontSize',12, ...
0209         'enable','off', ...
0210         'ToolTipString','Similarity to prototypical blink topography', ...
0211         'HorizontalAlignment','left', ...
0212         'tag','blink_topo');
0213     
0214     % horizontal eye movement topography
0215     h_he_topo=uicontrol(h_fig,...
0216         'Units','normalized', ...
0217         'CallBack',['tmp=get(gcf,''userdata''); ',...
0218         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0219         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0220         ' set(tmp.h_mn_std,''value'',0); ', ...
0221         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0222         ' set(tmp.h_heart_topo,''value'',0); ', ...
0223         ' set(tmp.h_he_topo,''value'',1); ', ...
0224         ' set(tmp.h_blink_topo,''value'',0); ', ...
0225         ' set_ic_ftr_thresh(''new feature'');'], ...
0226         'Position',[ 0.01 0.72 0.24 0.06 ], ...
0227         'String','Horz EOG Topo', ...
0228         'Style','radiobutton', ...
0229         'FontSize',12, ...
0230         'Value',0, ...
0231         'enable','off', ...
0232         'ToolTipString','Similarity to prototypical horizontal eye movement topography', ...
0233         'HorizontalAlignment','left', ...
0234         'tag','he_topo');
0235     
0236     % heart artifact topography
0237     h_heart_topo=uicontrol(h_fig,...
0238         'Units','normalized', ...
0239         'CallBack',['tmp=get(gcf,''userdata''); ',...
0240         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0241         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0242         ' set(tmp.h_mn_std,''value'',0); ', ...
0243         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0244         ' set(tmp.h_heart_topo,''value'',1); ', ...
0245         ' set(tmp.h_he_topo,''value'',0); ', ...
0246         ' set(tmp.h_blink_topo,''value'',0); ', ...
0247         ' set_ic_ftr_thresh(''new feature'');'], ...
0248         'Position',[ 0.01 0.66 0.24 0.06 ], ...
0249         'String','Heart Topo', ...
0250         'Style','radiobutton', ...
0251         'Value',0, ...
0252         'FontSize',12, ...
0253         'enable','off', ...
0254         'ToolTipString','Similarity to prototypical heart artifact topography', ...
0255         'HorizontalAlignment','left', ...
0256         'tag','heart_topo');
0257     
0258     % extreme topography weight
0259     h_xtrm_topo=uicontrol(h_fig,...
0260         'Units','normalized', ...
0261         'CallBack',['tmp=get(gcf,''userdata''); ',...
0262         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0263         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0264         ' set(tmp.h_mn_std,''value'',0); ', ...
0265         ' set(tmp.h_xtrm_topo,''value'',1); ', ...
0266         ' set(tmp.h_heart_topo,''value'',0); ', ...
0267         ' set(tmp.h_he_topo,''value'',0); ', ...
0268         ' set(tmp.h_blink_topo,''value'',0); ', ...
0269         ' set_ic_ftr_thresh(''new feature'');'], ...
0270         'Position',[ 0.01 0.6 0.24 0.06 ], ...
0271         'String','Extrm Topo Wt', ...
0272         'Style','radiobutton', ...
0273         'Value',0, ...
0274         'enable','off', ...
0275         'FontSize',12, ...
0276         'ToolTipString','Maximum proportion of topography length accounted for by a single channel', ...
0277         'HorizontalAlignment','left', ...
0278         'tag','heart_topo');
0279     
0280     % EMG spectra
0281     h_emg_spectra=uicontrol(h_fig,...
0282         'Units','normalized', ...
0283         'CallBack',['tmp=get(gcf,''userdata''); ',...
0284         ' set(tmp.h_emg_spectra,''value'',1); ', ...
0285         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0286         ' set(tmp.h_mn_std,''value'',0); ', ...
0287         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0288         ' set(tmp.h_heart_topo,''value'',0); ', ...
0289         ' set(tmp.h_he_topo,''value'',0); ', ...
0290         ' set(tmp.h_blink_topo,''value'',0); ', ...
0291         ' set_ic_ftr_thresh(''new feature'');'], ...
0292         'Position',[ 0.01 0.54 0.24 0.06 ], ...
0293         'String','EMG Spectra', ...
0294         'Style','radiobutton', ...
0295         'Value',0, ...
0296         'FontSize',12, ...
0297         'enable','off', ...
0298         'ToolTipString','Activation spectra similar to that produced by EMG', ...
0299         'HorizontalAlignment','left', ...
0300         'tag','emg_spectra');
0301     
0302     % EOG spectra
0303     h_eog_spectra=uicontrol(h_fig,...
0304         'Units','normalized', ...
0305         'CallBack',['tmp=get(gcf,''userdata''); ',...
0306         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0307         ' set(tmp.h_eog_spectra,''value'',1); ', ...
0308         ' set(tmp.h_mn_std,''value'',0); ', ...
0309         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0310         ' set(tmp.h_heart_topo,''value'',0); ', ...
0311         ' set(tmp.h_he_topo,''value'',0); ', ...
0312         ' set(tmp.h_blink_topo,''value'',0); ', ...
0313         ' set_ic_ftr_thresh(''new feature'');'], ...
0314         'Position',[ 0.01 0.48 0.24 0.06 ], ...
0315         'String','EOG Spectra', ...
0316         'Style','radiobutton', ...
0317         'Value',0, ...
0318         'FontSize',12, ...
0319         'enable','off', ...
0320         'ToolTipString','Activation spectra similar to that produced by EOG', ...
0321         'HorizontalAlignment','left', ...
0322         'tag','eog_spectra');
0323     
0324     % Mean Time Point Standard Deviation
0325     h_mn_std=uicontrol(h_fig,...
0326         'Units','normalized', ...
0327         'CallBack',['tmp=get(gcf,''userdata''); ',...
0328         ' set(tmp.h_emg_spectra,''value'',0); ', ...
0329         ' set(tmp.h_eog_spectra,''value'',0); ', ...
0330         ' set(tmp.h_mn_std,''value'',1); ', ...
0331         ' set(tmp.h_xtrm_topo,''value'',0); ', ...
0332         ' set(tmp.h_heart_topo,''value'',0); ', ...
0333         ' set(tmp.h_he_topo,''value'',0); ', ...
0334         ' set(tmp.h_blink_topo,''value'',0); ', ...
0335         ' set_ic_ftr_thresh(''new feature'');'], ...
0336         'Position',[ 0.01 0.42 0.24 0.06 ], ...
0337         'String','Act Std Dev', ...
0338         'Style','radiobutton', ...
0339         'Value',0, ...
0340         'FontSize',12, ...
0341         'enable','off', ...
0342         'ToolTipString','Standard deviation of activation averaged across all time points', ...
0343         'HorizontalAlignment','left', ...
0344         'tag','mn_std');
0345     
0346     
0347     % Create threshold value text box
0348     uicontrol(h_fig,...
0349         'Units','normalized', ...
0350         'Position',[ 0.033 0.32 0.20 0.1 ],...
0351         'String','Current Threshold',...
0352         'Style','text', ...
0353         'FontWeight','bold', ...
0354         'FontSize',14, ...
0355         'tag','static', ...
0356         'ToolTipString',['ICs with feature values above this threshold will be labeled as artifacts.', ...
0357         10 'NaN stands for "not a number" and means that this feature is ignored.'], ...
0358         'HorizontalAlignment','center');
0359     h_thresh=uicontrol(h_fig,...
0360         'CallBack','set_ic_ftr_thresh(''new threshold'');',...
0361         'Units','normalized', ...
0362         'Position',[ 0.048 0.26 0.17 0.07 ],...
0363         'String','NaN',...
0364         'Style','edit', ...
0365         'FontSize',12, ...
0366         'enable','off', ...
0367         'backgroundcolor','w', ...
0368         'horizontalalignment','center', ...
0369         'tag','thresh');
0370     
0371     
0372     % Button to save EEG
0373     h_save=uicontrol(h_fig,...
0374         'CallBack','set_ic_ftr_thresh(''save changes'');',...
0375         'Units','normalized', ...
0376         'Position',[ 0.048 0.17 0.17 0.08],...
0377         'String','Save',...
0378         'Tag','save', ...
0379         'FontSize',14, ...
0380         'enable','off', ...
0381         'ToolTipString','Save changes to EEG variable.', ...
0382         'horizontalalignment','center', ...
0383         'Style','pushbutton');
0384     
0385     help_msg=sprintf(['This GUI allows you to interactively set IC rejection thresholds. The current feature''s threshold is represented with the red dashed line.  ', ...
0386         'Any ICs with features that fall in the rejection region (shaded in red) will be represented by red asterisks and rejected.', ...
0387         '  Magenta circles are ICs that are labelled as artifacts due to other features/', ...
0388         'thresholds or manual labels. Blue circles are ICs that won''t be rejected.\n\n', ...
0389         'Hold mouse cursor over a GUI control for an explanation of what it does or what the feature is.\n\n', ...
0390         'Click on circles or asterisks to see the properties of that IC.\n\n', ...
0391         'Type ''help set_ic_ftr_thresh'' for more information about what IC artifact features are.\n\n' ...
0392         'See the ICA_Artifact_Correction page of the lab wiki for further help.\n\n', ...
0393         'This GUI was produced by set_ic_ftr_thresh.m']);
0394     
0395     % Help Button
0396     h_help=uicontrol(h_fig,...
0397         'CallBack','dat=get(gcf,''userdata''); helpdlg(dat.help_msg,''set_ic_ftr_thresh GUI Help'');', ...
0398         'Units','normalized', ...
0399         'Position',[ 0.048 0.09 0.17 0.08],...
0400         'String','Help',...
0401         'Tag','help', ...
0402         'FontSize',14, ...
0403         'enable','on', ...
0404         'ToolTipString','GUI information and figure legend.', ...
0405         'horizontalalignment','center', ...
0406         'Style','pushbutton');
0407     
0408     
0409         
0410     % Button to close GUI
0411     uicontrol(h_fig,...
0412         'CallBack','close(gcf);',...
0413         'Units','normalized', ...
0414         'Position',[ 0.048 0.01 0.17 0.07 ],...
0415         'String','Close',...
0416         'Tag','close', ...
0417         'FontSize',14, ...
0418         'ToolTipString','Close GUI', ...
0419         'horizontalalignment','center', ...
0420         'backgroundcolor','m', ...
0421         'Style','pushbutton');
0422     
0423     
0424     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0425     %%% II.c Right part of GUI: IC feature values %%%
0426     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0427        
0428     % Create panel that axis can be drawn on top of
0429     h_panel_right=uipanel(h_fig,...
0430         'Units','normalized', ...
0431         'Position',[ 0.25 0 0.75 0.9 ],...
0432         'shadowcolor','k', ...
0433         'highlightcolor',frm_col, ...
0434         'foregroundcolor',frm_col, ...
0435         'backgroundcolor',frm_col);
0436 
0437     
0438     % Create an axes for plotting individual ICs
0439     h_axis=axes('position',[0.35 .1 .63 .78],'box','off');
0440     n_ics=64;
0441     h_xlab=xlabel('IC #');
0442     set(h_xlab,'fontsize',12,'fontweight','bold');
0443     h_ylab=ylabel('IC Feature');
0444     set(h_ylab,'fontsize',12,'fontweight','bold');
0445     axis([0 n_ics+1 0 1]);
0446     set(h_axis,'xtick',[1 [5:5:n_ics]]);
0447     h_txt=text(32,.5,'Data not yet loaded.');
0448     set(h_txt,'fontsize',12,'horizontalalignment','center');
0449     %    set(h_topo,'color',frm_col); %this doesn't appear to have any effect
0450     %    set(h_fig,'color',frm_col); %this doesn't appear to have any effect
0451     
0452     %tmp.h_ylab=h_ylab;
0453     tmp.h_axis=h_axis;
0454     tmp.h_thresh=h_thresh;
0455     tmp.h_mn_std=h_mn_std;
0456     tmp.h_eog_spectra=h_eog_spectra;
0457     tmp.h_emg_spectra=h_emg_spectra;
0458     tmp.h_xtrm_topo=h_xtrm_topo;
0459     tmp.h_heart_topo=h_heart_topo;
0460     tmp.h_he_topo=h_he_topo;
0461     tmp.h_blink_topo=h_blink_topo;
0462     tmp.h_in_fname=h_in_fname;
0463     tmp.h_in_fnameB=h_in_fnameB;
0464     tmp.h_save=h_save;
0465     tmp.h_help=h_help;
0466     tmp.help_msg=help_msg;
0467     set(h_fig,'userdata',tmp);
0468     
0469     if ~isempty(EEG),
0470         set_ic_ftr_thresh('refresh');
0471     end
0472     
0473 elseif strcmpi('refresh',command_str),
0474     tmp=get(h_fig,'userdata');
0475     
0476     %grab existing file in memory
0477     if isempty(EEG)
0478         set_ic_ftr_thresh('disable');
0479         err=lasterror;
0480         errordlg(err.message,'The global variable EEG is empty.  You need to load a data set.','on');
0481         return;
0482     end
0483     
0484     %Update GUI input filename
0485     set(tmp.h_in_fname,'string',[EEG.filepath EEG.filename]);
0486     
0487     %recompute IC features just in case
0488     EEG=cmpt_ic_art_ftrs(EEG);
0489    
0490     % Check to make all features are loaded, if not set them to NAN
0491     thresh_names{1}='thresh_blink_topo';
0492     thresh_names{2}='thresh_heart_topo';
0493     thresh_names{3}='thresh_he_topo';
0494     thresh_names{4}='thresh_ic_emg_spectra';
0495     thresh_names{5}='thresh_ic_xtrm_chan';
0496     thresh_names{6}='thresh_ic_mn_std';
0497     thresh_names{7}='thresh_ic_eog_spectra';
0498     fldnms=fieldnames(EEG.reject);
0499     for tn=1:length(thresh_names),
0500         fnd=0;
0501         for fn=1:length(fldnms),
0502             if strcmpi(fldnms{fn},thresh_names{tn}),
0503                fnd=1;
0504                break;
0505             end
0506         end
0507         if ~fnd,
0508            cmd=['EEG.reject.' thresh_names{tn} '=NaN;'];
0509            eval(cmd);
0510         end
0511     end
0512 
0513     
0514     %enable feature radio buttons and plot first feature
0515     set(tmp.h_emg_spectra,'enable','on','value',0);
0516     set(tmp.h_eog_spectra,'enable','on','value',0);
0517     set(tmp.h_mn_std,'enable','on','value',0);
0518     set(tmp.h_xtrm_topo,'enable','on','value',0);
0519     set(tmp.h_heart_topo,'enable','on','value',0);
0520     set(tmp.h_he_topo,'enable','on','value',0);
0521     set(tmp.h_blink_topo,'enable','on','value',1);
0522     set(tmp.h_thresh,'enable','on');
0523     verblevel=VERBLEVEL; %save current VERBLEVEL
0524     EEG=reject_ics_by_ftr(EEG); %update rejection labels
0525     VERBLEVEL=verblevel; %restore old VERBLEVEL
0526     set_ic_ftr_thresh('new feature');
0527     
0528 
0529 elseif strcmpi('load data',command_str),
0530     tmp=get(h_fig,'userdata');   
0531     
0532     %grab existing file in memory
0533     try
0534         in_fname=get(tmp.h_in_fname,'string');
0535         fprintf('Loading EEG variable from %s.\n',in_fname);
0536         EEG=pop_loadset(in_fname);
0537     catch  
0538         set_ic_ftr_thresh('disable');
0539         err=lasterror;
0540         errordlg(err.message,'Input File Error','on');
0541         return;
0542     end
0543     
0544     %recompute IC features just in case
0545     EEG=cmpt_ic_art_ftrs(EEG);
0546    
0547     % Check to make all features are loaded, if not set them to NAN
0548     thresh_names{1}='thresh_blink_topo';
0549     thresh_names{2}='thresh_heart_topo';
0550     thresh_names{3}='thresh_he_topo';
0551     thresh_names{4}='thresh_ic_emg_spectra';
0552     thresh_names{5}='thresh_ic_xtrm_chan';
0553     thresh_names{6}='thresh_ic_mn_std';
0554     thresh_names{7}='thresh_ic_eog_spectra';
0555     fldnms=fieldnames(EEG.reject);
0556     for tn=1:length(thresh_names),
0557         fnd=0;
0558         for fn=1:length(fldnms),
0559             if strcmpi(fldnms{fn},thresh_names{tn}),
0560                fnd=1;
0561                break;
0562             end
0563         end
0564         if ~fnd,
0565            cmd=['EEG.reject.' thresh_names{tn} '=NaN;'];
0566            eval(cmd);
0567         end
0568     end
0569 
0570     
0571     %enable feature radio buttons and plot first feature
0572     set(tmp.h_emg_spectra,'enable','on','value',0);
0573     set(tmp.h_eog_spectra,'enable','on','value',0);
0574     set(tmp.h_mn_std,'enable','on','value',0);
0575     set(tmp.h_xtrm_topo,'enable','on','value',0);
0576     set(tmp.h_heart_topo,'enable','on','value',0);
0577     set(tmp.h_he_topo,'enable','on','value',0);
0578     set(tmp.h_blink_topo,'enable','on','value',1);
0579     set(tmp.h_thresh,'enable','on');
0580     verblevel=VERBLEVEL; %save current VERBLEVEL
0581     EEG=reject_ics_by_ftr(EEG); %update rejection labels
0582     VERBLEVEL=verblevel; %restore old VERBLEVEL
0583     set_ic_ftr_thresh('new feature');
0584     
0585 elseif strcmpi('new feature',command_str),
0586     tmp=get(h_fig,'userdata'); 
0587     cla(tmp.h_axis);
0588     n_ics=length(EEG.icfeatures);
0589     ftr=zeros(1,n_ics);
0590     
0591     %find feature to plot
0592     if get(tmp.h_blink_topo,'value'),
0593         ftr_str='blink_topo';
0594         thresh_str='blink_topo';
0595         ylab='Blink-like Topography';
0596         iclabel='Blink (objective)';
0597     elseif get(tmp.h_he_topo,'value'),
0598         ftr_str='he_topo';
0599         thresh_str='he_topo';
0600         ylab='Horizontal EOG-like Topography';
0601         iclabel='HE (objective)';
0602     elseif get(tmp.h_heart_topo,'value'),
0603         ftr_str='heart_topo';
0604         thresh_str='heart_topo';
0605         ylab='Heart-like Topography';
0606         iclabel='Heart (objective)';
0607     elseif get(tmp.h_xtrm_topo,'value'),
0608         ftr_str='xtrm_chan';
0609         thresh_str='ic_xtrm_chan';
0610         ylab='Extreme Topography Weight';
0611         iclabel='Bad_chan (objective)';
0612     elseif get(tmp.h_emg_spectra,'value'),
0613         ftr_str='emg_spectra';
0614         thresh_str='ic_emg_spectra';
0615         ylab='EMG-like Spectra';
0616         iclabel='EMG (objective)';
0617     elseif get(tmp.h_eog_spectra,'value'),
0618         ftr_str='eog_spectra';
0619         thresh_str='ic_eog_spectra';
0620         ylab='EOG-like Spectra';
0621         iclabel='EOG (objective)';
0622     else
0623         ftr_str='mn_std';
0624         thresh_str='ic_mn_std';
0625         ylab='Activation Standard Deviation/Time Point';
0626         iclabel='Xtrm_activity (objective)';
0627     end
0628     
0629     cmnd=['thresh=EEG.reject.thresh_' thresh_str ';'];
0630     eval(cmnd);
0631     rej=zeros(1,n_ics);
0632     for c=1:n_ics,
0633        cmnd=['ftr(c)=EEG.icfeatures(' int2str(c) ').' ftr_str ';'];
0634        eval(cmnd);
0635        if ftr(c)>thresh,
0636           rej(c)=1;
0637        end
0638     end
0639     set(tmp.h_thresh,'string',num2str(thresh)); %update value of "current threshold" box
0640    
0641     yes_rej=find(rej==1);
0642     other_rej=setdiff(find(EEG.reject.gcompreject==1),yes_rej); %rejected for reasons besides the current feature
0643     no_rej=setdiff(find(rej==0),other_rej);
0644     axes(tmp.h_axis);
0645     %plot([0 n_ics+1],[1 1]*thresh,'r--'); hold on;
0646 
0647     mx=max([ftr thresh]);
0648     mn=min([ftr thresh]);
0649     ftr_pad=(mx-mn)*.1;
0650     axis([0 n_ics+1 mn-ftr_pad mx+ftr_pad]);
0651     hh=patch([0 n_ics+1 n_ics+1 0],[thresh thresh mx+ftr_pad mx+ftr_pad],'r');
0652     set(hh,'FaceAlpha',.5,'linestyle','--','edgecolor','r');
0653     hold on;
0654     for c=1:n_ics,
0655         if ismember(c,no_rej),
0656             h=plot(c,ftr(c),'o');
0657             set(h,'buttondownfcn',['ic_prop(' int2str(c) ',''from_set_ic_ftr_thresh'',1);']);
0658         elseif ismember(c,yes_rej),
0659             h=plot(c,ftr(c),'r*');
0660             set(h,'buttondownfcn',['ic_prop(' int2str(c) ',''from_set_ic_ftr_thresh'',1);']);
0661         elseif ismember(c,other_rej),
0662             h=plot(c,ftr(c),'mo');
0663             set(h,'buttondownfcn',['ic_prop(' int2str(c) ',''from_set_ic_ftr_thresh'',1);']);
0664         end
0665     end
0666     EEG.reject.gcompreject(yes_rej)=1;
0667     h_xlab=xlabel('IC #');
0668     set(h_xlab,'fontsize',12,'fontweight','bold');
0669     h_ylab=ylabel(ylab);
0670     set(h_ylab,'fontsize',12,'fontweight','bold');
0671     %mx=max([ftr thresh]);
0672     %mn=min([ftr thresh]);
0673     %ftr_pad=(mx-mn)*.1;
0674     %axis([0 n_ics+1 mn-ftr_pad mx+ftr_pad]);
0675     %hh=patch([0 n_ics+1 n_ics+1 0],[thresh thresh mx+ftr_pad mx+ftr_pad],'r');
0676     %set(hh,'FaceAlpha',.5,'linestyle','--','edgecolor','r');
0677     set(tmp.h_axis,'xtick',[1 [5:5:n_ics]]);
0678     
0679     if ~strcmpi(EEG.saved,'yes'),
0680         set(tmp.h_save,'enable','on');
0681     end
0682     
0683 elseif strcmpi('new threshold',command_str),
0684     tmp=get(h_fig,'userdata'); 
0685     
0686     %find feature to plot
0687     if get(tmp.h_blink_topo,'value'),
0688         thresh_str='blink_topo';
0689     elseif get(tmp.h_he_topo,'value'),
0690         thresh_str='he_topo';
0691     elseif get(tmp.h_heart_topo,'value'),
0692         thresh_str='heart_topo';
0693     elseif get(tmp.h_xtrm_topo,'value'),
0694         thresh_str='ic_xtrm_chan';
0695     elseif get(tmp.h_emg_spectra,'value'),
0696         thresh_str='ic_emg_spectra';
0697     elseif get(tmp.h_eog_spectra,'value'),
0698         thresh_str='ic_eog_spectra';
0699     else
0700         thresh_str='ic_mn_std';
0701     end
0702     
0703     new_val=str2num(get(tmp.h_thresh,'string'));
0704     cmnd=['EEG.reject.thresh_' thresh_str '=' num2str(new_val) ';'];
0705     eval(cmnd);
0706     EEG.saved='no';
0707     set(tmp.h_save,'enable','on');
0708     set(tmp.h_thresh,'string',num2str(new_val));
0709     verblevel=VERBLEVEL; %record current VERBLEVEL
0710     EEG=reject_ics_by_ftr(EEG,0); %update rejection labels
0711     VERBLEVEL=verblevel; %restore old VERBLEVEL
0712     set_ic_ftr_thresh('new feature');
0713 elseif strcmpi('save changes',command_str),
0714     tmp=get(h_fig,'userdata');
0715     try
0716         pop_saveset(EEG,'filename',EEG.filename,'filepath',EEG.filepath);
0717     catch
0718         err=lasterror;
0719         errordlg(err.message,'File Save Error','on');
0720         return;
0721     end
0722     set(tmp.h_save,'enable','off');
0723 elseif strcmpi('disable',command_str),
0724     tmp=get(h_fig,'userdata');
0725     
0726     %disable GUI
0727     for a=get(h_fig,'children')',
0728         f=fieldnames(set(a));
0729         for b=1:length(f),
0730             if strcmpi(f{b},'Callback') && ~strcmpi('close',get(a,'Tag')) && ...
0731                     ~strcmpi('help',get(a,'Tag')) &&  ~strcmpi('static',get(a,'Tag'))
0732                 % Static tag is necessary for keeping static text enabled.  I had no
0733                 % idea you could disable text or that it had a
0734                 % 'Callback' field
0735                 set(a,'enable','off');
0736                 break;
0737             end
0738         end
0739     end
0740     %re-enable file name inputs
0741     set(tmp.h_in_fname,'enable','on');
0742     set(tmp.h_in_fnameB,'enable','on');
0743     
0744     %turn off radio buttons and set threshold to NaN, enabling should be
0745     %redundant
0746     set(tmp.h_emg_spectra,'enable','off','value',0);
0747     set(tmp.h_eog_spectra,'enable','off','value',0);
0748     set(tmp.h_mn_std,'enable','off','value',0);
0749     set(tmp.h_xtrm_topo,'enable','off','value',0);
0750     set(tmp.h_heart_topo,'enable','off','value',0);
0751     set(tmp.h_he_topo,'enable','off','value',0);
0752     set(tmp.h_blink_topo,'enable','off','value',0);
0753     set(tmp.h_thresh,'enable','off','string','NaN');
0754     
0755     %erase figure
0756     n_ics=64;
0757     axes(tmp.h_axis);
0758     cla;
0759     h_ylab=ylabel('IC Feature');
0760     set(h_ylab,'fontsize',12,'fontweight','bold');
0761     axis([0 n_ics+1 0 1]);
0762     set(tmp.h_axis,'xtick',[1 [5:5:n_ics]]);
0763     h_txt=text(32,.5,'Data not yet loaded.');
0764     set(h_txt,'fontsize',12,'horizontalalignment','center');
0765 end
0766

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005