detect_transients#

pypillometry.signal.detect_transients(sy, smooth_winsize, low, high, min_len=5, free_high=None, max_len=None, tolerance=0, unusable=None, max_gap=0, min_change=None, flanks=True)[source]#

Transients in the pupil signal sy: fast changes that are artifacts.

Two kinds, with the same hysteresis (see flank_run()):

  • the flanks of dropouts (runs of missing or masked samples, blinks or not): the fall before and the rise after a dropout, if they reach high; a masked stretch counts like a missing one, also next to a missing one (e.g., the margin of another mask right at a blink)

  • free transients (with free_high): runs where the signal falls or rises faster than free_high anywhere else (e.g., partial blinks, jumps, spikes); without a dropout as evidence, free_high should be stricter than high, since fast responses of the pupil also have a high velocity

At a dropout, the flank can go either way (an artifact can also make the signal jump up). Each transient extends down to low on both sides; transients that overlap or are closer than a window (e.g., the fall and the rise of a spike) are merged.

Parameters:
  • sy (np.ndarray) – pupil data (NaN or 0 for missing values)

  • smooth_winsize (int) – size of the Savitzky-Golay window of the velocity in samples (odd)

  • low (float or np.ndarray) – rates (per sample, positive) of the flanks of dropouts

  • high (float or np.ndarray) – rates (per sample, positive) of the flanks of dropouts

  • min_len (int) – number of samples beyond the threshold (high or free_high)

  • free_high (float or np.ndarray, optional) – rate (per sample, positive) of free transients; None: only the flanks of dropouts

  • max_len (int, optional) – maximum length of one flank or side of a transient (safety bound)

  • tolerance (int) – samples next to a dropout that may be below the thresholds; also the number of samples below low that a transient goes on across (noise in its slow parts)

  • unusable (np.ndarray of bool, optional) – samples masked for other reasons: they are not part of a transient, a transient stops at them (unless they are bridged), and they are dropouts whose flanks are transients

  • max_gap (int) – a transient goes on across up to this many missing or masked samples in a row (e.g., a short dropout during the reopening; see flank_run())

  • min_change (float, optional) – a flank or free transient only counts if the signal changes by more than this across it (from its first to its last sample; e.g., a few times the noise, against fast but tiny changes)

  • flanks (bool) – False: only free transients (e.g., with the flanks of dropouts from detect_transients_excess())

Return type:

ndarray

Returns:

array (n x 2) of first/last sample (both inclusive), sorted