Bad segments and bad epochs

Hello friends,

While exploring how to exclude bad segments, epochs, trials, etc. from a process, I saw that for raw epoched data there is a flag for bad epochs, DataMat.F.epochs.bad, that seems to be only read for a few file types, and I couldn't really find how it is dealt with elsewhere. In particular, while the function panel_record('GetBadSegments' finds bad segments as defined by events, it doesn't seem to take into account those bad epochs.

That brings me to my questions:

  1. Should GetBadSegments take the bad epochs into account? I would think so.
  2. Should we simplify this by generating events for these bad epochs when reviewing the raw file?
  3. The CTF format has such bad epochs (in the file ClassFile.cls) and even bad segments (in the file bad.segments), but they are currently not read by Brainstorm. Is this something we want to do?
  4. Are there other ways to identify bad data that I might have missed? I saw that imported trials can also be flagged as bad and that they are excluded from the process panels so that's ok. Channels can also be flagged, but I'm not considering those here. Did I miss something else?

Thanks a lot!
Marc

Hi Marc,

Indeed, this field is not much used in Brainstorm.
It is read from two file formats (EEGLAB .set and EGI .raw) for data that is already fully pre-processed and epoched. These files should not be imported as "raw continuous" but directly as epochs in Brainstorm (using menu "Import MEG/EEG" instead of "Review raw file"), because there is not much that can be done with them otherwise. Therefore I can't see any use case where it would useful for the function GetBadSegment to retreive this info...

When importing EEGLAB .set or EGI .raw files as epochs, the epoch(i).bad info is used to mark the imported trial as good or bad in the Brainstorm database:

The CTF format has such bad epochs (in the file ClassFile.cls) and even bad segments (in the file bad.segments), but they are currently not read by Brainstorm. Is this something we want to do?

No one ever requested this, so I'm not sure it is worth investing time in it.
Do you have any clear use case in which there is some important information that is missing in the CTF recordings as currently processed by Brainstorm?

Ok thanks François.

Hi Francois and Marc,

I'm using CTF badsegment too.
I added this code in the script in_events_ctf.m ( line 132, before % Convert to CTF-CONTINUOUS if necessary ).

Can you update this script for a next release?

Thank you from all CTF users :wink:

Sebastien

% Import bad.segments
 %% SD 12/12/2016
 [PATHSTR,~,~] = fileparts(EventFile);
 BadsegmentsFile=fullfile(PATHSTR,'bad.segments');

 if exist(BadsegmentsFile,'file')==2
     badsegment=load(BadsegmentsFile);
     if size(badsegment,1)==0
         disp(['No badsegments : ' PATHSTR ]);
     else
         iEvt = length(events) + 1;
         list_epochbad=badsegment(:,1)';
         list_timebad=[badsegment(:,2)';badsegment(:,3)'];
         events(iEvt).label='BAD';
         events(iEvt).color=[1,0,0];
         events(iEvt).epochs=list_epochbad;
         events(iEvt).times=list_timebad;
         events(iEvt).reactTimes=[];
         events(iEvt).select=1;
         events(iEvt).channels=cell(size(list_epochbad));
         events(iEvt).notes=cell(size(list_epochbad));
    end
end
%% end SD 12/12/2016

Thanks for the suggestion.

I moved this code to in_fopen_ctf.m, because reading bad.segments is independent from reading the marker file. I pushed the modifications in this commit:
https://github.com/brainstorm-tools/brainstorm3/commit/64c6968a0cb7590b7db6f769615ba21e6baae1f7
You can simply update Brainstorm to get the modification.

Please test the timing of the new BAD events carefully: I don't have any example dataset where this file bad.segments is not empty, therefore I can't test it myself.
Thanks

Hi Francois,
I just tested with 'Review raw file' and 'Import MEG/EEG'.
It's okay for me. Thanks.

Have a nice week end !
Sebastien