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

neuromag_load_meg_header

PURPOSE ^

load sensor and data information from fiffile.

SYNOPSIS ^

function [MEGinfo_list, sensor_info] =neuromag_load_meg_header(data_fiffile, mri_fiffile)

DESCRIPTION ^

 load sensor and data information from fiffile.
 [USAGE]
   [MEGinfo_list, sensor_info] = ...
     neuromag_load_meg_header(data_fiffile, mri_fiffile);
 [IN]
    data_fiffile : data fiffile.
     mri_fiffile : MRI fiffile.
 [OUT]
    MEGinfo_list : <<struct array>> array of MEGinfo [1 x N_fileset]
     sensor_info : <<struct>> sensor information
            .pick       : n-th coil position  (Right-hand SPM coordinate) [m]
                        :  [Ncoil x 3]
            .Qpick      : n-th coil direction (Right-hand SPM coordinate)
                        :  [Ncoil x 3]
            .coord_type : coordinate system of pick, Qpick.
            .Weight     : n-th coil weight for m-th channel [Nchannel x Ncoil]
                        : basis(channel,dipole) = 
                            CoilWeight * basis(coil,dipole)

 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 [MEGinfo_list, sensor_info] = ...
0002             neuromag_load_meg_header(data_fiffile, mri_fiffile)
0003 % load sensor and data information from fiffile.
0004 % [USAGE]
0005 %   [MEGinfo_list, sensor_info] = ...
0006 %     neuromag_load_meg_header(data_fiffile, mri_fiffile);
0007 % [IN]
0008 %    data_fiffile : data fiffile.
0009 %     mri_fiffile : MRI fiffile.
0010 % [OUT]
0011 %    MEGinfo_list : <<struct array>> array of MEGinfo [1 x N_fileset]
0012 %     sensor_info : <<struct>> sensor information
0013 %            .pick       : n-th coil position  (Right-hand SPM coordinate) [m]
0014 %                        :  [Ncoil x 3]
0015 %            .Qpick      : n-th coil direction (Right-hand SPM coordinate)
0016 %                        :  [Ncoil x 3]
0017 %            .coord_type : coordinate system of pick, Qpick.
0018 %            .Weight     : n-th coil weight for m-th channel [Nchannel x Ncoil]
0019 %                        : basis(channel,dipole) =
0020 %                            CoilWeight * basis(coil,dipole)
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(data_fiffile, 'file') ~= 2
0035     error('data_fiffile:%s is not found.', data_fiffile);
0036 end
0037 if exist(mri_fiffile, 'file') ~= 2
0038     error('mri_fiffile:%s is not found', mri_fiffile);
0039 end
0040 
0041 %if ~exist('analyzefile', 'var')
0042 %    error('analyzefile is a required parameter.');
0043 %end
0044 %if exist(analyzefile, 'file') ~= 2
0045 %    error('analyzefile:%s is not found', analyzefile);
0046 %end
0047 
0048 
0049 %
0050 % --- Extract information
0051 %
0052 %[B, Vdim, Vsize] = vb_load_analyze_to_right(analyzefile);
0053 
0054 % load channel information and coordinate transform matrix
0055 % from the timeseries fiffile.
0056 [ch_info, pos_info] = neuromag_load_ch_info(data_fiffile);
0057 
0058 % load voxel data and transform matrix from mri fiffile.
0059 [voxel, mri_trans_info] = neuromag_load_mri_info(mri_fiffile);
0060 
0061 % transform coil coordinates from coil coordinate system to head coordinate system.
0062 [pick_head, Qpick_head, Weight] = get_pos_neuromag(ch_info);
0063 
0064 Vdim = size(voxel);
0065 
0066 % transform coil coordinates in head coordinate to SPM coordinate.
0067 pick  = neuro_head_to_spm_right(pick_head, mri_trans_info, Vdim);
0068 % only rotation
0069 Qpick = neuro_head_to_spm_right(Qpick_head, mri_trans_info, Vdim, 1);
0070 
0071 
0072 % Check the number of data sets in the fiffile.
0073 info = fiff_find_evoked(data_fiffile);
0074 
0075 if isempty(info)
0076     Nsets = 0;
0077 else
0078     Nsets = length(info);
0079 end
0080 
0081 if Nsets == 0
0082     % Continuous data
0083     trial_header_list = cell(1);
0084 
0085     % read header
0086     header = struct;
0087     header.Nrepeat    = 1;
0088     header.Pretrigger = 0;
0089     header.Comment    = '';
0090     header.acq_type   = 'Continuous_Raw';
0091     header.index_in_fiffile = -1;
0092 
0093     trial_header_list{1} = header;
0094     Nsets = 1;
0095 
0096 else
0097    % Averaged data
0098     data_sets = fiff_read_evoked_all(data_fiffile);
0099     trial_header_list = cell(Nsets, 1);
0100     for k=1:Nsets
0101         info_k = data_sets.evoked(k);
0102         header = struct;
0103         header.Nsample    = size(info_k.epochs, 2);
0104         header.Nrepeat    = size(info_k.epochs, 3);
0105         header.SampleFreq = data_sets.info.sfreq;
0106         header.Pretrigger = find(info_k.times == 0)-1;
0107         header.Comment    = info_k.comment;
0108         header.acq_type   = 'Evoked_Ave';
0109         header.index_in_fiffile = k;
0110         trial_header_list{k} = header;
0111    end
0112 end
0113 
0114 %
0115 % --- Make information
0116 %
0117 d = vb_define_coordinate;
0118 
0119 % Make Sensor infomation
0120 sensor_info = struct;
0121 sensor_info.pick  = pick;
0122 sensor_info.Qpick = Qpick;
0123 sensor_info.coord_type = d.COORDINATE_SPM_RIGHT_M;
0124 sensor_info.Weight = Weight;
0125 
0126 % --- Sensor_type info
0127 NEUROMAG_MagnetoMeter = ... % VBMEG's magnetometer id
0128   neuromag_get_channel_type('NEUROMAG_MagnetoMeter');
0129 NEUROMAG_PlanarGradioMeter = ... % VBMEG's planarmeter id
0130   neuromag_get_channel_type('NEUROMAG_PlanarGradioMeter');
0131 
0132 % --- sensor basic information
0133 n_ch = size(ch_info.channel_name, 1);
0134 sensor_type = zeros(n_ch, 1);
0135 sensor_name = ch_info.channel_ix;
0136 sensor_id   = 1:n_ch;
0137 
0138 % ----- Convert channel type from neuromag to vbmeg's(MagnetoMeter)
0139 ix = ch_info.sensor_type == 0;
0140 sensor_type(ix) = NEUROMAG_MagnetoMeter;
0141 
0142 % ----- Convert channel type from neuromag to vbmeg's(PlanarGradioMeter)
0143 ix = ch_info.sensor_type == 1;
0144 sensor_type(ix) = NEUROMAG_PlanarGradioMeter;
0145 
0146 [f_path, f_name] = vb_get_file_parts(data_fiffile);
0147 
0148 % -- Make MEGinfo
0149 MEGinfo_list = cell(Nsets, 1);
0150 for k=1:Nsets
0151   MEGinfo = struct;
0152   % -- MEGinfo device properties
0153   MEGinfo.MEG_ID   = f_name;
0154     
0155   % -- MEGinfo data properties
0156   MEGinfo.Nchannel      = ch_info.Nch;
0157 %  MEGinfo.Nsample       = trial_header_list{k}.Nsample;
0158   MEGinfo.Pretrigger    = trial_header_list{k}.Pretrigger;
0159 %  MEGinfo.SampleFreq    = trial_header_list{k}.SampleFreq;
0160   MEGinfo.sensor_weight = sensor_info.Weight;
0161     
0162   MEGinfo.MEGch_id   = sensor_id'; % [n_channel x 1]
0163   MEGinfo.MEGch_name = sensor_name;
0164 
0165   % ----- MEGinfo .ChannelInfo
0166   ChannelInfo.Active = ones(n_ch, 1);
0167   ChannelInfo.ID     = MEGinfo.MEGch_id;
0168   ChannelInfo.Name   = MEGinfo.MEGch_name;
0169   ChannelInfo.Type   = sensor_type;
0170   MEGinfo.ChannelInfo= ChannelInfo;
0171 
0172   MEGinfo.MRI_ID        = '';
0173   MEGinfo.Nrepeat     = trial_header_list{k}.Nrepeat;
0174 
0175   % -- MEGinfo sphere model
0176   MEGinfo.Vcenter = [];
0177   MEGinfo.Vradius = [];
0178 
0179   % ----- device dependent information
0180   device_info.acq_type = trial_header_list{k}.acq_type;
0181 
0182   % ------- Neuromag specific information
0183   device_info.index_in_fiffile = trial_header_list{k}.index_in_fiffile; 
0184   device_info.Comment = trial_header_list{k}.Comment;
0185 
0186   MEGinfo.device_info = device_info;
0187 
0188   MEGinfo_list{k} = MEGinfo;
0189 end
0190 
0191 return;
0192 
0193 % --- END OF FILE --- %

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