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.10.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
100%|██████████| 20/20 [00:00<00:00, 202.25it/s]
[2]:
<pymovements.dataset.dataset.Dataset at 0x7f36a463a7f0>

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

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

dataset.detect_events(pm.events.microsaccades)

dataset.events[0].frame.head()
100%|██████████| 20/20 [00:00<00:00, 784.99it/s]
100%|██████████| 20/20 [00:00<00:00, 657.55it/s]
20it [00:00, 73.80it/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 [00:13,  1.52it/s]
[4]:
shape: (5, 7)
text_idpage_idnameonsetoffsetdurationpeak_velocity
i64i64stri64i64i64f64
01"saccade"198832319883371451.184996
01"saccade"198834219883508202.367951
01"saccade"198854719885672056.535391
01"saccade"1988571198858211250.889337
01"saccade"198873719887602331.723029

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:13,  1.46it/s]
[5]:
shape: (5, 9)
text_idpage_idnameonsetoffsetdurationpeak_velocityamplitudedispersion
i64i64stri64i64i64f64f64f64
01"saccade"198832319883371451.1849961.2520961.292118
01"saccade"198834219883508202.3679510.3350180.37109
01"saccade"198854719885672056.5353912.4167162.551492
01"saccade"1988571198858211250.8893370.4809820.526459
01"saccade"198873719887602331.7230293.3040353.487752

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()