Home > vbmeg > functions > job > job_plot_currentmap_dir > job_plot_cmap_update_timecourse.m

job_plot_cmap_update_timecourse

PURPOSE ^

Update temporal pattern of brain activity

SYNOPSIS ^

function job_plot_cmap_update_timecourse(inst_id)

DESCRIPTION ^

 Update temporal pattern of brain activity
 
 --- Syntax
 function job_plot_cmap_update_timecourse(inst_id)

 --- History
 ????-??-?? Taku Yoshioka
 2008-08-28 Taku Yoshioka
 2008-10-22 Taku Yoshioka
   Faster display of timecourse. 
 2008-11-07 Taku Yoshioka
   Bug fix.
 2008-03-08 rhayashi
   not to occure Divide by zero.
 2010-12-11 taku-y
  [major] Time-frequency data supported. 
 2011-01-27 taku-y
  [debug] Time-frequency window selection for 'linear' scaling. 
 2011-04-01 taku-y
  [minor] Colorbar fnc argument changed depending on MATLAB version.
 2012-01-26 sako
  [minor change] n_trial -> "n_trial" was replaced to "ix_trial"

 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:

SOURCE CODE ^

0001 function job_plot_cmap_update_timecourse(inst_id)
0002 % Update temporal pattern of brain activity
0003 %
0004 % --- Syntax
0005 % function job_plot_cmap_update_timecourse(inst_id)
0006 %
0007 % --- History
0008 % ????-??-?? Taku Yoshioka
0009 % 2008-08-28 Taku Yoshioka
0010 % 2008-10-22 Taku Yoshioka
0011 %   Faster display of timecourse.
0012 % 2008-11-07 Taku Yoshioka
0013 %   Bug fix.
0014 % 2008-03-08 rhayashi
0015 %   not to occure Divide by zero.
0016 % 2010-12-11 taku-y
0017 %  [major] Time-frequency data supported.
0018 % 2011-01-27 taku-y
0019 %  [debug] Time-frequency window selection for 'linear' scaling.
0020 % 2011-04-01 taku-y
0021 %  [minor] Colorbar fnc argument changed depending on MATLAB version.
0022 % 2012-01-26 sako
0023 %  [minor change] n_trial -> "n_trial" was replaced to "ix_trial"
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 global vbmeg_inst; 
0029 if isempty(vbmeg_inst.plotcmap{inst_id}.V), return; end
0030 const = vb_define_verbose;
0031 VERBOSE_LEVEL_DEBUG = const.VERBOSE_LEVEL_DEBUG;
0032 
0033 %
0034 % Global variables
0035 %
0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037 h_fig     = vbmeg_inst.plotcmap{inst_id}.h_fig; 
0038 h_time    = vbmeg_inst.plotcmap{inst_id}.h_time;
0039 h_cbar_tf = vbmeg_inst.plotcmap{inst_id}.h_cbar_tf;
0040 ix_trial  = vbmeg_inst.plotcmap{inst_id}.ix_trial;
0041 Jinfo     = vbmeg_inst.plotcmap{inst_id}.Jinfo;
0042 TFinfo    = vbmeg_inst.plotcmap{inst_id}.TFinfo;
0043 TFmax     = vbmeg_inst.plotcmap{inst_id}.TFmax;
0044 TFmin     = vbmeg_inst.plotcmap{inst_id}.TFmin;
0045 toi       = vbmeg_inst.plotcmap{inst_id}.toi;
0046 foi       = vbmeg_inst.plotcmap{inst_id}.foi;
0047 ix_peak   = vbmeg_inst.plotcmap{inst_id}.ix_peak;
0048 J_hold    = vbmeg_inst.plotcmap{inst_id}.J_hold; 
0049 cb4       = vbmeg_inst.plotcmap{inst_id}.cb4;
0050 ed10      = vbmeg_inst.plotcmap{inst_id}.ed10; % Jmax_tf_plot_edit
0051 
0052 
0053 set(h_fig,'Pointer','watch');
0054 drawnow;
0055 
0056 if ~isempty(Jinfo), 
0057   Tmsec = Jinfo.Tmsec;
0058 elseif ~isempty(TFinfo), 
0059   Tmsec = TFinfo.Tmsec;
0060 else
0061   return;
0062 end
0063 
0064 % Vertex check
0065 I = size(vbmeg_inst.plotcmap{inst_id}.V,1); 
0066 ix_peak = ceil(ix_peak);
0067 if ix_peak<1, ix_peak = 1; end
0068 if ix_peak>I, ix_peak = I; end 
0069 vbmeg_inst.plotcmap{inst_id}.ix_peak = ix_peak;
0070 
0071 % Time window range check
0072 if toi(1)<min(Tmsec), toi(1)=min(Tmsec); end
0073 if toi(1)>max(Tmsec), toi(1)=max(Tmsec); end
0074 if toi(2)<min(Tmsec), toi(2)=min(Tmsec); end
0075 if toi(2)>max(Tmsec), toi(2)=max(Tmsec); end
0076 if toi(1)>toi(2), toi=toi(2:-1:1); end
0077 vbmeg_inst.plotcmap{inst_id}.toi = toi;
0078 
0079 % Frequency window range check
0080 if ~isempty(TFinfo),
0081   if foi(1)<min(TFinfo.freq), foi(1)=min(TFinfo.freq); end
0082   if foi(1)>max(TFinfo.freq), foi(1)=max(TFinfo.freq); end
0083   if foi(2)<min(TFinfo.freq), foi(2)=min(TFinfo.freq); end
0084   if foi(2)>max(TFinfo.freq), foi(2)=max(TFinfo.freq); end
0085   if foi(1)>foi(2), foi=foi(2:-1:1); end
0086   vbmeg_inst.plotcmap{inst_id}.foi = foi;
0087 end
0088 
0089 ixx = ix_peak;
0090 W = vbmeg_inst.plotcmap{inst_id}.W(ixx,:);
0091 
0092 % Calculate timecourse of brain acvitity in Region of Interest
0093 if ~isempty(Jinfo), 
0094   if ixx==0, 
0095     J = zeros(length(Tmsec),1); 
0096   else
0097     ixx2 = find(sum(abs(W),1)>0);
0098     W = W(:,ixx2); % ROI window
0099     Jtmp = zeros(I,length(Jinfo.Tmsec));
0100 
0101     if size(vbmeg_inst.plotcmap{inst_id}.Jact, 3) > 1
0102       ix_trial = vbmeg_inst.plotcmap{inst_id}.ix_trial;
0103       Jtmp(Jinfo.ix_act_ex,:) ...
0104         = vbmeg_inst.plotcmap{inst_id}.Jact(:,:,ix_trial);
0105     else
0106       Jtmp(Jinfo.ix_act_ex,:) ...
0107         = vbmeg_inst.plotcmap{inst_id}.Jact(:,:);
0108     end
0109     
0110     if length(W(:))>0, 
0111       J = W*Jtmp(ixx2,:)/sum(W(:));
0112     end
0113     
0114     % holding
0115     if get(cb4,'Value')==get(cb4,'Max'), 
0116       J_hold = [J_hold; J];
0117     else
0118       J_hold = J;
0119     end
0120     vbmeg_inst.plotcmap{inst_id}.J_hold = J_hold;
0121   end
0122     
0123   % Ylabel of graph
0124   if Jinfo.patch_norm==ON, 
0125     ylabel_str = 'Dipole moment density [pAm/mm^2]';
0126   else
0127     ylabel_str = 'Dipole moment [nA\cdot m]';
0128   end
0129 elseif ~isempty(TFinfo), 
0130   if ixx==0, 
0131     data = zeros(length(TFinfo.freq),length(Tmsec));
0132   else
0133     W = sparse(W*TFinfo.Wact);
0134     ixx = find(W>0);
0135 
0136     c = 0.0; % normalize constant
0137     data = zeros(length(TFinfo.freq),length(TFinfo.Tmsec));
0138     for i=1:length(ixx)
0139       data ...
0140           = data+W(ixx(i))*vbmeg_inst.plotcmap{inst_id}.data(:,:,ixx(i));
0141       c = c+W(ixx(i));
0142     end
0143     data = data./c;
0144 
0145     % Ylabel of graph
0146     ylabel_str = 'Frequency [Hz]';
0147   end
0148 else
0149   return;
0150 end
0151 
0152 %
0153 % Plot timecourse of brain activity
0154 %
0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0156 set(0,'CurrentFigure',h_fig);
0157 set(h_fig,'CurrentAxes',h_time);
0158 if ~isempty(Jinfo),
0159   h_plot = plot(repmat(Tmsec,[size(J_hold,1) 1])',J_hold');
0160   set(h_plot, 'HitTest', 'off');
0161   xlim([min(Tmsec) max(Tmsec)]);
0162   set(h_time,'YDir','normal');
0163   
0164   % Set callback function
0165   plotcmap_str = ['vbmeg_inst.plotcmap{' num2str(inst_id) '}']; 
0166   command = ['global vbmeg_inst; ' ...
0167              plotcmap_str '.toi = xrange;' ...
0168              'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0169              'job_plot_cmap_update_timecourse(inst_id);' ...
0170              'job_plot_cmap_update_spatialpattern(inst_id);'];
0171   select_xrange('init',gca,'ButtonUpFcn',command,...
0172                 'InitialRange',toi);
0173 else
0174   if strcmp(TFinfo.freq_scale,'log'), 
0175     h_img = imagesc(TFinfo.Tmsec,log2(TFinfo.freq),data);
0176     ylim(log2([min(TFinfo.freq) max(TFinfo.freq)]));
0177     yy = [2 5 10 20 50 100 200 500 1000 2000 5000 10000];
0178     [tmp,ix_yy1] = find(yy<=max(TFinfo.freq));
0179     [tmp,ix_yy2] = find(yy>=min(TFinfo.freq));
0180     yy = sort(yy(intersect(ix_yy1,ix_yy2)));
0181     set(h_time,'YDir','normal','YTick',log2(yy),'YTickLabel',yy);
0182   else
0183     h_img = imagesc(TFinfo.Tmsec,TFinfo.freq,data);
0184     ylim([min(TFinfo.freq) max(TFinfo.freq)]);
0185     set(h_time,'YDir','normal');
0186     %yy = [2 5 10 20 50 100 200 500 1000 2000 5000 10000];
0187     %[tmp,ix_yy1] = find(yy<=max(TFinfo.freq));
0188     %[tmp,ix_yy2] = find(yy>=min(TFinfo.freq));
0189     %yy = sort(yy(intersect(ix_yy1,ix_yy2)));
0190     %set(h_time,'YDir','normal','YTick',log2(yy),'YTickLabel',yy);
0191   end
0192   
0193   % Debug code
0194   if vb_get_verbose==VERBOSE_LEVEL_DEBUG,
0195     fprintf('job_plot_cmap_update_timecourse\n');
0196     fprintf('max(max(data))=%e\n',max(max(data)));
0197     fprintf('TFmax=%e\n',TFmax);
0198   end
0199   
0200   % Color scale
0201   tfmax = str2num(get(ed10,'String'));
0202   %if TFmax>=abs(max(max(data)))*10, % Color scale too large
0203   %  tfmax = abs(max(max(data)));
0204   %else
0205   %  tfmax = TFmax;
0206   %end
0207   
0208   % Color range and colorbar
0209   reset(h_cbar_tf);
0210   if TFmin<0,     
0211     caxis(h_time,[-1*tfmax tfmax]);
0212     
0213     if datenum(version('-date'))<=733071, % January 29, 2007 or older
0214       reset(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0215       colorbar(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0216     else
0217       pos = get(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf,'Position');
0218       delete(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0219       h_cbar_tf = colorbar('Position',pos);
0220       vbmeg_inst.plotcmap{inst_id}.h_cbar_tf = h_cbar_tf;
0221     end
0222 
0223     set(h_cbar_tf,'Ylim',[-1*tfmax tfmax],'XTick',[]);
0224   else
0225     caxis(h_time,[0 tfmax]);
0226     
0227     if datenum(version('-date'))<=733071, % January 29, 2007 or older
0228       reset(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0229       colorbar(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0230     else
0231       pos = get(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf,'Position');
0232       delete(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0233       h_cbar_tf = colorbar('Position',pos);
0234       vbmeg_inst.plotcmap{inst_id}.h_cbar_tf = h_cbar_tf;
0235     end
0236 
0237     set(h_cbar_tf,'Ylim',[0 tfmax],'XTick',[]);
0238   end
0239   
0240   % Set callback function
0241   plotcmap_str = ['vbmeg_inst.plotcmap{' num2str(inst_id) '}']; 
0242   if strcmp(TFinfo.freq_scale,'log'), 
0243     command = ['global vbmeg_inst; ' ...
0244                plotcmap_str '.toi = [xyrange(1) xyrange(3)];' ...
0245                plotcmap_str '.foi = [2.^xyrange(2) 2.^xyrange(4)];' ...
0246                'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0247                'job_plot_cmap_update_timecourse(inst_id);' ...
0248                'job_plot_cmap_update_spatialpattern(inst_id);'];
0249     vb_select_xyrange('init',h_img,'ButtonUpFcn',command,...
0250                       'InitialRange',[toi(1) log2(foi(1)) toi(2) ...
0251                         log2(foi(2))]);
0252   else
0253     command = ['global vbmeg_inst; ' ...
0254                plotcmap_str '.toi = [xyrange(1) xyrange(3)];' ...
0255                plotcmap_str '.foi = [xyrange(2) xyrange(4)];' ...
0256                'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0257                'job_plot_cmap_update_timecourse(inst_id);' ...
0258                'job_plot_cmap_update_spatialpattern(inst_id);'];
0259     vb_select_xyrange('init',h_img,'ButtonUpFcn',command,...
0260                       'InitialRange',[toi(1) foi(1) toi(2) foi(2)]);
0261   end
0262   
0263 end
0264 
0265 xlabel('Time [ms]');
0266 ylabel(ylabel_str);
0267 set(h_time, 'Box', 'off');
0268 set(h_time, 'TickDir', 'out');
0269 
0270 %
0271 % Update GUI components
0272 %
0273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0274 
0275 % Update text box
0276 set(vbmeg_inst.plotcmap{inst_id}.ed2,'String',num2str(toi(1))); 
0277 set(vbmeg_inst.plotcmap{inst_id}.ed3,'String',num2str(toi(2))); 
0278 if ~isempty(TFinfo),
0279   set(vbmeg_inst.plotcmap{inst_id}.ed8,'String',num2str(foi(1)));
0280   set(vbmeg_inst.plotcmap{inst_id}.ed9,'String',num2str(foi(2)));
0281 else
0282   set(vbmeg_inst.plotcmap{inst_id}.ed8,'String','');
0283   set(vbmeg_inst.plotcmap{inst_id}.ed9,'String','');
0284 end
0285 
0286 set(h_fig,'Pointer','arrow');
0287 
0288 return;

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