{ "cells": [ { "cell_type": "markdown", "id": "61b1b919", "metadata": {}, "source": [ "# Event-related pupil dilations\n", "\n", "We are often interested in how the pupil responds to certain events, for example stimuli. One method to investigate this is to extract the average pupil dilation surrounding the events of interest (event-related pupil dilation, ERPD).\n", "\n", "In `pypillometry`, this works in two steps:\n", "\n", "1. `get_epochs()` selects the events and defines a time window around each of them\n", "2. `get_segments()` cuts the data in these windows into a `SegmentedEyeData` object; its pupil methods (`.pupil`) baseline-correct and plot the segments, and they can be averaged across subjects" ] }, { "cell_type": "code", "execution_count": 1, "id": "c5ccd4de", "metadata": { "execution": { "iopub.execute_input": "2026-11-10T13:34:46.735593Z", "iopub.status.busy": "2026-11-10T13:34:46.735172Z", "iopub.status.idle": "2026-11-10T13:34:47.243565Z", "shell.execute_reply": "2026-11-10T13:34:47.242506Z" } }, "outputs": [], "source": [ "import pypillometry as pp\n", "from pypillometry import u\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "ca234d3f", "metadata": {}, "source": [ "Here, we use the EDF file from the [import](importdata_edf.ipynb) examples, which is stored in the `data` folder of the repository." ] }, { "cell_type": "code", "execution_count": 2, "id": "38a5f333", "metadata": { "execution": { "iopub.execute_input": "2026-11-10T13:34:47.246950Z", "iopub.status.busy": "2026-11-10T13:34:47.246662Z", "iopub.status.idle": "2026-11-10T13:35:01.419782Z", "shell.execute_reply": "2026-11-10T13:35:01.419370Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32mpp: 14:34:47\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36m_read_edf\u001b[0m:\u001b[36m730\u001b[0m | \u001b[1mLoading EDF file: ../../data/test.edf (current log level: INFO, set to DEBUG to see eyelinkio output)\u001b[0m\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32mpp: 14:35:01\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mfrom_eyelink\u001b[0m:\u001b[36m1639\u001b[0m | \u001b[1mFiltering out Eyelink triggers\u001b[0m\n" ] }, { "data": { "text/html": [ "
EyeDataDict(vars=6,n=1245363,shape=(1245363,)): \n",
" left_x (float64): 817.3, 817.0, 816.7, 816.7, 816.7...\n",
" left_y (float64): 345.2, 343.5, 341.6, 340.4, 340.2...\n",
" left_pupil (float64): 1707.0, 1706.0, 1705.0, 1706.0, 1707.0...\n",
" right_x (float64): 860.6, 860.7, 861.2, 861.7, 861.6...\n",
" right_y (float64): 375.2, 375.9, 376.6, 376.8, 376.9...\n",
" right_pupil (float64): 1738.0, 1739.0, 1739.0, 1740.0, 1742.0...\n",
"\n",
" Epochs 'C_' | 400 epochs, window (-500, 2000) ms\n", "
| \n", " | Onset (ms) | \n", "Label | \n", "cond | \n", "block | \n", "trial | \n", "
|---|---|---|---|---|---|
| 0 | \n", "1345.0 | \n", "C_GW_1_1_UD_UD | \n", "GW | \n", "1.0 | \n", "1.0 | \n", "
| 1 | \n", "6859.0 | \n", "C_NW_1_2_UD_UD | \n", "NW | \n", "1.0 | \n", "2.0 | \n", "
| 2 | \n", "12074.0 | \n", "C_NA_1_3_UD_UD | \n", "NA | \n", "1.0 | \n", "3.0 | \n", "
| 3 | \n", "17306.0 | \n", "C_GA_1_4_UD_UD | \n", "GA | \n", "1.0 | \n", "4.0 | \n", "
| 4 | \n", "22487.0 | \n", "C_GA_1_5_UD_UD | \n", "GA | \n", "1.0 | \n", "5.0 | \n", "
Total: 5 events
" ], "text/plain": [ "Events: 5 events | units=ms | meta=[cond, block, trial]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ev = d.events.parse_labels(r\"^C_(?P