Skip to content

Instantly share code, notes, and snippets.

@marc-tonsen
Last active January 5, 2023 08:27
Show Gist options
  • Save marc-tonsen/dab718d8dcd841b6e6b3b1899e049b5b to your computer and use it in GitHub Desktop.
Save marc-tonsen/dab718d8dcd841b6e6b3b1899e049b5b to your computer and use it in GitHub Desktop.
This script extends blink, fixation and gaze data by adding an additional column "world_frame_index" to every CSV file. This column indicates the closest available world video frame for each data sample.

This script extends blink, fixation and gaze data by adding an additional column "world_frame_index" to every CSV file. This column indicates the closest available world video frame for each data sample.

To install the dependencies, run the following

pip install numpy pandas

Before executing the file, customize the file paths in the beginning of the file. If you do not want one of the files to be edited, e.g. the fixations file, then set the according path to "None", i.e. fixations_path = None.

import numpy as np
import pandas as pd
world_ts_path = "C:/Users/Admin/Downloads/raw-data-export (3)/2023-01-02_11-27-54-77333307/world_timestamps.csv"
blinks_path = "C:/Users/Admin/Downloads/raw-data-export (3)/2023-01-02_11-27-54-77333307/blinks.csv"
fixations_path = "C:/Users/Admin/Downloads/raw-data-export (3)/2023-01-02_11-27-54-77333307/fixations.csv"
gaze_path = "C:/Users/Admin/Downloads/raw-data-export (3)/2023-01-02_11-27-54-77333307/gaze.csv"
world_ts = pd.read_csv(world_ts_path)
world_ts["world_frame_index"] = np.arange(len(world_ts))
world_ts = world_ts[["world_frame_index", "timestamp [ns]"]]
if fixations_path is not None:
fixations = pd.read_csv(fixations_path)
fixations = pd.merge_asof(fixations, world_ts, left_on="start timestamp [ns]", right_on="timestamp [ns]", direction="nearest")
fixations.to_csv(fixations_path)
if gaze_path is not None:
gaze = pd.read_csv(gaze_path)
gaze = pd.merge_asof(gaze, world_ts, left_on="timestamp [ns]", right_on="timestamp [ns]", direction="nearest")
gaze.to_csv(gaze_path)
if blinks_path is not None:
blinks = pd.read_csv(blinks_path)
blinks = pd.merge_asof(blinks, world_ts, left_on="start timestamp [ns]", right_on="timestamp [ns]", direction="nearest")
blinks.to_csv(blinks_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment