Skip to content

Commit 583d72f

Browse files
committed
impro saveEvents
- skip trial for exmpty events (missing onset or duration) - trial_type is no longer required - write tests for warnings and errors
1 parent c23210f commit 583d72f

File tree

2 files changed

+230
-93
lines changed

2 files changed

+230
-93
lines changed

src/saveEventsFile.m

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
checklLogFile('checkID', logFile);
8888
checklLogFile('type&size', logFile);
8989

90-
logFile = saveToLogFile(logFile);
90+
logFile = saveToLogFile(logFile, cfg);
9191

9292
case 'close'
9393

@@ -108,7 +108,7 @@
108108

109109
end
110110

111-
function logFile = checklLogFile(action, logFile, iEvent)
111+
function logFile = checklLogFile(action, logFile, iEvent, cfg)
112112

113113
switch action
114114

@@ -137,7 +137,7 @@
137137
end
138138
end
139139

140-
logFile = checkExtracolumns(logFile, iEvent);
140+
logFile = checkExtracolumns(logFile, iEvent, cfg);
141141

142142
end
143143

@@ -192,7 +192,7 @@ function printHeaderExtraColumns(logFile)
192192

193193
end
194194

195-
function logFile = checkExtracolumns(logFile, iEvent)
195+
function logFile = checkExtracolumns(logFile, iEvent, cfg)
196196
% loops through the extra columns
197197
% if the field we are looking for does not exist or is empty in the
198198
% action logFile structure we will write a n/a
@@ -216,11 +216,19 @@ function printHeaderExtraColumns(logFile)
216216
logFile(iEvent).(namesExtraColumns{iExtraColumn}) = data;
217217

218218
if any(isnan(data))
219-
warning('Missing some %s data for this event.', namesExtraColumns{iExtraColumn});
220-
disp(logFile(iEvent));
221-
elseif all(isnan(data))
219+
warning('saveEventsFile:missingData', ...
220+
'Missing some %s data for this event.', namesExtraColumns{iExtraColumn});
221+
222+
if cfg.verbose
223+
disp(logFile(iEvent));
224+
end
225+
226+
elseif all(isnan(data))
222227
warning('Missing %s data for this event.', namesExtraColumns{iExtraColumn});
223-
disp(logFile(iEvent));
228+
229+
if cfg.verbose
230+
disp(logFile(iEvent));
231+
end
224232
end
225233

226234
end
@@ -258,30 +266,34 @@ function printHeaderExtraColumns(logFile)
258266
padding = expectedLength - max(size(data));
259267
data(end + 1:end + padding) = nan(1, padding);
260268
elseif ~isempty(expectedLength) && isnumeric(data) && max(size(data)) > expectedLength
261-
warning('A field for this event is longer than expected. Truncating the extra values.');
269+
warning('saveEventsFile:arrayTooLong', ...
270+
'A field for this event is longer than expected. Truncating the extra values.');
262271
data = data(1:expectedLength);
263272
end
264273

265274
end
266275

267-
function logFile = saveToLogFile(logFile)
276+
function logFile = saveToLogFile(logFile, cfg)
268277

269278
% appends to the logfile all the data stored in the structure
270279
% first with the standard BIDS data and then any extra things
271280
for iEvent = 1:size(logFile, 1)
272281

273-
logFile = checklLogFile('fields', logFile, iEvent);
282+
logFile = checklLogFile('fields', logFile, iEvent, cfg);
274283

275284
onset = logFile(iEvent).onset;
276285
duration = logFile(iEvent).duration;
277286
trial_type = logFile(iEvent).trial_type;
278287

279-
if isnan(onset) || ischar(onset) || any(isempty({onset trial_type})) || ...
280-
strcmp(trial_type, 'n/a')
288+
% we skip events with onset or duration that are empty, nan or char
289+
if any(cell2mat(cellfun(@isnan, {onset duration}, 'UniformOutput', false))) || ...
290+
any(cellfun(@ischar, {onset duration})) || ...
291+
any(isempty({onset duration}))
281292

282-
warning('\nSkipping saving this event.\n onset: %f \n trial_type: %s\n', ...
293+
warning('saveEventsFile:emptyEvent', ...
294+
'\nSkipping saving this event.\n onset: %s \n duration: %s\n', ...
283295
onset, ...
284-
trial_type);
296+
duration);
285297

286298
else
287299

0 commit comments

Comments
 (0)