{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Computing Event Properties" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## What you will learn in this tutorial:\n", "\n", "* how to add event properties for peak velocity and amplitude" ] }, { "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": [ "Now let's do some basic preprocessing and detect some saccades:" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "dataset.pix2deg()\n", "dataset.pos2vel('smooth')\n", "\n", "dataset.detect_events('microsaccades')\n", "\n", "dataset.events[0].frame.head()" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "## Computing Event Properties" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "*pymovements* provides a range of event properties.\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 properties.\n", "\n", "For this tutorial we will compute several properties of saccades.\n", "\n", "We start out with the peak velocity:" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "dataset.compute_event_properties(\"peak_velocity\")\n", "\n", "dataset.events[0].frame.head()" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "We notice that a new column with the name `peak_velocity` has appeared in the event dataframe.\n", "\n", "We can also pass a list of properties. Let's add the amplitude and dispersion:" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "dataset.compute_event_properties([\"amplitude\", \"dispersion\"])\n", "\n", "dataset.events[0].frame.head()" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "This way we can compute all of our desired properties in a single run." ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "## What you have learned in this tutorial:\n", "\n", "* how to compute event properties by using `Dataset.compute_event_properties()`\n" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }