{ "cells": [ { "cell_type": "markdown", "id": "011263bd", "metadata": {}, "source": [ "# Preprocessing Raw Gaze Data" ] }, { "cell_type": "markdown", "id": "c364cece", "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": "da10de1a", "metadata": {}, "source": [ "## Preparations" ] }, { "cell_type": "markdown", "id": "b3416fcd", "metadata": {}, "source": [ "We import `pymovements` as the alias `pm` for convenience." ] }, { "cell_type": "code", "execution_count": null, "id": "77dd8252", "metadata": {}, "outputs": [], "source": [ "import pymovements as pm" ] }, { "cell_type": "markdown", "id": "2169ec44", "metadata": {}, "source": [ "Let's start by downloading our `ToyDataset` and loading in its data:" ] }, { "cell_type": "code", "execution_count": null, "id": "375b5f97", "metadata": {}, "outputs": [], "source": [ "dataset = pm.Dataset('ToyDataset', path='data/ToyDataset')\n", "dataset.download()\n", "dataset.load()" ] }, { "cell_type": "markdown", "id": "ddc3b9ff", "metadata": {}, "source": [ "We can verify that all files have been loaded in by checking the `fileinfo` attribute:" ] }, { "cell_type": "code", "execution_count": null, "id": "ff93298e", "metadata": {}, "outputs": [], "source": [ "dataset.fileinfo" ] }, { "cell_type": "markdown", "id": "88cfa24a", "metadata": {}, "source": [ "Now let's inpect our gaze dataframe:" ] }, { "cell_type": "code", "execution_count": null, "id": "1cbab15d", "metadata": {}, "outputs": [], "source": [ "dataset.gaze[0].frame.head()" ] }, { "cell_type": "markdown", "id": "4bce5e1a", "metadata": {}, "source": [ "Apart from some additional labels we see the following columns:\n", "`time`, `x_right_pix` and `y_right_pix`." ] }, { "cell_type": "markdown", "id": "1275c5b6", "metadata": {}, "source": [ "## Preprocessing" ] }, { "cell_type": "markdown", "id": "6e671122", "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": "edd59432", "metadata": {}, "outputs": [], "source": [ "dataset.pix2deg()\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "e416a71b", "metadata": {}, "source": [ "The processed result has been added as new columns to our gaze dataframe: `x_right_pos`, `y_right_pos`." ] }, { "cell_type": "markdown", "id": "850c2306", "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 `polyorder`. Depending on your parameters this will lead to the best results.\n", "\n", "Let's use the `smooth` method first:" ] }, { "cell_type": "code", "execution_count": null, "id": "a4c4f363", "metadata": {}, "outputs": [], "source": [ "dataset.pos2vel(method='smooth')\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "98d43a6e", "metadata": {}, "source": [ "This added the following new velocity columns to our gaze dataframe: `x_right_vel`, `y_right_vel`" ] }, { "cell_type": "markdown", "id": "7e881a9b", "metadata": {}, "source": [ "We can also use the *Savitzky-Golay* differentiation filter with some additional parameters like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "4590b9fd", "metadata": {}, "outputs": [], "source": [ "dataset.pos2vel(method='savitzky_golay', window_length=7, polyorder=2)\n", "\n", "dataset.gaze[0].frame" ] }, { "cell_type": "markdown", "id": "50e5075a", "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": "3447c7ee", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "id": "54e69cf4", "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 }