Skip to content

Commit f28ac17

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 9b90f0d commit f28ac17

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
@@ -277,6 +277,7 @@
277277
.. _Richard Scholz: https://github.com/scholzri
278278
.. _Riessarius Stargardsky: https://github.com/Riessarius
279279
.. _Roan LaPlante: https://github.com/aestrivex
280+
.. _Robert Dazi: https://github.com/v01dxyz
280281
.. _Robert Luke: https://github.com/rob-luke
281282
.. _Robert Seymour: https://neurofractal.github.io
282283
.. _Romain Derollepot: https://github.com/rderollepot

mne/annotations.py

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

12341234

1235-
def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=False):
1235+
def _annotations_starts_stops(
1236+
raw, kinds, name="skip_by_annotation", invert=False, exact_match=False
1237+
):
12361238
"""Get starts and stops from given kinds.
12371239
1240+
It picks an annotation if its description starts with one element
1241+
of kinds, unless exact_match=True then if it is equal to one of
1242+
them.
1243+
12381244
onsets and ends are inclusive.
12391245
"""
12401246
_validate_type(kinds, (str, list, tuple), name)
@@ -1247,11 +1253,18 @@ def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=Fals
12471253
if len(raw.annotations) == 0:
12481254
onsets, ends = np.array([], int), np.array([], int)
12491255
else:
1250-
idxs = [
1251-
idx
1252-
for idx, desc in enumerate(raw.annotations.description)
1253-
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1254-
]
1256+
if exact_match:
1257+
idxs = [
1258+
idx
1259+
for idx, desc in enumerate(raw.annotations.description)
1260+
if desc in kinds
1261+
]
1262+
else:
1263+
idxs = [
1264+
idx
1265+
for idx, desc in enumerate(raw.annotations.description)
1266+
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1267+
]
12551268
# onsets are already sorted
12561269
onsets = raw.annotations.onset[idxs]
12571270
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)