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.22.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()
INFO:pymovements.dataset.dataset:        You are downloading the pymovements Toy Dataset. Please be aware that pymovements does not
        host or distribute any dataset resources and only provides a convenient interface to
        download the public dataset resources that were published by their respective authors.

        Please cite the referenced publication if you intend to use the dataset in your research.

Using already downloaded and verified file: data/ToyDataset/downloads/pymovements-toy-dataset.zip
Extracting pymovements-toy-dataset.zip to data/ToyDataset/raw
100%|██████████| 23/23 [00:00<00:00, 309.70it/s]
100%|██████████| 20/20 [00:00<00:00, 65.74it/s]
[2]:
Dataset
  • DatasetDefinition
    DatasetDefinition
    • None
      None
    • dict (0 items)
      • dict (1 items)
        • dict (4 items)
          • list (5 items)
            • 'timestamp'
            • 'x'
            • (3 more)
          • dict (5 items)
            • Float64
              Float64
            • Float64
              Float64
            • (3 more)
          • (2 more)
      • None
        None
      • Experiment
        Experiment
        • EyeTracker
          EyeTracker
          • None
            None
          • None
            None
          • None
            None
          • None
            None
          • 1000
            1000
          • None
            None
          • None
            None
        • 1000
          1000
        • Screen
          Screen
          • 68
            68
          • 30.2
            30.2
          • 1024
            1024
          • 'upper left'
            'upper left'
          • 38
            38
          • 1280
            1280
          • 15.599386487782953
            15.599386487782953
          • -15.599386487782953
            -15.599386487782953
          • 12.508044410882546
            12.508044410882546
          • -12.508044410882546
            -12.508044410882546
      • dict (1 items)
        • True
          True
      • dict (1 items)
        • 'trial_{text_id:d}_{page_id:d}.csv'
          'trial_{text_id:d}_{page_id:d}.csv'
      • dict (1 items)
        • dict (2 items)
          • <class 'int'>
            <class 'int'>
          • <class 'int'>
            <class 'int'>
      • dict (3 items)
        • True
          True
        • False
          False
        • (1 more)
      • 'pymovements Toy Dataset'
        'pymovements Toy Dataset'
      • dict (0 items)
        • 'ToyDataset'
          'ToyDataset'
        • list (2 items)
          • 'x'
          • 'y'
        • None
          None
        • dict (1 items)
          • list (1 items)
              • str
                'http://github.com/aeye-lab/pymovements-toy-dataset/zipball/6cb5d663317bf418cec0c9abe1dde5085a8a8ebd/'
              • 'pymovements-toy-dataset.zip'
                'pymovements-toy-dataset.zip'
              • (1 more)
        • 'timestamp'
          'timestamp'
        • 'ms'
          'ms'
        • None
          None
        • None
          None
      • list (0 items)
        • dict (1 items)
          • DataFrame (3 columns, 20 rows)
            shape: (20, 3)
            text_idpage_idfilepath
            i64i64str
            01"aeye-lab-pymovements-toy-datas…
            02"aeye-lab-pymovements-toy-datas…
            03"aeye-lab-pymovements-toy-datas…
            04"aeye-lab-pymovements-toy-datas…
            05"aeye-lab-pymovements-toy-datas…
            31"aeye-lab-pymovements-toy-datas…
            32"aeye-lab-pymovements-toy-datas…
            33"aeye-lab-pymovements-toy-datas…
            34"aeye-lab-pymovements-toy-datas…
            35"aeye-lab-pymovements-toy-datas…
        • list (20 items)
          • GazeDataFrame
            • DataFrame (6 columns, 17223 rows)
              shape: (17_223, 6)
              timestimuli_xstimuli_ytext_idpage_idpixel
              i64f64f64i64i64list[f64]
              1988145-1.0-1.001[206.8, 152.4]
              1988146-1.0-1.001[206.9, 152.1]
              1988147-1.0-1.001[207.0, 151.8]
              1988148-1.0-1.001[207.1, 151.7]
              1988149-1.0-1.001[207.0, 151.5]
              2005363-1.0-1.001[361.0, 415.4]
              2005364-1.0-1.001[358.0, 414.5]
              2005365-1.0-1.001[355.8, 413.8]
              2005366-1.0-1.001[353.1, 413.2]
              2005367-1.0-1.001[351.2, 412.9]
            • EventDataFrame
              EventDataFrame
              • DataFrame (6 columns, 0 rows)
                shape: (0, 6)
                text_idpage_idnameonsetoffsetduration
                i64i64stri64i64i64
              • list (2 items)
                • 'text_id'
                • 'page_id'
            • list (2 items)
              • 'text_id'
              • 'page_id'
            • Experiment
              Experiment
              • EyeTracker
                EyeTracker
                • None
                  None
                • None
                  None
                • None
                  None
                • None
                  None
                • 1000
                  1000
                • None
                  None
                • None
                  None
              • 1000
                1000
              • Screen
                Screen
                • 68
                  68
                • 30.2
                  30.2
                • 1024
                  1024
                • 'upper left'
                  'upper left'
                • 38
                  38
                • 1280
                  1280
                • 15.599386487782953
                  15.599386487782953
                • -15.599386487782953
                  -15.599386487782953
                • 12.508044410882546
                  12.508044410882546
                • -12.508044410882546
                  -12.508044410882546
          • GazeDataFrame
            • DataFrame (6 columns, 29799 rows)
              shape: (29_799, 6)
              timestimuli_xstimuli_ytext_idpage_idpixel
              i64f64f64i64i64list[f64]
              2008305-1.0-1.002[141.4, 153.6]
              2008306-1.0-1.002[141.1, 153.2]
              2008307-1.0-1.002[140.7, 152.8]
              2008308-1.0-1.002[140.6, 152.7]
              2008309-1.0-1.002[140.5, 152.6]
              2038099-1.0-1.002[273.8, 773.8]
              2038100-1.0-1.002[273.8, 774.1]
              2038101-1.0-1.002[273.9, 774.5]
              2038102-1.0-1.002[274.0, 774.4]
              2038103-1.0-1.002[274.0, 773.9]
            • EventDataFrame
              EventDataFrame
              • DataFrame (6 columns, 0 rows)
                shape: (0, 6)
                text_idpage_idnameonsetoffsetduration
                i64i64stri64i64i64
              • list (2 items)
                • 'text_id'
                • 'page_id'
            • list (2 items)
              • 'text_id'
              • 'page_id'
            • Experiment
              Experiment
              • EyeTracker
                EyeTracker
                • None
                  None
                • None
                  None
                • None
                  None
                • None
                  None
                • 1000
                  1000
                • None
                  None
                • None
                  None
              • 1000
                1000
              • Screen
                Screen
                • 68
                  68
                • 30.2
                  30.2
                • 1024
                  1024
                • 'upper left'
                  'upper left'
                • 38
                  38
                • 1280
                  1280
                • 15.599386487782953
                  15.599386487782953
                • -15.599386487782953
                  -15.599386487782953
                • 12.508044410882546
                  12.508044410882546
                • -12.508044410882546
                  -12.508044410882546
          • (18 more)
        • PosixPath('data/ToyDataset')
          PosixPath('data/ToyDataset')
        • DatasetPaths
          DatasetPaths
          • PosixPath('data/ToyDataset')
            PosixPath('data/ToyDataset')
          • PosixPath('data/ToyDataset/downloads')
            PosixPath('data/ToyDataset/downloads')
          • PosixPath('data/ToyDataset/events')
            PosixPath('data/ToyDataset/events')
          • PosixPath('data/ToyDataset/precomputed_events')
            PosixPath('data/ToyDataset/precomputed_events')
          • PosixPath
            PosixPath('data/ToyDataset/precomputed_reading_measures')
          • PosixPath('data/ToyDataset/preprocessed')
            PosixPath('data/ToyDataset/preprocessed')
          • PosixPath('data/ToyDataset/raw')
            PosixPath('data/ToyDataset/raw')
          • PosixPath('data/ToyDataset')
            PosixPath('data/ToyDataset')
        • list (0 items)
          • list (0 items)

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

            [3]:
            
            dataset.pix2deg()
            dataset.pos2vel('smooth')
            
            dataset.detect_events('microsaccades')
            
            dataset.events[0]
            
            100%|██████████| 20/20 [00:00<00:00, 33.10it/s]
            100%|██████████| 20/20 [00:00<00:00, 67.79it/s]
            20it [00:00, 77.69it/s]
            
            [3]:
            
            EventDataFrame
            • DataFrame (6 columns, 142 rows)
              shape: (142, 6)
              text_idpage_idnameonsetoffsetduration
              i64i64stri64i64i64
              01"saccade"1988323198833714
              01"saccade"198834219883508
              01"saccade"1988547198856720
              01"saccade"1988571198858211
              01"saccade"1988737198876023
              01"saccade"2005110200512616
              01"saccade"2005128200513810
              01"saccade"2005288200534557
              01"saccade"200534720053569
              01"saccade"200535920053656
            • list (2 items)
              • 'text_id'
              • 'page_id'

            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]
            
            100%|██████████| 20/20 [00:02<00:00,  9.80it/s]
            
            [4]:
            
            EventDataFrame
            • DataFrame (7 columns, 142 rows)
              shape: (142, 7)
              text_idpage_idnameonsetoffsetdurationpeak_velocity
              i64i64stri64i64i64f64
              01"saccade"1988323198833714129.856451
              01"saccade"19883421988350850.527286
              01"saccade"1988547198856720200.144558
              01"saccade"198857119885821156.048003
              01"saccade"1988737198876023249.67823
              01"saccade"2005110200512616137.917594
              01"saccade"200512820051381061.197926
              01"saccade"2005288200534557352.550667
              01"saccade"20053472005356985.484987
              01"saccade"20053592005365666.68761
            • list (2 items)
              • 'text_id'
              • 'page_id'

            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]
            
            100%|██████████| 20/20 [00:02<00:00,  8.15it/s]
            
            [5]:
            
            EventDataFrame
            • DataFrame (9 columns, 142 rows)
              shape: (142, 9)
              text_idpage_idnameonsetoffsetdurationpeak_velocityamplitudedispersion
              i64i64stri64i64i64f64f64f64
              01"saccade"1988323198833714129.8564511.2367411.277295
              01"saccade"19883421988350850.5272860.3307480.367263
              01"saccade"1988547198856720200.1445582.3911842.527725
              01"saccade"198857119885821156.0480030.4768110.522859
              01"saccade"1988737198876023249.678233.2851153.471233
              01"saccade"2005110200512616137.9175941.4053541.501217
              01"saccade"200512820051381061.1979260.440980.534678
              01"saccade"2005288200534557352.55066714.68254116.101153
              01"saccade"20053472005356985.4849870.6298610.737591
              01"saccade"20053592005365666.687610.3682680.469185
            • list (2 items)
              • 'text_id'
              • 'page_id'

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