Skip to content

Commit 208231a

Browse files
committed
ENH - MEEG: edit and diag
1 parent bc63235 commit 208231a

3 files changed

Lines changed: 54 additions & 17 deletions

File tree

aa_modules/aamod_meeg_converttoeeglab.m

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
resp='';
44

55
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
719
for fn = cellstr(spm_select('FPList',aas_getsesspath(aap,subj,sess),'^diagnostic_.*jpg$'))'
820
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});
1022
aap = aas_report_add(aap,subj,'</td></tr></table>');
1123
end
1224
case 'doit'
@@ -67,7 +79,7 @@
6779
if ~isempty(toEdit)
6880
for e = toEdit
6981
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));
7183
catch
7284
aas_log(aap,false,sprintf('No trial %s found', e.type));
7385
ind = false(size(EEG.event));
@@ -78,12 +90,17 @@
7890
op = strsplit(e.operation,':');
7991
if ~any(ind) && ~startsWith(op{1},'insert'), continue; end
8092
switch op{1}
93+
case 'clear'
94+
EEG.event(1:end) = [];
95+
EEG.urevent(1:end) = [];
8196
case 'remove'
97+
urind = [EEG.event(ind).urevent];
8298
EEG.event(ind) = [];
83-
EEG.urevent(ind) = [];
99+
EEG.urevent(urind) = [];
84100
case 'keep'
101+
urind = [EEG.event(ind).urevent];
85102
EEG.event = EEG.event(ind);
86-
EEG.urevent = EEG.urevent(ind);
103+
EEG.urevent = EEG.urevent(urind);
87104
case 'keepbeforeevent'
88105
ind = find(ind);
89106
indCrit = find(strcmp({EEG.event.type},op{2}));
@@ -131,10 +148,20 @@
131148
EEG.event = events;
132149
EEG.urevent = rmfield(events,'urevent');
133150
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
138165
end
139166
newE = struct(...
140167
'type',e.type,...
@@ -193,23 +220,28 @@
193220
EEG.urevent(i).latency = EEG.urevent(i).latency - samplecorr;
194221
end
195222
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
199228
otherwise
200229
aas_log(aap,false,sprintf('Operation %s not yet implemented',op{1}));
201230
end
202231
% update events
203232
for i = 1:numel(EEG.event)
204233
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
205237
EEG.event(i).urevent = urind(1);
206238
end
207239
end
208240
end
209241

210242
% diagnostics
211243
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);
213245

214246
fnameroot = sprintf('eeg_%s',aas_getsubjname(aap,subj));
215247
while ~isempty(spm_select('List',aas_getsesspath(aap,subj,sess),[fnameroot '.*']))

aa_modules/aamod_meeg_converttoeeglab.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
to modify events or data
1717
event can be a single event or a 1xN array indicating events in the event list
1818
valid operations are
19+
'clear' - remove all markers
1920
'remove' - remove
2021
'keep' - remove all others
2122
'keepbeforeevent:<event>' - remove all not before <event>
@@ -24,8 +25,8 @@
2425
'rename:<new type>' - rename event(s) to <new type>
2526
'iterate' - add suffix to recurring event to indicate the number of occurrence
2627
'insert:[<array of indices>] - insert event before the locations specified by <array of indices> with timings of the events at the locations'
27-
'insertwithlatency:[<array of latencies>] - insert event with latencies'
28-
'insertwithtime:[<array of latencies>] - insert event with time'
28+
'insertwithlatency:[<array of latencies>] - insert event with latencies; "end" puts it at the last timepoint'
29+
'insertwithtime:[<array of latencies>] - insert event with time; "end" puts it at the last timepoint'
2930
'inserteachbetween:<start event>:<step in sec>:<end event>' - insert events at each <step in sec> between <start event> and <end event>
3031
'prefixpattern:<pattern>:[<space-delimited list of prefixes>]' - prefix pattern matched in event name
3132
'ignorebefore' - remove heading data before the first occurence (excluding the event)

extrafunctions/meeg_diagnostics_continuous.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ function meeg_diagnostics_continuous(EEG,diag,figtitle,savepath)
33
if ~isempty(diag.freqrange)
44
f = figure('Name',figtitle);
55
if isempty(diag.freq)
6-
pop_spectopo(EEG,1,[0 650399],'EEG','freqrange',diag.freqrange,'electrodes','off');
6+
pop_spectopo(EEG,1,[],'EEG','freqrange',diag.freqrange,'electrodes','off');
77
else
8-
pop_spectopo(EEG,1,[0 650399],'EEG','freq',diag.freq,'freqrange',diag.freqrange,'electrodes','off');
8+
pop_spectopo(EEG,1,[],'EEG','freq',diag.freq,'freqrange',diag.freqrange,'electrodes','off');
99
end
10+
% title to the main axes
11+
all_axes = findall(gcf, 'Type', 'axes');
12+
ax = all_axes(arrayfun(@(a) isequal(a.XLim, diag.freqrange), all_axes));
13+
title(ax,figtitle);
1014
if nargin >= 4
1115
set(f,'Position',[1 1 1920 1080]);
1216
set(f,'PaperPositionMode','auto');

0 commit comments

Comments
 (0)