Signal processing#

These functions work on plain numpy arrays and do not keep any state. They are in the submodule pp.signal (e.g., pp.signal.smooth_window). The methods of the data classes call them with the right arguments, so you usually do not need them directly, but they are useful for your own processing steps or for data that are not in a data object.

Filtering and baseline#

butter_lowpass

Get lowpass-filter coefficients for Butterworth-filter.

butter_lowpass_filter

Lowpass-filter signal using a Butterworth-filter.

lowpass_filter_iterative

Lowpass filter that handles NaN values via iterative interpolation.

smooth_window

Smooth the data using a window with requested size.

downsample

Simple downsampling scheme using mean within the downsampling window.

zscale

Z-transform an array, ignoring NaNs.

bspline

Re-implementation from https://mc-stan.org/users/documentation/case-studies/splines_in_stan.html.

baseline_envelope

Extract baseline based on the lower envelope of the (filtered) signal.

baseline_envelope_iter_bspline

Extract baseline based on (re-)estimating the lower envelope using B-splines.

baseline_pupil_model

Extract baseline based on filtering after removing stim-locked activity.

Pupil response#

pupil_kernel

According to Hoeks and Levelt (1993, https://link.springer.com/content/pdf/10.3758%2FBF03204445.pdf), the PRF can be described by the so-called Erlang gamma function $$h_{HL}(t) = t^n e^{-nt/t_{max}}$$ which we normalize to $$h(t)=frac{1}{h_{max}} h_{HL}(t)$$ where $$h_{max} = max_t{left(h_{HL}(t)right)} = e^{-n}t_{max}^{n}$$ which yields a maximum value of 1 for this function.

pupil_kernel_t

According to Hoeks and Levelt (1993, https://link.springer.com/content/pdf/10.3758%2FBF03204445.pdf), the PRF can be described by the so-called Erlang gamma function $$h_{HL}(t) = t^n e^{-nt/t_{max}}$$ which we normalize to $$h(t)=frac{1}{h_{max}} h_{HL}(t)$$ where $$h_{max} = max_t{left(h_{HL}(t)right)} = e^{-n}t_{max}^{n}$$ which yields a maximum value of 1 for this function.

pupil_get_max_duration

Get the time when the PRF with parameters $n$ and $t_{max}$ is decayed to thr.

plot_prf

Plot profile of the pupil-response function (PRF) with parameters npar and tmax.

pupil_build_design_matrix

Construct design matrix (nevents x n).

pupil_response

Estimate pupil-response based on event-onsets.

pupil_response_coverage

Share of each event's response that falls on valid samples.

pupilresponse_nnls

Estimate single-event pupil responses based on canonical PRF (pupil_kernel()) using non-negative least-squares (NNLS).

pupil_signal_quality

Compute local signal quality metric for pupil signal.

pupil_eye_offset

Compute a slowly-varying offset between left and right pupil signals.

Simulated data#

fake_pupil_baseline

Generate smooth baseline pupil size via filtered noise.

fake_gaze_fixations

Generate step-function gaze positions (fixations with random locations and durations).

add_measurement_noise

Add Gaussian measurement noise to a signal.

generate_foreshortening_data

Generate complete synthetic dataset for testing foreshortening correction algorithm.