Skip to content

Commit 26f00db

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 b6a0cdc commit 26f00db

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
@@ -280,6 +280,7 @@
280280
.. _Richard Scholz: https://github.com/scholzri
281281
.. _Riessarius Stargardsky: https://github.com/Riessarius
282282
.. _Roan LaPlante: https://github.com/aestrivex
283+
.. _Robert Dazi: https://github.com/v01dxyz
283284
.. _Robert Luke: https://github.com/rob-luke
284285
.. _Robert Seymour: https://neurofractal.github.io
285286
.. _Romain Derollepot: https://github.com/rderollepot

mne/annotations.py

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

16641664

1665-
def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=False):
1665+
def _annotations_starts_stops(
1666+
raw, kinds, name="skip_by_annotation", invert=False, exact_match=False
1667+
):
16661668
"""Get starts and stops from given kinds.
16671669
1670+
It picks an annotation if its description starts with one element
1671+
of kinds, unless exact_match=True then if it is equal to one of
1672+
them.
1673+
16681674
onsets and ends are inclusive.
16691675
"""
16701676
_validate_type(kinds, (str, list, tuple), name)
@@ -1677,11 +1683,18 @@ def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=Fals
16771683
if len(raw.annotations) == 0:
16781684
onsets, ends = np.array([], int), np.array([], int)
16791685
else:
1680-
idxs = [
1681-
idx
1682-
for idx, desc in enumerate(raw.annotations.description)
1683-
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1684-
]
1686+
if exact_match:
1687+
idxs = [
1688+
idx
1689+
for idx, desc in enumerate(raw.annotations.description)
1690+
if desc in kinds
1691+
]
1692+
else:
1693+
idxs = [
1694+
idx
1695+
for idx, desc in enumerate(raw.annotations.description)
1696+
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1697+
]
16851698
# onsets are already sorted
16861699
onsets = raw.annotations.onset[idxs]
16871700
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)