Skip to content

Commit db089c9

Browse files
flying-spagettipre-commit-ci[bot]larsonerscott-huberty
authored
FIX: Set calibration plot axes to screen resolution if available (#13558)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <larson.eric.d@gmail.com> Co-authored-by: Scott Huberty <seh33@uw.edu>
1 parent 9f784fa commit db089c9

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

doc/changes/dev/13558.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix axis limits in :meth:`mne.preprocessing.eyetracking.Calibration.plot` to use screen resolution if available, by :newcontrib:`Gnaneswar Lopinti`.

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
.. _Gennadiy Belonosov: https://github.com/Genuster
107107
.. _Geoff Brookshire: https://github.com/gbrookshire
108108
.. _George O'Neill: https://georgeoneill.github.io
109+
.. _Gnaneswar Lopinti: https://github.com/flying-spagetti
109110
.. _Gonzalo Reina: https://orcid.org/0000-0003-4219-2306
110111
.. _Guillaume Dumas: https://mila.quebec/en/person/guillaume-dumas
111112
.. _Guillaume Favelier: https://github.com/GuillaumeFavelier

mne/preprocessing/eyetracking/calibration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ def plot(self, show_offsets=True, axes=None, show=True):
169169

170170
# Invert y-axis because the origin is in the top left corner
171171
ax.invert_yaxis()
172+
if self["screen_resolution"] is not None:
173+
w, h = self["screen_resolution"]
174+
ax.set_xlim(0, w)
175+
ax.set_ylim(h, 0)
172176
ax.scatter(px, py, color="gray")
173177
ax.scatter(gaze_x, gaze_y, color="red", alpha=0.5)
174178

tutorials/preprocessing/90_eyetracking_data.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
# will return a list of :class:`~mne.preprocessing.eyetracking.Calibration` instances,
7575
# one for each calibration. We can index that list to access a specific calibration.
7676

77-
cals = read_eyelink_calibration(et_fpath)
77+
cals = read_eyelink_calibration(et_fpath, screen_resolution=(1920, 1080))
7878
print(f"number of calibrations: {len(cals)}")
7979
first_cal = cals[0] # let's access the first (and only in this case) calibration
8080
print(first_cal)
@@ -97,20 +97,28 @@
9797
# and the offsets (in visual degrees) between the calibration position and the actual
9898
# gaze position of each calibration point.
9999

100+
# %%
100101
first_cal.plot()
101102

103+
# %%
104+
# .. hint::
105+
# If you supply the eyetracker monitor’s screen resolution to
106+
# :class:`~mne.preprocessing.eyetracking.Calibration`,
107+
# :meth:`~mne.preprocessing.eyetracking.Calibration.plot` will automatically set the
108+
# canvas bounds accordingly.
109+
102110
# %%
103111
# Standardizing eyetracking data to SI units
104112
# ------------------------------------------
105113
#
106114
# EyeLink stores eyegaze positions in pixels, and pupil size in arbitrary units.
107115
# MNE-Python expects eyegaze positions to be in radians of visual angle, and pupil
108116
# size to be in meters. We can convert the eyegaze positions to radians using
109-
# :func:`~mne.preprocessing.eyetracking.convert_units`. We'll pass the calibration
110-
# object we created above, after specifying the screen resolution, screen size, and
111-
# screen distance.
117+
# :func:`~mne.preprocessing.eyetracking.convert_units`. In addition to the
118+
# screen resolution, we need to supply the eyetracker screen size and screen distance
119+
# to our :class:`~mne.preprocessing.eyetracking.Calibration` object, before calling the
120+
# convert units function.
112121

113-
first_cal["screen_resolution"] = (1920, 1080)
114122
first_cal["screen_size"] = (0.53, 0.3)
115123
first_cal["screen_distance"] = 0.9
116124
mne.preprocessing.eyetracking.convert_units(raw_et, calibration=first_cal, to="radians")

0 commit comments

Comments
 (0)