{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot saccadic main sequence\n", "\n", "In this notebook we show how you can load a dataset, compute all the necessary properties and the plot the main sequence." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What you will learn in this tutorial:\n", "\n", "* how to prepare your data to plot the saccadic main sequence\n", "* how to create a main sequence plot of your saccade events and style it to your liking" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading and preprocessing your data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We import `pymovements` as the alias `pm` for convenience." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pymovements as pm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's start by downloading our `ToyDataset` and loading in its data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = pm.Dataset('ToyDataset', path='data/ToyDataset')\n", "dataset.download()\n", "dataset.load()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, you have to convert the raw x and y coordinates in pixels to degrees in visual angle." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.pix2deg()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we can convert these positions into velocitites." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.pos2vel()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check if we now have all our expected columns:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.gaze[0].frame.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Detecting your events and compute properties" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the next step we have to detect our saccades and compute the event properties `amplitude` and `peak_velocity`.\n", "\n", "We can run the microsaccade detection algorithm with its default parameters:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.detect_events('microsaccades')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we compute the event properties 'amplitude' and 'peak velocity' for the detected saccades." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.compute_event_properties(['amplitude', 'peak_velocity'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's verify that we have detected some saccades and have the desired columns available." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset.events[0].frame.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot the main sequence" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we just pass the event dataframe to the plotting function:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# only showing the first three event dataframes here.\n", "# note that you can adjust the styling of the plot, e.g. setting a low\n", "# alpha value allows you to see overlapping data points\n", "for event_df in dataset.events[:3]:\n", " pm.plotting.main_sequence_plot(\n", " event_df,\n", " title='Main sequence plot for '\n", " f'text {event_df[0, \"text_id\"]}, '\n", " f'page {event_df[0, \"page_id\"]}',\n", " alpha=0.3,\n", " color='green',\n", " marker='x',\n", " marker_size=30,\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What you have learned in this tutorial:\n", "\n", "* how to prepare your data to plot a main sequence\n", "* how to create a main sequence plot by using `main_sequence_plot`" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 1 }