Home > 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   plot(repmat(Tmsec,[size(J_hold,1) 1])',J_hold');
0160   xlim([min(Tmsec) max(Tmsec)]);
0161   set(h_time,'YDir','normal');
0162   
0163   % Set callback function
0164   plotcmap_str = ['vbmeg_inst.plotcmap{' num2str(inst_id) '}']; 
0165   command = ['global vbmeg_inst; ' ...
0166              plotcmap_str '.toi = xrange;' ...
0167              'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0168              'job_plot_cmap_update_timecourse(inst_id);' ...
0169              'job_plot_cmap_update_spatialpattern(inst_id);'];
0170   select_xrange('init',gca,'ButtonUpFcn',command,...
0171                 'InitialRange',toi);
0172 else
0173   if strcmp(TFinfo.freq_scale,'log'), 
0174     h_img = imagesc(TFinfo.Tmsec,log2(TFinfo.freq),data);
0175     ylim(log2([min(TFinfo.freq) max(TFinfo.freq)]));
0176     yy = [2 5 10 20 50 100 200 500 1000 2000 5000 10000];
0177     [tmp,ix_yy1] = find(yy<=max(TFinfo.freq));
0178     [tmp,ix_yy2] = find(yy>=min(TFinfo.freq));
0179     yy = sort(yy(intersect(ix_yy1,ix_yy2)));
0180     set(h_time,'YDir','normal','YTick',log2(yy),'YTickLabel',yy);
0181   else
0182     h_img = imagesc(TFinfo.Tmsec,TFinfo.freq,data);
0183     ylim([min(TFinfo.freq) max(TFinfo.freq)]);
0184     set(h_time,'YDir','normal');
0185     %yy = [2 5 10 20 50 100 200 500 1000 2000 5000 10000];
0186     %[tmp,ix_yy1] = find(yy<=max(TFinfo.freq));
0187     %[tmp,ix_yy2] = find(yy>=min(TFinfo.freq));
0188     %yy = sort(yy(intersect(ix_yy1,ix_yy2)));
0189     %set(h_time,'YDir','normal','YTick',log2(yy),'YTickLabel',yy);
0190   end
0191   
0192   % Debug code
0193   if vb_get_verbose==VERBOSE_LEVEL_DEBUG,
0194     fprintf('job_plot_cmap_update_timecourse\n');
0195     fprintf('max(max(data))=%e\n',max(max(data)));
0196     fprintf('TFmax=%e\n',TFmax);
0197   end
0198   
0199   % Color scale
0200   tfmax = str2num(get(ed10,'String'));
0201   %if TFmax>=abs(max(max(data)))*10, % Color scale too large
0202   %  tfmax = abs(max(max(data)));
0203   %else
0204   %  tfmax = TFmax;
0205   %end
0206   
0207   % Color range and colorbar
0208   reset(h_cbar_tf);
0209   if TFmin<0,     
0210     caxis(h_time,[-1*tfmax tfmax]);
0211     
0212     if datenum(version('-date'))<=733071, % January 29, 2007 or older
0213       reset(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0214       colorbar(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0215     else
0216       pos = get(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf,'Position');
0217       delete(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0218       h_cbar_tf = colorbar('Position',pos);
0219       vbmeg_inst.plotcmap{inst_id}.h_cbar_tf = h_cbar_tf;
0220     end
0221 
0222     set(h_cbar_tf,'Ylim',[-1*tfmax tfmax],'XTick',[]);
0223   else
0224     caxis(h_time,[0 tfmax]);
0225     
0226     if datenum(version('-date'))<=733071, % January 29, 2007 or older
0227       reset(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0228       colorbar(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0229     else
0230       pos = get(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf,'Position');
0231       delete(vbmeg_inst.plotcmap{inst_id}.h_cbar_tf);
0232       h_cbar_tf = colorbar('Position',pos);
0233       vbmeg_inst.plotcmap{inst_id}.h_cbar_tf = h_cbar_tf;
0234     end
0235 
0236     set(h_cbar_tf,'Ylim',[0 tfmax],'XTick',[]);
0237   end
0238   
0239   % Set callback function
0240   plotcmap_str = ['vbmeg_inst.plotcmap{' num2str(inst_id) '}']; 
0241   if strcmp(TFinfo.freq_scale,'log'), 
0242     command = ['global vbmeg_inst; ' ...
0243                plotcmap_str '.toi = [xyrange(1) xyrange(3)];' ...
0244                plotcmap_str '.foi = [2.^xyrange(2) 2.^xyrange(4)];' ...
0245                'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0246                'job_plot_cmap_update_timecourse(inst_id);' ...
0247                'job_plot_cmap_update_spatialpattern(inst_id);'];
0248     vb_select_xyrange('init',h_img,'ButtonUpFcn',command,...
0249                       'InitialRange',[toi(1) log2(foi(1)) toi(2) ...
0250                         log2(foi(2))]);
0251   else
0252     command = ['global vbmeg_inst; ' ...
0253                plotcmap_str '.toi = [xyrange(1) xyrange(3)];' ...
0254                plotcmap_str '.foi = [xyrange(2) xyrange(4)];' ...
0255                'inst_id = job_plot_cmap_get_inst_id(gcf);' ...
0256                'job_plot_cmap_update_timecourse(inst_id);' ...
0257                'job_plot_cmap_update_spatialpattern(inst_id);'];
0258     vb_select_xyrange('init',h_img,'ButtonUpFcn',command,...
0259                       'InitialRange',[toi(1) foi(1) toi(2) foi(2)]);
0260   end
0261   
0262 end
0263 
0264 xlabel('Time [ms]');
0265 ylabel(ylabel_str);
0266 
0267 %
0268 % Update GUI components
0269 %
0270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0271 
0272 % Update text box
0273 set(vbmeg_inst.plotcmap{inst_id}.ed2,'String',num2str(toi(1))); 
0274 set(vbmeg_inst.plotcmap{inst_id}.ed3,'String',num2str(toi(2))); 
0275 if ~isempty(TFinfo),
0276   set(vbmeg_inst.plotcmap{inst_id}.ed8,'String',num2str(foi(1)));
0277   set(vbmeg_inst.plotcmap{inst_id}.ed9,'String',num2str(foi(2)));
0278 else
0279   set(vbmeg_inst.plotcmap{inst_id}.ed8,'String','');
0280   set(vbmeg_inst.plotcmap{inst_id}.ed9,'String','');
0281 end
0282 
0283 set(h_fig,'Pointer','arrow');
0284 
0285 return;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005