Home > vbmeg > functions > device > meg > yokogawa > vb_meg_yokogawa_make_data.m

vb_meg_yokogawa_make_data

PURPOSE ^

Read MEG data saved on Yokogawa system and convert it to .meg.mat file.

SYNOPSIS ^

function [err] = vb_meg_yokogawa_make_data(proj_root, meg_parm)

DESCRIPTION ^

 Read MEG data saved on Yokogawa system and convert it to .meg.mat file. 

 [usage]
   [err] = vb_meg_yokogawa_make_data(proj_root, meg_parm)

 [input]
   proj_root : <required> Project root directory
    meg_parm : <required> <<struct>> structure with following field
             :     <<fields>>
             :   .yokogawa_file : <required> <<file>> YOKOGAWA-MEG file
             :                  :  .con | .ave | .raw
             :   .meg_file      : <required> Output MEG file.
             :                  :  This is used in connecting to proj_root.
             :                  : [proj_root '/' <meg_parm.meg_file>] : 
             :   .pos_file      : <optional> <<file>> POS-MAT file
             :                  :   the members of which are as follows
             :                  :    mri_key   - hash key [x1 string]
             :                  :    coord_type- coordinate type [x1 string]
             :                  :    pos       - coordinate [Nch x3 double]
             :                  :    name      - channel name [Nch x1 string]
             :                  :    trans_mri - transform matrix [4x4 double]
             :                  :    header    - header information <<struct>>
             :                  :      .digit_file_name : <optional>
             :                  :      .meg_market_id : <optional>
             :   .ex_ch_gain    : <optional> gain of extra channel[]
             :   .memory_max    : <optional> const.DEFAULT_MEMORY_MAX(10000000)
             :   .saveman       : <optional> <<struct>>
             :                  : .data_dir : ['./(name of .meg_file)_bin']
             :                  :  - directory where the data will be stored
             :                  :  - relative path from the path of .meg_file
             :                  : .precision : ['float64']
             :                  :  - precision which is used for fwrite

 [output]
         err : error code
             :      0) success
             :  not 0) failure

 [note]
   1) If pos member in POS-MAT file is empty, only import MEG data

   2) This function transform coordinates by using trans_mri matrix

   3) data format of output file MEG-MAT is as follows
      <<MEG-MAT>>
       pick(n,      1:3) : position of detector coils.
           (n+1:2n, 1:3) : position of conpensation detector coils.
       Qpick             : vector of pick [Nch x3]
       ref_pick          : position of reference channels [N_ref_ch x3]
       ref_Qpick         : vector of ref_pick [N_ref_ch x3]
       Measurement       : <<string>> measurement code 'MEG'
       CoordType         : <<string>> coordinate type which all the 
                         :  coordinates in MEG-MAT file apply
       PositionFile      : <<string>> position file (POS-MAT file) name
       MEGinfo           : <<struct>> with MEG acquisition information

      <<MEGinfo>>
     .Measurement        : <<string>> measurement code 'MEG'
     .device             : device name (e.g. 'YOKOGAWA')
     .sensor_weight      : weight to calculate lead field
             : sensor_weight = n-th coil weight for m-th sensor channel
             : basis(channel,dipole) = sensor_weight * basis(coil,dipole)
     .Nchannel           : number of active gardiometers
     .Nsample            : number of sampling data
     .Pretrigger         : number of sampling data before trigger
     .SampleFreq         : sampling frequency
     .Nrepeat            : number of trial
     .Trial              : <<struct>> trial information [Ntrial x 1]
                         :  .number : trial number (index)
                         :  .sample : [Nsample x 1] sample list
     .Vcenter            : [3 x 1] origin of sphere model [m]
     .MEG_ID             : MEG system ID(meg filename with no extension)
     .MRI_ID             : MRI key (hash key)
     .MEGch_name         : Active MEG channel name
     .MEGch_id           : Active MEG channel index
     .saveman            : <<struct>> saving specifications

     .device_info        : <<struct>> device dependent information
       .sensor_weight_ref: 
       .TransInfo        : <<struct>> transform information
       .acq_type         : acquisition type
                         :  (e.g.'Continuous_Raw', 'Evoked_Ave', 'Evoked_Raw')
       .acq_info         : <<struct>> acquisition information

 [history]
   2007-07-05 (Sako) initial version
   2008-03-13 (Sako) thoroughly rewrote according to the new specification
   2009-07-14 (Sako) modified to store data as external file inevitably
   2010-02-04 (Sako) removed invalid setting of bit_len
   2011-02-17 (Sako) changed default value of saveman.data_dir
   2011-02-17 (Sako) got rid of old data fields 'bexp' 'bexp_ext', 'refmg'
   2011-02-24 (Sako) supported in case ref channels are empty
   2011-02-24 (Sako) supported in case memory_max is given but empty
   2011-05-26 (Sako) modified according to the new data format
   2011-06-22 (Sako) changed the order of load_calibinfo

 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 [err] = vb_meg_yokogawa_make_data(proj_root, meg_parm)
0002 % Read MEG data saved on Yokogawa system and convert it to .meg.mat file.
0003 %
0004 % [usage]
0005 %   [err] = vb_meg_yokogawa_make_data(proj_root, meg_parm)
0006 %
0007 % [input]
0008 %   proj_root : <required> Project root directory
0009 %    meg_parm : <required> <<struct>> structure with following field
0010 %             :     <<fields>>
0011 %             :   .yokogawa_file : <required> <<file>> YOKOGAWA-MEG file
0012 %             :                  :  .con | .ave | .raw
0013 %             :   .meg_file      : <required> Output MEG file.
0014 %             :                  :  This is used in connecting to proj_root.
0015 %             :                  : [proj_root '/' <meg_parm.meg_file>] :
0016 %             :   .pos_file      : <optional> <<file>> POS-MAT file
0017 %             :                  :   the members of which are as follows
0018 %             :                  :    mri_key   - hash key [x1 string]
0019 %             :                  :    coord_type- coordinate type [x1 string]
0020 %             :                  :    pos       - coordinate [Nch x3 double]
0021 %             :                  :    name      - channel name [Nch x1 string]
0022 %             :                  :    trans_mri - transform matrix [4x4 double]
0023 %             :                  :    header    - header information <<struct>>
0024 %             :                  :      .digit_file_name : <optional>
0025 %             :                  :      .meg_market_id : <optional>
0026 %             :   .ex_ch_gain    : <optional> gain of extra channel[]
0027 %             :   .memory_max    : <optional> const.DEFAULT_MEMORY_MAX(10000000)
0028 %             :   .saveman       : <optional> <<struct>>
0029 %             :                  : .data_dir : ['./(name of .meg_file)_bin']
0030 %             :                  :  - directory where the data will be stored
0031 %             :                  :  - relative path from the path of .meg_file
0032 %             :                  : .precision : ['float64']
0033 %             :                  :  - precision which is used for fwrite
0034 %
0035 % [output]
0036 %         err : error code
0037 %             :      0) success
0038 %             :  not 0) failure
0039 %
0040 % [note]
0041 %   1) If pos member in POS-MAT file is empty, only import MEG data
0042 %
0043 %   2) This function transform coordinates by using trans_mri matrix
0044 %
0045 %   3) data format of output file MEG-MAT is as follows
0046 %      <<MEG-MAT>>
0047 %       pick(n,      1:3) : position of detector coils.
0048 %           (n+1:2n, 1:3) : position of conpensation detector coils.
0049 %       Qpick             : vector of pick [Nch x3]
0050 %       ref_pick          : position of reference channels [N_ref_ch x3]
0051 %       ref_Qpick         : vector of ref_pick [N_ref_ch x3]
0052 %       Measurement       : <<string>> measurement code 'MEG'
0053 %       CoordType         : <<string>> coordinate type which all the
0054 %                         :  coordinates in MEG-MAT file apply
0055 %       PositionFile      : <<string>> position file (POS-MAT file) name
0056 %       MEGinfo           : <<struct>> with MEG acquisition information
0057 %
0058 %      <<MEGinfo>>
0059 %     .Measurement        : <<string>> measurement code 'MEG'
0060 %     .device             : device name (e.g. 'YOKOGAWA')
0061 %     .sensor_weight      : weight to calculate lead field
0062 %             : sensor_weight = n-th coil weight for m-th sensor channel
0063 %             : basis(channel,dipole) = sensor_weight * basis(coil,dipole)
0064 %     .Nchannel           : number of active gardiometers
0065 %     .Nsample            : number of sampling data
0066 %     .Pretrigger         : number of sampling data before trigger
0067 %     .SampleFreq         : sampling frequency
0068 %     .Nrepeat            : number of trial
0069 %     .Trial              : <<struct>> trial information [Ntrial x 1]
0070 %                         :  .number : trial number (index)
0071 %                         :  .sample : [Nsample x 1] sample list
0072 %     .Vcenter            : [3 x 1] origin of sphere model [m]
0073 %     .MEG_ID             : MEG system ID(meg filename with no extension)
0074 %     .MRI_ID             : MRI key (hash key)
0075 %     .MEGch_name         : Active MEG channel name
0076 %     .MEGch_id           : Active MEG channel index
0077 %     .saveman            : <<struct>> saving specifications
0078 %
0079 %     .device_info        : <<struct>> device dependent information
0080 %       .sensor_weight_ref:
0081 %       .TransInfo        : <<struct>> transform information
0082 %       .acq_type         : acquisition type
0083 %                         :  (e.g.'Continuous_Raw', 'Evoked_Ave', 'Evoked_Raw')
0084 %       .acq_info         : <<struct>> acquisition information
0085 %
0086 % [history]
0087 %   2007-07-05 (Sako) initial version
0088 %   2008-03-13 (Sako) thoroughly rewrote according to the new specification
0089 %   2009-07-14 (Sako) modified to store data as external file inevitably
0090 %   2010-02-04 (Sako) removed invalid setting of bit_len
0091 %   2011-02-17 (Sako) changed default value of saveman.data_dir
0092 %   2011-02-17 (Sako) got rid of old data fields 'bexp' 'bexp_ext', 'refmg'
0093 %   2011-02-24 (Sako) supported in case ref channels are empty
0094 %   2011-02-24 (Sako) supported in case memory_max is given but empty
0095 %   2011-05-26 (Sako) modified according to the new data format
0096 %   2011-06-22 (Sako) changed the order of load_calibinfo
0097 %
0098 % Copyright (C) 2011, ATR All Rights Reserved.
0099 % License : New BSD License(see VBMEG_LICENSE.txt)
0100   
0101 % --- CHECK ARGUMENTS --- %
0102 if ~exist('proj_root', 'var'), proj_root = []; end
0103 if ~exist('meg_parm', 'var'), meg_parm = []; end
0104 [proj_root, meg_parm, ykgwfile, posfile, out_file, meg_info] = ...
0105     inner_check_arguments(proj_root, meg_parm);
0106 
0107 % --- MAIN PROCEDURE --------------------------------------------------------- %
0108 %
0109 err = 0;  % success
0110 
0111 % --- new spec - meg_info has acqfile field
0112 [meg_info] = vb_meginfo_set_acqfile(meg_info, ykgwfile);
0113 % <at this moment> determined fields of meg_info are ...
0114 %   device_info.acq_info.data_file     % acquisition file path
0115 
0116 
0117 [pick, Qpick, ref_pick, ref_Qpick, CoordType, meg_info] = ...
0118   vb_ykgwfile_load_meg_channel_info(ykgwfile, meg_info);
0119 % only load hardware coordinate here
0120 % later, apply appropriate coordinate system
0121 % <at this moment> determined fields of meg_info are ...
0122 %   MEGch_id      % Active MEG channel index
0123 %   MEGch_name    % Active MEG channel name
0124 %   Nchannel      % number of active axialmeters
0125 %   nch0          % number of axialmeters
0126 %   sensor_weight % coil weight
0127 %   ActiveChannel % active channel flag
0128 
0129 
0130 [meg_info] = vb_ykgwfile_load_header(ykgwfile, meg_info);
0131 % <at this moment> newly determined fields of meg_info are ...
0132 %   MEG_ID      % MEG filename (non extention)
0133 %   device      % 'YOKOGAWA' <-- hard-coded
0134 %   coord_type
0135 %   acq_type
0136 %   Nsample     % sampling number of measurement
0137 %   Pretrigger  % number of sample before trigger
0138 %   SampleFreq  % sampling frequency
0139 %   Nrepeat     % repeat number
0140 %   Trial       % struct of trial information
0141 
0142 
0143 [meg_info] = vb_ykgwfile_load_extra_channel_info(ykgwfile, meg_info);
0144 % <at this moment> newly determined fields of meg_info are ...
0145 %   ExtraChannelInfo  % <<struct>> extra channels' information
0146 
0147 
0148 [meg_info] = vb_info_add_posfile_info(meg_info, posfile);
0149 % <at this moment> fields of meg_info which may be newly determined are ...
0150 %   Vcenter
0151 %   Vradius
0152 %   MRI_ID
0153 %   TransInfo
0154 
0155 
0156 % --- load calibrate and separate data
0157 [out_path] = vb_get_file_parts(out_file);
0158 [meg_info] = vb_ykgwfile_load_data(ykgwfile, meg_info, out_path);
0159 % <at this moment> fields of meg_info which may be newly determined are ...
0160 %   MEGch_id
0161 
0162 
0163 % --- convert information struct ---> MEGinfo
0164 [MEGinfo] = vb_meginfo_convert_raw2vbmeg(meg_info);
0165 
0166 
0167 % --- affine transform 'pick', 'Qpick', 'ref_pick', 'ref_Qpick'
0168 if ~isempty(ref_pick) && ~isempty(ref_Qpick)
0169   [ref_pick, ref_Qpick] = ...
0170     vb_meg_transform_coordinate(ref_pick, ref_Qpick, CoordType, posfile);
0171 end
0172 
0173 [pick, Qpick, CoordType] = ...
0174   vb_meg_transform_coordinate(pick, Qpick, CoordType, posfile);
0175 
0176 % store data
0177 % !!! if you use vb_save, it is very slower than using vb_fsave !!!
0178 Measurement = 'MEG';
0179 MEGinfo.Measurement = Measurement;
0180 PositionFile = posfile;
0181 bexp = [];
0182 bexp_ext = [];
0183 
0184 vb_fsave(out_file, 'pick', 'Qpick', ...
0185   'ref_pick', 'ref_Qpick', 'CoordType', ...
0186   'Measurement', 'PositionFile', ...
0187   'MEGinfo', 'bexp', 'bexp_ext', 'meg_parm');
0188 
0189 fprintf('---\n--- make %s\n---\n', out_file);
0190 return;
0191 %
0192 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0193 
0194 % --- INNER FUNCTIONS -------------------------------------------------------- %
0195 %
0196 % --- inner_check_arguments()
0197 %
0198 function [proj_root, meg_parm, ykgwfile, posfile, outfile, meginfo] = ...
0199    inner_check_arguments(proj_root, meg_parm)
0200 func_ = mfilename;
0201 
0202 const = vb_define_yokogawa;
0203 
0204 % --- check parameters
0205 if isempty(meg_parm)
0206   error('(%s)meg_parm is a required parameter', func_);
0207 end
0208 
0209 % --- check fields of file
0210 if ~isfield(meg_parm, 'yokogawa_file')
0211   error('(%s)yokogawa_file is a required field of meg_parm', func_);
0212 end
0213 
0214 if ~isfield(meg_parm, 'pos_file')
0215   meg_parm.pos_file = '';
0216 %   error('(%s)pos_file is a required field of meg_parm', func_);
0217 end
0218 
0219 % --- check files
0220 if exist(meg_parm.yokogawa_file, 'file') ~= 2
0221   error('(%s)cannot find yokogawa_file : %s', func_, meg_parm.yokogawa_file);
0222 end
0223 
0224 if ~isempty(meg_parm.pos_file) && exist(meg_parm.pos_file, 'file') ~= 2
0225   error('(%s)cannot find pos_file : %s', func_, meg_parm.pos_file);
0226 end
0227 
0228 ykgwfile = meg_parm.yokogawa_file;
0229 posfile  = meg_parm.pos_file;
0230 
0231 % --- MEGinfo
0232 meginfo = [];
0233 
0234 % --- EEG GAIN
0235 if isfield(meg_parm, 'ex_ch_gain')
0236   meginfo = vb_meginfo_set_extra_ch_gain(meginfo, meg_parm.ex_ch_gain);
0237 else
0238   meginfo = vb_meginfo_set_extra_ch_gain(meginfo, []);
0239 end
0240 
0241 % --- OUTPUT FILE
0242 outfile = fullfile(proj_root, meg_parm.meg_file);
0243 
0244 % --- SAVING SPECIFICATION
0245 DEFAULT_PRECISION = 'float64';
0246 
0247 real_dir = '';
0248 
0249 % --- check and fill saveman if necessary
0250 if ~isfield(meg_parm, 'saveman') ...
0251   || isempty(meg_parm.saveman)
0252 
0253   meg_parm.saveman = struct;
0254 end
0255 
0256 if ~isfield(meg_parm.saveman, 'data_dir') ...
0257   || isempty(meg_parm.saveman.data_dir)
0258 
0259   [DEFAULT_DATA_DIR, real_dir] = vb_device_make_data_dir(outfile);
0260   meg_parm.saveman.data_dir = DEFAULT_DATA_DIR;
0261 end
0262 
0263 if ~isfield(meg_parm.saveman, 'precision') ...
0264   || isempty(meg_parm.saveman.precision)
0265 
0266   meg_parm.saveman.precision = DEFAULT_PRECISION;
0267 end
0268 
0269 if isempty(real_dir)
0270   base_dir = vb_get_file_parts(outfile);
0271   real_dir = fullfile(base_dir, meg_parm.saveman.data_dir);
0272 end
0273 
0274 % --- check real directory
0275 if exist(real_dir, 'dir') ~= 7
0276   vb_mkdir(real_dir);
0277 end
0278 
0279 meginfo.saveman = meg_parm.saveman;
0280 
0281 if isfield(meg_parm, 'memory_max') && ~isempty(meg_parm.memory_max)
0282   meginfo.memory_max = meg_parm.memory_max;
0283 else
0284   meginfo.memory_max = const.DEFAULT_MEMORY_MAX;
0285 end
0286 return;
0287 %
0288 % --- end of inner_check_arguments()
0289 %
0290 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0291 
0292 %--- END OF FILE ---%

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