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]:
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 [03:03, 9.15s/it]
[4]:
text_id | page_id | name | onset | offset | duration | peak_velocity |
---|---|---|---|---|---|---|
i64 | i64 | str | i64 | i64 | i64 | f32 |
0 | 1 | "saccade" | 1988323 | 1988337 | 14 | 129.856674 |
0 | 1 | "saccade" | 1988342 | 1988350 | 8 | 50.527161 |
0 | 1 | "saccade" | 1988547 | 1988567 | 20 | 200.144379 |
0 | 1 | "saccade" | 1988571 | 1988582 | 11 | 56.048248 |
0 | 1 | "saccade" | 1988737 | 1988760 | 23 | 249.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]:
text_id | page_id | name | onset | offset | duration | peak_velocity | amplitude | dispersion |
---|---|---|---|---|---|---|---|---|
i64 | i64 | str | i64 | i64 | i64 | f32 | f32 | f32 |
0 | 1 | "saccade" | 1988323 | 1988337 | 14 | 129.856674 | 1.236741 | 1.277296 |
0 | 1 | "saccade" | 1988342 | 1988350 | 8 | 50.527161 | 0.330749 | 0.367264 |
0 | 1 | "saccade" | 1988547 | 1988567 | 20 | 200.144379 | 2.391184 | 2.527725 |
0 | 1 | "saccade" | 1988571 | 1988582 | 11 | 56.048248 | 0.476812 | 0.522859 |
0 | 1 | "saccade" | 1988737 | 1988760 | 23 | 249.678116 | 3.285114 | 3.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()