Home > vbmeg > functions > tool_box > neuromag > neuromag_to_megmat.m

neuromag_to_megmat

PURPOSE ^

make MEG-MAT file from neuromag fiffile.

SYNOPSIS ^

function megmat_file = neuromag_to_megmat(data_fiffile, mri_fiffile,output_prefix, face_file)

DESCRIPTION ^

 make MEG-MAT file from neuromag fiffile.
 [USAGE]
    neuromag_to_megmat(data_fiffile, mri_fiffile, ...
                       output_prefix, face_file, sensor_mode)
 [IN]
      data_fiffile : Data fiffile.
       mri_fiffile : MRI fiffile.
     output_prefix : output filename prefix.
                     (ex. '/home/RH/RH' => /home/RH/RH.meg.mat)
 [optional input]
         face_file : If you want to calculate by using spherical model,
                     center position and radius of spherical model are 
                     necessary.
                     A face file which is made by positioning tool has them.
                     For face file, please refer to the manual of the
                     positioning tool
 [OUT]
    meg.mat file with output_prefix is saved

 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:

SOURCE CODE ^

0001 function megmat_file = neuromag_to_megmat(data_fiffile, mri_fiffile, ...
0002                         output_prefix, face_file)
0003 % make MEG-MAT file from neuromag fiffile.
0004 % [USAGE]
0005 %    neuromag_to_megmat(data_fiffile, mri_fiffile, ...
0006 %                       output_prefix, face_file, sensor_mode)
0007 % [IN]
0008 %      data_fiffile : Data fiffile.
0009 %       mri_fiffile : MRI fiffile.
0010 %     output_prefix : output filename prefix.
0011 %                     (ex. '/home/RH/RH' => /home/RH/RH.meg.mat)
0012 % [optional input]
0013 %         face_file : If you want to calculate by using spherical model,
0014 %                     center position and radius of spherical model are
0015 %                     necessary.
0016 %                     A face file which is made by positioning tool has them.
0017 %                     For face file, please refer to the manual of the
0018 %                     positioning tool
0019 % [OUT]
0020 %    meg.mat file with output_prefix is saved
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 %
0026 % --- Previous check
0027 %
0028 if ~exist('data_fiffile', 'var')
0029     error('data_fiffile is a required parameter.');
0030 end
0031 if ~exist('mri_fiffile', 'var')
0032     error('mri_fiffile is a required parameter.');
0033 end
0034 if ~exist('output_prefix', 'var')
0035     error('output_prefix is a required parameter.');
0036 end
0037 if ~exist('face_file', 'var')
0038     face_file = [];
0039 end
0040 if exist(data_fiffile, 'file') ~= 2
0041     error('data_fiffile:%s is not found.', data_fiffile);
0042 end
0043 if exist(mri_fiffile, 'file') ~= 2
0044     error('mri_fiffile:%s is not found.', mri_fiffile);
0045 end
0046 
0047 [f_path] = vb_get_file_parts(output_prefix);
0048 if exist(f_path, 'dir') ~= 7
0049     error('output_prefix directory:%s is invalid.', f_path);
0050 end
0051 if ~exist('sensor_mode','var'), sensor_mode = 'All'; end
0052 
0053 %
0054 % --- Main Procedure
0055 %
0056 
0057 
0058 %
0059 % --- Load Header
0060 %
0061 fprintf('--- now loading neuromag header.\n');
0062 [MEGinfo_list, sensor_info] = neuromag_load_meg_header(data_fiffile, ...
0063                                                        mri_fiffile);%, ...
0064 %                                                       analyzefile);
0065 
0066 %
0067 % --- Extra channel info
0068 %
0069 [extra_info] = neuromag_load_extra_info(data_fiffile);
0070 
0071 %
0072 % --- Make sphere model
0073 %
0074 if ~isempty(face_file)
0075 
0076     if exist(face_file,'file') ~= 2
0077     warning('face_file:%s is not found.\n', face_file);
0078 %     error('face_file:%s is not found.', face_file);
0079   end
0080   
0081   [state, guide_def] = ...
0082     vb_util_check_variable_in_matfile(face_file, 'spherical_head');
0083 
0084   if state == guide_def.VALID
0085     load(face_file, 'spherical_head');
0086     Vcenter = spherical_head.Vcenter;
0087     Vradius = spherical_head.Vradius;
0088   else
0089     [state, guide_def] = ...
0090       vb_util_check_variable_in_matfile(face_file, 'surf_face');
0091     if state == guide_def.VALID
0092       % --- calculate center position and radius of spherical model
0093       % --- Upper face is used for fitting sphere model
0094       %    --- ix = find(V(:,3) > (h * Zmax + (1-h) * Zmin));
0095       h = 0.4;
0096         load(face_file, 'surf_face')
0097     
0098         V = surf_face.V_reduce;
0099         Zmax = max(V(:,3));
0100         Zmin = min(V(:,3));
0101         ix = find(V(:,3) > (h * Zmax + (1-h) * Zmin));
0102     
0103         % Fit face to sphere
0104         [Vcenter,Vradius] = vb_center_sphere(V(ix,:));
0105     else
0106         Vcenter = [];
0107         Vradius = [];
0108     end
0109   end
0110     
0111 else
0112     Vcenter = [];
0113     Vradius = [];
0114 end
0115 
0116 pick   = sensor_info.pick;
0117 Qpick  = sensor_info.Qpick;
0118 weight = sensor_info.Weight;
0119 
0120 Ninfo = length(MEGinfo_list);
0121 
0122 %
0123 % --- Make MEG-MAT file(s).
0124 %
0125 fprintf('--- now loading neuromag data.\n');
0126 for k=1:Ninfo
0127   % -- Make file name
0128   if Ninfo == 1
0129     megmat_file{1} = [output_prefix, '.meg.mat'];
0130   else
0131     megmat_file{k} = [output_prefix, '_', num2str(k), '.meg.mat'];
0132   end
0133     
0134     % Set MEGinfo
0135   MEGinfo = MEGinfo_list{k};
0136     
0137   session_no = MEGinfo.device_info.index_in_fiffile;
0138 
0139   % load data
0140   [bexp, ch_info, sfreq] = neuromag_load_meg_data_SSP(data_fiffile, session_no);
0141   [bexp_ext, extra_info] = neuromag_load_extra_data(data_fiffile, session_no);
0142 
0143   if ~isempty(Vcenter)
0144       MEGinfo.Vcenter = Vcenter;
0145       MEGinfo.Vradius = Vradius;
0146   end
0147   
0148   MEGinfo.Nsample    = size(bexp, 2);
0149   MEGinfo.SampleFreq = sfreq;
0150 
0151   % ----- MEGinfo.Trial
0152   Trial(1).number = 1;
0153   Trial(1).sample = 1:MEGinfo.Nsample;
0154   Trial(1).Active = true;
0155   MEGinfo.Trial = Trial;
0156     
0157   MEGinfo.sensor_weight = weight;
0158   MEGinfo.ExtraChannelInfo = extra_info;
0159 
0160   MEGinfo.device   = 'NEUROMAG';
0161   CoordType   = 'SPM_Right_m';
0162     
0163   Measurement = 'MEG';
0164 
0165   MEGinfo.Measurement   = Measurement;
0166   MEGinfo.ActiveChannel = MEGinfo.ChannelInfo.Active;
0167   MEGinfo.ActiveTrial   = MEGinfo.Trial.Active;
0168 
0169   
0170   
0171   % save MEG-MAT file
0172   vb_fsave(megmat_file{k}, 'MEGinfo', 'Measurement', 'CoordType', ...
0173        'pick', 'Qpick', 'bexp', 'bexp_ext');
0174   fprintf('%s was created.\n', megmat_file{k});
0175 end
0176 fprintf('--- conversion were finished.\n');

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