Home > functions > job > vb_job_leadfield.m

vb_job_leadfield

PURPOSE ^

Calculate leadfield matrix and create leadfiled file (.basis.mat).

SYNOPSIS ^

function vb_job_leadfield(proj_root, basis_parm)

DESCRIPTION ^

 Calculate leadfield matrix and create leadfiled file (.basis.mat). 
 (VBMEG public function)

 This function can calculate leadfield matrix for using the following
 numerical methods: 
  MEG Sphere model (Sarvas equation)
  MEG 1-shell BEM (boundary element method)
  MEG Spherical harmonics expansion
  EEG 3-shell Sphere model
  EEG 3-shell BEM

 [syntax]
 vb_job_leadfield(proj_root, basis_parm)

 [input]
 proj_root : <<string>> VBMEG project root directory. 
 basis_parm: <<struct>> Parameters for leadfield calculation. 
 --- fields of basis_parm
  brain_file : <<string>> Cortical surface model file (.brain.mat).
  area_file  : <<string>> Cortical area file (.area.mat).
  meg_file   : <<string>> MEG-MAT or EEG-MAT file (.meg.mat).
  basis_file : <<string>> Leadfield file (.basis.mat). 
  bem_mode   : <<int>> Specify numerical method for calculating
               leadfield. 
   =0: MEG Sphere model (Sarvas equation).
   =1: MEG 1-shell BEM (boundary element method).
   =2: MEG Spherical harmonics expansion.
   =3: EEG 3-shell Sphere model.
   =4: EEG 3-shell BEM.
  head_file  : <optional><<string>> Head model file (.head.mat). This
               parameter is referred if the lead field is calculated by
               BEM or spherical harmonics expansion (see 'bem_mode'). 
               expansion 
  Basis_mode : <<int>> Degree of freedom of current direction. Not only
               the DOF, but also the direction of current dipoles at each
               vertex is also specified by this parameter. Currently
               VBMEG supports Basis_mode=1 (1st June, 2010). 
   =1: Single dipole perpendicular to the cortical surface. 
   =2: Double dipoles tangental to the cortical surface. 
   =3: Triple dipoles parallel to three axes (x, y, z). 
  Vcenter    : <<vector>> Coordinate value of the head center (1x3 on
               SPM_Right_m).
  func_order : <<int?>> Order of spherical harmonics function. This
               parameter is effective when employing spherical harmonics
               expansion (see 'bem_mode'). 
  sigma      : <<vector>> Conductivity from innermost to outermost. 
  radius     : <<vector>> Relative radius of sphere from innermost to
               outermost. 
  area_key   : <optional><<string>>
  normal_mode: <optional><int>
  Recalc     : <optional>
 ---

 [output]
 Leadfield file (.basis.mat) is created with filename specified by
 'basis_file' field. If BEM is used, head model file (.head.mat) is
 updated with a matrix, which depends only on the head model, not on the
 cortical surface model. So, if size of .head.mat file become large, it
 is not an error. 

 [note]
 This function call the following sub-functions in accordance with
 basis_parm.bem_mode: 
  vb_job_leadfield_meg_sphere
  vb_job_leadfield_meg_bem
  vb_job_leadfield_meg_harmonics
  vb_job_leadfield_eeg_sphere
  vb_job_leadfield_eeg_bem

 'vbmeg_inst' structure have constants for specifying the numerical
 method and model related to leadfield calculation. Those constants are
 recommended to specify parameters for readability of your program. 
 --- Constants for 'basis_parm.bem_mode'
  vbmeg_inst.const.BASIS_MEG_SPHERE    = 0
  vbmeg_inst.const.BASIS_MEG_BEM       = 1
  vbmeg_inst.const.BASIS_MEG_HARMONICS = 2
  vbmeg_inst.const.BASIS_MEG_SPHERE    = 3
  vbmeg_inst.const.BASIS_MEG_BEM       = 4
 --- Constants for 'basis_parm.Basis_mode'
  vbmeg_inst.const.CURRENT_NORMAL  = 1
  vbmeg_inst.const.CURRENT_TANGENT = 2
  vbmeg_inst.const.CURRENT_3D      = 3
 --- Constants for 'basis_parm.normal_mode
  vbmeg_inst.const.NORMAL_ADJACENT_MEAN = 0
  vbmeg_inst.const.NORMAL_NEIGHBOR_MEAN = 1
 ---

 [history]
   2007-01-26 (Sako) reworked the architecture
 2008-10-15 Taku Yoshioka
  Support '.sensortype' parameter (argument check)
 2010-05-?? Taku Yoshioka
  Minor change (verbose level support)

 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 vb_job_leadfield(proj_root, basis_parm)
0002 % Calculate leadfield matrix and create leadfiled file (.basis.mat).
0003 % (VBMEG public function)
0004 %
0005 % This function can calculate leadfield matrix for using the following
0006 % numerical methods:
0007 %  MEG Sphere model (Sarvas equation)
0008 %  MEG 1-shell BEM (boundary element method)
0009 %  MEG Spherical harmonics expansion
0010 %  EEG 3-shell Sphere model
0011 %  EEG 3-shell BEM
0012 %
0013 % [syntax]
0014 % vb_job_leadfield(proj_root, basis_parm)
0015 %
0016 % [input]
0017 % proj_root : <<string>> VBMEG project root directory.
0018 % basis_parm: <<struct>> Parameters for leadfield calculation.
0019 % --- fields of basis_parm
0020 %  brain_file : <<string>> Cortical surface model file (.brain.mat).
0021 %  area_file  : <<string>> Cortical area file (.area.mat).
0022 %  meg_file   : <<string>> MEG-MAT or EEG-MAT file (.meg.mat).
0023 %  basis_file : <<string>> Leadfield file (.basis.mat).
0024 %  bem_mode   : <<int>> Specify numerical method for calculating
0025 %               leadfield.
0026 %   =0: MEG Sphere model (Sarvas equation).
0027 %   =1: MEG 1-shell BEM (boundary element method).
0028 %   =2: MEG Spherical harmonics expansion.
0029 %   =3: EEG 3-shell Sphere model.
0030 %   =4: EEG 3-shell BEM.
0031 %  head_file  : <optional><<string>> Head model file (.head.mat). This
0032 %               parameter is referred if the lead field is calculated by
0033 %               BEM or spherical harmonics expansion (see 'bem_mode').
0034 %               expansion
0035 %  Basis_mode : <<int>> Degree of freedom of current direction. Not only
0036 %               the DOF, but also the direction of current dipoles at each
0037 %               vertex is also specified by this parameter. Currently
0038 %               VBMEG supports Basis_mode=1 (1st June, 2010).
0039 %   =1: Single dipole perpendicular to the cortical surface.
0040 %   =2: Double dipoles tangental to the cortical surface.
0041 %   =3: Triple dipoles parallel to three axes (x, y, z).
0042 %  Vcenter    : <<vector>> Coordinate value of the head center (1x3 on
0043 %               SPM_Right_m).
0044 %  func_order : <<int?>> Order of spherical harmonics function. This
0045 %               parameter is effective when employing spherical harmonics
0046 %               expansion (see 'bem_mode').
0047 %  sigma      : <<vector>> Conductivity from innermost to outermost.
0048 %  radius     : <<vector>> Relative radius of sphere from innermost to
0049 %               outermost.
0050 %  area_key   : <optional><<string>>
0051 %  normal_mode: <optional><int>
0052 %  Recalc     : <optional>
0053 % ---
0054 %
0055 % [output]
0056 % Leadfield file (.basis.mat) is created with filename specified by
0057 % 'basis_file' field. If BEM is used, head model file (.head.mat) is
0058 % updated with a matrix, which depends only on the head model, not on the
0059 % cortical surface model. So, if size of .head.mat file become large, it
0060 % is not an error.
0061 %
0062 % [note]
0063 % This function call the following sub-functions in accordance with
0064 % basis_parm.bem_mode:
0065 %  vb_job_leadfield_meg_sphere
0066 %  vb_job_leadfield_meg_bem
0067 %  vb_job_leadfield_meg_harmonics
0068 %  vb_job_leadfield_eeg_sphere
0069 %  vb_job_leadfield_eeg_bem
0070 %
0071 % 'vbmeg_inst' structure have constants for specifying the numerical
0072 % method and model related to leadfield calculation. Those constants are
0073 % recommended to specify parameters for readability of your program.
0074 % --- Constants for 'basis_parm.bem_mode'
0075 %  vbmeg_inst.const.BASIS_MEG_SPHERE    = 0
0076 %  vbmeg_inst.const.BASIS_MEG_BEM       = 1
0077 %  vbmeg_inst.const.BASIS_MEG_HARMONICS = 2
0078 %  vbmeg_inst.const.BASIS_MEG_SPHERE    = 3
0079 %  vbmeg_inst.const.BASIS_MEG_BEM       = 4
0080 % --- Constants for 'basis_parm.Basis_mode'
0081 %  vbmeg_inst.const.CURRENT_NORMAL  = 1
0082 %  vbmeg_inst.const.CURRENT_TANGENT = 2
0083 %  vbmeg_inst.const.CURRENT_3D      = 3
0084 % --- Constants for 'basis_parm.normal_mode
0085 %  vbmeg_inst.const.NORMAL_ADJACENT_MEAN = 0
0086 %  vbmeg_inst.const.NORMAL_NEIGHBOR_MEAN = 1
0087 % ---
0088 %
0089 % [history]
0090 %   2007-01-26 (Sako) reworked the architecture
0091 % 2008-10-15 Taku Yoshioka
0092 %  Support '.sensortype' parameter (argument check)
0093 % 2010-05-?? Taku Yoshioka
0094 %  Minor change (verbose level support)
0095 %
0096 % Copyright (C) 2011, ATR All Rights Reserved.
0097 % License : New BSD License(see VBMEG_LICENSE.txt)
0098 
0099 global vbmeg_inst;
0100 const = vbmeg_inst.const;
0101 
0102 % --- CHECK ARGUMENTS --- %
0103 if ~exist('proj_root', 'var'), proj_root = []; end;
0104 if ~exist('basis_parm', 'var'), basis_parm = []; end;
0105 [proj_root, basis_parm] = inner_check_arguments(const, proj_root, basis_parm);
0106 
0107 % --- MAIN PROCEDURE --------------------------------------------------------- %
0108 %
0109 switch basis_parm.bem_mode
0110   case const.BASIS_MEG_SPHERE, 
0111     [basis, basis_parm] = vb_job_leadfield_meg_sphere(proj_root, basis_parm);
0112     
0113   case const.BASIS_MEG_BEM, 
0114     [basis, basis_parm] = vb_job_leadfield_meg_bem(proj_root, basis_parm);
0115   
0116   case const.BASIS_MEG_HARMONICS, 
0117     [basis, basis_parm] = vb_job_leadfield_meg_harmonics(proj_root, basis_parm);
0118 
0119   case const.BASIS_EEG_SPHERE, 
0120     [basis, basis_parm] = vb_job_leadfield_eeg_sphere(proj_root, basis_parm);
0121 
0122   case const.BASIS_EEG_BEM, 
0123     [basis, basis_parm] = vb_job_leadfield_eeg_bem(proj_root, basis_parm);
0124 end
0125 
0126 inner_terminate(const, proj_root, basis_parm, basis);
0127 %
0128 % --- MAIN PROCEDURE --------------------------------------------------------- %
0129 
0130 
0131 % --- INNER FUNCTIONS -------------------------------------------------------- %
0132 %
0133 % --- inner_terminate()
0134 %
0135 function inner_terminate(const, proj_root, basis_parm, basis)
0136 
0137 % const.BASIS_MEG_SPHERE;   %  MEG Sphere model (Sarvas)
0138 % const.BASIS_MEG_BEM;      %  MEG BEM
0139 % const.BASIS_MEG_HARMONICS;%  MEG Spherical harmonics expansion
0140 % const.BASIS_EEG_SPHERE;   %  EEG 3-shell Sphere model
0141 % const.BASIS_EEG_BEM;      %  EEG 3-shell BEM
0142 
0143 bem_name = { ...
0144     'MEG spherical model (Sarvas)'; ...
0145     'MEG BEM 1 shell model'; ...
0146     'MEG spherical harmonics expansion'; ...
0147     'EEG spherical 3 shell model'; ...
0148     'EEG BEM 3 shell model'; ...
0149 };
0150 
0151 switch basis_parm.bem_mode
0152   case  const.BASIS_MEG_SPHERE
0153     calc_type = bem_name{1};
0154     
0155   case  const.BASIS_MEG_BEM
0156     calc_type = bem_name{2};
0157     
0158   case  const.BASIS_MEG_HARMONICS
0159     calc_type = bem_name{3};
0160     
0161   case  const.BASIS_EEG_SPHERE
0162     calc_type = bem_name{4};
0163     
0164   case  const.BASIS_EEG_BEM
0165     calc_type = bem_name{5};
0166     
0167   otherwise
0168     calc_type = 'unknown calculation type';
0169 end
0170 
0171 vb_disp(sprintf('Leadfield calculation : %s', calc_type));
0172 vb_disp(sprintf('Current direction = %d',basis_parm.Basis_mode));
0173 
0174 if isfield(basis_parm, 'normal_mode') ...
0175       & basis_parm.normal_mode == const.NORMAL_NEIGHBOR_MEAN,
0176   vb_disp('Normal vector is averaged over neighborhood');
0177 end
0178 
0179 % Output file path
0180 basis_file = [proj_root filesep basis_parm.basis_file];
0181 vb_disp(sprintf('Save basis file [%s]', basis_file));
0182 vb_save(basis_file,'basis','basis_parm');
0183 
0184 % project_file save
0185 proj_file = get_project_filename;
0186 if isempty(proj_file)
0187     return;
0188 end
0189 
0190 project_file_mgr('load', proj_file);
0191 project_file_mgr('add', 'basis_parm', basis_parm);
0192 %
0193 % --- end of inner_terminate()
0194 
0195 
0196 % --- inner_check_arguments()
0197 %
0198 function [proj_root, basis_parm] = ...
0199   inner_check_arguments(const, proj_root, basis_parm)
0200 
0201 if isempty(proj_root), error('proj_root is a required parameter'); end;
0202 if isempty(basis_parm), error('basis_parm is a required parameter'); end;
0203 
0204 proj_root = vb_rm_trailing_slash(proj_root);
0205 
0206 % check common fields of basis_parm
0207 if ~isfield(basis_parm, 'normal_mode')
0208      basis_parm.normal_mode = const.NORMAL_ADJACENT_MEAN;
0209 end
0210 
0211 if ~isfield(basis_parm,'Recalc'),
0212     % Recalculation force flag
0213     basis_parm.Recalc = OFF;
0214 end
0215 
0216 if ~isfield(basis_parm,'DEBUG'),
0217     basis_parm.DEBUG = OFF;
0218 end
0219 
0220 if ~isfield(basis_parm,'sensortype'), 
0221   basis_parm.sensortype = [];
0222 end
0223 
0224 % if you want to check other points, you can do that here
0225 % ...
0226 
0227 %
0228 % --- end of inner_check_arguments()
0229 %
0230 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0231 
0232 %%% END OF FILE %%%

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