|
3 | 3 | resp=''; |
4 | 4 |
|
5 | 5 | switch task |
6 | | - case 'report' |
| 6 | + case 'report' |
| 7 | + % summary |
| 8 | + % - init |
| 9 | + if ~isfield(aap.report, aap.tasklist.currenttask.name) |
| 10 | + aap.report.(aap.tasklist.currenttask.name).pnts = NaN(aas_getN_bydomain(aap,'subject'),numel(aap.acq_details.meeg_sessions)); |
| 11 | + end |
| 12 | + |
| 13 | + % - save pnts |
| 14 | + outFn = cellstr(aas_getfiles_bystream(aap,'meeg_session',[subj,sess],'meeg','output')); |
| 15 | + EEG = pop_loadset(outFn{strcmp(spm_file(outFn,'ext'),'set')}); |
| 16 | + aap.report.(aap.tasklist.currenttask.name).pnts(subj,sess) = EEG.pnts; |
| 17 | + |
| 18 | + % figures |
7 | 19 | for fn = cellstr(spm_select('FPList',aas_getsesspath(aap,subj,sess),'^diagnostic_.*jpg$'))' |
8 | 20 | aap = aas_report_add(aap,subj,'<table><tr><td>'); |
9 | | - aap=aas_report_addimage(aap,subj,fn{1}); |
| 21 | + aap = aas_report_addimage(aap,subj,fn{1}); |
10 | 22 | aap = aas_report_add(aap,subj,'</td></tr></table>'); |
11 | 23 | end |
12 | 24 | case 'doit' |
|
67 | 79 | if ~isempty(toEdit) |
68 | 80 | for e = toEdit |
69 | 81 | if ischar(e.type) |
70 | | - try, ind = ~cellfun(@isempty, regexp({EEG.event.type},e.type)); |
| 82 | + try ind = ~cellfun(@isempty, regexp({EEG.event.type},e.type)); |
71 | 83 | catch |
72 | 84 | aas_log(aap,false,sprintf('No trial %s found', e.type)); |
73 | 85 | ind = false(size(EEG.event)); |
|
78 | 90 | op = strsplit(e.operation,':'); |
79 | 91 | if ~any(ind) && ~startsWith(op{1},'insert'), continue; end |
80 | 92 | switch op{1} |
| 93 | + case 'clear' |
| 94 | + EEG.event(1:end) = []; |
| 95 | + EEG.urevent(1:end) = []; |
81 | 96 | case 'remove' |
| 97 | + urind = [EEG.event(ind).urevent]; |
82 | 98 | EEG.event(ind) = []; |
83 | | - EEG.urevent(ind) = []; |
| 99 | + EEG.urevent(urind) = []; |
84 | 100 | case 'keep' |
| 101 | + urind = [EEG.event(ind).urevent]; |
85 | 102 | EEG.event = EEG.event(ind); |
86 | | - EEG.urevent = EEG.urevent(ind); |
| 103 | + EEG.urevent = EEG.urevent(urind); |
87 | 104 | case 'keepbeforeevent' |
88 | 105 | ind = find(ind); |
89 | 106 | indCrit = find(strcmp({EEG.event.type},op{2})); |
|
131 | 148 | EEG.event = events; |
132 | 149 | EEG.urevent = rmfield(events,'urevent'); |
133 | 150 | case {'insertwithlatency' 'insertwithtime'} |
134 | | - latencies = str2num(op{2}); |
135 | | - if strcmp(op{1}, 'insertwithtime') |
136 | | - % find the samples at latencies exact or just later |
137 | | - latencies = arrayfun(@(lat) find(EEG.times - lat>=0, 1, 'first'), latencies); |
| 151 | + latencies = op{2}; |
| 152 | + if ~any(strcmp(latencies,{'beginning' 'end'})), latencies = str2num(latencies); end |
| 153 | + if ischar(latencies) % special cases |
| 154 | + switch latencies |
| 155 | + case 'beginning' |
| 156 | + latencies = 1; |
| 157 | + case 'end' |
| 158 | + latencies = EEG.pnts; |
| 159 | + end |
| 160 | + else |
| 161 | + if strcmp(op{1}, 'insertwithtime') |
| 162 | + % find the samples at latencies exact or just later |
| 163 | + latencies = arrayfun(@(lat) find(EEG.times - lat>=0, 1, 'first'), latencies); |
| 164 | + end |
138 | 165 | end |
139 | 166 | newE = struct(... |
140 | 167 | 'type',e.type,... |
|
193 | 220 | EEG.urevent(i).latency = EEG.urevent(i).latency - samplecorr; |
194 | 221 | end |
195 | 222 | case 'ignoreafter' |
196 | | - EEG = pop_select(EEG,'nopoint',[EEG.event(find(ind,1,'last')).latency+1 EEG.pnts]); |
197 | | - beInd = find(strcmp({EEG.event.type},'boundary'),1,'last'); |
198 | | - EEG.event(beInd) = []; |
| 223 | + if EEG.pnts > EEG.event(find(ind,1,'last')).latency |
| 224 | + EEG = pop_select(EEG,'nopoint',[EEG.event(find(ind,1,'last')).latency+1 EEG.pnts]); |
| 225 | + beInd = find(strcmp({EEG.event.type},'boundary'),1,'last'); |
| 226 | + EEG.event(beInd) = []; |
| 227 | + end |
199 | 228 | otherwise |
200 | 229 | aas_log(aap,false,sprintf('Operation %s not yet implemented',op{1})); |
201 | 230 | end |
202 | 231 | % update events |
203 | 232 | for i = 1:numel(EEG.event) |
204 | 233 | urind = find(strcmp({EEG.urevent.type},EEG.event(i).type) & [EEG.urevent.latency]==EEG.event(i).latency); |
| 234 | + if isempty(urind) % try based on timing only |
| 235 | + urind = find([EEG.urevent.latency]==EEG.event(i).latency);urind = find(strcmp({EEG.urevent.type},EEG.event(i).type) & [EEG.urevent.latency]==EEG.event(i).latency); |
| 236 | + end |
205 | 237 | EEG.event(i).urevent = urind(1); |
206 | 238 | end |
207 | 239 | end |
208 | 240 | end |
209 | 241 |
|
210 | 242 | % diagnostics |
211 | 243 | diagpath = fullfile(aas_getsesspath(aap,subj,sess),['diagnostic_' mfilename '_raw.jpg']); |
212 | | - meeg_diagnostics_continuous(EEG,aas_getsetting(aap,'diagnostics'),'Raw',diagpath); |
| 244 | + meeg_diagnostics_continuous(EEG,aas_getsetting(aap,'diagnostics'),sprintf('Raw with %d timepoint (~%d s)',EEG.pnts, round(EEG.xmax-EEG.xmin)),diagpath); |
213 | 245 |
|
214 | 246 | fnameroot = sprintf('eeg_%s',aas_getsubjname(aap,subj)); |
215 | 247 | while ~isempty(spm_select('List',aas_getsesspath(aap,subj,sess),[fnameroot '.*'])) |
|
0 commit comments