Home > functions > job > job_plot_currentmap_dir > job_plot_cmap_load_data.m

job_plot_cmap_load_data

PURPOSE ^

Open file dialog and load data.

SYNOPSIS ^

function job_plot_cmap_load_data(inst_id,parms)

DESCRIPTION ^

 Open file dialog and load data.

 [syntax]
 job_plot_cmap_load_data(inst_id,parms)

 [input]
 inst_id: ID of instant of job_plot_currentmap GUI.
 parms  : <optional> <<struct>> Replaces brain_file, curr_file,
          area_file, act_file, tf_file, ix_trial and ave_mode if these
          fields exist in this struct.

 [history]
 2012-02-20 taku-y
 2012-02-28 taku-y
  [minor] File dialog was modified to recognize input arguments as
  default value of the file names and trial index. 
 2012-03-08 taku-y
  [major] The file dialog was renewed refs #198. 

 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_load_data(inst_id,parms)
0002 % Open file dialog and load data.
0003 %
0004 % [syntax]
0005 % job_plot_cmap_load_data(inst_id,parms)
0006 %
0007 % [input]
0008 % inst_id: ID of instant of job_plot_currentmap GUI.
0009 % parms  : <optional> <<struct>> Replaces brain_file, curr_file,
0010 %          area_file, act_file, tf_file, ix_trial and ave_mode if these
0011 %          fields exist in this struct.
0012 %
0013 % [history]
0014 % 2012-02-20 taku-y
0015 % 2012-02-28 taku-y
0016 %  [minor] File dialog was modified to recognize input arguments as
0017 %  default value of the file names and trial index.
0018 % 2012-03-08 taku-y
0019 %  [major] The file dialog was renewed refs #198.
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 global vbmeg_inst; 
0025 
0026 % handle of GUI components
0027 h_fig = vbmeg_inst.plotcmap{inst_id}.h_fig;
0028 ed1   = vbmeg_inst.plotcmap{inst_id}.ed1; 
0029 ed11  = vbmeg_inst.plotcmap{inst_id}.ed11;
0030 ed12  = vbmeg_inst.plotcmap{inst_id}.ed12;
0031 
0032 % check existing files
0033 brain_file = vbmeg_inst.plotcmap{inst_id}.brain_file;
0034 curr_file  = vbmeg_inst.plotcmap{inst_id}.curr_file;
0035 tf_file    = vbmeg_inst.plotcmap{inst_id}.tf_file;
0036 area_file  = vbmeg_inst.plotcmap{inst_id}.area_file;
0037 act_file   = vbmeg_inst.plotcmap{inst_id}.act_file;
0038 ix_trial   = vbmeg_inst.plotcmap{inst_id}.ix_trial;
0039 ave_mode   = vbmeg_inst.plotcmap{inst_id}.ave_mode;
0040 
0041 % input arguments
0042 if nargin<2, parms = []; end
0043 
0044 % dialog properties (input of job_plot_cmap_setting_dlg)
0045 props_in = [];
0046 
0047 % dialog property: brain_file
0048 p.key = 'brain_file';
0049 
0050 if ~isempty(brain_file), 
0051   p.value       = brain_file;
0052   p.update_flag = false;
0053 elseif isfield(parms,'brain_file'), 
0054   p.value       = parms.brain_file;
0055   p.update_flag = true;
0056 else
0057   p.value       = '';
0058   p.update_flag = false;
0059 end
0060 
0061 props_in = vb_table_insert(props_in,p);
0062 
0063 % dialog property: area_file
0064 p.key = 'area_file';
0065 
0066 if ~isempty(area_file), 
0067   p.value       = area_file;
0068   p.update_flag = false;
0069 elseif isfield(parms,'area_file'), 
0070   p.value       = parms.area_file;
0071   p.update_flag = true;
0072 else
0073   p.value       = '';
0074   p.update_flag = false;
0075 end
0076 
0077 props_in = vb_table_insert(props_in,p);
0078 
0079 % dialog property: act_file
0080 p.key = 'act_file';
0081 
0082 if ~isempty(act_file), 
0083   p.value       = act_file;
0084   p.update_flag = false;
0085 elseif isfield(parms,'act_file'), 
0086   p.value       = parms.act_file;
0087   p.update_flag = true;
0088 else
0089   p.value       = '';
0090   p.update_flag = false;
0091 end
0092 
0093 props_in = vb_table_insert(props_in,p);
0094 
0095 % dialog property: current_file
0096 p.key = 'current_file';
0097 
0098 if ~isempty(curr_file), 
0099   p.value       = curr_file;
0100   p.update_flag = false;
0101 elseif isfield(parms,'curr_file'), 
0102   p.value       = parms.curr_file;
0103   p.update_flag = true;
0104 else
0105   p.value       = '';
0106   p.update_flag = false;
0107 end
0108 
0109 props_in = vb_table_insert(props_in,p);
0110 
0111 % dialog property: ave_mode
0112 p.key = 'current_load_mode';
0113 
0114 if isfield(parms,'ave_mode'), 
0115   ave_mode      = parms.ave_mode;
0116   p.update_flag = true;
0117 else
0118   p.update_flag = false;
0119 end
0120 
0121 if ave_mode,
0122   ave_mode_str = 'ave';
0123 else
0124   ave_mode_str = 'raw';
0125 end
0126 
0127 p.value = ave_mode_str;
0128 
0129 props_in = vb_table_insert(props_in,p);
0130 
0131 % dialog property: ix_trial
0132 p.key = 'current_trial';
0133 
0134 if isfield(parms,'ix_trial'), 
0135   p.value       = parms.ix_trial;
0136   p.update_flag = true;
0137 else
0138   p.value       = ix_trial;
0139   p.update_flag = false;
0140 end
0141 
0142 if strcmp(ave_mode_str,'ave') & p.value>=2, 
0143   p.value       = 1;
0144   p.update_flag = true;
0145 end
0146 
0147 p.value = ceil(p.value);
0148 if isstr(p.value) | isempty(p.value) | length(p.value)>1, 
0149   vb_disp(['Trial index must be an integer value. Forced ix_trial to ' ...
0150            'be 1 (in job_plot_cmap_load_data.m). '], 'WARNING');
0151   p.value = 1;
0152 end
0153 
0154 props_in = vb_table_insert(props_in,p);
0155 
0156 % dialog property: tf_file
0157 p.key = 'tf_file';
0158 
0159 if ~isempty(tf_file), 
0160   p.value       = tf_file;
0161   p.update_flag = false;
0162 elseif isfield(parms,'tf_file'), 
0163   p.value       = parms.tf_file;
0164   p.update_flag = true;
0165 else
0166   p.value       = '';
0167   p.update_flag = false;
0168 end
0169 
0170 props_in = vb_table_insert(props_in,p);
0171 
0172 % open dialog
0173 props_out = job_plot_cmap_setting_dlg(props_in);
0174 
0175 % load cortical surface model
0176 update_flag = vb_table_query_update_flag(props_out,'brain_file');
0177 
0178 if update_flag,
0179   brain_file = vb_table_query_value(props_out,'brain_file');
0180 else
0181   brain_file = '';
0182 end
0183 
0184 if ~isempty(brain_file),
0185   set(h_fig,'Pointer','watch');
0186   drawnow; 
0187 
0188   vbmeg_inst.plotcmap{inst_id}.brain_file = brain_file;
0189   
0190   % cortical surface model
0191   [Vinf,F,xx,inf_C,xxA] = vb_load_cortex(brain_file,'Inflate');
0192   V = vb_load_cortex(brain_file);
0193   vbmeg_inst.plotcmap{inst_id}.V = V;
0194   vbmeg_inst.plotcmap{inst_id}.Vinf = Vinf;
0195   vbmeg_inst.plotcmap{inst_id}.F = F;
0196   vbmeg_inst.plotcmap{inst_id}.inf_C = inf_C;
0197   vbmeg_inst.plotcmap{inst_id}.xxA = xxA;
0198   
0199   % Standard brain coordinate
0200   Vtal = vb_load_cortex(brain_file,'Talairach');
0201   Vmni = vb_load_cortex(brain_file,'MNI');
0202   if ~exist('Vtal','var') || isempty(Vtal), Vtal = zeros(size(V)); end
0203   if ~exist('Vmni','var') || isempty(Vmni), Vmni = zeros(size(V)); end
0204   vbmeg_inst.plotcmap{inst_id}.Vtal = Vtal*1e3;
0205   vbmeg_inst.plotcmap{inst_id}.Vmni = Vmni*1e3;
0206   
0207   % Load neighbour data for filter calculation
0208   [nextDD,nextIX] = vb_load_cortex_neighbour(brain_file); 
0209   vbmeg_inst.plotcmap{inst_id}.nextDD = nextDD;
0210   vbmeg_inst.plotcmap{inst_id}.nextIX = nextIX;
0211 
0212   set(h_fig,'Pointer','arrow');
0213   vb_disp('Cortical surface file loaded: job_plot_cmap_load_data', ...
0214           'DEBUG');
0215 
0216 end
0217 
0218 % load current data
0219 update_flag = vb_table_query_update_flag(props_out,'current_file');
0220 
0221 if update_flag, 
0222   curr_file = vb_table_query_value(props_out,'current_file');
0223 else
0224   curr_file = '';
0225 end
0226 
0227 if ~isempty(curr_file),
0228   vbmeg_inst.plotcmap{inst_id}.curr_file = curr_file;
0229   
0230   % clear time-frequency variables
0231   vbmeg_inst.plotcmap{inst_id}.tf_file    = [];
0232   vbmeg_inst.plotcmap{inst_id}.data       = [];
0233   vbmeg_inst.plotcmap{inst_id}.TFmax      = [];
0234   vbmeg_inst.plotcmap{inst_id}.TFmin      = [];
0235   vbmeg_inst.plotcmap{inst_id}.TFmax_plot = [];
0236   vbmeg_inst.plotcmap{inst_id}.TFmin_plot = [];
0237   vbmeg_inst.plotcmap{inst_id}.foi        = [];
0238   vbmeg_inst.plotcmap{inst_id}.TFinfo     = [];
0239   
0240   % load Jinfo (header of current data)
0241   set(h_fig,'Pointer','watch');
0242   drawnow;
0243   Jinfo = vb_load_current_info(curr_file);
0244   vbmeg_inst.plotcmap{inst_id}.Jinfo = Jinfo;
0245   set(h_fig,'Pointer','arrow');
0246   
0247   % average mode
0248   ave_mode_str = vb_table_query_value(props_out,'current_load_mode');
0249 
0250   if strcmp(ave_mode_str,'ave'), 
0251     ave_mode = true;
0252   elseif Jinfo.Ntrial==1, 
0253     ave_mode = true;
0254   else
0255     ave_mode = false;
0256   end
0257   
0258   if ave_mode,
0259     set(ed1,'Enable','off');
0260   else
0261     set(ed1,'Enable','on');
0262   end
0263   vbmeg_inst.plotcmap{inst_id}.ave_mode = ave_mode;
0264   
0265   % trial index
0266   ix_trial = vb_table_query_value(props_out,'current_trial');
0267   
0268   %if ix_trial>Jinfo.Ntrial
0269   %  ix_trial = 1;
0270   %  % some message of this overwrite should be helpful
0271   %end
0272 
0273   vbmeg_inst.plotcmap{inst_id}.ix_trial = ix_trial;
0274   set(ed1,'String',num2str(ix_trial));
0275   
0276   % load current data
0277   set(h_fig,'Pointer','watch');
0278   drawnow; 
0279   [tmp,Jact] = vb_load_current(curr_file,0,ave_mode,ix_trial);
0280   set(h_fig,'Pointer','arrow');
0281   if ~isempty(vbmeg_inst.plotcmap{inst_id}.V), 
0282     if max(Jinfo.ix_act_ex)>size(vbmeg_inst.plotcmap{inst_id}.V,1), 
0283       warndlg(['Index of dipole currents exceeds the number of ' ...
0284                'vertices.']);
0285       return;
0286     end
0287   end
0288 
0289   % dipole current direction is flipped to inward
0290   vbmeg_inst.plotcmap{inst_id}.Jact = -1*Jact;
0291   clear Jact;
0292   
0293   % plotcmap.ix_act was obsoleted
0294   if ~isfield(Jinfo,'version') || ...
0295         vb_version_cmp(Jinfo.version,'<','0.9-0.a.0'),
0296     if isfield(Jinfo,'ix_act_ex'), 
0297       vbmeg_inst.plotcmap{inst_id}.ix_act = Jinfo.ix_act_ex;
0298     else
0299       vbmeg_inst.plotcmap{inst_id}.ix_act = Jinfo.ix_act;
0300     end
0301   end
0302 
0303   % background current is not supported.
0304   vbmeg_inst.plotcmap{inst_id}.Jbck = [];
0305   vbmeg_inst.plotcmap{inst_id}.ix_bck = [];
0306 
0307   % temporal information
0308   if isfield(Jinfo,'version') & ...
0309         vb_version_cmp(Jinfo.version,'>=','0.9-0.a.0'), 
0310     T = Jinfo.Tmsec;
0311     vbmeg_inst.plotcmap{inst_id}.Jinfo = Jinfo;
0312   else
0313     load(curr_file,'MEGinfo');
0314     if exist('MEGinfo'), 
0315       T = (1000/MEGinfo.SampleFreq) ...
0316           *(Jinfo.Tsample-vb_meginfo_get_pre_trigger(MEGinfo));
0317       if exist('Jinfo'), 
0318         vbmeg_inst.plotcmap{inst_id}.Jinfo = Jinfo;
0319       else
0320         vbmeg_inst.plotcmap{inst_id}.Jinfo = MEGinfo;
0321       end
0322       vbmeg_inst.plotcmap{inst_id}.Jinfo.version = '0.7';
0323       vbmeg_inst.plotcmap{inst_id}.Tstart = Jinfo.Tsample(1);
0324     else
0325       T = Jinfo.Tmsec;
0326       vbmeg_inst.plotcmap{inst_id}.Jinfo = Jinfo;
0327       vbmeg_inst.plotcmap{inst_id}.Jinfo.version = '0.7';
0328       vbmeg_inst.plotcmap{inst_id}.Tstart = Jinfo.Tsample(1);
0329     end
0330   end
0331 
0332   vbmeg_inst.plotcmap{inst_id}.toi = [T(1) T(2)];
0333 
0334   % other parameters
0335   if isfield(Jinfo,'patch_norm'), 
0336     vbmeg_inst.plotcmap{inst_id}.Jinfo.patch_norm = Jinfo.patch_norm;
0337   else
0338     if isfield(Jinfo,'bayes_parm') ...
0339           & isfield(Jinfo.bayes_parm,'patch_norm'), 
0340       vbmeg_inst.plotcmap{inst_id}.Jinfo.patch_norm ...
0341           = Jinfo.bayes_parm.patch_norm;
0342     else
0343       load(curr_file,'bayes_parm');
0344       if exist('bayes_parm'), 
0345         % following line will be deleted after checking function:
0346         % vbmeg_inst.plotcmap{inst_id}.bayes_parm = bayes_parm;
0347         vbmeg_inst.plotcmap{inst_id}.Jinfo.patch_norm = ...
0348             bayes_parm.patch_norm;
0349       else
0350         vbmeg_inst.plotcmap{inst_id}.Jinfo.patch_norm = false;
0351       end
0352     end
0353   end
0354 
0355   % The following code about current amplitude is the same with that in
0356   % job_plot_cmap_change_trial, and thus should be modified such as
0357   % invoking the function in some way to remove duplication of code.
0358   % physical unit of current
0359   if vbmeg_inst.plotcmap{inst_id}.patch_norm, % [pAm/mm^2]
0360     vbmeg_inst.plotcmap{inst_id}.Jact ...
0361         = vbmeg_inst.plotcmap{inst_id}.Jact*1e6; % (=1e12*1e-6);
0362     vbmeg_inst.plotcmap{inst_id}.Jbck ...
0363         = vbmeg_inst.plotcmap{inst_id}.Jbck*1e6; % (=1e12*1e-6);
0364   else                          % [nAm]
0365     vbmeg_inst.plotcmap{inst_id}.Jact ...
0366         = vbmeg_inst.plotcmap{inst_id}.Jact*1e9;
0367     vbmeg_inst.plotcmap{inst_id}.Jbck ...
0368         = vbmeg_inst.plotcmap{inst_id}.Jbck*1e9;
0369   end
0370 
0371   % scale of current amplitude
0372   if size(vbmeg_inst.plotcmap{inst_id}.Jact,3) > 1
0373     ix_trial = vbmeg_inst.plotcmap{inst_id}.ix_trial;
0374     Jmax = max(max(abs(vbmeg_inst.plotcmap{inst_id}.Jact(:,:,ix_trial))));
0375     Jmin = min(min(abs(vbmeg_inst.plotcmap{inst_id}.Jact(:,:,ix_trial))));
0376   else
0377     Jmax = max(max(abs(vbmeg_inst.plotcmap{inst_id}.Jact(:,:))));
0378     Jmin = min(min(abs(vbmeg_inst.plotcmap{inst_id}.Jact(:,:))));
0379   end
0380   vbmeg_inst.plotcmap{inst_id}.Jmax = Jmax;
0381   vbmeg_inst.plotcmap{inst_id}.Jmin = Jmin;
0382   vbmeg_inst.plotcmap{inst_id}.Jmax_plot = Jmax;
0383   vbmeg_inst.plotcmap{inst_id}.Jmin_plot = Jmax*0.1;
0384   
0385   % clear string in textbox for time-frequency data
0386   set(vbmeg_inst.plotcmap{inst_id}.ed10,'String','');
0387 end
0388 
0389 % load cortical area data
0390 update_flag = vb_table_query_update_flag(props_out,'area_file');
0391 
0392 if update_flag,
0393   area_file = vb_table_query_value(props_out,'area_file');
0394 else
0395   area_file = '';
0396 end
0397 
0398 if ~isempty(area_file),
0399   vbmeg_inst.plotcmap{inst_id}.area_file = area_file;
0400   
0401   % update listbox
0402   keyset = vb_get_keyset_area(area_file);
0403   set(vbmeg_inst.plotcmap{inst_id}.lb2,'String',keyset);
0404   set(vbmeg_inst.plotcmap{inst_id}.lb2,'Value',1);
0405   
0406   % Update cortical area
0407   job_plot_cmap_update_area(inst_id);
0408 end
0409 
0410 % load cortical activity data
0411 update_flag = vb_table_query_update_flag(props_out,'act_file');
0412 
0413 if update_flag, 
0414   act_file = vb_table_query_value(props_out,'act_file');
0415 else
0416   act_file = '';
0417 end
0418 
0419 if ~isempty(act_file),
0420   % filename
0421   vbmeg_inst.plotcmap{inst_id}.act_file = act_file;
0422   
0423   % update listbox
0424   keyset = vb_get_keyset_act(act_file);
0425   set(vbmeg_inst.plotcmap{inst_id}.lb1,'String',keyset);
0426   set(vbmeg_inst.plotcmap{inst_id}.lb1,'Value',1);
0427   
0428   % update activity map
0429   job_plot_cmap_update_xxP(inst_id);
0430 end
0431 
0432 % change figure title/act_file/area_file edit box
0433 if ~isempty(curr_file), 
0434   [tmp,fname,ext] = fileparts(curr_file);
0435   set(h_fig,'Name',['job_plot_currentmap: ' fname ext]);
0436 %elseif ~isempty(tf_file),
0437 %  [tmp,fname,ext] = fileparts(curr_file);
0438 %  set(h_fig,'Name',['job_plot_currentmap: ' fname ext]);
0439 else
0440   set(h_fig,'Name',['job_plot_currentmap: ']);
0441 end
0442 
0443 % Update plots
0444 job_plot_cmap_update_colorbarscale(inst_id);
0445 job_plot_cmap_update_filterradius(inst_id);
0446 job_plot_cmap_update_timecourse(inst_id); 
0447 job_plot_cmap_update_spatialpattern(inst_id);
0448 
0449 return;

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