pymovements.gaze.GazeDataFrame#
- class pymovements.gaze.GazeDataFrame(data: pl.DataFrame | None = None, experiment: Experiment | None = None, events: pm.EventDataFrame | None = None, *, trial_columns: str | list[str] | None = None, time_column: str | None = None, time_unit: str | None = 'ms', pixel_columns: list[str] | None = None, position_columns: list[str] | None = None, velocity_columns: list[str] | None = None, acceleration_columns: list[str] | None = None, distance_column: str | None = None)#
A DataFrame for gaze time series data.
Each row is a sample at a specific timestep. Each column is a channel in the gaze time series.
- Parameters:
data (pl.DataFrame | None) – A dataframe to be transformed to a polars dataframe. (default: None)
experiment (Experiment | None) – The experiment definition. (default: None)
events (pm.EventDataFrame | None) – A dataframe of events in the gaze signal. (default: None)
trial_columns (str | list[str] | None) – The name of the trial columns in the input data frame. If the list is empty or None, the input data frame is assumed to contain only one trial. If the list is not empty, the input data frame is assumed to contain multiple trials and the transformation methods will be applied to each trial separately. (default: None)
time_column (str | None) – The name of the timestamp column in the input data frame. This column will be renamed to
time
. (default: None)time_unit (str | None) – The unit of the timestamps in the timestamp column in the input data frame. Supported units are ‘s’ for seconds, ‘ms’ for milliseconds and ‘step’ for steps. If the unit is ‘step’ the experiment definition must be specified. All timestamps will be converted to milliseconds. (default: ‘ms’)
pixel_columns (list[str] | None) – The name of the pixel position columns in the input data frame. These columns will be nested into the column
pixel
. If the list is empty or None, the nestedpixel
column will not be created. (default: None)position_columns (list[str] | None) – The name of the dva position columns in the input data frame. These columns will be nested into the column
position
. If the list is empty or None, the nestedposition
column will not be created. (default: None)velocity_columns (list[str] | None) – The name of the velocity columns in the input data frame. These columns will be nested into the column
velocity
. If the list is empty or None, the nestedvelocity
column will not be created. (default: None)acceleration_columns (list[str] | None) – The name of the acceleration columns in the input data frame. These columns will be nested into the column
acceleration
. If the list is empty or None, the nestedacceleration
column will not be created. (default: None)distance_column (str | None) – The name of the column containing eye-to-screen distance in millimeters for each sample in the input data frame. If specified, the column will be used for pixel to dva transformations. If not specified, the constant eye-to-screen distance will be taken from the experiment definition. This column will be renamed to
distance
. (default: None)
Notes
About using the arguments
pixel_columns
,position_columns
,velocity_columns
, andacceleration_columns
:By passing a list of columns as any of these arguments, these columns will be merged into a single column with the corresponding name , e.g. using pixel_columns will merge the respective columns into the column pixel.
The supported number of component columns with the expected order are:
zero columns: No nested component column will be created.
two columns: monocular data; expected order: x-component, y-component
- four columns: binocular data; expected order: x-component left eye, y-component left eye,
x-component right eye, y-component right eye,
- six columns: binocular data with additional cyclopian data; expected order: x-component
left eye, y-component left eye, x-component right eye, y-component right eye, x-component cyclopian eye, y-component cyclopian eye,
Examples
First let’s create an example DataFrame with three columns: the timestamp
t
andx
andy
for the pixel position.>>> df = pl.from_dict( ... data={'t': [1000, 1001, 1002], 'x': [0.1, 0.2, 0.3], 'y': [0.1, 0.2, 0.3]}, ... ) >>> df shape: (3, 3) ┌──────┬─────┬─────┐ │ t ┆ x ┆ y │ │ --- ┆ --- ┆ --- │ │ i64 ┆ f64 ┆ f64 │ ╞══════╪═════╪═════╡ │ 1000 ┆ 0.1 ┆ 0.1 │ │ 1001 ┆ 0.2 ┆ 0.2 │ │ 1002 ┆ 0.3 ┆ 0.3 │ └──────┴─────┴─────┘
We can now initialize our
GazeDataFrame
by specyfing the names of the pixel position columns, the timestamp column and the unit of the timestamps.>>> gaze = GazeDataFrame(data=df, pixel_columns=['x', 'y'], time_column='t', time_unit='ms') >>> gaze.frame shape: (3, 2) ┌──────┬────────────┐ │ time ┆ pixel │ │ --- ┆ --- │ │ i64 ┆ list[f64] │ ╞══════╪════════════╡ │ 1000 ┆ [0.1, 0.1] │ │ 1001 ┆ [0.2, 0.2] │ │ 1002 ┆ [0.3, 0.3] │ └──────┴────────────┘
In case your data has no time column available, you can pass an :py:class:
Experiment
to create a time column with the correct sampling rate during initialization. The time column will be represented in millisecond units.>>> df_no_time = df.select(pl.exclude('t')) >>> df_no_time shape: (3, 2) ┌─────┬─────┐ │ x ┆ y │ │ --- ┆ --- │ │ f64 ┆ f64 │ ╞═════╪═════╡ │ 0.1 ┆ 0.1 │ │ 0.2 ┆ 0.2 │ │ 0.3 ┆ 0.3 │ └─────┴─────┘
>>> experiment = Experiment(1024, 768, 38, 30, 60, 'center', sampling_rate=100) >>> gaze = GazeDataFrame(data=df_no_time, experiment=experiment, pixel_columns=['x', 'y']) >>> gaze.frame shape: (3, 2) ┌──────┬────────────┐ │ time ┆ pixel │ │ --- ┆ --- │ │ i64 ┆ list[f64] │ ╞══════╪════════════╡ │ 0 ┆ [0.1, 0.1] │ │ 10 ┆ [0.2, 0.2] │ │ 20 ┆ [0.3, 0.3] │ └──────┴────────────┘
- __init__(data: pl.DataFrame | None = None, experiment: Experiment | None = None, events: pm.EventDataFrame | None = None, *, trial_columns: str | list[str] | None = None, time_column: str | None = None, time_unit: str | None = 'ms', pixel_columns: list[str] | None = None, position_columns: list[str] | None = None, velocity_columns: list[str] | None = None, acceleration_columns: list[str] | None = None, distance_column: str | None = None)
Methods
__init__
([data, experiment, events, ...])apply
(function, **kwargs)Apply preprocessing method to GazeDataFrame.
clip
(lower_bound, upper_bound, *, ...)Clip gaze signal values.
clone
()Return a copy of the GazeDataFrame.
deg2pix
([pixel_origin, position_column, ...])Compute gaze positions in pixel position coordinates from degrees of visual angle.
detect
(method, *[, eye, clear])Detect events by applying a specific event detection method.
measure_samples
(method, **kwargs)Calculate eye movement measure for gaze data samples.
nest
(input_columns, output_column)Nest component columns into a single tuple column.
pix2deg
()Compute gaze positions in degrees of visual angle from pixel position coordinates.
pos2acc
(*[, degree, window_length, padding])Compute gaze acceleration in dva/s^2 from dva position coordinates.
pos2vel
([method])Compute gaze velocity in dva/s from dva position coordinates.
smooth
([method, window_length, degree, ...])Smooth data in a column.
transform
(transform_method, **kwargs)Apply transformation method.
unnest
([input_columns, output_suffixes, ...])Explode a column of type
pl.List
into one column for each list component.Attributes
columns
List of column names.
schema
Schema of event dataframe.