0001 function job_plot_cmap_load_data(inst_id,parms)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 global vbmeg_inst;
0025
0026
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
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
0042 if nargin<2, parms = []; end
0043
0044
0045 props_in = [];
0046
0047
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
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
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
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
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
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
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
0173 props_out = job_plot_cmap_setting_dlg(props_in);
0174
0175
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
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
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
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
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
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
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
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
0266 ix_trial = vb_table_query_value(props_out,'current_trial');
0267
0268
0269
0270
0271
0272
0273 vbmeg_inst.plotcmap{inst_id}.ix_trial = ix_trial;
0274 set(ed1,'String',num2str(ix_trial));
0275
0276
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
0290 vbmeg_inst.plotcmap{inst_id}.Jact = -1*Jact;
0291 clear Jact;
0292
0293
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
0304 vbmeg_inst.plotcmap{inst_id}.Jbck = [];
0305 vbmeg_inst.plotcmap{inst_id}.ix_bck = [];
0306
0307
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
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
0346
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
0356
0357
0358
0359 if vbmeg_inst.plotcmap{inst_id}.patch_norm,
0360 vbmeg_inst.plotcmap{inst_id}.Jact ...
0361 = vbmeg_inst.plotcmap{inst_id}.Jact*1e6;
0362 vbmeg_inst.plotcmap{inst_id}.Jbck ...
0363 = vbmeg_inst.plotcmap{inst_id}.Jbck*1e6;
0364 else
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
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
0386 set(vbmeg_inst.plotcmap{inst_id}.ed10,'String','');
0387 end
0388
0389
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
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
0407 job_plot_cmap_update_area(inst_id);
0408 end
0409
0410
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
0421 vbmeg_inst.plotcmap{inst_id}.act_file = act_file;
0422
0423
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
0429 job_plot_cmap_update_xxP(inst_id);
0430 end
0431
0432
0433 if ~isempty(curr_file),
0434 [tmp,fname,ext] = fileparts(curr_file);
0435 set(h_fig,'Name',['job_plot_currentmap: ' fname ext]);
0436
0437
0438
0439 else
0440 set(h_fig,'Name',['job_plot_currentmap: ']);
0441 end
0442
0443
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;