Home > functions > common > loadfunc > vb_load_meg_data.m

vb_load_meg_data

PURPOSE ^

load measured data of MEG (meg.mat) and EEG (eeg.mat)

SYNOPSIS ^

function [data, channel_info] = vb_load_meg_data(megfile, load_spec, new_file)

DESCRIPTION ^

 load measured data of MEG (meg.mat) and EEG (eeg.mat)
 and can make new file if required

 [usage]
   [data, channel_info] = vb_load_meg_data(megfile, load_spec, new_file);

 [input]
     megfile : <required> <<file>> measurement file
             :   meg-mat file(.meg.mat)
             :   eeg-mat file(.eeg.mat)

   load_spec : <required> <<struct>> loading instruction
             :
             : if this is not specified or is empty and 'megfile' has
             : its data internally, only return internal data
             :
                   :     
      .ChannelName : <optional> channel name list [Nch x 1] []
                   :  name(string) list of  target channel
                   :  The way to be used this depends on the
                   :  "ChannelSwitch" field
                   :  e.g.
                   :   {'1';'2';'3';'4'}
                   :  If this is empty, all the channels are
                   :  specified
    .ChannelSwitch : <optiolal> <<boolean>> [true] | false
                   :   Which is "ChannelName", to read, or not?
                   :   [true] : to read
                   :    false : to omit
      .ChannelType : <optional> <<string>> channel type ['MEG(EEG)']
                   :  'MEG'       : MEG channel data (only MEG)
                   :  'EEG'       : EEG channel data (only EEG)
                   :  'EXTRA'     : extra channel data
                   :  'REFERENCE' : reference channel data (only MEG)
                   :  'ALL'       : 'MEG(EEG)'+'EXTRA'(+'REFERENCE')
                   :  - case insensitive
          .Trigger : <optional> [Ntrial x 1] [1]
       .Pretrigger : <optional> [0] equal to zero or over
      .Posttrigger : <optional> [Nsample - 1] equal to zero or over
      .TrialNumber : <optional> trial number list [] [Ntrial x 1]
                   :   "1" start
                   :    e.g. [1;2;3]
                   :    if this is empty, all the trials are specified
    .ActiveChannel : <optional> <<boolean>>
                   :  active channel filter switch
                   :    true) active channels
                   :   false) all the channels
                   :   if .ActiveChannel is valid [true]
                   :   if .ActiveChannel is invalid [false]
      .ActiveTrial : <optional> <<boolean>>
                   :  active trial filter switch
                   :  valid only when data type is Evoked_Raw
                   :    true) active trials
                   :   false) all the trials
                   :   if .ActiveTrial is valid [true]
                   :   if .ActiveTrial is invalid [false]
             (only MEG)
          .saveman : <optional> <<struct>>
                   :  When you want to make a new file, loaded data will be
                   :  stored in external directory.
                   :  If this field is invalid or switch field is set false,
                   :  data is stored internally.
                   :    .data_dir  : data directory (relative path)
                   :               : ['(name of new_file)_bin']
                   :               : @see vb_device_make_data_dir.m
                   :    .precision : data type ['float64']
                   :    .switch    : <<optional>> switch to store externally
                   :               :  [true]) store the data externally
                   :               :   false) store the data internally
             (only EEG)
     .bin_data_dir : <optional> relative path from new_file
                   :  This field is valid only when #3 argument newfile is 
                   :  specified.
                   :  if this field is not given or is empty, sampling data
                   :  will be stored internally.

    new_file : <optional> new MEG-MAT file name which is stored picked up
             :  data and changed information []
             :  if this is empty, new file will not be created
             :  This parameter must include the full extension.
             :  MEG : ".meg.mat"
             :  EEG : ".eeg.mat"

 [output]
           data : loaded data [Nchannel x Nsample x Ntrial]
   channel_info : <<struct>> channel information of loaded data
                :  .Active [Nchannel x 1]
                :  .Name   [Nchannel x 1]
                :  .Type   [Nchannel x 1]
                :  .ID     [Nchannel x 1]

 [note]
   See also
     vb_megfile_load_data
     vb_eegfile_load_data
     vb_load_channel_info

 [history]
   2006-12-13 (Sako) modified for EEG (acceptable eeg.mat)
   2007-07-23 (Sako) added loaded channel mode
   2007-08-10 (Sako) added mode type 'EEG' for load_eeg_data
   2008-02-20 (Sako) thoroughly revised
   2008-04-16 (Sako) added .ActiveSwitch in load_spec
   2008-06-06 (Sako) you can specify ChannelType and get channel_info
   2008-11-28 (Taku Yoshioka) Use vb_disp() for displaying message
   2009-07-22 (Sako) added the case only to return internal data
   2009-08-19 (Sako) modified the case that simply return data,
                     to return only sensor data (EEG) and channel_info
   2010-06-30 (Sako) supported storing data externally (only MEG)
   2010-11-15 (Sako) supported load_spec for 'INFO' file
   2011-02-08 (Sako) modified for EEG to store data externally
                     when newfile is valid
   2011-02-09 (Sako) modified not to output warning message
                     when cheking internal data
   2011-06-01 (Sako) supported unknown devices to load
   2011-07-15 (Sako) modified help about saveman(MEG) and bin_data_dir(EEG)
   2011-07-15 (Sako) modified the internal EEG data can be loaded correctly
   2011-08-19 (Sako) modified to avoid errors for the minimum data format

 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    [data, channel_info] = vb_load_meg_data(megfile, load_spec, new_file)
0002 % load measured data of MEG (meg.mat) and EEG (eeg.mat)
0003 % and can make new file if required
0004 %
0005 % [usage]
0006 %   [data, channel_info] = vb_load_meg_data(megfile, load_spec, new_file);
0007 %
0008 % [input]
0009 %     megfile : <required> <<file>> measurement file
0010 %             :   meg-mat file(.meg.mat)
0011 %             :   eeg-mat file(.eeg.mat)
0012 %
0013 %   load_spec : <required> <<struct>> loading instruction
0014 %             :
0015 %             : if this is not specified or is empty and 'megfile' has
0016 %             : its data internally, only return internal data
0017 %             :
0018 %                   :
0019 %      .ChannelName : <optional> channel name list [Nch x 1] []
0020 %                   :  name(string) list of  target channel
0021 %                   :  The way to be used this depends on the
0022 %                   :  "ChannelSwitch" field
0023 %                   :  e.g.
0024 %                   :   {'1';'2';'3';'4'}
0025 %                   :  If this is empty, all the channels are
0026 %                   :  specified
0027 %    .ChannelSwitch : <optiolal> <<boolean>> [true] | false
0028 %                   :   Which is "ChannelName", to read, or not?
0029 %                   :   [true] : to read
0030 %                   :    false : to omit
0031 %      .ChannelType : <optional> <<string>> channel type ['MEG(EEG)']
0032 %                   :  'MEG'       : MEG channel data (only MEG)
0033 %                   :  'EEG'       : EEG channel data (only EEG)
0034 %                   :  'EXTRA'     : extra channel data
0035 %                   :  'REFERENCE' : reference channel data (only MEG)
0036 %                   :  'ALL'       : 'MEG(EEG)'+'EXTRA'(+'REFERENCE')
0037 %                   :  - case insensitive
0038 %          .Trigger : <optional> [Ntrial x 1] [1]
0039 %       .Pretrigger : <optional> [0] equal to zero or over
0040 %      .Posttrigger : <optional> [Nsample - 1] equal to zero or over
0041 %      .TrialNumber : <optional> trial number list [] [Ntrial x 1]
0042 %                   :   "1" start
0043 %                   :    e.g. [1;2;3]
0044 %                   :    if this is empty, all the trials are specified
0045 %    .ActiveChannel : <optional> <<boolean>>
0046 %                   :  active channel filter switch
0047 %                   :    true) active channels
0048 %                   :   false) all the channels
0049 %                   :   if .ActiveChannel is valid [true]
0050 %                   :   if .ActiveChannel is invalid [false]
0051 %      .ActiveTrial : <optional> <<boolean>>
0052 %                   :  active trial filter switch
0053 %                   :  valid only when data type is Evoked_Raw
0054 %                   :    true) active trials
0055 %                   :   false) all the trials
0056 %                   :   if .ActiveTrial is valid [true]
0057 %                   :   if .ActiveTrial is invalid [false]
0058 %             (only MEG)
0059 %          .saveman : <optional> <<struct>>
0060 %                   :  When you want to make a new file, loaded data will be
0061 %                   :  stored in external directory.
0062 %                   :  If this field is invalid or switch field is set false,
0063 %                   :  data is stored internally.
0064 %                   :    .data_dir  : data directory (relative path)
0065 %                   :               : ['(name of new_file)_bin']
0066 %                   :               : @see vb_device_make_data_dir.m
0067 %                   :    .precision : data type ['float64']
0068 %                   :    .switch    : <<optional>> switch to store externally
0069 %                   :               :  [true]) store the data externally
0070 %                   :               :   false) store the data internally
0071 %             (only EEG)
0072 %     .bin_data_dir : <optional> relative path from new_file
0073 %                   :  This field is valid only when #3 argument newfile is
0074 %                   :  specified.
0075 %                   :  if this field is not given or is empty, sampling data
0076 %                   :  will be stored internally.
0077 %
0078 %    new_file : <optional> new MEG-MAT file name which is stored picked up
0079 %             :  data and changed information []
0080 %             :  if this is empty, new file will not be created
0081 %             :  This parameter must include the full extension.
0082 %             :  MEG : ".meg.mat"
0083 %             :  EEG : ".eeg.mat"
0084 %
0085 % [output]
0086 %           data : loaded data [Nchannel x Nsample x Ntrial]
0087 %   channel_info : <<struct>> channel information of loaded data
0088 %                :  .Active [Nchannel x 1]
0089 %                :  .Name   [Nchannel x 1]
0090 %                :  .Type   [Nchannel x 1]
0091 %                :  .ID     [Nchannel x 1]
0092 %
0093 % [note]
0094 %   See also
0095 %     vb_megfile_load_data
0096 %     vb_eegfile_load_data
0097 %     vb_load_channel_info
0098 %
0099 % [history]
0100 %   2006-12-13 (Sako) modified for EEG (acceptable eeg.mat)
0101 %   2007-07-23 (Sako) added loaded channel mode
0102 %   2007-08-10 (Sako) added mode type 'EEG' for load_eeg_data
0103 %   2008-02-20 (Sako) thoroughly revised
0104 %   2008-04-16 (Sako) added .ActiveSwitch in load_spec
0105 %   2008-06-06 (Sako) you can specify ChannelType and get channel_info
0106 %   2008-11-28 (Taku Yoshioka) Use vb_disp() for displaying message
0107 %   2009-07-22 (Sako) added the case only to return internal data
0108 %   2009-08-19 (Sako) modified the case that simply return data,
0109 %                     to return only sensor data (EEG) and channel_info
0110 %   2010-06-30 (Sako) supported storing data externally (only MEG)
0111 %   2010-11-15 (Sako) supported load_spec for 'INFO' file
0112 %   2011-02-08 (Sako) modified for EEG to store data externally
0113 %                     when newfile is valid
0114 %   2011-02-09 (Sako) modified not to output warning message
0115 %                     when cheking internal data
0116 %   2011-06-01 (Sako) supported unknown devices to load
0117 %   2011-07-15 (Sako) modified help about saveman(MEG) and bin_data_dir(EEG)
0118 %   2011-07-15 (Sako) modified the internal EEG data can be loaded correctly
0119 %   2011-08-19 (Sako) modified to avoid errors for the minimum data format
0120 %
0121 % Copyright (C) 2011, ATR All Rights Reserved.
0122 % License : New BSD License(see VBMEG_LICENSE.txt)
0123 
0124 const = vb_define_verbose;
0125 VERBOSE_LEVEL_NOTICE = const.VERBOSE_LEVEL_NOTICE;
0126 
0127 % --- CHECK ARGUMENTS --- %
0128 if ~exist('megfile', 'var'), megfile = []; end
0129 if ~exist('load_spec', 'var'), load_spec = ''; end
0130 if ~exist('new_file', 'var'), new_file = ''; end
0131 [megfile, load_spec, new_file] = ...
0132   inner_check_arguments(megfile, load_spec, new_file);
0133 
0134 % --- MAIN PROCEDURE --------------------------------------------------------- %
0135 %
0136 func_ = mfilename;
0137 
0138 data = [];
0139 channel_info = [];
0140 [measurement, device] = vb_load_device(megfile);
0141 
0142 Measurement = upper(measurement);
0143 Device      = upper(device);
0144 
0145 switch Measurement
0146   case  'MEG'
0147     switch Device
0148       case 'SBI'
0149         vb_disp(['(' func_ ')return all data because this is ' ...
0150                  'SBI data file'],VERBOSE_LEVEL_NOTICE);
0151         [data] = load_sbi_meg_data(megfile);
0152 
0153       case 'YOKOGAWA'
0154         
0155         % --- simplest mode check
0156         if isempty(load_spec)
0157           [result, a_list] = ...
0158             vb_util_check_variable_in_matfile(megfile, 'bexp');
0159 
0160           if result == a_list.VALID
0161             load(megfile, 'bexp');
0162             data = bexp;
0163             
0164             % --- make channel info
0165             channel_info = vb_load_channel_info(megfile);
0166             return;
0167           end
0168         end
0169         
0170         [data, channel_info] = ...
0171           vb_megfile_load_data(megfile, load_spec, new_file);
0172         
0173       case 'BASIC'
0174         load(megfile, 'bexp');
0175         if exist('bexp', 'var') && ~isempty(bexp)
0176           data = bexp;
0177           channel_info = [];
0178           return;
0179         end
0180         
0181       otherwise
0182         warning('(%s) unknown Device: %s of %s', func_, Device, Measurement);
0183 
0184         % --- simplest mode check
0185         if isempty(load_spec)
0186           [result, a_list] = ...
0187             vb_util_check_variable_in_matfile(megfile, 'bexp');
0188 
0189           if result == a_list.VALID
0190             load(megfile, 'bexp');
0191             data = bexp;
0192             channel_info = [];
0193             return;
0194           end
0195         end
0196 
0197         [data, channel_info] = ...
0198           vb_megfile_load_data(megfile, load_spec, new_file);
0199     end
0200     
0201   case  'EEG'
0202     switch Device
0203       case 'BIOSEMI'
0204         % --- simplest mode check
0205         if isempty(load_spec)
0206           [result, a_list] = ...
0207             vb_util_check_variable_in_matfile(megfile, 'eeg_data');
0208           if result == a_list.VALID
0209             % --- extract sensor data
0210             load(megfile, 'eeg_data');
0211             eeg_info = vb_load_measurement_info(megfile);
0212             ch_id = vb_eeginfo_get_channel_index(eeg_info);
0213             data = eeg_data(ch_id, :, :);
0214             
0215             % --- make channel info
0216             channel_info = vb_load_channel_info(megfile);
0217             return;
0218           end
0219         end
0220         [data, channel_info] = ...
0221           vb_eegfile_load_data(megfile, load_spec, new_file);
0222 
0223       case 'BASIC'
0224         load(megfile, 'eeg_data');
0225         if exist('eeg_data', 'var') && ~isempty(eeg_data)
0226           data = eeg_data;
0227           channel_info = [];
0228           return;
0229         end
0230 
0231       otherwise
0232         warning('(%s)unknown Device: %s of %s\n', func_, Device, Measurement);
0233 
0234         % --- simplest mode check
0235         if isempty(load_spec)
0236           [result, a_list] = ...
0237             vb_util_check_variable_in_matfile(megfile, 'eeg_data');
0238           if result == a_list.VALID
0239             % --- extract sensor data
0240             load(megfile, 'eeg_data');
0241             data = eeg_data;
0242             channel_info = [];
0243             return;
0244           end
0245         end
0246         [data, channel_info] = ...
0247           vb_eegfile_load_data(megfile, load_spec, new_file);
0248     end
0249 
0250   case  'INFO'
0251     load(megfile, 'fileinfo');
0252     
0253     % --- support loadspec --- %
0254     if ~isempty(load_spec)
0255       tmp_file = fileinfo.filename{1};
0256     
0257       % ----- check loadspec
0258       load_spec = vb_loadspec_check(load_spec, tmp_file);
0259 
0260       % ----- narrow channel by user-specified list and active filter
0261       meginfo = vb_megfile_load_meginfo(tmp_file);
0262       [read_ch, idx] = vb_meginfo_get_read_channels(meginfo, ...
0263         load_spec.ChannelName, load_spec.ChannelSwitch, ...
0264         load_spec.ActiveChannel);
0265 
0266       % --- convert loadspec setting to fileinfo setting
0267       ch_info = vb_info_get_channel_info(meginfo, 2);
0268       fileinfo.channel_id = ch_info.ID(idx);
0269       fileinfo.act_trial  = load_spec.TrialNumber;
0270     end
0271     % --- support loadspec --- %
0272     
0273     [data, channel_info] = vb_load_active_trial_data(fileinfo);
0274   
0275 
0276   otherwise
0277     error('(%s)undefined Measurement : %s', Measurement);
0278 end
0279 return;
0280 %
0281 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0282 
0283 % --- INNER FUNCTIONS -------------------------------------------------------- %
0284 %
0285 % --- inner_check_arguments()
0286 %
0287 function [megfile, load_spec, new_file] = ...
0288   inner_check_arguments(megfile, load_spec, new_file)
0289 func_ = mfilename;
0290 
0291 if isempty(megfile)
0292   error('(%s)megfile is a required parameter', func_);
0293 end
0294 
0295 if exist(megfile, 'file') ~= 2
0296   error('(%s)cannot find megfile : %s', func_, megfile);
0297 end
0298 
0299 if isempty(load_spec)
0300   % require no action
0301 end
0302 
0303 if isempty(new_file)
0304   % require no action
0305 end
0306 return
0307 %
0308 % --- end of inner_check_arguments()
0309 
0310 % --- END OF FILE --- %

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