{ "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" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Loading and preprocessing your data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pymovements as pm\n", "from pymovements.events import microsaccades\n", "from pymovements.plotting import main_sequence_plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, you have to define your dataset. You can already download and extract all the files." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = pm.datasets.toy_dataset.ToyDataset(\n", " root='data/', download=True, extract=True, remove_finished=True)\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", "for event_df in dataset.events[:3]:\n", " print(\n", " f'Showing main sequence plot for '\n", " f'text {event_df[0, \"text_id\"]}, '\n", " f'page {event_df[0, \"page_id\"]}:')\n", " main_sequence_plot(event_df)" ] }, { "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": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 1 }