View source: R/pipeline-loadgeneric.R
| load_generic | R Documentation |
Construct a valid eyeris S3 object from standardized data frames so that
data from eye trackers other than SR Research EyeLink can enter the
eyeris preprocessing pipeline. While load_asc() parses EyeLink
.asc files specifically, load_generic() provides a tracker-agnostic
ingestion path: you supply the raw samples (and, optionally, event messages,
gaze coordinates, and blink intervals) as plain R data frames, and
load_generic() assembles them into the same object structure that the rest
of eyeris (including glassbox()) expects.
load_generic(
pupil,
events = NULL,
blinks = NULL,
gaze = NULL,
sample_rate = NULL,
time_unit = c("ms", "s"),
block = "auto",
eye = c("L", "R", "LR"),
pupil_type = c("area", "diameter"),
screen_width = NA_real_,
screen_height = NA_real_,
tracker = "generic",
model = NA_character_,
mapping = NULL,
path = NULL,
verbose = TRUE
)
pupil |
A data frame of raw samples. Must contain a timestamp column and
a pupil-size column (see |
events |
An optional data frame of event messages with a timestamp column
(on the same clock as |
blinks |
An optional data frame of blink intervals with start and end
timestamp columns. If |
gaze |
An optional data frame of gaze coordinate samples (timestamp,
|
sample_rate |
Numeric sampling rate of the tracker in Hz. If |
time_unit |
Unit of all timestamp columns (in |
block |
Block specification, mirroring
|
eye |
Which eye the data correspond to: |
pupil_type |
Pupil measurement units: |
screen_width, screen_height |
Optional screen dimensions in pixels, used
for gaze heatmaps and gaze-based confounds. Leave as |
tracker |
Character label for the source tracker/system (default
|
model |
Optional character label for the specific tracker model.
Recorded in |
mapping |
An optional named list remapping the default column names to
the ones present in your data frames. Recognized names are |
path |
Optional character path/identifier stored in the object's |
verbose |
Logical. Whether to print verbose output (default |
eyeris was designed to be extensible, but historically load_asc() was the
only implemented loader. load_generic() closes that gap. Native support for
specific tracker formats (e.g., Tobii, SMI, Pupil Labs, GazePoint) can be
layered on top of this function incrementally: a format-specific reader only
needs to produce the standardized data frames documented below and then call
load_generic().
The resulting object is structurally identical to one returned by
load_asc(), so it is a drop-in input to glassbox() and the
individual preprocessing steps (deblink(), detransient(),
interpolate(), lpfilt(), downsample(),
bin(), detrend(), zscore()),
epoch(), bidsify(), and the plotting methods.
Following the conceptual model that most trackers export, load_generic()
accepts three core data frames (plus an optional fourth for gaze that is
exported separately):
pupil (required) – the raw sample stream. Must contain a timestamp
column and a pupil-size column. May also carry gaze coordinate columns
(eye_x, eye_y) if your tracker exports samples as one wide table.
events (optional) – experimental event messages. Must contain a
timestamp column (on the same clock as pupil) and a message-text column.
Required only if you intend to epoch on event messages later.
blinks (optional) – blink intervals reported by the tracker. Must
contain blink start and end timestamp columns. Note that blink padding via
deblink() does not depend on this table – it reconstructs
missing/blink regions directly from NA (and 0) values in the pupil
column – so this table is purely for record-keeping and export.
A fourth, gaze, data frame is accepted for the less common case where
gaze coordinates are exported separately from pupil size (timestamp + x/y
columns); it is joined onto pupil by timestamp. If your pupil data frame
already contains gaze columns, leave this NULL.
If a column in your data frames does not use the default name expected by
load_generic(), remap it via the mapping argument (see below) rather than
renaming your data by hand.
By default load_generic() looks for these columns (override any of them with
mapping):
| data frame | role | default column |
pupil | timestamp | time |
pupil | pupil size | pupil |
pupil | gaze x (optional) | eye_x |
pupil | gaze y (optional) | eye_y |
pupil | block (optional) | block |
events | timestamp | time |
events | message text | text |
blinks | blink start | stime |
blinks | blink end | etime |
gaze | timestamp | time |
gaze | gaze x | eye_x |
gaze | gaze y | eye_y |
eyeris assumes EyeLink-style regularly-sampled data. Two practical notes for
other trackers:
Missing samples. deblink() reconstructs missing/blink regions
directly from NA (and 0) values in the pupil column – it does not
require the blinks table. If your tracker drops samples or encodes missing
pupil data some other way, set those samples to NA in the pupil
column so deblinking and the confound calculations behave correctly.
Irregular sampling. If consecutive timestamps are not uniformly spaced,
load_generic() emits a warning, because several downstream steps assume a
fixed sampling interval. (A fuller guardrail is tracked separately.)
An object of S3 class eyeris with the same structure as
load_asc():
file: The path identifier for the source data.
timeseries: A named list of per-block data frames of raw time series
data (time_orig, time_secs, time_scaled, eye_x, eye_y, eye,
hz, type, pupil_raw).
events: A named list of per-block event-message data frames.
blinks: A named list of per-block blink data frames.
info: Tracker metadata (sample.rate, mono, left, right,
pupil.dtype, version, model, screen.x, screen.y).
latest: eyeris pointer for tracking pipeline run history.
binocular, binocular_mode, decimated.sample.rate, params.
load_asc() for loading SR Research EyeLink .asc files.
glassbox() for running the full eyeris preprocessing
pipeline on the object returned by this function.
# build three small standardized data frames from any non-EyeLink tracker
set.seed(1)
n <- 1000
samples <- data.frame(
time = seq(0, by = 1, length.out = n), # 1000 Hz -> 1 ms spacing
pupil = 1000 + cumsum(rnorm(n, 0, 5)),
eye_x = 960 + rnorm(n, 0, 10),
eye_y = 540 + rnorm(n, 0, 10)
)
events <- data.frame(
time = c(100, 500),
text = c("TRIALID 1", "TRIALID 2")
)
# construct a valid eyeris object
eye <- eyeris::load_generic(
pupil = samples,
events = events,
sample_rate = 1000,
screen_width = 1920,
screen_height = 1080,
tracker = "my-tracker"
)
# ...and run it straight through the glassbox pipeline
eye |>
eyeris::glassbox(lpfilt = list(plot_freqz = FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.