0001 function [MEGinfo_list, sensor_info] = ...
0002 neuromag_load_meg_header(data_fiffile, mri_fiffile)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
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
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 [ch_info, pos_info] = neuromag_load_ch_info(data_fiffile);
0057
0058
0059 [voxel, mri_trans_info] = neuromag_load_mri_info(mri_fiffile);
0060
0061
0062 [pick_head, Qpick_head, Weight] = get_pos_neuromag(ch_info);
0063
0064 Vdim = size(voxel);
0065
0066
0067 pick = neuro_head_to_spm_right(pick_head, mri_trans_info, Vdim);
0068
0069 Qpick = neuro_head_to_spm_right(Qpick_head, mri_trans_info, Vdim, 1);
0070
0071
0072
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
0083 trial_header_list = cell(1);
0084
0085
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
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
0116
0117 d = vb_define_coordinate;
0118
0119
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
0127 NEUROMAG_MagnetoMeter = ...
0128 neuromag_get_channel_type('NEUROMAG_MagnetoMeter');
0129 NEUROMAG_PlanarGradioMeter = ...
0130 neuromag_get_channel_type('NEUROMAG_PlanarGradioMeter');
0131
0132
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
0139 ix = ch_info.sensor_type == 0;
0140 sensor_type(ix) = NEUROMAG_MagnetoMeter;
0141
0142
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
0149 MEGinfo_list = cell(Nsets, 1);
0150 for k=1:Nsets
0151 MEGinfo = struct;
0152
0153 MEGinfo.MEG_ID = f_name;
0154
0155
0156 MEGinfo.Nchannel = ch_info.Nch;
0157
0158 MEGinfo.Pretrigger = trial_header_list{k}.Pretrigger;
0159
0160 MEGinfo.sensor_weight = sensor_info.Weight;
0161
0162 MEGinfo.MEGch_id = sensor_id';
0163 MEGinfo.MEGch_name = sensor_name;
0164
0165
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
0176 MEGinfo.Vcenter = [];
0177 MEGinfo.Vradius = [];
0178
0179
0180 device_info.acq_type = trial_header_list{k}.acq_type;
0181
0182
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