0001 function [res] = mne_ex_read_evoked(fname,setno,apply_proj,dest_comp,use_ctf_head)
0002
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
0029
0030
0031
0032
0033 me='MNE:mne_ex_read_evoked';
0034
0035
0036
0037
0038 if nargin == 1
0039 setno = 1;
0040 apply_proj = true;
0041 use_ctf_head = false;
0042 keep_comp = true;
0043 elseif nargin == 2
0044 apply_proj = true;
0045 use_ctf_head = false;
0046 keep_comp = true;
0047 elseif nargin == 3
0048 use_ctf_head = false;
0049 keep_comp = true;
0050 elseif nargin == 4
0051 use_ctf_head = false;
0052 keep_comp = false;
0053 elseif nargin == 5
0054 keep_comp = false;
0055 else
0056 error(me,'Incorrect number of arguments');
0057 end
0058
0059
0060
0061 fprintf(1,'\nLoading set %d from %s...\n\n',setno,fname);
0062
0063 try
0064 res = fiff_read_evoked(fname,setno);
0065 catch
0066 error(me,'%s',mne_omit_first_line(lasterr));
0067 end
0068
0069
0070
0071 fprintf(1,'\nPreprocessing...\n');
0072
0073
0074
0075
0076 want_meg = true;
0077 want_eeg = false;
0078 want_stim = false;
0079
0080
0081 include = [];
0082
0083 res = fiff_pick_types_evoked(res,want_meg,want_eeg,want_stim,include,res.info.bads);
0084 fprintf(1,'\t%d channels remain after picking\n',res.info.nchan);
0085
0086
0087
0088 comp=[];
0089 current_comp = mne_get_current_comp(res.info);
0090 if current_comp > 0
0091 fprintf(1,'\tCurrent compensation grade : %d\n',current_comp);
0092 end
0093 if keep_comp
0094 dest_comp = current_comp;
0095 end
0096 if current_comp ~= dest_comp
0097 try
0098 comp = mne_make_compensator(res.info,current_comp,dest_comp);
0099 res.info.chs = mne_set_current_comp(res.info.chs,dest_comp);
0100 fprintf(1,'\tAppropriate compensator created to change to grade %d.\n',dest_comp);
0101 catch
0102 error(me,'%s',mne_omit_first_line(lasterr));
0103 end
0104 end
0105 if ~isempty(comp)
0106 for k = 1:length(res.evoked)
0107 res.evoked(k).epochs = comp*res.evoked(k).epochs;
0108 end
0109 fprintf(1,'\tThe data are now compensated to grade %d.\n',dest_comp);
0110 end
0111
0112
0113
0114 if apply_proj
0115 if isempty(res.info.projs)
0116 fprintf(1,'\tNo projector specified in these data\n');
0117 else
0118
0119
0120
0121 for k = 1:length(res.info.projs)
0122 res.info.projs(k).active = true;
0123 end
0124 fprintf(1,'\t%d projection items activated\n',length(res.info.projs));
0125
0126
0127
0128 [res.info.proj,nproj] = mne_make_projector_info(res.info);
0129 if nproj == 0
0130 fprintf(1,'\tThe projection vectors do not apply to these channels\n');
0131 else
0132 fprintf(1,'\tCreated an SSP operator (subspace dimension = %d)\n',nproj);
0133 for k = 1:length(res.evoked)
0134 res.evoked(k).epochs = res.info.proj*res.evoked(k).epochs;
0135 end
0136 fprintf(1,'\tSSP operator applied to the evoked data\n');
0137 end
0138 end
0139 end
0140
0141
0142
0143 if use_ctf_head
0144 if isempty(res.info.dev_ctf_t)
0145 error(me,'No CTF head transformation available');
0146 end
0147 meg_trans = res.info.dev_ctf_t;
0148 eeg_trans = fiff_invert_transform(res.info.ctf_head_t);
0149 fprintf(1,'\tEmploying the CTF/4D head coordinate system\n');
0150 else
0151 meg_trans = res.info.dev_head_t;
0152 eeg_trans = [];
0153 fprintf(1,'\tEmploying the Neuromag head coordinate system\n');
0154 end
0155
0156
0157
0158 res.info.chs = fiff_transform_meg_chs(res.info.chs,meg_trans);
0159 res.info.chs = fiff_transform_eeg_chs(res.info.chs,eeg_trans);
0160
0161
0162
0163 try
0164 accuracy = 1;
0165 res.info.chs = mne_add_coil_defs(res.info.chs,accuracy);
0166 catch
0167 fprintf(1,'\tCoil definitions not added\n');
0168 end
0169
0170
0171
0172 if false
0173 coil_def_file = 'whatever';
0174 templates = mne_load_coil_def(coil_def_file);
0175 res.info.chs = mne_add_coil_defs(res.info.chs,accuracy,templates);
0176 end
0177
0178 fprintf(1,'\nReady.\n\n');
0179
0180 return;
0181
0182 end