Home > functions > common > loadfunc > vb_load_sensor.m

vb_load_sensor

PURPOSE ^

This function returns sensor coordinate value and sensor information.

SYNOPSIS ^

function [pick, Qpick, CoilWeight, Vcenter, result] =vb_load_sensor(megfile, ch_type, ch_name, active_swt, method)

DESCRIPTION ^

 This function returns sensor coordinate value and sensor information.
 [usage]
   [pick, Qpick, CoilWeight, Vcenter, result] = ...
     vb_load_sensor(megfile, ch_type, ch_name, active_swt, method)
 [input]
      megfile : <required> <<file>> MEG-MAT file or EEG-MAT file
      ch_type : <optional> <<string>> channel type ['']
              :  '' or 'MEG' : MEG channels of MEG
              :        'REF' : REFFERENCE channels of MEG
              :        'ALL' : MEG + REFFERENCE channels of MEG
              :        'AXIAL' : axial channels
              :        'PLANAR' : planar channels
              :  case-insensitive
      ch_name : <optional> <<cell array>> channel name list [{''}(empty)]
              :  If ch_type is specified, this is ignored.
   active_swt : <optional> <<boolean>> switch to filter channel
              :   if .ActiveChannel is valid [true]
              :   if .ActiveChannel is invalid [false]
              :    true) return only active channels
              :   false) return all the channels
       method : <optional> method of calculation
              :  ['AVE'] : average
              :   'TOP'  : use top data
              :  this is valid for 'INIT' mode
 [output]
         pick : n-th coil position  (Right-hand SPM coordinate) [m]
              :  [Ncoil x 3]
        Qpick : n-th coil direction (Right-hand SPM coordinate)
              :  [Ncoil x 3]
   CoilWeight : n-th coil weight for m-th channel [Nchannel x Ncoil]
              : basis(channel,dipole) = CoilWeight * basis(coil,dipole)
      Vcenter : Center of spherical head model [m] [1 x 3]
       result : <<integer>> error infomation
              :  In the case that meg_file is '.info.mat' file and method is
              :  'AVE', this will become error struct.
              :  fields are as follows:
              :  These are errors between base data of each file and average.
              :   .error_pick [n_ch x 3 x n_file]
              :   .error_Qpick [n_ch x 3 x n_file] (if they are)
 [note]
   if megfile is SBI data file or EEG-MAT file, REFFERENCE channel is empty

 [see also]
   vb_megfile_get_sensor_position_by_name
   vb_megfile_get_sensor_position_by_type

 [history]
   2006-11-01 (Sako) modified to be able to accept EEGinfo
   2007-07-24 (Sako) added channel mode
   2008-04-16 (Sako) added active_swt, result
   2008-06-04 (Sako) changed default value of active_swt
   2009-08-21 (????) supported 'INFO' as "Measurement" but 'mode' is ignored
   2010-08-24 (Sako) added method argument
   2011-06-02 (Sako) converted return values of vb_load_device to upper case
   2011-07-26 (Sako) changed mode to ch_type, added ch_name as arguments

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [pick, Qpick, CoilWeight, Vcenter, result] = ...
0002   vb_load_sensor(megfile, ch_type, ch_name, active_swt, method)
0003 % This function returns sensor coordinate value and sensor information.
0004 % [usage]
0005 %   [pick, Qpick, CoilWeight, Vcenter, result] = ...
0006 %     vb_load_sensor(megfile, ch_type, ch_name, active_swt, method)
0007 % [input]
0008 %      megfile : <required> <<file>> MEG-MAT file or EEG-MAT file
0009 %      ch_type : <optional> <<string>> channel type ['']
0010 %              :  '' or 'MEG' : MEG channels of MEG
0011 %              :        'REF' : REFFERENCE channels of MEG
0012 %              :        'ALL' : MEG + REFFERENCE channels of MEG
0013 %              :        'AXIAL' : axial channels
0014 %              :        'PLANAR' : planar channels
0015 %              :  case-insensitive
0016 %      ch_name : <optional> <<cell array>> channel name list [{''}(empty)]
0017 %              :  If ch_type is specified, this is ignored.
0018 %   active_swt : <optional> <<boolean>> switch to filter channel
0019 %              :   if .ActiveChannel is valid [true]
0020 %              :   if .ActiveChannel is invalid [false]
0021 %              :    true) return only active channels
0022 %              :   false) return all the channels
0023 %       method : <optional> method of calculation
0024 %              :  ['AVE'] : average
0025 %              :   'TOP'  : use top data
0026 %              :  this is valid for 'INIT' mode
0027 % [output]
0028 %         pick : n-th coil position  (Right-hand SPM coordinate) [m]
0029 %              :  [Ncoil x 3]
0030 %        Qpick : n-th coil direction (Right-hand SPM coordinate)
0031 %              :  [Ncoil x 3]
0032 %   CoilWeight : n-th coil weight for m-th channel [Nchannel x Ncoil]
0033 %              : basis(channel,dipole) = CoilWeight * basis(coil,dipole)
0034 %      Vcenter : Center of spherical head model [m] [1 x 3]
0035 %       result : <<integer>> error infomation
0036 %              :  In the case that meg_file is '.info.mat' file and method is
0037 %              :  'AVE', this will become error struct.
0038 %              :  fields are as follows:
0039 %              :  These are errors between base data of each file and average.
0040 %              :   .error_pick [n_ch x 3 x n_file]
0041 %              :   .error_Qpick [n_ch x 3 x n_file] (if they are)
0042 % [note]
0043 %   if megfile is SBI data file or EEG-MAT file, REFFERENCE channel is empty
0044 %
0045 % [see also]
0046 %   vb_megfile_get_sensor_position_by_name
0047 %   vb_megfile_get_sensor_position_by_type
0048 %
0049 % [history]
0050 %   2006-11-01 (Sako) modified to be able to accept EEGinfo
0051 %   2007-07-24 (Sako) added channel mode
0052 %   2008-04-16 (Sako) added active_swt, result
0053 %   2008-06-04 (Sako) changed default value of active_swt
0054 %   2009-08-21 (????) supported 'INFO' as "Measurement" but 'mode' is ignored
0055 %   2010-08-24 (Sako) added method argument
0056 %   2011-06-02 (Sako) converted return values of vb_load_device to upper case
0057 %   2011-07-26 (Sako) changed mode to ch_type, added ch_name as arguments
0058 %
0059 % Copyright (C) 2011, ATR All Rights Reserved.
0060 % License : New BSD License(see VBMEG_LICENSE.txt)
0061 
0062 % --- CHECK ARGUMENTS --- %
0063 if ~exist('megfile', 'var'), megfile = []; end
0064 if ~exist('ch_type', 'var'), ch_type = []; end
0065 if ~exist('ch_name', 'var'), ch_name = []; end
0066 if ~exist('active_swt', 'var'), active_swt = []; end
0067 if ~exist('method', 'var'), method = ''; end
0068 [megfile, ch_type, ch_name, active_swt, method, result] = ...
0069   inner_check_arguments(megfile, ch_type, ch_name, active_swt, method);
0070 
0071 % --- MAIN PROCEDURE --------------------------------------------------------- %
0072 %
0073 pick = [];
0074 Qpick = [];
0075 CoilWeight = [];
0076 Vcenter = [];
0077 
0078 if result ~= 0
0079   return;
0080 end
0081 
0082 func_ = mfilename;
0083 
0084 measurement = vb_load_device(megfile);
0085 Measurement = upper(measurement);
0086 
0087 % return variables
0088 % check measurement parameter
0089 switch  Measurement
0090   case  'MEG'
0091     if ~isempty(ch_type)
0092       [pick, Qpick, CoilWeight, Vcenter, result] = ...
0093         vb_megfile_get_sensor_position_by_type(megfile, ch_type, active_swt);
0094 
0095     elseif ~isempty(ch_name) && ~isempty(ch_name{1})
0096       [pick, Qpick, CoilWeight, Vcenter, result] = ...
0097         vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt);
0098       
0099     else
0100       error('(%s) Both ch_type and ch_name are invalid', mfilename);
0101     end
0102 
0103   case  'EEG'
0104     % for EEG
0105     if strcmp(ch_type, 'REF')
0106       % return empty
0107       return;
0108     else
0109       [pick, Vcenter, result] = vb_load_eeg_sensor(megfile, active_swt);
0110       return;
0111     end
0112   
0113   case  'INFO'
0114     load(megfile, 'fileinfo');
0115 
0116     switch method
0117       case 'AVE'
0118         [pick, Qpick, CoilWeight, Vcenter, result] = ...
0119           inner_calc_average(fileinfo);
0120       case 'TOP'
0121         [pick, Qpick, CoilWeight, Vcenter, result] = ...
0122           vb_load_sensor(fileinfo.filename{1});
0123       otherwise
0124         msg = sprintf('(%s) undefined method : %s --> average', ...
0125           'vb_load_sensor', method);
0126         vb_disp(msg);
0127         [pick, Qpick, CoilWeight, Vcenter, result] = ...
0128           inner_calc_average(fileinfo);
0129     end
0130 
0131     channel_id = fileinfo.channel_id;
0132 
0133     if isempty(CoilWeight)
0134         pick = pick(channel_id,:);
0135       else    
0136         weight  = CoilWeight(channel_id,:);
0137         ix_coil = find( sum(abs(weight), 1) > 0);
0138         
0139         pick = pick(ix_coil,:);
0140         Qpick = Qpick(ix_coil,:);
0141         CoilWeight = weight(:,ix_coil);
0142     end
0143 
0144   otherwise
0145     msg = sprintf('(%s)unknown Measurement : %s', func_, Measurement);
0146     vb_disp(msg);
0147     result = 2;
0148 end
0149 
0150 % --- solve empty center problem
0151 if isempty(Vcenter)
0152   msg = sprintf('(%s)\n--- MEGinfo may not have ''Vcenter'' field in %s.', ...
0153     mfilename, megfile);
0154   if ~isempty(pick)
0155     msg = sprintf('%s\n--- calculate temporary center coordinate', msg);
0156     Vcenter = sum(pick, 1) ./ size(pick, 1);
0157   end
0158   vb_disp(msg, 'WARNING');
0159 end
0160 return;
0161 %
0162 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0163 
0164 % --- INNER FUNCTIONS -------------------------------------------------------- %
0165 %
0166 % --- inner_check_arguments()
0167 %
0168 function [megfile, ch_type, ch_name, active_swt, method, result] = ...
0169   inner_check_arguments(megfile, ch_type, ch_name, active_swt, method)
0170 func_ = mfilename;
0171 result = 0; % success
0172 
0173 if isempty(megfile)
0174   msg = sprintf('(%s)megfile is a required parameter', func_);
0175   vb_disp(msg);
0176   result = 1; % error code 1 means bad megfile
0177   return;
0178 end
0179 
0180 if exist(megfile, 'file') ~= 2
0181   msg = sprintf('(%s)cannot find megfile : %s', func_, megfile);
0182   vb_disp(msg);
0183   result = 1;
0184   return;
0185 end
0186 
0187 % --- ch_name must be a cell array
0188 if ~iscell(ch_name)
0189   ch_name = {ch_name};
0190 end
0191 
0192 if isempty(ch_type)
0193   if isempty(ch_name) || isempty(ch_name{1})
0194     ch_type = 'MEG';
0195   end
0196 end
0197 
0198 % case-insensitive
0199 ch_type = upper(ch_type);
0200 
0201 if isempty(active_swt)
0202   if vb_msrmnt_active_channel_is_valid(megfile)
0203     active_swt = true;
0204   else
0205     active_swt = false;
0206   end
0207 end
0208 
0209 if isempty(method)
0210   method = 'AVE';
0211 end
0212 method = upper(method);
0213 return;
0214 %
0215 % --- end of inner_check_arguments()
0216 
0217 % --- inner_calc_average()
0218 %
0219 function [pick, Qpick, CoilWeight, Vcenter, result] = ...
0220           inner_calc_average(fileinfo)
0221 %
0222 n_file = length(fileinfo.filename);
0223 
0224 pick = 0;
0225 Qpick = 0;
0226 CoilWeight = 0;
0227 Vcenter = 0;
0228 
0229 for i_file = 1:n_file
0230   cur_file = fileinfo.filename{i_file};
0231   [a, b, c, d] = vb_load_sensor(cur_file);
0232   
0233   pick = pick + a;
0234   Qpick = Qpick + b;
0235   CoilWeight = CoilWeight + c;
0236   Vcenter = Vcenter + d;
0237 end
0238 
0239 pick = pick / n_file;
0240 Qpick = Qpick / n_file;
0241 CoilWeight = CoilWeight / n_file;
0242 Vcenter = Vcenter / n_file;
0243 
0244 error_pick = zeros(size(pick,1), size(pick,2), n_file);
0245 error_Qpick = zeros(size(Qpick,1), size(Qpick,2), n_file);
0246 
0247 % --- error
0248 for i_file = 1:n_file
0249   cur_file = fileinfo.filename{i_file};
0250   [a, b, c, d, result] = vb_load_sensor(cur_file);
0251   error_pick(:,:,i_file) = pick - a;
0252   error_Qpick(:,:,i_file) = Qpick - b;
0253 end
0254 
0255 result.error_pick = error_pick;
0256 result.error_Qpick = error_Qpick;
0257 return;
0258 %
0259 % --- end of inner_calc_average()
0260 %
0261 % --- END OF INNER FUNCTIONS ------------------------------------------------- %

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