Home > vbmeg > functions > job > job_plot_meg_dir > job_plot_meg_load_meg.m

job_plot_meg_load_meg

PURPOSE ^

Load MEG data (callback function of job_plot_meg).

SYNOPSIS ^

function job_plot_meg_load_meg(inst_id,megfile,mode,twin_lim,twin_ini)

DESCRIPTION ^

 Load MEG data (callback function of job_plot_meg).

 [syntax]
 job_plot_meg_load_meg(inst_id,megfile,mode,twin_lim,twin_ini)
 [input]
 - inst_id       : instance id of gui.
 - megfile       : MEG data file (.meg.mat)
 - mode          : = 0 % loading average data
                   = 1 % loading all trials
                   = 2 % intaraction mode(default)
 - twin_lim      : Time window selection limit(meg data index)
                   e.g. twin_lim = [300, 500];
 - twin_ini      : Initial Time window selection(meg data index)
                   (default:[Pretrigger, Pretrigger] from 0msec to 0msec)
                   e.g. twin_ini = [300, 500];

 [history]
 2008-09-02 Taku Yoshioka
 2008-10-24 Taku Yoshioka
   Support EEG data
 2011-02-10 taku-y
  [debug] Channelinfo correctly loaded.
 2011-06-01 (Sako) converted return values of vb_load_device to upper case
 2012-06-12 taku-y
  [minor] Not invoke confirmation dialog for trial averaging when
  MEG-MAT file contains single trial. 
 2013-7-05  Masa-aki Sato 
    load sensor pos using 'vb_load_channel_pos'
 2015-12-14 rhayashi
    supported fileinfo MEG/EEG-MAT format.

 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_meg_load_meg(inst_id,megfile,mode,twin_lim,twin_ini)
0002 % Load MEG data (callback function of job_plot_meg).
0003 %
0004 % [syntax]
0005 % job_plot_meg_load_meg(inst_id,megfile,mode,twin_lim,twin_ini)
0006 % [input]
0007 % - inst_id       : instance id of gui.
0008 % - megfile       : MEG data file (.meg.mat)
0009 % - mode          : = 0 % loading average data
0010 %                   = 1 % loading all trials
0011 %                   = 2 % intaraction mode(default)
0012 % - twin_lim      : Time window selection limit(meg data index)
0013 %                   e.g. twin_lim = [300, 500];
0014 % - twin_ini      : Initial Time window selection(meg data index)
0015 %                   (default:[Pretrigger, Pretrigger] from 0msec to 0msec)
0016 %                   e.g. twin_ini = [300, 500];
0017 %
0018 % [history]
0019 % 2008-09-02 Taku Yoshioka
0020 % 2008-10-24 Taku Yoshioka
0021 %   Support EEG data
0022 % 2011-02-10 taku-y
0023 %  [debug] Channelinfo correctly loaded.
0024 % 2011-06-01 (Sako) converted return values of vb_load_device to upper case
0025 % 2012-06-12 taku-y
0026 %  [minor] Not invoke confirmation dialog for trial averaging when
0027 %  MEG-MAT file contains single trial.
0028 % 2013-7-05  Masa-aki Sato
0029 %    load sensor pos using 'vb_load_channel_pos'
0030 % 2015-12-14 rhayashi
0031 %    supported fileinfo MEG/EEG-MAT format.
0032 %
0033 % Copyright (C) 2011, ATR All Rights Reserved.
0034 % License : New BSD License(see VBMEG_LICENSE.txt)
0035 
0036 global vbmeg_inst;
0037 define_job_plot_meg_const;
0038 
0039 %
0040 % Input parameters
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 if nargin<5, twin_ini = []; end
0044 if nargin<4, twin_lim = []; end
0045 if nargin<3, mode = 2; end
0046 
0047 %
0048 % Check file and switch average/raw data
0049 %
0050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051 if ~exist(megfile,'file'),
0052   warndlg(['File ' megfile ' does not exist.']);
0053   return;
0054 end
0055 
0056 if mode == 2, 
0057   MEGinfo = vb_load_meg_info(megfile);
0058   if MEGinfo.Nrepeat>1, 
0059     button = questdlg(['Which of average or raw MEG/EEG data ' ...
0060                        'do you want to load?'],'Load MEG/EEG data', ...
0061                       'Average','Raw','Average');
0062     if strcmp(button,'Average'), 
0063       mode = 0; 
0064     else 
0065       mode = 1; 
0066     end
0067   else
0068     mode = 0;
0069   end
0070 end
0071 
0072 %
0073 % Load MEG data
0074 %
0075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0076 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Pointer','watch');
0077 drawnow;
0078 
0079 % MEG data
0080 pick = vb_load_channel(megfile);
0081 if isempty(pick)
0082     job_plot_meg_close(inst_id);
0083     error('Specified MEG/EEG file doesn''t contain sensor position. Import data with .pos.mat file.');
0084     return;
0085 end
0086 measurement_str = vb_load_device(megfile);
0087 if strcmpi(measurement_str, 'INFO')
0088     load(megfile, 'fileinfo');
0089     measurement_str = vb_load_device(fileinfo.filename{1});
0090 end
0091 Measurement_str = upper(measurement_str);
0092 [bexp, ch_info] = vb_load_meg_data(megfile);
0093 MEGinfo = vb_load_meg_info(megfile);
0094 
0095 % Channel type information
0096 MEGinfo.ChannelInfo = ch_info;
0097 
0098 if mode==0, bexp = mean(bexp,3); end
0099 pretrigger = vb_meginfo_get_pre_trigger(MEGinfo);
0100 if isempty(pretrigger), pretrigger = 0; end
0101 N = size(bexp,1);
0102 T = ((1:MEGinfo.Nsample)-pretrigger-1)*(1000/MEGinfo.SampleFreq);
0103 if isempty(twin_lim), twin_lim = [1, MEGinfo.Nsample]; end
0104 if isempty(twin_ini), twin_ini = [1, 1]; end
0105 
0106 vbmeg_inst.plotmeg{inst_id}.megfile = megfile;
0107 % Measurement_str = vb_load_device(megfile);
0108 switch Measurement_str
0109  case 'MEG', 
0110   vbmeg_inst.plotmeg{inst_id}.bexp = bexp*1e15; % T -> fT
0111   vbmeg_inst.plotmeg{inst_id}.ylabel_str = 'MEG signal [fT]';
0112  case 'EEG',
0113   vbmeg_inst.plotmeg{inst_id}.bexp = bexp*1e6; % V -> micro V
0114   vbmeg_inst.plotmeg{inst_id}.ylabel_str = 'EEG signal [\mu V]';
0115 end
0116 
0117 clear bexp;
0118 vbmeg_inst.plotmeg{inst_id}.pick = pick;
0119 vbmeg_inst.plotmeg{inst_id}.MEGinfo = MEGinfo;
0120 vbmeg_inst.plotmeg{inst_id}.N = N; 
0121 vbmeg_inst.plotmeg{inst_id}.T = T;
0122 vbmeg_inst.plotmeg{inst_id}.twin_lim = twin_lim;
0123 vbmeg_inst.plotmeg{inst_id}.twin_ini = twin_ini;
0124 
0125 % Display parameters
0126 vbmeg_inst.plotmeg{inst_id}.n_trial = 1; 
0127 vbmeg_inst.plotmeg{inst_id}.t = [T(min(twin_ini)) T(max(twin_ini))]; 
0128 
0129 %
0130 % Delete old menu for sensor type
0131 %
0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133 h = vbmeg_inst.plotmeg{inst_id}.sensor_type_menu;
0134 hh = get(h,'Children');
0135 for i=1:length(hh)
0136   delete(hh(i));
0137 end
0138 
0139 %
0140 % Create new menu for sensor type
0141 %
0142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0143 
0144 sensor_type_list   = [];
0145 sensor_type_string = cell(0);
0146 if strcmpi(Measurement_str, 'MEG') && ~isempty(ch_info)
0147 
0148     % Sensor type information for Yokogawa MEG (@ATR)
0149     meg_sensor_type_list = sort(unique(ch_info.Type));
0150 
0151     for k=1:length(meg_sensor_type_list)
0152         sensor_type = meg_sensor_type_list(k);
0153         if sensor_type == 1
0154             sensor_type_list = [sensor_type_list, 1];
0155             sensor_type_string{k} = 'Magnetometer';
0156         elseif sensor_type == 2
0157             sensor_type_list = [sensor_type_list, 2];
0158             sensor_type_string{k} = 'Axial gradiometer';
0159         elseif sensor_type == 3
0160             sensor_type_list = [sensor_type_list, 3];
0161             sensor_type_string{k} = 'Planar gradiometer';
0162         end
0163     end
0164 end
0165 sensor_type_list = [sensor_type_list, -1]; % -1 is all;
0166 sensor_type_string{end+1} = 'All';
0167 
0168 % Create menu
0169 vbmeg_inst.plotmeg{inst_id}.sensor_type_list = sensor_type_list;
0170 h = vbmeg_inst.plotmeg{inst_id}.sensor_type_menu;
0171 
0172 for i=1:length(sensor_type_list)
0173   command = ['job_plot_meg_change_sensor_type(' num2str(inst_id) ...
0174              ',' num2str(i) ');'];
0175   hh = uimenu(h,'Label',sensor_type_string{i},'Callback',command, ...
0176               'Tag',['submenu' num2str(i)]);
0177   vbmeg_inst.plotmeg{inst_id}.h_sensortype(i) = hh;
0178   set(hh,'Checked','off');
0179 end
0180 
0181 % Set sensor type (default:Axial gradiometer)
0182 ix = find(sensor_type_list == 2);
0183 if ~isempty(ix)
0184     vbmeg_inst.plotmeg{inst_id}.sensor_type = 2;  % Axial gradiometer
0185     set(vbmeg_inst.plotmeg{inst_id}.h_sensortype(ix),'Checked','on');
0186 else
0187     vbmeg_inst.plotmeg{inst_id}.sensor_type = -1; % All
0188     set(vbmeg_inst.plotmeg{inst_id}.h_sensortype(end),'Checked','on');
0189 end
0190 
0191 % Reset sensor infomation
0192 job_plot_meg_choose_plot_sensor(inst_id, 'reset');
0193 
0194 %
0195 % Update plots
0196 %
0197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0198 job_plot_meg_update_spatialpattern(inst_id);
0199 job_plot_meg_update_timecourse(inst_id,FORCE_UPDATE); 
0200 
0201 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Pointer','arrow');
0202 
0203 %
0204 % Change figure title
0205 %
0206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0207 [tmp,fname,ext] = fileparts(megfile);
0208 set(vbmeg_inst.plotmeg{inst_id}.h_fig,'Name', ...
0209                   ['job_plot_meg: ' fname ext]);

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