Events#

class pymovements.Events(data: DataFrame | None = None, name: str | list[str] | None = None, onsets: list[int | float] | ndarray | None = None, offsets: list[int | float] | ndarray | None = None, trials: list[int | float | str | None] | ndarray | None = None, trial_columns: list[str] | str | None = None)[source]#

A data structure for event data.

Each row has at least an event name with its onset and offset specified.

Parameters:
  • data (polars.DataFrame | None) – A dataframe to be transformed to a polars dataframe. This argument is mutually exclusive with all the other arguments. (default: None)

  • name (str | list[str] | None) – Name of events. (default: None)

  • onsets (list[int | float] | np.ndarray | None) – List of onsets. (default: None)

  • offsets (list[int | float] | np.ndarray | None) – List of offsets. (default: None)

  • trials (list[int | float | str | None] | np.ndarray | None) – List of trial identifiers. (default: None)

  • trial_columns (list[str] | str | None) – List of trial columns in the passed dataframe.

frame#

A dataframe of events.

Type:

polars.DataFrame

trial_columns#

The name of the trial columns in the data frame. If not None, processing methods will be applied to each trial separately.

Type:

list[str] | None

schema#

Schema of the event dataframe.

Type:

polars.type_aliases.SchemaDict

columns#

List of column names in the event dataframe.

Type:

list[str]

event_property_columns#

Event property columns for this dataframe.

Type:

list[str]

fixations#

Fixation events.

Type:

polars.DataFrame

saccades#

Saccade events.

Type:

polars.DataFrame

Blink events.

Type:

polars.DataFrame

microsaccades#

Microsaccade events.

Type:

polars.DataFrame

Raises:

ValueError – If list of onsets is passed but not a list of offsets, or vice versa, or if length of onsets does not match length of offsets.

Examples

We define an event dataframe with given names of events and lists of onsets and offsets. Durations are computed automatically.

>>> event = Events(
...    name=['fixation', 'fixation', 'fixation', 'fixation', ],
...    onsets=[1988147, 1988351, 1988592, 1988788],
...    offsets=[1988322, 1988546, 1988736, 1989013]
... )
>>> event
shape: (4, 4)
┌──────────┬─────────┬─────────┬──────────┐
│ name     ┆ onset   ┆ offset  ┆ duration │
│ ---      ┆ ---     ┆ ---     ┆ ---      │
│ str      ┆ i64     ┆ i64     ┆ i64      │
╞══════════╪═════════╪═════════╪══════════╡
│ fixation ┆ 1988147 ┆ 1988322 ┆ 175      │
│ fixation ┆ 1988351 ┆ 1988546 ┆ 195      │
│ fixation ┆ 1988592 ┆ 1988736 ┆ 144      │
│ fixation ┆ 1988788 ┆ 1989013 ┆ 225      │
└──────────┴─────────┴─────────┴──────────┘

Methods

__init__([data, name, onsets, offsets, ...])

add_event_properties(event_properties, join_on)

Add new event properties into dataframe.

add_trial_column(column, data)

Add new trial columns with constant values.

clone()

Return a copy of an Events object.

drop(columns)

Remove columns from the events data frame.

drop_nulls([subset, how])

Drop events with null values.

filter_by_name(name)

Filter events by name.

map_to_aois(aoi_dataframe, *[, ...])

Map events to AOIs, ignoring non-fixations.

merge_subsequent_close_events([name, ...])

Merge subsequent events if they are separated by a gap smaller than a threshold.

split(-> list[~pymovements.events.events.Events])

Split the Events into multiple frames based on specified column(s).

unnest([input_columns, output_suffixes, ...])

Explode columns of type polars.List into one column for each list component.