MCPcopy
hub / github.com/mne-tools/mne-python / convert_units

Function convert_units

mne/preprocessing/eyetracking/eyetracking.py:156–267  ·  view source on GitHub ↗

Convert Eyegaze data from pixels to radians of visual angle or vice versa. .. warning:: Currently, depending on the units (pixels or radians), eyegaze channels may not be reported correctly in visualization functions like :meth:`mne.io.Raw.plot`. They will be shown corr

(inst, calibration, to="radians")

Source from the content-addressed store, hash-verified

154
155
156def convert_units(inst, calibration, to="radians"):
157 """Convert Eyegaze data from pixels to radians of visual angle or vice versa.
158
159 .. warning::
160 Currently, depending on the units (pixels or radians), eyegaze channels may not
161 be reported correctly in visualization functions like :meth:`mne.io.Raw.plot`.
162 They will be shown correctly in :func:`mne.viz.eyetracking.plot_gaze`.
163 See :gh:`11879` for more information.
164
165 .. Important::
166 There are important considerations to keep in mind when using this function,
167 see the Notes section below.
168
169 Parameters
170 ----------
171 inst : instance of Raw, Epochs, or Evoked
172 The Raw, Epochs, or Evoked instance with eyegaze channels.
173 calibration : Calibration
174 Instance of Calibration, containing information about the screen size
175 (in meters), viewing distance (in meters), and the screen resolution
176 (in pixels).
177 to : str
178 Must be either ``"radians"`` or ``"pixels"``, indicating the desired unit.
179
180 Returns
181 -------
182 inst : same type as the input data
183 The Raw, Epochs, or Evoked instance, modified in place.
184
185 Notes
186 -----
187 There are at least two important considerations to keep in mind when using this
188 function:
189
190 1. Converting between on-screen pixels and visual angle is not a linear
191 transformation. If the visual angle subtends less than approximately ``.44``
192 radians (``25`` degrees), the conversion could be considered to be approximately
193 linear. However, as the visual angle increases, the conversion becomes
194 increasingly non-linear. This may lead to unexpected results after converting
195 between pixels and visual angle.
196
197 * This function assumes that the head is fixed in place and aligned with the center
198 of the screen, such that gaze to the center of the screen results in a visual
199 angle of ``0`` radians.
200
201 .. versionadded:: 1.7
202 """
203 _validate_type(inst, (BaseRaw, BaseEpochs, Evoked), "inst")
204 _validate_type(calibration, Calibration, "calibration")
205 _check_option("to", to, ("radians", "pixels"))
206 _check_calibration(calibration)
207
208 # get screen parameters
209 screen_size = calibration["screen_size"]
210 screen_resolution = calibration["screen_resolution"]
211 dist = calibration["screen_distance"]
212
213 # loop through channels and convert units

Callers

nothing calls this directly

Calls 8

_validate_typeFunction · 0.85
_check_optionFunction · 0.85
_check_calibrationFunction · 0.85
warnFunction · 0.85
infoMethod · 0.80
apply_functionMethod · 0.45
appendMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected