Skip to content

Commit eadd832

Browse files
author
v01dxyz
committed
Remove hardcoded value "BAD_blinks" in interpolate_blink (#13531)
Add an argument to `_annotations_starts_stops` to allow matching exactly instead of being prefix.
1 parent b82bf18 commit eadd832

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

mne/annotations.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,9 @@ 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", exact_match=False, invert=False
1237+
):
12361238
"""Get starts and stops from given kinds.
12371239
12381240
onsets and ends are inclusive.
@@ -1247,11 +1249,18 @@ def _annotations_starts_stops(raw, kinds, name="skip_by_annotation", invert=Fals
12471249
if len(raw.annotations) == 0:
12481250
onsets, ends = np.array([], int), np.array([], int)
12491251
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-
]
1252+
if exact_match:
1253+
idxs = [
1254+
idx
1255+
for idx, desc in enumerate(raw.annotations.description)
1256+
if desc in kinds
1257+
]
1258+
else:
1259+
idxs = [
1260+
idx
1261+
for idx, desc in enumerate(raw.annotations.description)
1262+
if any(desc.upper().startswith(kind.upper()) for kind in kinds)
1263+
]
12551264
# onsets are already sorted
12561265
onsets = raw.annotations.onset[idxs]
12571266
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):

0 commit comments

Comments
 (0)