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

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