blink_onsets_mahot#
- pypillometry.signal.blink_onsets_mahot(sy, blinks, smooth_winsize, rate_onset, rate_offset, margin, blinkwindow, min_onset_len=1, min_offset_len=1, max_gap=None)[source]#
Method for finding the on- and offset for each blink (including the transient). See https://figshare.com/articles/A_simple_way_to_reconstruct_pupil_size_during_eye_blinks/688001.
The search starts from the core of each blink: the stretch from its first to its last missing (NaN or 0) sample, or its smallest pupil if it has no missing samples. The onset is the start of the closest closing transient (falling faster than rate_onset) that starts before the core, the offset the end of the closest opening transient (rising faster than rate_offset) that ends after it. The search (and the margins) stop at the neighbouring blinks, so that a transient of a neighbour is not taken for one of the blink. The result therefore does not depend on how far the blinks were extended when they were detected, and for a blink that contains several transients (e.g., merged blinks), the outermost ones are used.
Uses asymmetric Savitzky-Golay velocity estimation: - Backward-looking velocity for onset detection (so future zeros/NaN don’t affect the estimate) - Forward-looking velocity for offset detection (so past zeros/NaN don’t affect the estimate)
- Parameters:
sy (np.ndarray) – pupil data (can contain NaN or zeros for missing values)
blinks (np.ndarray or Intervals) – blink start/end sample indices (nblinks x 2, end-exclusive), e.g. an
Intervalsobject in index units; anything that iterates over (start, end) pairs workssmooth_winsize (int) – size of the Savitzky-Golay window in samples (odd)
rate_onset (float or np.ndarray) – rate (in units per sample) of the fall at the onset of the blink (its absolute value is used; one for all samples, or one per sample)
rate_offset (float or np.ndarray) – rate (in units per sample) of the rise at the offset of the blink
margin (tuple of int) – (before, after) margin that is subtracted/added to onset and offset (in samples)
blinkwindow (int) – how far before and after the core of each blink to search for the on-/offset (in samples)
min_onset_len (int) – minimum number of consecutive samples in an onset run to be considered valid
min_offset_len (int) – minimum number of consecutive samples in an offset run to be considered valid
max_gap (int or None) – runs of threshold crossings separated by at most this many samples are joined into one transient; None (default) uses smooth_winsize
- Return type:
- Returns:
array (n x 2) of refined onset/offset sample indices, one row per input blink; if no transient is found before (after) the core of a blink, the start (end) of the core is used