Repository navigation
Description
Describe the new feature or enhancement
While I wrap up my open PR soon, I wanted to initiate a discussion on the next task that I'd like to work on for my GSoC project.
CC @larsoner and @britta-wstnr
Proposed function:
mne.preprocessing.interpolate_blinks (or remove_blink_artifact). For pupil channels
Background
it is a common pre-processing step in pupillometry research to interpolate missing values during blinks (see this paper, this paper, this package, and this package).
The basic idea is that blinks are very short in duration, but the pupil response is relatively slow; so it can be reasonably assumed that the pupil size during a blink was close to the pupil size values just before and just after the blink.
Use-case
Currently in mne, if you have a RawEyelink object with pupil channels, and you want to to assess the average pupil size across trials, you have to:
- epoch the data
- drop any
epochsthat have a blink in them (which can result in data loss). - average aross the remaining
epochs
This is because pupil channels contain 0's during blinks. Including blink periods in epochs.average() would bias the result such that the the pupil size would seem to be unrealistically small!
Having an interpolate_blinks function would help users move beyond a Raw object to epoching the data and being able to use those epochs for analyses.
Describe your proposed implementation
I propose we add a function, called interpolate_blinks or remove_blink_artifact to mne.preprocessing.eyetracking.
How:
The way I am thinking about it now:
-
This function would accept a
Rawobject, and will rely onAnnotationsin theRawobject that start withblinkto identify periods to be interpolated.- For example,
mne.io.read_raw_eyelinkextracts any blink periods (that EyeLink wrote to the file) and stores them asmne.Annotations. So this function would rely on thoseAnnotations.
- For example,
-
This function would accept a parameter named something like
method, which would accept'linear'or'cubic_spline', and would use:numpy.interpfor linear interpolationscipy.interpolate.CubicSplinefor cubic-spline interpolation (see this eye-tracking paper).
Summary:
So I suggest that:
- This function will only operate on
pupilchannels (noteyegaze,EEG,MEG,NIRSetc.). - This function can start with interpolating data during blinks. Then maybe we can extend this to interpolating
pupildata during saccades (There is precedent for this because pupil-size measurement is thought to be less reliable during saccades). - Then, maybe we can extend this function to
eyegazechannels (There is one package that does this), but AFAIK it is harder to justify interpolatingeyegazedata, because it can change at a much faster rate / is more variable across time. I'll need to do more literature review to see how often this has been done.
Describe possible alternatives
I'm open to any other ideas!
Additional context
To see an example of a file that could benefit from interpolate_blinks see:
from mne.datasets.testing import data_path
from mne.io import read_raw_eyelink
fname = data_path() / "eyetrack" / "test_eyelink.asc"
raw = read_raw_eyelink(fname, find_overlaps=True, create_annotations=['blinks'])
raw.plot(scalings='auto')

Activity
larsoner commentedon Jun 8, 2023
I like the suggestion to start with the basics (just interp during blinks) and expand later as needed/helpful for people. I'd suggest to put in
mne.preprocessing.eyetracking.interpolate_blinksto make it clear it's eye-tracking-related interp, not to be confused with interpolating brain data or EOG during blinks or anything like that.scott-huberty commentedon Jun 8, 2023
yes totally, sorry, I meant to say
mne.preprocessing.eyetracking.!britta-wstnr commentedon Jun 9, 2023
I like it!
schekroud commentedon Jun 20, 2023
would be nice to add an option to pad data around the blinks - when you inspect blink periods in eyetracking data it's often corrupted just before/after the blink too. it's pretty common to leave some space around the blink that you also interpolate to account for this (which can vary between researchers). an option to allow this would be cool
(i should say this is such a cool addition i've been using my own hacky stuff for years and tried to get it to work within mne but struggled. I just stumbled upon eyelink data now being supported)