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/stable/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, 20.47it/s]
[2]:
<pymovements.dataset.dataset.Dataset at 0x7f14f6e9f8b0>

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:01<00:00, 10.52it/s]
100%|██████████| 20/20 [00:01<00:00, 19.41it/s]
20it [00:00, 24.93it/s]
[3]:
shape: (5, 6)
text_idpage_idnameonsetoffsetduration
i64i64stri64i64i64
01"saccade"1988323198833714
01"saccade"198834219883508
01"saccade"1988547198856720
01"saccade"1988571198858211
01"saccade"1988737198876023

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 [03:03,  9.15s/it]
[4]:
shape: (5, 7)
text_idpage_idnameonsetoffsetdurationpeak_velocity
i64i64stri64i64i64f32
01"saccade"1988323198833714129.856674
01"saccade"19883421988350850.527161
01"saccade"1988547198856720200.144379
01"saccade"198857119885821156.048248
01"saccade"1988737198876023249.678116

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 [03:02,  9.11s/it]
[5]:
shape: (5, 9)
text_idpage_idnameonsetoffsetdurationpeak_velocityamplitudedispersion
i64i64stri64i64i64f32f32f32
01"saccade"1988323198833714129.8566741.2367411.277296
01"saccade"19883421988350850.5271610.3307490.367264
01"saccade"1988547198856720200.1443792.3911842.527725
01"saccade"198857119885821156.0482480.4768120.522859
01"saccade"1988737198876023249.6781163.2851143.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()