.. gallery-section: psychopy .. _eyelink_gaze_demo: Experiment example (PsychoPy): EyeLink eye-tracking starter demo ---------------------------------------------------------------- Author: Hadi Zaatiti, hadi.zaatiti@nyu.edu Description ^^^^^^^^^^^ A single PsychoPy script to get started with the EyeLink eye tracker on the MEG stimulus computer. It calibrates the tracker, shows where the participant is looking in real time, and measures how accurate the calibration is, so a new user can check the whole eye-tracking chain before writing their own experiment. It is built from SR Research's official PsychoPy Coder examples (``picture.py`` and ``GC_window.py``, psychopy-eyelink 2.2.1.1), which are kept in the repository next to it, and uses the same calibration settings as the lab's MATLAB/Psychtoolbox MGS eye-tracking task. The script runs in three steps: 1. **Camera setup and calibration.** The standard EyeLink setup screen opens on the participant screen. From the stimulus computer keyboard: ``ENTER`` shows or hides the camera image, ``C`` calibrates, ``V`` validates, ``ESC`` or ``O`` leaves the setup screen. 2. **Live gaze.** A blue dot follows the eye and an orange line shows the path it took, either as a 1.5 s fading trail or as the full path since it was last cleared. Nine reference circles mark the calibration points: look at each one and check the dot lands on it. 3. **Accuracy check.** Nine dots appear one at a time on the calibration points. For each dot the script takes the median gaze position and reports the error in degrees of visual angle, then shows a summary screen (green < 0.5°, yellow < 1°, red otherwise) with an overall GOOD / FAIR / POOR verdict. The experimenter can recalibrate and repeat from that screen. The script also has a **dummy mode** in which the mouse plays the role of the eye, so it can be tried on any computer without the tracker. If the tracker cannot be reached, the script offers to continue in dummy mode. Keys ^^^^ .. list-table:: :header-rows: 1 :widths: 25 15 60 * - Screen - Key - Action * - Camera setup - ``ENTER`` - Show / hide the camera image * - - ``C`` / ``V`` - Calibrate / validate * - - ``ESC`` or ``O`` - Leave the setup screen * - Live gaze - ``P`` - Switch between fading trail and full path * - - ``C`` - Clear the path * - - ``R`` - Recalibrate * - - ``SPACE`` - Go to the accuracy check * - Accuracy summary - ``R`` - Recalibrate and repeat the check * - - ``SPACE`` - Finish * - Anywhere - ``ESC`` - Stop the demo (the data is still saved) Calibration settings ^^^^^^^^^^^^^^^^^^^^ The calibration follows the lab's MATLAB MGS task (``mgs_meg_main...m``): - ``HV9`` calibration, with the calibration and validation points confined to the central 50% of the screen (``calibration_area_proportion = 0.5 0.5``) instead of the EyeLink default of about 88% × 83%. - Monocular tracking of the **right eye** (``binocular_enabled = NO``, ``active_eye = RIGHT``), set before calibration, with EDF and link data filtered to the right eye. - Saccade parser thresholds of 35 °/s (velocity) and 9500 °/s² (acceleration). - Mid-grey calibration target (200/255) on a dark-grey background (100/255), 1% of the screen width. - Screen geometry used for the degree conversion: 65 cm wide screen, eyes 56.5 cm from the screen centre (the MEG-room measurements). All of these are set at the top of the script: .. literalinclude:: /../../experiments/psychopy/eyetracker_demo_scripts/meg_stimulus_computer_tested/eyelink_gaze_demo.py :language: python :start-after: # SETTINGS - adjust these for your setup :end-before: MISSING = getattr Running the demo ^^^^^^^^^^^^^^^^ 1. Install the dependencies, either PsychoPy Standalone with the EyeLink plugin (*Tools > Plugins / packages manager*), or a conda environment created from the ``environment.yml`` next to the script (``conda env create -f environment.yml``). It installs ``psychopy``, ``psychopy-eyelink``, ``psychopy-eyelink-coregraphics`` and ``sr-research-pylink``. 2. Turn on the EyeLink Host PC and make sure it is showing the EyeLink software. The stimulus computer's tracker network port should be ``100.1.1.2`` / ``255.255.255.0``; the Host PC is ``100.1.1.1``. 3. Run ``eyelink_gaze_demo.py`` (PsychoPy Coder or VS Code with the PsychoPy environment). 4. In the start dialog, enter an EDF file name (8 characters max, letters / numbers / ``_``), leave *Dummy mode* unticked, and choose the **participant screen**. The dialog lists every screen with its index, resolution and position; the default is screen 1, as in the lab's other PsychoPy scripts. .. note:: The EyeLink setup screen reads keys through the PsychoPy window. When the window opens full screen on the second (participant) screen it may not have keyboard focus, and ``ENTER`` / ``C`` then go to whatever window does (for example the VS Code terminal). The script gives the window focus when it opens, and the instruction screen before the setup screen reads ``SPACE`` the same way: if ``SPACE`` does nothing there, click once on the participant screen. Output ^^^^^^ Each run creates ``results/_/`` next to the script, containing: - ``.EDF``: the full-rate EyeLink recording, copied from the Host PC when the demo exits. Open it in Data Viewer, or convert it with ``edf2asc`` and load it in MNE with ``mne.io.read_raw_eyelink("file.asc")``. - ``_gaze_samples.csv``: gaze during the live-gaze step, one row per screen frame (a convenient lower-rate copy; use the EDF for analysis). - ``_accuracy_check.csv``: target position, measured gaze and error for every accuracy-check dot. The EDF contains messages that can be used as event markers, such as ``LIVE_GAZE_START`` / ``LIVE_GAZE_END``, ``TARGET_ON ``, ``TARGET_OFF `` and ``ACCURACY_RESULT mean max deg``. The ``results/`` folder is git-ignored so participant eye-tracking data does not end up in the repository. Using it in your own experiment ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ All the tracker code is in the ``EyeLinkSession`` class of the script (``connect``, ``attach_window``, ``calibrate``, ``start_recording``, ``get_gaze``, ``message``, ``close``). Copy it into your experiment, send a ``message()`` at each stimulus onset alongside the MEG trigger, and call ``close()`` at the end to copy the EDF to the stimulus computer. Code Access ^^^^^^^^^^^ :github-file:`EyeLink gaze demo script ` :github-file:`Demo folder (script, README, environment.yml) ` :github-file:`Official SR Research PsychoPy examples ` References ^^^^^^^^^^ - `SR Research: Getting started with PsychoPy `_ - `EyeLink Developers Kit `_ - `psychopy-eyelink on PyPI `_