interpolate_intervals#
- pypillometry.interpolate_intervals(intervals, eyes=[], variables=[], method='linear', margin=(-20, 20), store_as_suffix=None, policy='default')#
Pipeline step for
interpolate_intervals()(d | pp.interpolate_intervals(...)).Interpolate data within specified intervals.
This function replaces data within the specified intervals with interpolated values based on boundary points outside each interval. The interpolated samples get the
"interpolated"layer (seeget_interpolated()), so they are used under the default mask policy and masked under the"strict"one (seemask()). Intervals without usable boundary points on both sides are skipped with a warning.- Parameters:
intervals (Intervals, Epochs, list of tuple or dict) –
Either:
A single Intervals (or
Epochs) object or a list of(start, end)tuples (in ms, or with units): applied to all specified eyes/variablesA dict of Intervals (or Epochs): keys like “left_pupil”, “right_x”, etc. When dict is provided, eyes and variables are ignored.
eyes (str or list of str, optional) – eye(s) to interpolate; if empty, all available eyes. Ignored if intervals is a dict.
variables (str or list of str, optional) – variable(s) to interpolate; if empty, all available variables. Ignored if intervals is a dict.
method (str, default "linear") – Interpolation method. Options: “linear”, “nearest”, “zero”, “slinear”, “quadratic”, “cubic”, “previous”, “next”. Passed to scipy.interpolate.interp1d.
margin (tuple, default (-20, 20)) – Time window (in ms) before and after the interval to collect boundary points for interpolation, relative to the start and end of each interval: points are taken from
start + margin[0]to the start and from the end toend + margin[1], so margin[0] must be <= 0 and margin[1] >= 0. Samples that are unusable under policy (masked or NaN) are not used. For higher-order methods like “cubic” or “quadratic”, more boundary points from this margin are used to fit the interpolation curve.store_as_suffix (str or None, default None) – If None, replace the original data. If a string, store interpolated data in a new variable with this suffix (e.g., “_interp” creates “left_pupil_interp”).
policy (str, MaskPolicy or list of str) – mask policy that decides which boundary points are usable (see
mask()); default"default"inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)
- Return type:
- Returns:
The object with interpolated data (self or a copy, depending on inplace).
See also
mask_intervalsApply intervals as masks without interpolation
get_blinksRetrieve stored blink intervals
Examples
Interpolate blinks for left eye pupil data:
>>> import pypillometry as pp >>> d = pp.get_example_data("rlmw_002_short").pupil.blinks_detect() >>> blinks = d.get_blinks(eyes="left", variables="pupil")["left_pupil"] >>> d1 = d.interpolate_intervals(blinks, eyes=["left"], variables=["pupil"], ... inplace=False)
Interpolate using a dict of intervals:
>>> blinks = d.get_blinks() # returns dict >>> d2 = d.interpolate_intervals(blinks, inplace=False)
Store interpolated data in a new variable:
>>> d3 = d.interpolate_intervals(blinks, store_as_suffix="_interp", ... inplace=False) >>> "left_pupil_interp" in d3.data True
Use cubic interpolation with wider margin:
>>> d4 = d.interpolate_intervals(blinks, method="cubic", margin=(-50, 50), ... inplace=False)