Skip to content

Reset first_time and shift EEG signal #11

@jschepers

Description

@jschepers

@behinger and I discussed whether it makes sense to reset the first_time field of the EEG/ET raw object to 0 after the synchronisation and shift the event onsets accordingly. Here are some thoughts on this.

Context

!! As I understood it. Might be wrong !!

For synchronising the EEG and ET data we use the mne.preprocessing.realign_raw function. It crops the start of the recording that started earlier. When cropping the start of a signal using the mne crop function, the events in the cropped chunk are removed from the annotations (but the onsets are not changed (?) but first_samp (and thereby first_time) is adapted accordingly to keep track of how many samples were cropped. The times of a raw object however always start at 0 and are relative to first_time, As a consequence, event onsets in the annotations can only be aligned with times when subtracting first_time from the event onsets.

Idea

@behinger and I thought it might be more intuitive if times and event onsets in annotations match without subtracting anything, therefore we thought about shifting the onsets and resetting first_time.

One possibility I found is subtracting first_time from the onsets after synchronisation and setting the _cropped_samp field to back to 0.
first_samp and first_time are based on _cropped_samp (https://github.com/mne-tools/mne-python/blob/4c3d0bf0f6cee03d02d3fe7e1f0f910f89e7a4c7/mne/io/base.py#L607-L617).

if raw_eeg.first_time > 0:
    raw_eeg.annotations.onset -= raw_eeg.first_time
    raw_eeg._cropped_samp = 0

if raw_et.first_time > 0:
    raw_et.annotations.onset -= raw_et.first_time
    raw_et._cropped_samp = 0

One downside of this is messing around with internal/private fields and counteracting MNE logic. Another aspect to think about is that one does not only need to think about the EEG signal but also the ET signal and either the EEG signal or ET signal could be cropped during the synchronisation. And one would need to make sure that the onsets never get negative.

For now I decided that it's to much effort/to complicated to think about all possible cases and test it properly and therefore I did not reset first_time and I did not shift the event onsets. But I wanted to document my thoughts in case we want to work on it again in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions