Skip to content

Commit ed7bfa1

Browse files
author
v01dxyz
committed
Remove hardcoded value "BAD_blinks" in interpolate_blink (#13531)
The previous behaviour is faulty as there is no reason to think `blink_annots` are "BAD_blinks"-prefixed. Add an argument to `_annotations_starts_stops` to allow matching exactly instead of being prefix.
1 parent e50c572 commit ed7bfa1

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

doc/changes/dev/13740.bugfix.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where :func:`mne.preprocessing.eyetracking.interpolate_blinks` was overriding the user-passed ``match`` argument with the value ``"BAD_blink"``, by :newcontrib:`Robert Dazi`

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
.. _Richard Scholz: https://github.com/scholzri
282282
.. _Riessarius Stargardsky: https://github.com/Riessarius
283283
.. _Roan LaPlante: https://github.com/aestrivex
284+
.. _Robert Dazi: https://github.com/v01dxyz
284285
.. _Robert Luke: https://github.com/rob-luke
285286
.. _Robert Seymour: https://neurofractal.github.io
286287
.. _Romain Derollepot: https://github.com/rderollepot

mne/annotations.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,9 +1635,15 @@ def _sync_onset(raw, onset, inverse=False):
16351635
return annot_start
16361636

16371637

1638-
def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=False):
1638+
def _annotations_starts_stops(
1639+
raw, kinds, name="skip_by_annotation", invert=False, exact_match=False
1640+
):
16391641
"""Get starts and stops from given kinds.
16401642
1643+
It picks an annotation if its description starts with one element
1644+
of kinds, unless exact_match=True then if it is equal to one of
1645+
them.
1646+
16411647
onsets and ends are inclusive.
16421648
"""
16431649
_validate_type(kinds, (str, list, tuple), name)
@@ -1650,11 +1656,18 @@ def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=Fals
16501656
if len(raw.annotations) == 0:
16511657
onsets, ends = np.array([], int), np.array([], int)
16521658
else:
1653-
idxs = [
1654-
idx
1655-
for idx, desc in enumerate(raw.annotations.description)
1656-
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1657-
]
1659+
if exact_match:
1660+
idxs = [
1661+
idx
1662+
for idx, desc in enumerate(raw.annotations.description)
1663+
if desc in kinds
1664+
]
1665+
else:
1666+
idxs = [
1667+
idx
1668+
for idx, desc in enumerate(raw.annotations.description)
1669+
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1670+
]
16581671
# onsets are already sorted
16591672
onsets = raw.annotations.onset[idxs]
16601673
onsets = _sync_onset(raw, onsets)

mne/preprocessing/eyetracking/_pupillometry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ def _interpolate_blinks(raw, buffer, blink_annots, interpolate_gaze):
8888
continue
8989
# Create an empty boolean mask
9090
mask = np.zeros_like(raw.times, dtype=bool)
91-
starts, ends = _annotations_starts_stops(raw, "BAD_blink")
91+
starts, ends = _annotations_starts_stops(
92+
raw,
93+
list({annot["description"] for annot in blink_annots}),
94+
exact_match=True,
95+
)
9296
starts = np.divide(starts, raw.info["sfreq"])
9397
ends = np.divide(ends, raw.info["sfreq"])
9498
for annot, start, end in zip(blink_annots, starts, ends):

mne/preprocessing/eyetracking/tests/test_pupillometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_interpolate_bad_blinks(
3535
raw = read_raw_eyelink(fname, create_annotations=["blinks"], find_overlaps=True)
3636

3737
# read_raw_eyelink prefixes any blink description with "BAD_" but we want to
38-
# test interpolate_blinks do not depend on this convention
38+
# test interpolate_blinks does not depend on this convention
3939
if description_prefix != "BAD_":
4040
blink_description = f"{description_prefix}blink"
4141
raw.annotations.rename({"BAD_blink": blink_description})

0 commit comments

Comments
 (0)