Skip to content

Commit

Permalink
ENH: DRAFT: find_blinks (pupil) [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff committed Nov 5, 2024
1 parent c63da99 commit d969926
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mne/preprocessing/eyetracking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

from .eyetracking import set_channel_types_eyetrack, convert_units
from .eyetracking import set_channel_types_eyetrack, convert_units, find_blinks
from .calibration import Calibration, read_eyelink_calibration
from ._pupillometry import interpolate_blinks
from .utils import get_screen_visual_angle
63 changes: 61 additions & 2 deletions mne/preprocessing/eyetracking/eyetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,68 @@
from ...epochs import BaseEpochs
from ...evoked import Evoked
from ...io import BaseRaw
from ...utils import _check_option, _validate_type, logger, warn
from ...utils import _check_option, _validate_type, logger, verbose, warn
from .calibration import Calibration
from .utils import _check_calibration


@verbose
def find_blinks(
inst,
*,
chs_src=None,
method="by_dropout",
dropout_value=None,
description="BAD_blink",
chs_dest=None,
verbose=None,
):
"""Find blinks in eye-tracking data and create corresponding annotations.
Parameters
----------
inst : instance of Raw
The data instance to use for finding blinks. Must contain pupil channels.
chs_src : list | None
A list of channel names that will be used to find blinks. None (default) will
result in selecting all channels of type ``pupil``. See Notes for more
information.
method : str
Which method to use to find blinks in ``inst``. Currently the only supported
method is ``'by_dropout'`` (default), which uses the value specified via
``dropout_value`` to identify blinks.
dropout_value : float | None
Which value in the data denotes a dropout. In Eyelink data, this is ``0``,
whereas for other eye-tracking data this may be ``np.nan``, or something else.
Defaults to None, which sets the ``dropout_value`` to ``np.nan``.
description : str
Which description to use for the blink annotations. Defaults to ``'BAD_blink'``.
chs_dest : list | None
A list of channel names that will be associated with the blink annotations.
None (default) and passing an empty lists will associate each blink annotation
with all channels in ``inst``.
%(verbose)s
Returns
-------
annots : mne.Annotations
The annotations objects containing blink annotations.
Notes
-----
If multiple channels are used to find blinks in ``inst``, resulting overlapping
blink annotations are always merged over all channels. That is, if a left and a
right pupil channel would be used for blink detection, and each on their own would
produce overlapping blink annotations with onsets ``[1.5, 1.6]`` and durations
``[0.2, 0.3]``, respectively, then passing both channels into this function will
result in a single blink annotation with onset ``1.5`` and duration ``0.4``.
Note that this corresponds to the minimum onset and the maximum offset between
the two annotations.
"""
logger.info("Found blinks")
return


# specific function to set eyetrack channels
def set_channel_types_eyetrack(inst, mapping):
"""Define sensor type for eyetrack channels.
Expand Down Expand Up @@ -168,7 +225,8 @@ def _convert_deg_to_rad(array):
return array * np.pi / 180.0


def convert_units(inst, calibration, to="radians"):
@verbose
def convert_units(inst, calibration, to="radians", verbose=None):
"""Convert Eyegaze data from pixels to radians of visual angle or vice versa.
.. warning::
Expand All @@ -191,6 +249,7 @@ def convert_units(inst, calibration, to="radians"):
(in pixels).
to : str
Must be either ``"radians"`` or ``"pixels"``, indicating the desired unit.
%(verbose)s
Returns
-------
Expand Down
6 changes: 6 additions & 0 deletions mne/preprocessing/eyetracking/tests/test_eyetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

import mne
from mne._fiff.constants import FIFF
from mne.preprocessing.eyetracking import find_blinks
from mne.utils import _record_warnings


def test_find_blinks():
"""Test creating blink annotations."""
find_blinks


def test_set_channel_types_eyetrack(eyetrack_raw):
"""Test that set_channel_types_eyetrack worked on the fixture."""
assert eyetrack_raw.info["chs"][0]["kind"] == FIFF.FIFFV_EYETRACK_CH
Expand Down

0 comments on commit d969926

Please sign in to comment.