{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Detecting Gaze Events" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## What you will learn in this tutorial:\n", "\n", "* how to detect saccades using the microsaccades algorithm\n", "* how to detect fixations using the I-DT and I-VT algorithms" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Preparations" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "We import `pymovements` as the alias `pm` for convenience." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "import polars as pl\n", "\n", "import pymovements as pm" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "Let's start by downloading our `ToyDataset` and loading in its data:" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "dataset = pm.Dataset('ToyDataset', path='data/ToyDataset')\n", "dataset.download()\n", "dataset.load()" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "Now let's do some basic preprocessing:" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "dataset.pix2deg()\n", "dataset.pos2vel('smooth')\n", "\n", "dataset.gaze[0].frame.head()" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "## Detecting Events" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "*pymovements* provides a range of event detection methods for several types of gaze events.\n", "\n", "See the reference for [pymovements.events](https://pymovements.readthedocs.io/en/latest/reference/pymovements.events.html) to get an overview of all the supported methods.\n", "\n", "For this tutorial we will use the `microsaccades` algorithm for detecting saccades and the I-DT and I-VT algorithms for detecting fixations." ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "We start out by detecting saccades." ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "dataset.detect_events('microsaccades', minimum_duration=12)" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "The detected events are added as rows with the name `saccade` to the event dataframe:" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "dataset.events[0].frame.head()" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "Next we will detect fixations using the I-DT and I-VT algorithms.\n", "\n", "To be able to differentiate between the detected events, we specify custom event names for each algorithm:" ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "outputs": [], "source": [ "dataset.detect_events('idt', dispersion_threshold=2.7, name='fixation.idt')\n", "dataset.detect_events('ivt', velocity_threshold=20, name='fixation.ivt')" ] }, { "cell_type": "markdown", "id": "17", "metadata": {}, "source": [ "This has added new rows with the fixation events to the event dataframe." ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "dataset.events[0].frame.filter(pl.col('name') == 'fixation.idt').head()" ] }, { "cell_type": "code", "execution_count": null, "id": "19", "metadata": {}, "outputs": [], "source": [ "dataset.events[0].frame.filter(pl.col('name') == 'fixation.ivt').head()" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "id": "21", "metadata": {}, "source": [ "## What you have learned in this tutorial:\n", "\n", "* detecting saccades by using the microsaccades algorithm\n", "* detecting fixations by using the I-DT and I-VT algorithms" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }