# eyetracking and qt browser: traces of x/y position disappear

**URL:** <https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254>\
**Category:** Support & Discussions\
**Tags:** visualization, eyetracking\
**Created:** [July 18, 2023, 1:31pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254 "2023-07-18T13:31:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sappelhoff](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sappelhoff/32/3276_2.png) [@sappelhoff](https://mne.discourse.group/u/sappelhoff)\
**Post date:** [July 18, 2023, 1:31pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/1 "2023-07-18T13:31:38Z")

</div>

- MNE version: 1.4.2
- operating system: Ubuntu 22.04 (but same issue on macOS)

I am following the tutorial on reading eyetracking data:

- [Importing Data from Eyetracking devices — MNE 1.5.1 documentation](https://mne.tools/stable/auto_tutorials/io/70_reading_eyetracking_data.html#sphx-glr-auto-tutorials-io-70-reading-eyetracking-data-py)

The first coding cell in the tutorial produces a plot like this one:

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/a/a84504330b4677d66e9c0cdde1c50a30f088cfb5.png)

I can reproduce this plot. **HOWEVER** when I start scrolling left and right in the viz browser, the traces for `xpos_right` and `ypos_right` disappear around annotation events. Even when scrolling back to exact same position as before, the traces are gone.

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/6/660efb4432097ea4610f7b61c9d5aabe5014ed6c.png)

I can replicate this on different computers (linux, macOS) and this also happens with:

- `clipping=None` and `use_opengl=False` (or `True`)
- calling `raw.set_annotations(None)` first

**What’s the issue here?** There **are** NaN in the data, but I don’t think they should lead to the observed effects.

cc @scott-huberty @mscheltienne

Here is my mne sys info:

```python
Platform Linux-5.19.0-46-generic-x86_64-with-glibc2.35
Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0]
Executable /home/stefanappelhoff/miniconda3/envs/mne/bin/python
CPU x86_64 (8 cores)
Memory 31.2 GB

Core
├☑ mne 1.4.2
├☑ numpy 1.24.4 (OpenBLAS 0.3.23 with 8 threads)
├☑ scipy 1.11.1
├☑ matplotlib 3.7.2 (backend=module://matplotlib_inline.backend_inline)
├☑ pooch 1.7.0
└☑ jinja2 3.1.2

Numerical (optional)
├☑ sklearn 1.3.0
├☑ numba 0.57.1
├☑ nibabel 5.1.0
├☑ nilearn 0.10.1
├☑ dipy 1.7.0
├☑ openmeeg 2.5.6
├☑ pandas 2.0.3
└☐ unavailable cupy

Visualization (optional)
├☑ pyvista 0.40.1 (OpenGL 4.6 (Core Profile) Mesa 22.2.5-0ubuntu0.1~22.04.3 via Mesa Intel(R) UHD Graphics 620 (KBL GT2))

```

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [July 18, 2023, 1:50pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/2 "2023-07-18T13:50:43Z")

</div>

That’s an interesting one, maybe `nan` interfering with the `qt` browser. It’s not the case with the `matplotlib` backend. Looking into it now.

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [July 18, 2023, 2:04pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/3 "2023-07-18T14:04:58Z")

</div>

Hi @sappelhoff ,

Thanks for looking at the tutorial and for raising this! It makes me feel better having more devs look at the eye-tracking stuff we’ve built so far.

As @mscheltienne mentioned, For me, the issue where the NaN’s cause the traces to disappear only occurs when using `mne-qt-browser`. If I use the matplotlib browser, I can’ replicate the issue:

```python
import mne
from mne.datasets import misc

mne.viz.set_browser_backend("matplotlib")
fpath = misc.data_path() / "eyetracking" / "eyelink"
raw = read_raw_eyelink(fpath / "px_textpage_ws.asc", create_annotations=["blinks"])

custom_scalings = dict(eyegaze=1e3)
raw.plot(scaling=custom_scalings)

```

 ![Screen Shot 2023-07-18 at 9.52.58 AM](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/1/1f4eb1af2cc2632435d0808122e2a5ac559fcc21.png)

I wonder if this has something to do with a filter being applied to the plotted data (and the Nans causing issues with the filter)?

More generally, I was speaking with @drammock and @britta-wstnr on Friday about the issue of `NaN`’s in eye-tracking data. Correct me if I’m wrong but it seems to me that up until now, MNE has been able to expect that incoming data is dense (no missing values). Having NaN’s in the data causes issues in a number of MNE functions (filtering, resamping, etc).

I was tasked with opening a ticket about this (which I still need to do!), so that the devs can weigh in on the best path forward. I was also hoping to share an example file with this issue during the next MNE office hours, to demonstrate the issue.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [July 18, 2023, 2:38pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/4 "2023-07-18T14:38:55Z")

</div>

In the end barely had time to look for now, but if you do `raw.plot(scalings=custom_scalings, precompute=False)` it works. That should already narrow down the issue.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [July 18, 2023, 3:13pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/5 "2023-07-18T15:13:49Z")

</div>

That PR should fix it: [Fix removal of DC on precomputed data when nan's are present in the array by mscheltienne · Pull Request #176 · mne-tools/mne-qt-browser · GitHub](https://github.com/mne-tools/mne-qt-browser/pull/176)

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [July 19, 2023, 1:55pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/6 "2023-07-19T13:55:27Z")

</div>

Thanks!

I wonder if we should eventually add some code to prevent the DC-offset adjustment from being applied to eye-track channels? I don’t think it applies here. If you all agree I can open a ticket and take a look into it.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [July 19, 2023, 4:38pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/7 "2023-07-19T16:38:56Z")

</div>

I was thinking about it yesterday, should we actually remove DC-offset from non voltage-based channels (extending beyong eye-tracking)? I convinced myself that it was safe to do in all cases since it would _not alter the waveform shape_.  
But I’m questionning this again as eye-tracking position, if e.g. in pixels, should retain the orignal values; else DC removal is synonym of silently changing the origin location. And I wonder if the same logic applies to other channels types which should _not_ have their mean removed prior to plotting.

On the otherhand, I would not be surprised if the y-range defined for plotting is centered around 0 and that plotting non centered data would end up creating issues, e.g. clipping or data outside the y-range.

---

<div class="post-metadata">

**Author:** ![britta-wstnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/britta-wstnr/32/3538_2.png) [@britta-wstnr](https://mne.discourse.group/u/britta-wstnr)\
**Post date:** [July 19, 2023, 5:04pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/8 "2023-07-19T17:04:31Z")

</div>

I don’t think eye tracking data like gaze should be “DC offset corrected”.  
BTW, should we move this conversation over to a GitHub issue so we can more easily find it in the future in case we want to look back at some point?

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [July 19, 2023, 7:34pm UTC](https://mne.discourse.group/t/eyetracking-and-qt-browser-traces-of-x-y-position-disappear/7254/9 "2023-07-19T19:34:28Z")

</div>

Sure, I will open a ticket!
