Home > functions > device > meg > yokogawa > vb_ykgwfile_load_meg_channel_info.m

vb_ykgwfile_load_meg_channel_info

PURPOSE ^

load and return channel information like as sensor coordinate, setting loaded

SYNOPSIS ^

function [pick, Qpick, ref_pick, ref_Qpick, type, meg_info] =vb_ykgwfile_load_meg_channel_info(ykgwfile, meg_info)

DESCRIPTION ^

 load and return channel information like as sensor coordinate, setting loaded 
 information into meg_info

 [usage]
   [pick, Qpick, ref_pick, ref_Qpick, type, meg_info] = ...
     vb_ykgwfile_load_meg_channel_info(ykgwfile, meg_info)

 [input]
     ykgwfile : <required> <<file>> YOKOGAWA data file
     meg_info : <optional> <<struct>> vase of information []
              :  if this is not specified or is empty, meg_info will be 
              :  created newly.

 [output]
       pick : 3D-coordinates of sensor [Nchannel x 3]
      Qpick : 3D-coordinates of normal vector [Nchannel x 3]
   meg_info : <<struct>> MEGinfo the updated fields of which are as follows
            : .MEGch_id      % Active MEG channel index [Nchannel x 1]
            : .MEGch_name    % Active MEG channel name [Nchannel x 1]
            : .Nchannel      % number of active axialmeters [x1]
            : .nch0          % number of all channels [x1]
            : .sensor_weight % coil weight [Nchannel x Nchannel*2]
            : .device_info.sensor_weight_ref % sensor weight of ref channels
   ref_pick : 3D-coordinates of positions of reference channels
            :  [N_refCh x 3]
  ref_Qpick : 3D-coordinates of directions of reference channels
            :  [N_refCh x 3]
       type : coordinate type like 'SPM_Right_m' etc.

 [note]
   set hardware coordinate at first
   after that try to transform coordinate system

   --- channel information - now unused
   ChannelInfo.Active = Channel_active;
   ChannelInfo.Name   = Channel_name_str;
   ChannelInfo.Type   = Channel_type;
   ChannelInfo.ID     = Channel_id;
   meg_info.ChannelInfo = ChannelInfo;

   See also
     getYkgwHdrChannel
     vb_meg_yokogawa_load_ref_sensor
     vb_yokogawa_get_channel_type

 [history]
   2007-07-10 (Sako) initial version
   2008-03-28 (Sako) modified according to new specification
   2008-04-23 (Sako) added ChannelInfo to meg_info (for future)
   2008-05-12 (M.Sato) modified according to planar gradiometer.
                       pick, Qpick calculation is separeted by sensor type.
   2011-07-04 (Sako) modified to use the new YOKOGAWA libarary
   2011-07-22 (Sako) modified how to deal with sensor_weight_ref

 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, ref_pick, ref_Qpick, type, meg_info] = ...
0002   vb_ykgwfile_load_meg_channel_info(ykgwfile, meg_info)
0003 % load and return channel information like as sensor coordinate, setting loaded
0004 % information into meg_info
0005 %
0006 % [usage]
0007 %   [pick, Qpick, ref_pick, ref_Qpick, type, meg_info] = ...
0008 %     vb_ykgwfile_load_meg_channel_info(ykgwfile, meg_info)
0009 %
0010 % [input]
0011 %     ykgwfile : <required> <<file>> YOKOGAWA data file
0012 %     meg_info : <optional> <<struct>> vase of information []
0013 %              :  if this is not specified or is empty, meg_info will be
0014 %              :  created newly.
0015 %
0016 % [output]
0017 %       pick : 3D-coordinates of sensor [Nchannel x 3]
0018 %      Qpick : 3D-coordinates of normal vector [Nchannel x 3]
0019 %   meg_info : <<struct>> MEGinfo the updated fields of which are as follows
0020 %            : .MEGch_id      % Active MEG channel index [Nchannel x 1]
0021 %            : .MEGch_name    % Active MEG channel name [Nchannel x 1]
0022 %            : .Nchannel      % number of active axialmeters [x1]
0023 %            : .nch0          % number of all channels [x1]
0024 %            : .sensor_weight % coil weight [Nchannel x Nchannel*2]
0025 %            : .device_info.sensor_weight_ref % sensor weight of ref channels
0026 %   ref_pick : 3D-coordinates of positions of reference channels
0027 %            :  [N_refCh x 3]
0028 %  ref_Qpick : 3D-coordinates of directions of reference channels
0029 %            :  [N_refCh x 3]
0030 %       type : coordinate type like 'SPM_Right_m' etc.
0031 %
0032 % [note]
0033 %   set hardware coordinate at first
0034 %   after that try to transform coordinate system
0035 %
0036 %   --- channel information - now unused
0037 %   ChannelInfo.Active = Channel_active;
0038 %   ChannelInfo.Name   = Channel_name_str;
0039 %   ChannelInfo.Type   = Channel_type;
0040 %   ChannelInfo.ID     = Channel_id;
0041 %   meg_info.ChannelInfo = ChannelInfo;
0042 %
0043 %   See also
0044 %     getYkgwHdrChannel
0045 %     vb_meg_yokogawa_load_ref_sensor
0046 %     vb_yokogawa_get_channel_type
0047 %
0048 % [history]
0049 %   2007-07-10 (Sako) initial version
0050 %   2008-03-28 (Sako) modified according to new specification
0051 %   2008-04-23 (Sako) added ChannelInfo to meg_info (for future)
0052 %   2008-05-12 (M.Sato) modified according to planar gradiometer.
0053 %                       pick, Qpick calculation is separeted by sensor type.
0054 %   2011-07-04 (Sako) modified to use the new YOKOGAWA libarary
0055 %   2011-07-22 (Sako) modified how to deal with sensor_weight_ref
0056 %
0057 % Copyright (C) 2011, ATR All Rights Reserved.
0058 % License : New BSD License(see VBMEG_LICENSE.txt)
0059 
0060 global  vbmeg_inst;
0061 
0062 % Define constant
0063 define = vbmeg_inst.const;
0064 
0065 % MEG Channel_type
0066 MagnetoMeter          = 1;
0067 AxialGradioMeter      = 2;
0068 PlanarGradioMeter     = 3;
0069 
0070 % --- CHECK ARGUMENTS --- %
0071 if ~exist('ykgwfile', 'var'), ykgwfile = []; end
0072 if ~exist('meg_info', 'var'), meg_info = []; end
0073 [ykgwfile, meg_info] = inner_check_arguments(ykgwfile, meg_info);
0074 
0075 % --- MAIN PROCEDURE --------------------------------------------------------- %
0076 %
0077 pick = [];
0078 Qpick = [];
0079 ref_pick = [];
0080 ref_Qpick = [];
0081 
0082 channel_info = getYkgwHdrChannel(ykgwfile);
0083 %
0084 % --- for Refference Magneto Meter
0085 [ref_pick, ref_Qpick, Nref] = vb_meg_yokogawa_load_ref_sensor(channel_info);
0086 
0087 % Coil -> Channel matrix
0088 meg_info = vb_meginfo_init_sensor_weight_refmg(meg_info, Nref);
0089 
0090 meg_ch_types = vb_yokogawa_get_channel_type(1);
0091 
0092 Channel_active = [];
0093 Channel_name = [];
0094 Channel_type = [];
0095 Channel_id = [];
0096 
0097 % -----------------------------------------------------------------------------
0098 
0099 % --- channel information list [1 x n_channel]
0100 % --- <<struct array>> fields are 'type' and 'data'
0101 ch_info_list = channel_info.channel;
0102 ch_type_list = [ch_info_list(:).type];
0103 
0104 % pick1 = zeros(Nch,3);
0105 ch_start = 1;
0106 
0107 for i_type = 1:length(meg_ch_types)
0108   cur_type = meg_ch_types(i_type).id;
0109   cur_idx = find(ch_type_list(:) == cur_type);
0110   
0111   if isempty(cur_idx)
0112     continue;
0113   end
0114 
0115   cur_data_list = [ch_info_list(cur_idx).data];
0116 
0117   num_ch = length(cur_idx);
0118 
0119   % active or not (NullChannel or not)
0120   Channel_active = [Channel_active; ones(num_ch,1)];
0121   Channel_name   = [Channel_name; (cur_idx-1)];
0122   Channel_type   = [Channel_type; ch_type_list(cur_idx)'];
0123   Channel_id     = [Channel_id; cur_idx];
0124 
0125   ch_end = ch_start + num_ch - 1;
0126   pick1(ch_start:ch_end, 1) = [cur_data_list(:).x]; % X
0127   pick1(ch_start:ch_end, 2) = [cur_data_list(:).y]; % Y
0128   pick1(ch_start:ch_end, 3) = [cur_data_list(:).z]; % Z
0129   ch_start = ch_end + 1;
0130 end
0131 
0132 Nch = length(Channel_name);
0133 
0134 % ------------------------------------------------------------------------------
0135 
0136 Channel_name_str = cell(Nch,1);
0137 for i_ch = 1:Nch
0138   Channel_name_str(i_ch) = {num2str(Channel_name(i_ch))};
0139 end
0140 
0141 % --- field format of channel_info.channel.data ------------------------------ %
0142 %
0143 % ----- fields common to all MEG channels
0144 %
0145 % .x          : x coordinate of inner coil position [meter]
0146 % .y          : y coordinate of inner coil position [meter]
0147 % .z          : z coordinate of inner coil position [meter]
0148 % .size       : Inner coil size [meter]
0149 %
0150 % ---------------------------------------------------------------------------- %
0151 
0152 % Select sensor type
0153 % Index for pick1
0154 ix_axial = find(Channel_type == AxialGradioMeter  );
0155 ix_plana = find(Channel_type == PlanarGradioMeter);
0156 ix_magne = find(Channel_type == MagnetoMeter);
0157 
0158 % Index for channel_info
0159 id_axial = Channel_id(ix_axial);
0160 id_plana = Channel_id(ix_plana);
0161 id_magne = Channel_id(ix_magne);
0162 
0163 % Number of sensors for each type
0164 Nch_axial = length(id_axial);
0165 Nch_plana = length(id_plana);
0166 Nch_magne = length(id_magne);
0167 
0168 if Nch ~= (Nch_axial + Nch_plana + Nch_magne),
0169   error('Channel type mismatch')
0170 end
0171 
0172 % --- current (AxialGradioMeter) list
0173 axial_list = [ch_info_list(id_axial).data];
0174 plana_list = [ch_info_list(id_plana).data];
0175 magne_list = [ch_info_list(id_magne).data];
0176 
0177 % --- field format of channel_info.channel.data ------------------------------ %
0178 %
0179 % ----- fields for AxialGradioMeter or ReferenceAxialGradioMeter
0180 % .zdir       : Sensor orientation from z-axis [degree]
0181 % .xdir       : Sensor orientation from x-axis [degree]
0182 % .baseline   : Baseline length [meter]
0183 % ---------------------------------------------------------------------------- %
0184 %
0185 % ----- fields for PlanarGradioMeter or ReferencePlanarGradioMeter
0186 % .zdir1      : Sensor orientation from z-axis [degree]
0187 % .xdir1      : Sensor orientation from x-axis [degree]
0188 % .zdir2      : Baseline orientation from z-axis [degree]
0189 % .xdir2      : Baseline orientation from x-axis [degree]
0190 % .baseline   : Baseline length [meter]
0191 % ---------------------------------------------------------------------------- %
0192 %
0193 % ----- fields for MagnetoMeter or ReferenceMagnetoMeter
0194 % .zdir       : Sensor orientation from z-axis [degree]
0195 % .xdir       : Sensor orientation from x-axis [degree]
0196 % ---------------------------------------------------------------------------- %
0197 
0198 % --- AxialGradioMeter
0199 if ~isempty(axial_list)
0200   zdir = ([axial_list(:).zdir] * (pi/180))'; 
0201   xdir = ([axial_list(:).xdir] * (pi/180))'; 
0202   baseline = ([axial_list(:).baseline])';
0203 
0204   unit_axial  = [sin(zdir).* cos(xdir), sin(zdir).* sin(xdir), cos(zdir)];
0205   pick2_axial = pick1(ix_axial, :) + vb_repmultiply( unit_axial, baseline);
0206 else
0207   unit_axial = [];
0208   pick2_axial = [];
0209 end
0210 
0211 
0212 % --- PlanarGradioMeter
0213 if ~isempty(plana_list)
0214   zdir1 = ([plana_list(:).zdir1] * (pi/180))'; 
0215   xdir1 = ([plana_list(:).xdir1] * (pi/180))'; 
0216   zdir2 = ([plana_list(:).zdir2] * (pi/180))'; 
0217   xdir2 = ([plana_list(:).xdir2] * (pi/180))'; 
0218   baseline = ([plana_list(:).baseline])';
0219 
0220   unit_plana1 = [sin(zdir1).* cos(xdir1), sin(zdir1).* sin(xdir1), cos(zdir1)];
0221   unit_plana2 = [sin(zdir2).* cos(xdir2), sin(zdir2).* sin(xdir2), cos(zdir2)];
0222   pick2_plana = pick1(ix_plana, :) + vb_repmultiply( unit_plana2, baseline);
0223 else
0224   unit_plana1 = [];
0225   unit_plana2 = [];
0226   pick2_plana = [];
0227 end
0228 
0229 % --- MagnetoMeter
0230 if ~isempty(magne_list)
0231   zdir = ([magne_list(:).zdir] * (pi/180))'; % zdir1
0232   xdir = ([magne_list(:).xdir] * (pi/180))'; % xdir1
0233 
0234   unit_magne = [sin(zdir) .* cos(xdir), sin(zdir) .* sin(xdir), cos(zdir)];
0235 else
0236   unit_magne = [];
0237 end
0238 
0239 % --- PICK
0240 pick = [pick1; pick2_axial; pick2_plana];
0241 
0242 % --- QPICK
0243 % normal vector of pick1, pick2
0244 %
0245 unit_vector = zeros(Nch,3);
0246 if ~isempty(ix_axial)
0247   unit_vector(ix_axial,:) = unit_axial;
0248 end
0249 
0250 if ~isempty(ix_plana)
0251   unit_vector(ix_plana,:) = unit_plana1;
0252 end
0253 
0254 if ~isempty(ix_magne)
0255   unit_vector(ix_magne,:) = unit_magne;
0256 end
0257 
0258 Qpick = [unit_vector; unit_axial; unit_plana1];
0259 
0260 Ncoil     = Nch + Nch_axial + Nch_plana;
0261 n_channel = [ix_axial', ix_plana', ix_magne'];
0262 n_axial   = (1:Nch_axial) + Nch;                % pick2_axial -> ix_axial
0263 n_plana   = (1:Nch_plana) + Nch + Nch_axial;    % pick2_plana -> ix_plana
0264 n_coils   = [n_channel , n_axial,   n_plana];
0265 n_channel = [n_channel , ix_axial', ix_plana'];
0266 n_weight  = [ones(1,Nch) , - ones(1,Nch_axial), - ones(1,Nch_plana)];
0267 
0268 CoilWeight = sparse( n_channel, n_coils, n_weight, Nch, Ncoil);
0269 
0270 
0271 % --- store some data to meg_info
0272 meg_info.MEGch_id      = Channel_id;         % Active MEG channel index
0273 meg_info.MEGch_name    = Channel_name_str;   % Active MEG channel name
0274 meg_info.Nchannel      = Nch;                % number of active channel
0275 meg_info.nch0          = length(Channel_id); % number of channel
0276 meg_info.sensor_weight = CoilWeight;         % coil weight
0277 
0278 type = define.COORDINATE_YOKOGAWA_RIGHT_M;
0279 
0280 % --- channel information - now unused
0281 ChannelInfo.Active = Channel_active;
0282 ChannelInfo.Name   = Channel_name_str;
0283 ChannelInfo.Type   = Channel_type;
0284 ChannelInfo.ID     = Channel_id;
0285 meg_info.ChannelInfo = ChannelInfo;
0286 
0287 % --- active channel flags
0288 meg_info = vb_info_set_active_channel(meg_info, ChannelInfo.Active);
0289 
0290 return;
0291 %
0292 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0293 
0294 
0295 % --- INNER FUNCTIONS -------------------------------------------------------- %
0296 %
0297 % --- inner_check_arguments()
0298 %
0299 function [ykgwfile, meg_info] = ...
0300   inner_check_arguments(ykgwfile, meg_info)
0301 
0302 func_ = mfilename;
0303 if isempty(ykgwfile)
0304   error('(%s)ykgwfile is a required parameter', func_);
0305 end
0306 
0307 if exist(ykgwfile, 'file') ~= 2
0308   error('(%s)cannot find ykgwfile : %s', func_, ykgwfile);
0309 end
0310 
0311 if isempty(meg_info)
0312   % required no action
0313 end
0314 return;
0315 %
0316 % --- end of inner_check_arguments()
0317 %
0318 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0319 
0320 % --- END OF FILE --- %

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