r"""
.. _tut-importing-eyetracking-data:
=======================================
Importing Data from Eyetracking devices
=======================================
Eyetracking devices record a persons point of gaze, usually in relation to a
screen. Typically, gaze position (also referred to as eye or pupil position)
and pupil size are recorded as separate channels. This section describes how to
read data from supported eyetracking manufacturers.
MNE-Python provides functions for reading eyetracking data. When possible,
MNE-Python will internally convert and store eyetracking data according to an
SI unit (for example radians for position data, and meters for pupil size).
.. note:: If you have eye tracking data in a format that MNE does not support
yet, you can try reading it using other tools and create an MNE
object from a numpy array. Then you can use
:func:`mne.preprocessing.eyetracking.set_channel_types_eyetrack`
to assign the correct eyetrack channel types.
.. seealso:: Some MNE functions may not be available to eyetracking and other
physiological data, because MNE does not consider them to be data
channels. See the :ref:`glossary` for more information.
.. _import-eyelink_asc:
SR Research (Eyelink) (.asc)
============================
.. note:: MNE-Python currently only supports reading Eyelink eyetracking data
stored in the ASCII (.asc) format.
Eyelink recordings are stored in the Eyelink Data Format (EDF; .edf), which are
binary files and thus relatively complex to support. To make the data in EDF
files accessible, Eyelink provides the application EDF2ASC, which converts EDF
files to a plain text ASCII format (.asc). These files can be imported
into MNE using :func:`mne.io.read_raw_eyelink`.
.. note:: The Eyelink Data Format (EDF), should not be confused
with the European Data Format, the common EEG data format that also
uses the .edf extension.
Supported measurement types from Eyelink files include eye position, pupil
size, saccadic velocity, resolution, and head position (for recordings
collected in remote mode). Eyelink files often report ocular events (blinks,
saccades, and fixations), MNE will store these events as `mne.Annotations`.
Blink annotation descriptions will be ``'BAD_blink'``. For more information
on the various measurement types that can be present in Eyelink files. read below.
Eye Position Data
-----------------
Eyelink samples can report eye position data in pixels, units of visual
degrees, or as raw pupil coordinates. Samples are written as (x, y) coordinate
pairs (or two pairs for binocular data). The type of position data present in
an ASCII file will be detected automatically by MNE. The three types of
position data are explained below.
Gaze
^^^^
Gaze position data report the estimated (x, y) pixel coordinates of the
participants's gaze on the stimulus screen, compensating for head position
changes and distance from the screen. This datatype may be preferable if you
are interested in knowing where the participant was looking at on the stimulus
screen. The default (0, 0) location for Eyelink systems is at the top left of
the screen.
This may be best demonstrated with an example. In the file plotted below,
eyetracking data was recorded while the participant read text on a display.
In this file, as the participant read the each line from left to right, the
x-coordinate increased. When the participant moved their gaze down to read a
new line, the y-coordinate *increased*, which is why the ``ypos_right`` channel
in the plot below increases over time (for example, at about 4-seconds, and
at about 8-seconds).
.. seealso::
:ref:`tut-eyetrack`
"""
import mne
fpath = mne.datasets.misc.data_path() / "eyetracking" / "eyelink"
fname = fpath / "px_textpage_ws.asc"
raw = mne.io.read_raw_eyelink(fname, create_annotations=["blinks"])
cal = mne.preprocessing.eyetracking.read_eyelink_calibration(
fname,
screen_distance=0.7,
screen_size=(0.53, 0.3),
screen_resolution=(1920, 1080),
)[0]
mne.preprocessing.eyetracking.convert_units(raw, calibration=cal, to="radians")
cal.plot()
custom_scalings = dict(pupil=1e3)
raw.pick(picks="eyetrack").plot(scalings=custom_scalings)
fpath = mne.datasets.misc.data_path() / "eyetracking" / "eyelink"
fname_href = fpath / "HREF_textpage_ws.asc"
raw = mne.io.read_raw_eyelink(fname_href, create_annotations=["blinks"])
custom_scalings = dict(pupil=1e3)
raw.pick(picks="eyetrack").plot(scalings=custom_scalings)