Skip to content

Commit 9436527

Browse files
committed
ENH: DRAFT: find_blinks (pupil) [ci skip]
1 parent 1fb9dd6 commit 9436527

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

mne/preprocessing/eyetracking/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License: BSD-3-Clause
55
# Copyright the MNE-Python contributors.
66

7-
from .eyetracking import set_channel_types_eyetrack, convert_units
7+
from .eyetracking import set_channel_types_eyetrack, convert_units, find_blinks
88
from .calibration import Calibration, read_eyelink_calibration
99
from ._pupillometry import interpolate_blinks
1010
from .utils import get_screen_visual_angle

mne/preprocessing/eyetracking/eyetracking.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,68 @@
99
from ...epochs import BaseEpochs
1010
from ...evoked import Evoked
1111
from ...io import BaseRaw
12-
from ...utils import _check_option, _validate_type, logger, warn
12+
from ...utils import _check_option, _validate_type, logger, verbose, warn
1313
from .calibration import Calibration
1414
from .utils import _check_calibration
1515

1616

17+
@verbose
18+
def find_blinks(
19+
inst,
20+
*,
21+
chs_src=None,
22+
method="by_dropout",
23+
dropout_value=None,
24+
description="BAD_blink",
25+
chs_dest=None,
26+
verbose=None,
27+
):
28+
"""Find blinks in eye-tracking data and create corresponding annotations.
29+
30+
Parameters
31+
----------
32+
inst : instance of Raw
33+
The data instance to use for finding blinks. Must contain pupil channels.
34+
chs_src : list | None
35+
A list of channel names that will be used to find blinks. None (default) will
36+
result in selecting all channels of type ``pupil``. See Notes for more
37+
information.
38+
method : str
39+
Which method to use to find blinks in ``inst``. Currently the only supported
40+
method is ``'by_dropout'`` (default), which uses the value specified via
41+
``dropout_value`` to identify blinks.
42+
dropout_value : float | None
43+
Which value in the data denotes a dropout. In Eyelink data, this is ``0``,
44+
whereas for other eye-tracking data this may be ``np.nan``, or something else.
45+
Defaults to None, which sets the ``dropout_value`` to ``np.nan``.
46+
description : str
47+
Which description to use for the blink annotations. Defaults to ``'BAD_blink'``.
48+
chs_dest : list | None
49+
A list of channel names that will be associated with the blink annotations.
50+
None (default) and passing an empty lists will associate each blink annotation
51+
with all channels in ``inst``.
52+
%(verbose)s
53+
54+
Returns
55+
-------
56+
annots : mne.Annotations
57+
The annotations objects containing blink annotations.
58+
59+
Notes
60+
-----
61+
If multiple channels are used to find blinks in ``inst``, resulting overlapping
62+
blink annotations are always merged over all channels. That is, if a left and a
63+
right pupil channel would be used for blink detection, and each on their own would
64+
produce overlapping blink annotations with onsets ``[1.5, 1.6]`` and durations
65+
``[0.2, 0.3]``, respectively, then passing both channels into this function will
66+
result in a single blink annotation with onset ``1.5`` and duration ``0.4``.
67+
Note that this corresponds to the minimum onset and the maximum offset between
68+
the two annotations.
69+
"""
70+
logger.info("Found blinks")
71+
return
72+
73+
1774
# specific function to set eyetrack channels
1875
def set_channel_types_eyetrack(inst, mapping):
1976
"""Define sensor type for eyetrack channels.
@@ -168,7 +225,8 @@ def _convert_deg_to_rad(array):
168225
return array * np.pi / 180.0
169226

170227

171-
def convert_units(inst, calibration, to="radians"):
228+
@verbose
229+
def convert_units(inst, calibration, to="radians", verbose=None):
172230
"""Convert Eyegaze data from pixels to radians of visual angle or vice versa.
173231
174232
.. warning::
@@ -191,6 +249,7 @@ def convert_units(inst, calibration, to="radians"):
191249
(in pixels).
192250
to : str
193251
Must be either ``"radians"`` or ``"pixels"``, indicating the desired unit.
252+
%(verbose)s
194253
195254
Returns
196255
-------

mne/preprocessing/eyetracking/tests/test_eyetracking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
import mne
1010
from mne._fiff.constants import FIFF
11+
from mne.preprocessing.eyetracking import find_blinks
1112
from mne.utils import _record_warnings
1213

1314

15+
def test_find_blinks():
16+
"""Test creating blink annotations."""
17+
find_blinks
18+
19+
1420
def test_set_channel_types_eyetrack(eyetrack_raw):
1521
"""Test that set_channel_types_eyetrack worked on the fixture."""
1622
assert eyetrack_raw.info["chs"][0]["kind"] == FIFF.FIFFV_EYETRACK_CH

0 commit comments

Comments
 (0)