Computing Event Properties#

What you will learn in this tutorial:#

  • how to add event properties for peak velocity and amplitude

Preparations#

We import pymovements as the alias pm for convenience.

[1]:
import pymovements as pm
/home/docs/checkouts/readthedocs.org/user_builds/pymovements/envs/v0.16.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

Let’s start by downloading our ToyDataset and loading in its data:

[2]:
dataset = pm.Dataset('ToyDataset', path='data/ToyDataset')
dataset.download()
dataset.load()
Using already downloaded and verified file: data/ToyDataset/downloads/pymovements-toy-dataset.zip
Extracting pymovements-toy-dataset.zip to data/ToyDataset/raw
100%|██████████| 20/20 [00:00<00:00, 46.22it/s]
[2]:
<pymovements.dataset.dataset.Dataset at 0x7f68811d8f70>

Now let’s do some basic preprocessing and detect some saccades:

[3]:
dataset.pix2deg()
dataset.pos2vel('smooth')

dataset.detect_events('microsaccades')

dataset.events[0].frame.head()
100%|██████████| 20/20 [00:00<00:00, 22.83it/s]
100%|██████████| 20/20 [00:00<00:00, 48.70it/s]
20it [00:00, 21.42it/s]
[3]:
shape: (5, 6)
nameonsetoffsetdurationtext_idpage_id
stri64i64i64i64i64
"saccade"198832319883371401
"saccade"19883421988350801
"saccade"198854719885672001
"saccade"198857119885821101
"saccade"198873719887602301

Computing Event Properties#

pymovements provides a range of event properties.

See the reference for pymovements.events to get an overview of all the supported properties.

For this tutorial we will compute several properties of saccades.

We start out with the peak velocity:

[4]:
dataset.compute_event_properties("peak_velocity")

dataset.events[0].frame.head()
20it [00:22,  1.12s/it]
[4]:
shape: (5, 7)
nameonsetoffsetdurationtext_idpage_idpeak_velocity
stri64i64i64i64i64f64
"saccade"198832319883371401129.856451
"saccade"1988342198835080150.527286
"saccade"198854719885672001200.144558
"saccade"19885711988582110156.048003
"saccade"198873719887602301249.67823

We notice that a new column with the name peak_velocity has appeared in the event dataframe.

We can also pass a list of properties. Let’s add the amplitude and dispersion:

[5]:
dataset.compute_event_properties(["amplitude", "dispersion"])

dataset.events[0].frame.head()
20it [00:22,  1.14s/it]
[5]:
shape: (5, 9)
nameonsetoffsetdurationtext_idpage_idpeak_velocityamplitudedispersion
stri64i64i64i64i64f64f64f64
"saccade"198832319883371401129.8564511.2367411.277295
"saccade"1988342198835080150.5272860.3307480.367263
"saccade"198854719885672001200.1445582.3911842.527725
"saccade"19885711988582110156.0480030.4768110.522859
"saccade"198873719887602301249.678233.2851153.471233

This way we can compute all of our desired properties in a single run.

What you have learned in this tutorial:#

  • how to compute event properties by using Dataset.compute_event_properties()