annotate_fixations#
- pymovements.measure.reading.annotate_fixations(events: DataFrame, group_columns: list[str] | None = None, event_name: str = 'fixation', word_idx: str | Expr = 'word_idx') DataFrame[source]#
Annotate fixations with run- and pass-level information.
Computes the following per-fixation annotations:
run_id: integer ID for each contiguous sequence of fixations on the same word.
prev_word_idx / next_word_idx: word indices of the immediately preceding and following fixations.
is_reg_in / is_reg_out: whether the fixation arrives from a higher-index word (regression in) or departs to a lower-index word (regression out).
is_first_fix: whether this is the first fixation ever on the word within the reading sequence.
is_first_pass: whether the fixation belongs to the first-pass reading episode of the word (see
is_first_pass()).regression_path_word: the word whose regression-path window the fixation belongs to (see
regression_path_word()).
- Parameters:
events (pl.DataFrame) – DataFrame containing pymovements fixation events mapped to AOIs. Must contain at least
name,word_idx, andonsetcolumns, plus whatever columns are listed ingroup_columns.group_columns (list[str] | None) – Column names used to partition the data into independent reading sequences (e.g. one trial per page). If
Noneor empty, the whole table is treated as a single sequence. (default: None)event_name (str) – Name of the events to annotate. Rows with a different
nameare dropped. (default:'fixation')word_idx (str | pl.Expr) – Column name or expression of the fixated word index. (default:
'word_idx')
- Returns:
Fixation-level DataFrame with the original columns plus
fixation_id,run_id,prev_word_idx,next_word_idx,delta_in,delta_out,is_reg_in,is_reg_out,is_first_fix,is_first_pass, andregression_path_word.- Return type:
pl.DataFrame
Examples
Four fixations over a three-word text, with a regression from the second word back to the first:
>>> import polars as pl >>> from pymovements.measure.reading import annotate_fixations >>> fixations = pl.DataFrame({ ... 'name': ['fixation'] * 4, ... 'onset': [0, 250, 500, 750], ... 'word_idx': [0, 1, 0, 2], ... }) >>> annotated = annotate_fixations(fixations) >>> annotated.select('word_idx', 'run_id', 'is_first_pass', 'regression_path_word') shape: (4, 4) ┌──────────┬────────┬───────────────┬──────────────────────┐ │ word_idx ┆ run_id ┆ is_first_pass ┆ regression_path_word │ │ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ bool ┆ i64 │ ╞══════════╪════════╪═══════════════╪══════════════════════╡ │ 0 ┆ 1 ┆ true ┆ 0 │ │ 1 ┆ 2 ┆ true ┆ 1 │ │ 0 ┆ 3 ┆ false ┆ 1 │ │ 2 ┆ 4 ┆ true ┆ 2 │ └──────────┴────────┴───────────────┴──────────────────────┘