{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Preprocessing Raw Gaze Data" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## What you will learn in this tutorial:\n", "\n", "* how to transform pixel coordinates into degrees of visual angle\n", "* how to transform positional data into velocity data" ] }, { "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 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": [ "We can verify that all files have been loaded in by checking the `fileinfo` attribute:" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "dataset.fileinfo" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "Now let's inpect our gaze dataframe:" ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "dataset.gaze[0].frame.head()" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "Apart from some trial identifier columns we see the columns `time` and `pixel`." ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "## Preprocessing" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "We now want to transform these pixel position coordinates into coordinates in degrees of visual angle.\n", "This is simply done by:" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "dataset.pix2deg()\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "The processed result has been added as a new column named `position` to our gaze dataframe." ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "Additionally we would like to have velocity data available too.\n", "We have four different methods available:\n", "\n", "* `preceding`: this will just take the single preceding sample in account for velocity calculation. Most noisy variant.\n", "* `neighbors`: this will take the neighboring samples in account for velocity calculation. A bit less noisy.\n", "* `smooth`: this will increase the neighboring samples to two on each side. You can get a smooth conversion this way.\n", "* `savitzky_golay`: this is using the *Savitzky-Golay* differentiation filter for conversion. You can specify additional parameters like `window_length` and `degree`. Depending on your parameters this will lead to the best results.\n", "\n", "Let's use the `fivepoint` method first:" ] }, { "cell_type": "code", "execution_count": null, "id": "17", "metadata": {}, "outputs": [], "source": [ "dataset.pos2vel(method='fivepoint')\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "The processed result has been added as a new column named `velocity` to our gaze dataframe." ] }, { "cell_type": "markdown", "id": "19", "metadata": {}, "source": [ "We can also use the *Savitzky-Golay* differentiation filter with some additional parameters like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "20", "metadata": {}, "outputs": [], "source": [ "dataset.pos2vel(method='savitzky_golay', degree=2, window_length=7)\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "21", "metadata": {}, "source": [ "This has overwritten our velocity columns.\n", "As we see, the values in the velocity columns are slightly different." ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "id": "23", "metadata": {}, "source": [ "## What you have learned in this tutorial:\n", "\n", "* transforming pixel coordinates into degrees of visual angle by using `Dataset.pix2deg()`\n", "* transforming positional data into velocity data by using `Dataset.pos2vel()`\n", "* passing additional keyword arguments when using the *Savitzky-Golay* differentiation filter" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }