From d906f1cd02a8e42688b4566c9de153d76cd28340 Mon Sep 17 00:00:00 2001 From: Trevor Chartier Date: Sun, 15 Jun 2025 09:53:16 -0600 Subject: [PATCH] Fix IndexError when data has a single blink occuring at the start of the sequence Previously, if the data contained only one blink, and the blink occured at the start of the sequence (ie. pupil size is -1 for first index), blink onset would be empty, but length_blinks would be greater than zero because blink offset would not be empty. This would cause an IndexError when attempting to access blink_onset[0]. This change adds a guard clause to handle this edge case and prevent the error. --- PyTrack/Stimulus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTrack/Stimulus.py b/PyTrack/Stimulus.py index dce13fa..8d24285 100644 --- a/PyTrack/Stimulus.py +++ b/PyTrack/Stimulus.py @@ -217,7 +217,7 @@ def findBlinks(self, pupil_size, gaze=None, sampling_freq=1000, concat=False, co # Edge Case 2: # The data starts with a blink. In this case, blink onset will be # defined as the first missing value. - if length_blinks>0 and pupil_size[0]==-1 and blink_onset[0]>0: + if length_blinks>0 and pupil_size[0]==-1 and ((not blink_onset) or blink_onset[0]>0): blink_onset = np.insert(blink_onset, 0, 0) # Edge Case 3: