Basic Scanpath Processing
This example demonstrates how to generate a Gramian Angular Field (GAF) from a scanpath. GAF encodes time-series into an image, often used for Deep Learning models.
1"""
2Basic Scanpath Processing Example
3=================================
4
5This example demonstrates how to generate a Gramian Angular Field (GAF) from a scanpath.
6GAF is a technique to encode time-series (or in this case, scanpath) into an image,
7often used for Deep Learning input.
8"""
9
10import matplotlib.pyplot as plt
11import pandas as pd
12
13from eyefeatures.features.feature_maps import get_gaf
14
15# Load sample data
16fixations_df = pd.read_csv("data/fixations/fixations_subset.csv")
17print("Loaded fixations data:", fixations_df.shape)
18
19# Leave several texts(for speedup)
20fixations_df = fixations_df[fixations_df["tekst"].isin([1, 10, 17])]
21print("Selected data (several texts):", fixations_df.shape)
22
23# Calculate GAF
24# field_type: "sum" or "difference"
25# to_polar: "regular" or "cosine"
26gaf_matrix = get_gaf(
27 data=fixations_df,
28 x="norm_pos_x",
29 y="norm_pos_y",
30 t="start_timestamp",
31 field_type="difference",
32 to_polar="cosine",
33)
34
35print(f"\nGAF Matrix Shape: {gaf_matrix.shape}")
36
37# Visualize
38plt.figure(figsize=(8, 8))
39plt.imshow(gaf_matrix[0], cmap="viridis", origin="lower")
40plt.title("Gramian Angular Field (GAF)")
41plt.colorbar()
42# plt.show()