Home > vbmeg > functions > common > loadfunc > vb_load_current.m

vb_load_current

PURPOSE ^

load estimated current

SYNOPSIS ^

function [Jinfo,Jact,Plist,Jext] =vb_load_current(currfile,curr_type,ave_mode,trial,ix_area,verbose)

DESCRIPTION ^

 load estimated current

 USAGE:
  [Jinfo,Jact] = ...
          vb_load_current(currfile,curr_type,ave_mode,trial,ix_area,verbose)

 --- INPUT:
  currfile  - current file name
 --- Optional INPUT:
 curr_type - current type
         = 0 : J-current : Cortical current excluding zero activity vertex.
         = 1 : Z-current : Cortical current on reduced vertex. (bayes_parm_reduce)
         = 2 : Current   : Cortical current on all vertex.   [Default]
         = 3 : extra current : Current on extra dipoles (if exist)
  ave_mode : trial average mode
          = ON  : trial average is done  [Default]
          = OFF : No trial average
  trial   : trial number to load 
            if empty, all trials are loaded  [Default]
  ix_area : (absolute) vertex index to load
            if empty, all vertices are loaded  [Default]
  verbose : verbose mode for trial file loading
            0 (No print) , 1 ('.') , 2 ('session , trial')
 --- OUTPUT:
 Jinfo : structure of current info
    .version   : Version of current file
    .curr_type : current type(0:J-current, 1:Z-current 2:Current)
    .tindex    : Subsampled indices
    .Lact      : # of current direction at one vertex in active region
    .Wact      : Smoothing filter matrix
    .ix_act    : Vertex index corresponding to Z-current
    .ix_act_ex : Vertex index corresponding to J-current
    .NJact     : # of current vertices
    .Tsample   : Time sample index for 'Jact'
    .Ntrial    : # of trials
    .Nsession  : # of sessions
    .jactdir   : Current directory
    .SampleFreq: Sample Frequency [Hz]
    .Pretrigger: Pretrigger period
    .Tmsec     : Time in msec
    .trial     : Trial number to load (optional input for this function)
 
 Jact    : current timecourse
   Jact(Njact,Nsample)          for ave_mode = ON 
   Jact(Njact,Nsample,Ntrials)  for ave_mode = OFF
     Njact    : # of current
                   - curr_type = 0: Njact = length(Jinfo.ix_act);
                   - curr_type = 1: Njact = length(Jinfo.ix_act_ex);
                   - curr_type = 2: Njact = Nvertex(# of all vertex)
     Nsample  : # of time sample 
     Ntrials  : # of trials in all session

   Jact(:, t, :) 
    Time sample in MEG data : Jinfo.Tsample(t)
    Time (ms)   in MEG data : Jinfo.Tmsec(t)

 Plist : Information of extra dipoles
 Jext  : estimated current for extra dipoles

 2007-3-5 Masa-aki Sato
 2008-7-9 Masa-aki Sato
  support all file types and old files
 2008-09-30 Taku Yoshioka
  Minor change for variables in Jinfo
 2010-03-01 M. Sato
  modified not to use Jinfo.ix_act_ex
 2022-05-01 k_suzuki
  Merge with vb_load_current_ext
 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 [Jinfo,Jact,Plist,Jext] = ...
0002     vb_load_current(currfile,curr_type,ave_mode,trial,ix_area,verbose)
0003 % load estimated current
0004 %
0005 % USAGE:
0006 %  [Jinfo,Jact] = ...
0007 %          vb_load_current(currfile,curr_type,ave_mode,trial,ix_area,verbose)
0008 %
0009 % --- INPUT:
0010 %  currfile  - current file name
0011 % --- Optional INPUT:
0012 % curr_type - current type
0013 %         = 0 : J-current : Cortical current excluding zero activity vertex.
0014 %         = 1 : Z-current : Cortical current on reduced vertex. (bayes_parm_reduce)
0015 %         = 2 : Current   : Cortical current on all vertex.   [Default]
0016 %         = 3 : extra current : Current on extra dipoles (if exist)
0017 %  ave_mode : trial average mode
0018 %          = ON  : trial average is done  [Default]
0019 %          = OFF : No trial average
0020 %  trial   : trial number to load
0021 %            if empty, all trials are loaded  [Default]
0022 %  ix_area : (absolute) vertex index to load
0023 %            if empty, all vertices are loaded  [Default]
0024 %  verbose : verbose mode for trial file loading
0025 %            0 (No print) , 1 ('.') , 2 ('session , trial')
0026 % --- OUTPUT:
0027 % Jinfo : structure of current info
0028 %    .version   : Version of current file
0029 %    .curr_type : current type(0:J-current, 1:Z-current 2:Current)
0030 %    .tindex    : Subsampled indices
0031 %    .Lact      : # of current direction at one vertex in active region
0032 %    .Wact      : Smoothing filter matrix
0033 %    .ix_act    : Vertex index corresponding to Z-current
0034 %    .ix_act_ex : Vertex index corresponding to J-current
0035 %    .NJact     : # of current vertices
0036 %    .Tsample   : Time sample index for 'Jact'
0037 %    .Ntrial    : # of trials
0038 %    .Nsession  : # of sessions
0039 %    .jactdir   : Current directory
0040 %    .SampleFreq: Sample Frequency [Hz]
0041 %    .Pretrigger: Pretrigger period
0042 %    .Tmsec     : Time in msec
0043 %    .trial     : Trial number to load (optional input for this function)
0044 %
0045 % Jact    : current timecourse
0046 %   Jact(Njact,Nsample)          for ave_mode = ON
0047 %   Jact(Njact,Nsample,Ntrials)  for ave_mode = OFF
0048 %     Njact    : # of current
0049 %                   - curr_type = 0: Njact = length(Jinfo.ix_act);
0050 %                   - curr_type = 1: Njact = length(Jinfo.ix_act_ex);
0051 %                   - curr_type = 2: Njact = Nvertex(# of all vertex)
0052 %     Nsample  : # of time sample
0053 %     Ntrials  : # of trials in all session
0054 %
0055 %   Jact(:, t, :)
0056 %    Time sample in MEG data : Jinfo.Tsample(t)
0057 %    Time (ms)   in MEG data : Jinfo.Tmsec(t)
0058 %
0059 % Plist : Information of extra dipoles
0060 % Jext  : estimated current for extra dipoles
0061 %
0062 % 2007-3-5 Masa-aki Sato
0063 % 2008-7-9 Masa-aki Sato
0064 %  support all file types and old files
0065 % 2008-09-30 Taku Yoshioka
0066 %  Minor change for variables in Jinfo
0067 % 2010-03-01 M. Sato
0068 %  modified not to use Jinfo.ix_act_ex
0069 % 2022-05-01 k_suzuki
0070 %  Merge with vb_load_current_ext
0071 % Copyright (C) 2011, ATR All Rights Reserved.
0072 % License : New BSD License(see VBMEG_LICENSE.txt)
0073 
0074 
0075 if ~exist('curr_type','var'), curr_type = 2; end;
0076 if ~exist('ave_mode','var'), ave_mode = ON; end;
0077 if ~exist('trial','var'), trial = []; end;
0078 if ~exist('ix_area','var'), ix_area = []; end;
0079 if ~exist('verbose','var'), verbose = 0; end;
0080 
0081 if curr_type~=3
0082 %----- Load cortical current -----
0083 whole_vertex = false;
0084 if curr_type == 2
0085     whole_vertex = true;
0086     curr_type = 0;
0087 end
0088     
0089 [J_type, file_type] = vb_load_current_type(currfile);
0090 %  J_type = 0 : J-current
0091 %  J_type = 1 : Z-current
0092 %  file_type = 0: single file
0093 %  file_type = 1: parent file with trial files
0094 
0095 [Jinfo] = vb_load_current_info(currfile);
0096 
0097 if ave_mode==OFF && file_type==1
0098   % trial mode & each trial current file
0099   if J_type==1
0100     [Jact,ix_act] = ...
0101         vb_load_current_z_tr(currfile,curr_type,trial,ix_area,verbose);
0102     Jinfo.curr_type = curr_type;
0103   else
0104     if curr_type==1,
0105       fprintf('No Z-current and J-current is returned\n');
0106     end
0107     [Jact,ix_act] = ...
0108         vb_load_current_j_tr(currfile,trial,ix_area,verbose);
0109     Jinfo.curr_type = 0;
0110   end
0111 else
0112   % single current file
0113   if J_type==1
0114     [Jact,ix_act] = ...
0115         vb_load_current_z(currfile,curr_type,ave_mode,trial,ix_area);
0116     Jinfo.curr_type = curr_type;
0117   else
0118     if curr_type==1,
0119       fprintf('No Z-current and J-current is returned\n');
0120     end
0121     [Jact,ix_act] = ...
0122         vb_load_current_j(currfile,ave_mode,trial,ix_area);
0123     Jinfo.curr_type = 0;
0124   end
0125 end
0126 
0127 Jinfo.trial = trial;
0128 Jinfo.NJact = length(ix_act);
0129 
0130 if whole_vertex
0131     % create cortical current on whole vertex.
0132     warning('off', 'MATLAB:load:variableNotFound');
0133     load(currfile, 'Nvertex');
0134     warning('on',  'MATLAB:load:variableNotFound');
0135     if exist('Nvertex', 'var')
0136         [s1, s2, s3] = size(Jact);
0137         Jact_whole = zeros(Nvertex, s2, s3);
0138         Jact_whole(Jinfo.ix_act_ex, :, :) = Jact(:, :, :);
0139         Jact = Jact_whole;
0140         Jinfo.curr_type = 2;
0141         Jinfo.NJact     = Nvertex;
0142     else
0143         error('Current file format is old. re-run vb_job_current.');
0144     end
0145 end
0146 
0147 else
0148 %----- Load extra current -----
0149 load(currfile,'Pointlist');
0150 if exist('Pointlist', 'var')
0151     Plist = Pointlist;
0152     Jext = inner_load_extra_current(currfile, ave_mode, trial);
0153     Jinfo=[];Jact=[];
0154 else
0155     warning('Currfile does not contain extra current');
0156 end
0157 
0158 end
0159 
0160 end
0161 
0162 function Jext = inner_load_extra_current(currfile, ave_mode, ix_trial)
0163 const = vb_define_verbose;
0164 VERBOSE_LEVEL_INFO = const.VERBOSE_LEVEL_INFO;
0165 
0166 if ave_mode==OFF
0167   % trial mode
0168   load(currfile,'Jinfo');
0169   
0170   if isfield(Jinfo,'jactdir'),
0171     jactdir = [fileparts(currfile) '/' Jinfo.jactdir];
0172     if exist(jactdir,'dir')==0,
0173       error('No trial data directory')
0174     end
0175     
0176     % Session & Trial number list
0177     session = [];
0178     ntrial = [];
0179     
0180     for n=1:Jinfo.Nsession
0181       Ntry = Jinfo.Ntrial(n);
0182       session = [session, repmat(n,1,Ntry)];
0183       ntrial  = [ntrial, 1:Ntry];
0184     end
0185     
0186     % Trial loop
0187     if isempty(ix_trial), ix_trial = 1:length(ntrial); end
0188     Ntrial = length(ix_trial);
0189 
0190     for n=1:Ntrial
0191       nt = ix_trial(n);
0192       vb_disp(sprintf('Session: %04d , Trial: %04d', ...
0193                       session(nt), ntrial(nt)), VERBOSE_LEVEL_INFO);
0194       %if verbose==1,
0195       %  fprintf('.')
0196       %elseif verbose==2,
0197       %  fprintf('Session: %04d , Trial: %04d\n',session(nt), ntrial(nt))
0198       %end
0199       
0200       fname = sprintf('data_s%04dt%04d', session(nt), ntrial(nt));
0201       load([jactdir '/' fname],'Jext');    
0202       Jall(:,:,n) = Jext;
0203     end
0204     
0205     Jext = Jall;
0206   else
0207     load(currfile,'Jext');
0208     if ~isempty(ix_trial), Jext = Jext(:,:,ix_trial); end
0209   end
0210 else
0211   load(currfile,'Jext');
0212 end
0213 end
0214

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