detect_blinks_velocity#
- pypillometry.signal.detect_blinks_velocity(sy, smooth_winsize, vel_onset, vel_offset, min_onset_len=5, min_offset_len=5, min_blink_samples=1, max_blink_samples=None)[source]#
Detect blinks as everything between a fast downward and a fast upward-trending PD-changes.
Uses asymmetric Savitzky-Golay velocity estimation to handle NaN values properly: - Backward-looking velocity for onset detection (so future NaN doesn’t affect the estimate) - Forward-looking velocity for offset detection (so past NaN doesn’t affect the estimate)
This works similarly to
blink_onsets_mahot().- Parameters:
sy (np.ndarray) – pupil data (can contain NaN or zeros for missing values)
smooth_winsize (int) – size of the Savitzky-Golay window in samples (odd)
vel_onset (float) – velocity-threshold to detect the onset of the blink; in units per sample (negative value)
vel_offset (float) – velocity-threshold to detect the offset of the blink; in units per sample (positive value)
min_onset_len (int) – number of consecutive samples that must cross the threshold to detect an onset (runs must have at least min_onset_len samples)
min_offset_len (int) – number of consecutive samples that must cross the threshold to detect an offset (runs must have at least min_offset_len samples)
min_blink_samples (int) – minimum duration of a blink in samples; offsets that would create shorter intervals are skipped during matching (to avoid spurious short offsets stealing real onsets)
max_blink_samples (int or None) – maximum duration of a blink in samples; an onset without an offset within this many samples is not a blink and is dropped (otherwise it would be paired with an arbitrarily distant offset); None means no limit
- Return type:
np.ndarray
- Returns:
array (nblinks x 2) of blink onset/offset sample indices (both inclusive); the offset is the last sample of the matching offset run, or the last sample of sy if no offset was found after the last onset (and max_blink_samples allows it); empty array if no blinks were found