detect_blinks#
- pypillometry.signal.detect_blinks(sy, smooth_winsize, flank_low, flank_high, min_len, max_len=None, flank_min_len=5, require='either', tolerance=0, unusable=None, max_gap=0, method='velocity', noise=None, smooth=5, min_scale=10, max_scale=300, z=4.0)[source]#
Blinks in the pupil signal sy: runs of missing samples (NaN) whose flanks look like a blink (for dips without missing samples, see
detect_partial_blinks()).A blink leaves its mark next to the dropout: the lid covering the pupil makes the signal fall fast before it, and the reopening makes it rise fast after it. The flanks have no fixed length; they are found with one of two tests (method):
"velocity", the run where the velocity is beyond the thresholds (seeflank_run()), or"excess", a change faster than the pupil can manage over many scales (seeexcess_flank(); the signal falls before and rises after the dropout). Runs of missing samples without this (e.g., loss of tracking, looking away) are not blinks; they stay missing.Masked samples (unusable) right next to the missing samples belong to the dropout (e.g., the margin of another mask): the flanks are looked for beyond them. A stretch of masked samples without missing ones is not a blink. On a side without a flank, the blink ends with the missing samples (the masked ones stay masked by their own layer).
- Parameters:
sy (np.ndarray) – pupil data (NaN for missing values; convert codes like 0 before)
smooth_winsize (int) – size of the Savitzky-Golay window of the velocity in samples (odd;
method="velocity")flank_low (float or np.ndarray) – rates of the flanks (per sample, positive), see
flank_run(); withmethod="excess", flank_high is the largest plausible rate of the pupil and flank_low is not usedflank_high (float or np.ndarray) – rates of the flanks (per sample, positive), see
flank_run(); withmethod="excess", flank_high is the largest plausible rate of the pupil and flank_low is not usedmin_len (int) – minimum number of samples of a blink (with its flanks)
max_len (int or None) – maximum number of samples of a blink (with its flanks; None: no limit); longer runs of missing samples (from the first to the last missing sample of a dropout) are not blinks
flank_min_len (int) – number of samples beyond flank_high for a closing or reopening (
method="velocity")require (str) –
"either": a closing before or a reopening after the dropout"both": a closing before and a reopening after it"none": every run of missing samples (between min_len and max_len) is a blink, without looking at the flanks (e.g., for data where the tracker does not show the transients)
tolerance (int) – samples next to the dropout that may be below the thresholds (
method="velocity")unusable (np.ndarray of bool, optional) – samples masked for other reasons: no flank is found in them; next to missing samples, they belong to the dropout (see above)
max_gap (int) – a flank goes on across up to this many missing or masked samples in a row (see
flank_run(),excess_flank())method (str) – test of the flanks:
"velocity"(default) or"excess"noise (float, optional) – standard deviation of the noise of a sample (
method="excess"; required)smooth (int) – width of the running median and range of the scales (samples;
method="excess", seeexcess_flank())min_scale (int) – width of the running median and range of the scales (samples;
method="excess", seeexcess_flank())max_scale (int) – width of the running median and range of the scales (samples;
method="excess", seeexcess_flank())z (float) – threshold of the excess change (
method="excess")
- Return type:
- Returns:
blinks, other (np.ndarray) – arrays (n x 2) of first/last sample (both inclusive): the blinks (sorted; with their flanks, i.e. from the start of the closing to the end of the reopening), and the runs of missing samples that are not blinks