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.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
Let’s start by downloading and extracting our ToyDataset:
[2]:
dataset = pm.datasets.ToyDataset(root='data/')
dataset.download()
dataset.extract()
dataset.load()
Using already downloaded and verified file: data/ToyDataset/downloads/pymovements-toy-dataset.zip
100%|██████████| 20/20 [00:00<00:00, 196.66it/s]
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, 726.31it/s]
100%|██████████| 20/20 [00:00<00:00, 660.73it/s]
20it [00:00, 65.59it/s]
[3]:
| text_id | page_id | name | onset | offset | duration |
|---|---|---|---|---|---|
| i64 | i64 | str | i64 | i64 | i64 |
| 0 | 1 | "saccade" | 1988323 | 1988337 | 14 |
| 0 | 1 | "saccade" | 1988342 | 1988350 | 8 |
| 0 | 1 | "saccade" | 1988547 | 1988567 | 20 |
| 0 | 1 | "saccade" | 1988571 | 1988582 | 11 |
| 0 | 1 | "saccade" | 1988737 | 1988760 | 23 |
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.49it/s]
[4]:
| text_id | page_id | name | onset | offset | duration | peak_velocity |
|---|---|---|---|---|---|---|
| i64 | i64 | str | i64 | i64 | i64 | f64 |
| 0 | 1 | "saccade" | 1988323 | 1988337 | 14 | 177.17595 |
| 0 | 1 | "saccade" | 1988342 | 1988350 | 8 | 189.070783 |
| 0 | 1 | "saccade" | 1988547 | 1988567 | 20 | 28.552483 |
| 0 | 1 | "saccade" | 1988571 | 1988582 | 11 | 63.075546 |
| 0 | 1 | "saccade" | 1988737 | 1988760 | 23 | 172.362192 |
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.43it/s]
[5]:
| text_id | page_id | name | onset | offset | duration | peak_velocity | amplitude | dispersion |
|---|---|---|---|---|---|---|---|---|
| i64 | i64 | str | i64 | i64 | i64 | f64 | f64 | f64 |
| 0 | 1 | "saccade" | 1988323 | 1988337 | 14 | 177.17595 | 0.162003 | 0.194267 |
| 0 | 1 | "saccade" | 1988342 | 1988350 | 8 | 189.070783 | 0.333463 | 0.379375 |
| 0 | 1 | "saccade" | 1988547 | 1988567 | 20 | 28.552483 | 0.565603 | 0.584686 |
| 0 | 1 | "saccade" | 1988571 | 1988582 | 11 | 63.075546 | 2.960966 | 3.191079 |
| 0 | 1 | "saccade" | 1988737 | 1988760 | 23 | 172.362192 | 0.476811 | 0.522859 |
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()