Home > vbmeg > functions > device > meg > vb_megfile_get_sensor_position_by_name.m

vb_megfile_get_sensor_position_by_name

PURPOSE ^

return information of sensor position specified by name

SYNOPSIS ^

function [position, direction, coil_weight, center, channel_info] =vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt)

DESCRIPTION ^

 return information of sensor position specified by name

 [usage]
   [position, direction, coil_weight, center] = ...
     vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt)

 [input]
      megfile : <required> <<file>> MEG-MAT file
      ch_name : <optional> <<cell array>> channel name list {''}
              :  If this is invalid, return positions of 'MEG' channels
   active_swt : <optional> <<boolean>> [false] only for MEG channels
              :    true) return only active channels (MEG)
              :   false) return all the channels (MEG)

 [output]
     position : position data of sensors
              :  (pick in MEG-MAT) [Ncoil x 3]
    direction : direction data of sensors
              :  (Qpick in MEG-MAT) [Ncoil x 3]
  coil_weight : coil weight [Nchannel x Ncoil]
       center : center coordinate [1 x 3]
 channel_info : <<struct>> channel information of loaded data
                :  .Active [Nchannel x 1]
                :  .Name   [Nchannel x 1]
                :  .Type   [Nchannel x 1]
                :  .ID     [Nchannel x 1]
                empty return : including reference sensor name.
 [note]

   See also
     vb_megfile_get_sensor_position_by_type

 [history]
   2011-07-26 (Sako) initial version
   2017-03-06 (rhayashi) Add return : channel_info
   2018-08-23 (Takeda) modified so that NEUROMAG is acceptable

 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 [position, direction, coil_weight, center, channel_info] = ...
0002     vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt)
0003 % return information of sensor position specified by name
0004 %
0005 % [usage]
0006 %   [position, direction, coil_weight, center] = ...
0007 %     vb_megfile_get_sensor_position_by_name(megfile, ch_name, active_swt)
0008 %
0009 % [input]
0010 %      megfile : <required> <<file>> MEG-MAT file
0011 %      ch_name : <optional> <<cell array>> channel name list {''}
0012 %              :  If this is invalid, return positions of 'MEG' channels
0013 %   active_swt : <optional> <<boolean>> [false] only for MEG channels
0014 %              :    true) return only active channels (MEG)
0015 %              :   false) return all the channels (MEG)
0016 %
0017 % [output]
0018 %     position : position data of sensors
0019 %              :  (pick in MEG-MAT) [Ncoil x 3]
0020 %    direction : direction data of sensors
0021 %              :  (Qpick in MEG-MAT) [Ncoil x 3]
0022 %  coil_weight : coil weight [Nchannel x Ncoil]
0023 %       center : center coordinate [1 x 3]
0024 % channel_info : <<struct>> channel information of loaded data
0025 %                :  .Active [Nchannel x 1]
0026 %                :  .Name   [Nchannel x 1]
0027 %                :  .Type   [Nchannel x 1]
0028 %                :  .ID     [Nchannel x 1]
0029 %                empty return : including reference sensor name.
0030 % [note]
0031 %
0032 %   See also
0033 %     vb_megfile_get_sensor_position_by_type
0034 %
0035 % [history]
0036 %   2011-07-26 (Sako) initial version
0037 %   2017-03-06 (rhayashi) Add return : channel_info
0038 %   2018-08-23 (Takeda) modified so that NEUROMAG is acceptable
0039 %
0040 % Copyright (C) 2011, ATR All Rights Reserved.
0041 % License : New BSD License(see VBMEG_LICENSE.txt)
0042 
0043 % --- CHECK ARGUMENTS --- %
0044 if ~exist('megfile', 'var'), megfile = []; end
0045 if ~exist('ch_name', 'var'), ch_name = ''; end
0046 if ~exist('active_swt', 'var'), active_swt = []; end
0047 [megfile, ch_name, active_swt] = ...
0048     inner_check_arguments(megfile, ch_name, active_swt);
0049 
0050 % --- MAIN PROCEDURE --------------------------------------------------------- %
0051 %
0052 channel_info = [];
0053 meg_info = vb_megfile_load_meginfo(megfile);
0054 ch_info_cur = vb_load_channel_info(megfile, 'USER', ch_name);
0055 
0056 % --- for 'MEG' channels
0057 ch_info_meg = vb_load_channel_info(megfile, 'MEG');
0058 if isempty(ch_info_meg)
0059     active_swt = false;
0060 end
0061 
0062 if active_swt
0063     active_idx = find(ch_info_meg.Active == true);
0064     base_names = ch_info_meg.Name(active_idx, :);
0065 else
0066     base_names = ch_info_meg.Name;
0067 end
0068 
0069 base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0070 
0071 if ~isempty(base_idx)
0072     target_idx = base_idx;
0073     
0074     load(megfile, 'pick', 'Qpick');
0075     c_weight = vb_meginfo_get_sensor_weight_meg(meg_info);
0076     
0077     target_coil_idx = find(sum(abs(c_weight(target_idx, :)), 1) > 0);
0078     
0079     pick_meg = pick(target_coil_idx, :);
0080     Qpick_meg = Qpick(target_coil_idx, :);
0081     c_weight_meg = c_weight(target_idx, target_coil_idx);
0082     
0083     channel_info.Active = ch_info_meg.Active(target_idx);
0084     channel_info.Name   = ch_info_meg.Name(target_idx);
0085     channel_info.Type   = ch_info_meg.Type(target_idx);
0086     channel_info.ID     = ch_info_meg.ID(target_idx);
0087 else
0088     pick_meg = [];
0089     Qpick_meg = [];
0090     c_weight_meg = [];
0091 end
0092 
0093 % --- for 'REFERENCE' channels
0094 pick_ref = [];
0095 Qpick_ref = [];
0096 c_weight_ref = [];
0097 
0098 ch_info_ref = vb_load_channel_info(megfile, 'REFERENCE');
0099 if ~isempty(ch_info_ref) && size(ch_info_ref.Name, 1)>0
0100     
0101     if active_swt
0102         active_idx = find(ch_info_ref.Active == true);
0103         base_names = ch_info_ref.Name(active_idx, :);
0104     else
0105         base_names = ch_info_ref.Name;
0106     end
0107     
0108     base_idx = vb_util_get_matching_label_index(base_names, ch_info_cur.Name);
0109     
0110     if ~isempty(base_idx)
0111         target_idx = base_idx;
0112         
0113         load(meg_file, 'ref_pick', 'ref_Qpick');
0114         pick_ref = ref_pick;
0115         Qpick_ref = ref_Qpick;
0116         c_weight_ref = vb_meginfo_get_sensor_weight_refmg(meg_info);
0117         
0118         target_coil_idx = find(sum(abs(c_weight_ref(target_idx, :)), 1) > 0);
0119         
0120         pick_ref = pick_ref(target_coil_idx, :);
0121         Qpick_ref = Qpick_ref(target_coil_idx, :);
0122         c_weight_ref = c_weight_ref(target_idx, target_coil_idx);
0123     end
0124 end
0125 
0126 % --- combine data
0127 position = [pick_meg; pick_ref];
0128 direction = [Qpick_meg; Qpick_ref];
0129 
0130 len_meg_ch = size(c_weight_meg, 1);
0131 len_meg_cl = size(c_weight_meg, 2);
0132 len_ref_ch = size(c_weight_ref, 1);
0133 len_ref_cl = size(c_weight_ref, 2);
0134 
0135 len_ch = len_meg_ch + len_ref_ch;
0136 len_coil = len_meg_cl + len_ref_cl;
0137 coil_weight = zeros(len_ch, len_coil);
0138 
0139 % --- coil weight for meg channels
0140 coil_weight(1:len_meg_ch, 1:len_meg_cl) = c_weight_meg;
0141 
0142 % --- coil_weight for reference channels
0143 coil_weight((len_meg_ch+1):len_ch, (len_meg_cl+1):len_coil) = c_weight_ref;
0144 
0145 % --- solve center coordinate
0146 center = [];
0147 if isfield(meg_info, 'Vcenter')
0148     center = meg_info.Vcenter;
0149 end
0150 
0151 return;
0152 %
0153 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0154 
0155 % --- INNER FUNCTIONS -------------------------------------------------------- %
0156 %
0157 % --- inner_check_arguments()
0158 %
0159 function [megfile, ch_name, active_swt] = ...
0160     inner_check_arguments(megfile, ch_name, active_swt)
0161 func_ = mfilename;
0162 
0163 if isempty(megfile)
0164     error('(%s) MEG-MAT file is a required parameter', func_);
0165 end
0166 
0167 if exist(megfile, 'file') ~= 2
0168     error('(%s)cannot find MEG-MAT file : %s', megfile);
0169 end
0170 
0171 [Measurement] = vb_load_device(megfile);
0172 
0173 if ~strcmpi(Measurement, 'MEG')
0174     error('(%s)this file is not MEG file : %s', func_, megfile);
0175 end
0176 
0177 if ~iscell(ch_name)
0178     ch_name = {ch_name};
0179 end
0180 
0181 if isempty(ch_name{1})
0182     ch_info = vb_load_channel_info(megfile, 'MEG');
0183     ch_name = ch_info.Name;
0184 end
0185 
0186 if isempty(active_swt)
0187     active_swt = false;
0188 end
0189 return;
0190 %
0191 % --- end of inner_check_arguments()
0192 %
0193 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0194 
0195 % --- END OF FILE --- %

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