Plot saccadic main sequence#

In this notebook we show how you can load a dataset, compute all the necessary properties and the plot the main sequence.

What you will learn in this tutorial:#

  • how to prepare your data to plot the saccadic main sequence

  • how to create a main sequence plot of your saccade events

Loading and preprocessing your data#

[1]:
import pymovements as pm
from pymovements.events import microsaccades
from pymovements.plotting import main_sequence_plot
/home/docs/checkouts/readthedocs.org/user_builds/pymovements/envs/v0.7.0/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

First, you have to define your dataset. You can already download and extract all the files.

[2]:
dataset = pm.datasets.toy_dataset.ToyDataset(
    root='data/', download=True, extract=True, remove_finished=True)
dataset.load()
Downloading http://github.com/aeye-lab/pymovements-toy-dataset/zipball/6cb5d663317bf418cec0c9abe1dde5085a8a8ebd/ to data/ToyDataset/downloads/pymovements-toy-dataset.zip
pymovements-toy-dataset.zip: 100%|██████████| 3.06M/3.06M [00:00<00:00, 24.6MB/s]
100%|██████████| 20/20 [00:00<00:00, 199.85it/s]

Now, you have to convert the raw x and y coordinates in pixels to degrees in visual angle.

[3]:
dataset.pix2deg()
100%|██████████| 20/20 [00:00<00:00, 739.06it/s]

Next we can convert these positions into velocitites.

[4]:
dataset.pos2vel()
100%|██████████| 20/20 [00:00<00:00, 675.32it/s]

Let’s check if we now have all our expected columns:

[5]:
dataset.gaze[0].frame.head()
[5]:
shape: (5, 9)
text_idpage_idtimex_right_pixy_right_pixx_right_posy_right_posx_right_vely_right_vel
i64i64f64f64f64f64f64f64f64
011.988145e6206.8152.4-10.697598-8.8523991.207626-3.639106
011.988146e6206.9152.1-10.695183-8.8596782.415272-7.278067
011.988147e6207.0151.8-10.692768-8.8669561.610194-5.256267
011.988148e6207.1151.7-10.690352-8.8693810.402548-4.447465
011.988149e6207.0151.5-10.692768-8.8742330.402561-3.234462

Detecting your events and compute properties#

In the next step we have to detect our saccades and compute the event properties amplitude and peak_velocity.

We can run the microsaccade detection algorithm with its default parameters:

[6]:
dataset.detect_events(microsaccades)
20it [00:00, 65.50it/s]

Next we compute the event properties ‘amplitude’ and ‘peak velocity’ for the detected saccades.

[7]:
dataset.compute_event_properties(['amplitude', 'peak_velocity'])
20it [00:13,  1.49it/s]

Let’s verify that we have detected some saccades and have the desired columns available.

[8]:
dataset.events[0].frame.head()
[8]:
shape: (5, 8)
text_idpage_idnameonsetoffsetdurationamplitudepeak_velocity
i64i64stri64i64i64f64f64
01"saccade"19883231988337143.400319223.354404
01"saccade"1988342198835080.33740543.903782
01"saccade"19885471988567201.823525176.116206
01"saccade"19885711988582110.983307100.904927
01"saccade"198873719887602321.40854393.897938

Plot the main sequence#

Now we just pass the event dataframe to the plotting function:

[9]:
# only showing the first three event dataframes here.
for event_df in dataset.events[:3]:
    print(
        f'Showing main sequence plot for '
        f'text {event_df[0, "text_id"]}, '
        f'page {event_df[0, "page_id"]}:')
    main_sequence_plot(event_df)
Showing main sequence plot for text 0, page 1:
../_images/tutorials_plot-main-sequence_22_1.png
Showing main sequence plot for text 0, page 2:
../_images/tutorials_plot-main-sequence_22_3.png
Showing main sequence plot for text 0, page 3:
../_images/tutorials_plot-main-sequence_22_5.png

What you have learned in this tutorial:#

  • how to prepare your data to plot a main sequence

  • how to create a main sequence plot by using main_sequence_plot