Skip to content

read_raw_eyelink() cannot handle empty first trial #13550

Open

Description

@Cathaway

Description of the problem

In some experiments we start with a few practice trials that will be excluded from analysis, in some cases we put them outside the usual trial loop and has no calibration stage for them

read_raw_eyelink cannot handle these empty trials and will throw a ValueError because it cannot find eyetracking channels to parse annotations with

I know this looks pretty stupid and doesn't really look like a bug - but unexpected data format - though it'd be nice if read_raw_eyelink() can handle cases like these

Steps to reproduce

the problematic Eyelink files start with trials like these

START	1211913 	RIGHT	SAMPLES	EVENTS
PRESCALER	1
VPRESCALER	1
PUPIL	DIAMETER
EVENTS	GAZE	RIGHT	RATE	1000.00	TRACKING	CR	FILTER	1
SAMPLES	GAZE	RIGHT	RATE	1000.00	TRACKING	CR	FILTER	1	INPUT
INPUT	1211913	127
1211913	   .	   .	    0.0	  127.0	...
SSACC R  1211914
SBLINK R 1211914
1211914	   .	   .	    0.0	  127.0	...
1211915	   .	   .	    0.0	  127.0	...
1211916	   .	   .	    0.0	  127.0	...
MSG	1211917 TRIAL 1 STARTS
MSG	1211917 FIXATION START
MSG	1211917 pre 100 pause
1211917	   .	   .	    0.0	  127.0	...
1211918	   .	   .	    0.0	  127.0	...
1211919	   .	   .	    0.0	  127.0	...
1211920	   .	   .	    0.0	  127.0	...
1211921	   .	   .	    0.0	  127.0	...
1211922	   .	   .	    0.0	  127.0	...
1211923	   .	   .	    0.0	  127.0	...
1211924	   .	   .	    0.0	  127.0	...
1211925	   .	   .	    0.0	  127.0	...

calling read_raw_eyelink() will throw an error

Link to data

No response

Expected results

RawEyelink object with these trials converted to NaN values - or whatever value

Actual results


ValueError Traceback (most recent call last)
Cell In[15], line 10
8 pass
9 else:
---> 10 el_raw = read_eyelink_file(file=f)
11 s01e02_el_rawdict[el_parID] = (el_raw)

Cell In[13], line 24, in read_eyelink_file(file, raw, calib, screen_kwarg, event_id, interpolation_buffer, downsample)
22 file = Path(file) if isinstance(file, str) else file
23 assert isinstance(file, pathlib.Path), r'File needs to be string or pathlib.Path'
---> 24 raw = mne.io.read_raw_eyelink(file)
25 calib = mne.preprocessing.eyetracking.read_eyelink_calibration(file, **screen_kwarg)
26 elif (raw and calib) and not file:

File [~/AppData/Local/anaconda3/envs/mne/Lib/site-packages/mne/io/eyelink/eyelink.py#line=58), in read_raw_eyelink(fname, create_annotations, apply_offsets, find_overlaps, overlap_threshold, verbose)
29 """Reader for an Eyelink .asc file.
30
31 Parameters
(...) 55 'BAD_ACQ_SKIP'.
56 """
57 fname = _check_fname(fname, overwrite="read", must_exist=True, name="fname")
---> 59 raw_eyelink = RawEyelink(
60 fname,
61 create_annotations=create_annotations,
62 apply_offsets=apply_offsets,
63 find_overlaps=find_overlaps,
64 overlap_threshold=overlap_threshold,
65 verbose=verbose,
66 )
67 return raw_eyelink

File :12, in init(self, fname, create_annotations, apply_offsets, find_overlaps, overlap_threshold, verbose)

File [~/AppData/Local/anaconda3/envs/mne/Lib/site-packages/mne/io/eyelink/eyelink.py#line=126), in RawEyelink.init(self, fname, create_annotations, apply_offsets, find_overlaps, overlap_threshold, verbose)
123 eye_annots = _make_eyelink_annots(
124 self._raw_extras[0]["dfs"], create_annotations, apply_offsets
125 )
126 if gap_annots and eye_annots: # set both
--> 127 self.set_annotations(gap_annots + eye_annots)
128 elif gap_annots:
129 self.set_annotations(gap_annots)

File :12, in set_annotations(self, annotations, emit_warning, on_missing, verbose)

File [~/AppData/Local/anaconda3/envs/mne/Lib/site-packages/mne/io/base.py#line=746), in BaseRaw.set_annotations(self, annotations, emit_warning, on_missing, verbose)
745 delta = 1.0 / self.info["sfreq"]
746 new_annotations = annotations.copy()
--> 747 new_annotations._prune_ch_names(self.info, on_missing)
748 if annotations.orig_time is None:
749 new_annotations.crop(
750 0, self.times[-1] + delta, emit_warning=emit_warning
751 )

File [~/AppData/Local/anaconda3/envs/mne/Lib/site-packages/mne/annotations.py#line=653), in Annotations._prune_ch_names(self, info, on_missing)
652 if name not in keep:
653 if not warned:
--> 654 _on_missing(
655 on_missing,
656 "At least one channel name in "
657 f"annotations missing from info: {name}",
658 )
659 warned = True
660 else:

File [~/AppData/Local/anaconda3/envs/mne/Lib/site-packages/mne/utils/check.py#line=1220), in _on_missing(on_missing, msg, name, error_klass)
1219 on_missing = "warn" if on_missing == "warning" else on_missing
1220 if on_missing == "raise":
-> 1221 raise error_klass(msg)
1222 elif on_missing == "warn":
1223 warn(msg)

ValueError: At least one channel name in annotations missing from info: xpos_right

Additional information

Platform Windows-11-10.0.26100-SP0
Python 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:20:19) [MSC v.1943 64 bit (AMD64)]
Executable C:\Users...\AppData\Local\anaconda3\envs\mne\python.exe
CPU Intel(R) Core(TM) Ultra 5 135U (14 cores)
Memory 15.5 GiB

Core
X mne 1.10.1 (outdated, release 1.11.0 is available!) (sorry)

  • numpy 2.3.1 (MKL 2023.1-Product with 12 threads)
  • scipy 1.16.0
  • matplotlib 3.10.5 (backend=module://matplotlib_inline.backend_inline)

Numerical (optional)

  • sklearn 1.7.1
  • pandas 2.3.1
  • h5io 0.2.5
  • h5py 3.14.0
  • unavailable numba, nibabel, nilearn, dipy, openmeeg, cupy

Visualization (optional)

  • qtpy 2.4.1 (PyQt5=5.15.2)
  • pyqtgraph 0.13.7
  • mne-qt-browser 0.7.2
  • ipywidgets 8.1.8
  • unavailable pyvista, pyvistaqt, vtk, ipympl, trame_client, trame_server, trame_vtk, trame_vuetify

Ecosystem (optional)

  • mne-icalabel 0.7.0
  • unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv

To update to the latest supported release version to get bugfixes and improvements, visit https://mne.tools/stable/install/updating.html

Activity

  1. scott-huberty commented on Dec 22, 2025

    @scott-huberty
    Contributor

    Hey @Cathaway thanks for reporting! Do you want to checkout the PR branch at #13555 , try loading your problematic file, and tell us if it fixes your issue?

  2. qian-chu commented on Jan 2, 2026

    @qian-chu
    Contributor

    Hi @Cathaway thansk for reporting this! I'm working on a PR that tries to handle these cases. Would you mind sharing a bit more of your asc file, including the end of the first recording block and the start of the second recording block (which starts with a START string)? This will help me better understand how the file is organized. Thanks!

  3. Cathaway commented on Jan 4, 2026

    @Cathaway
    Author

    Hello @scott-huberty and @qian-chu, thanks for your work on this matter and happy holidays!

    Hey @Cathaway thanks for reporting! Do you want to checkout the PR branch at #13555 , try loading your problematic file, and tell us if it fixes your issue?

    So I updated mne and tried to read the problematic file. now read_raw_eyelink() works with a warning:
    RuntimeWarning: The eye being tracked changed during the recording. In order of acquisition blocks, they were ['left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right'...]
    But the function itself works.

    I should also note in the problematic file Eyelink made an error in identifying participant's eyes (as seen above in the warning). This may actually be the reason the old function did not work - It started recording with xpos_left and ypos_left as data channels but later the data were read in xpos_right and ypos_right channels

    Hi @Cathaway thansk for reporting this! I'm working on a PR that tries to handle these cases. Would you mind sharing a bit more of your asc file, including the end of the first recording block and the start of the second recording block (which starts with a START string)? This will help me better understand how the file is organized. Thanks!

    end of first recording block

    14722989	   .	   .	    0.0	  127.0	...
    14722990	   .	   .	    0.0	  127.0	...
    14722991	   .	   .	    0.0	  127.0	...
    14722992	   .	   .	    0.0	  127.0	...
    14722993	   .	   .	    0.0	  127.0	...
    14722994	   .	   .	    0.0	  127.0	...
    14722995	   .	   .	    0.0	  127.0	...
    14722996	   .	   .	    0.0	  127.0	...
    14722997	   .	   .	    0.0	  127.0	...
    14722998	   .	   .	    0.0	  127.0	...
    14722999	   .	   .	    0.0	  127.0	...
    14723000	   .	   .	    0.0	  127.0	...
    14723001	   .	   .	    0.0	  127.0	...
    14723002	   .	   .	    0.0	  127.0	...
    14723003	   .	   .	    0.0	  127.0	...
    14723004	   .	   .	    0.0	  127.0	...
    14723005	   .	   .	    0.0	  127.0	...
    14723006	   .	   .	    0.0	  127.0	...
    14723007	   .	   .	    0.0	  127.0	...
    14723008	   .	   .	    0.0	  127.0	...
    14723009	   .	   .	    0.0	  127.0	...
    14723010	   .	   .	    0.0	  127.0	...
    14723011	   .	   .	    0.0	  127.0	...
    14723012	   .	   .	    0.0	  127.0	...
    14723013	   .	   .	    0.0	  127.0	...
    14723014	   .	   .	    0.0	  127.0	...
    14723015	   .	   .	    0.0	  127.0	...
    14723016	   .	   .	    0.0	  127.0	...
    14723017	   .	   .	    0.0	  127.0	...
    14723018	   .	   .	    0.0	  127.0	...
    14723019	   .	   .	    0.0	  127.0	...
    14723020	   .	   .	    0.0	  127.0	...
    14723021	   .	   .	    0.0	  127.0	...
    14723022	   .	   .	    0.0	  127.0	...
    14723023	   .	   .	    0.0	  127.0	...
    14723024	   .	   .	    0.0	  127.0	...
    MSG	14723025 blank_screen
    MSG	14723025 !V CLEAR 128 128 128
    MSG	14723025 FEEDBACK_ENDS
    MSG	14723025 TRIAL 6 ENDS
    14723025	   .	   .	    0.0	  127.0	...
    14723026	   .	   .	    0.0	  127.0	...
    EBLINK L 14718107	14723026	4920
    ESACC L  14718107	14723026	4920	   .	   .	   .	   .	   0.00	      0
    INPUT	14723027	127
    END	14723027 	SAMPLES	EVENTS	RES	  67.40	  72.30
    

    start of second block

    START	15031197 	RIGHT	SAMPLES	EVENTS
    PRESCALER	1
    VPRESCALER	1
    PUPIL	DIAMETER
    EVENTS	GAZE	RIGHT	RATE	1000.00	TRACKING	CR	FILTER	1
    SAMPLES	GAZE	RIGHT	RATE	1000.00	TRACKING	CR	FILTER	1	INPUT
    INPUT	15031197	127
    15031197	  948.0	  610.4	 7880.0	  127.0	...
    15031198	  948.0	  610.8	 7900.0	  127.0	...
    15031199	  948.0	  610.8	 7900.0	  127.0	...
    15031200	  948.0	  610.4	 7891.0	  127.0	...
    MSG	15031201 TRIAL 7 STARTS
    MSG	15031201 FIXATION START
    MSG	15031201 pre 100 pause
    15031201	  947.3	  610.4	 7890.0	  127.0	...
    15031202	  947.2	  612.4	 7890.0	  127.0	...
    SFIX R   15031203
    15031203	  948.3	  612.4	 7891.0	  127.0	...
    15031204	  948.4	  609.8	 7893.0	  127.0	...
    15031205	  948.4	  608.2	 7910.0	  127.0	...
    15031206	  948.1	  608.4	 7910.0	  127.0	...
    15031207	  947.9	  608.4	 7912.0	  127.0	...
    15031208	  947.9	  607.9	 7912.0	  127.0	...
    15031209	  949.5	  607.9	 7904.0	  127.0	...
    15031210	  950.1	  608.2	 7904.0	  127.0	...
    

    I've noticed that before the second block started I ran two calibrations - first time Eyelink misidentified right eye as left

    >>>>>>> CALIBRATION (HV9,P-CR) FOR LEFT: <<<<<<<<<
    MSG	14783890 !CAL Calibration points:  
    MSG	14783890 !CAL -37.1, -64.1        -0,     82   
    MSG	14783890 !CAL -37.8, -79.6        -0,  -1935   
    MSG	14783890 !CAL -37.2, -53.3        -0,   2048   
    MSG	14783890 !CAL -66.8, -64.2     -3749,     82   
    ...
    

    and second time this error was corrected

    >>>>>>> CALIBRATION (HV9,P-CR) FOR RIGHT: <<<<<<<<<
    MSG	14937333 !CAL Calibration points:  
    MSG	14937333 !CAL -42.5, -61.0        -0,     82   
    MSG	14937333 !CAL -41.5, -74.9        -0,  -1935   
    MSG	14937333 !CAL -41.4, -49.4        -0,   2048   
    ...
    

    This might be why I observed the problem with the old read_raw_eyelink() function

    Currently this file can be read with the warning message I shared before

  4. qian-chu commented on Jan 4, 2026

    @qian-chu
    Contributor

    @Cathaway Thanks for sharing. Just want to quickly confirm by "updating MNE" did you mean updating to v1.11 or the branch at #13555? (so that I know if which part of the code fixed the bug)

    This is very helpful for diagnosing the problem. I thought there might have been some data block parsing error but it seems the empty block was read in successfully. The bug actually occurred rather late when setting channel name-specific annotations (and you are right MNE might be confused about what channel names to use). The warning message is expected.

    I will simulate data like yours to make the codebase more robust :)

  5. Cathaway commented on Jan 4, 2026

    @Cathaway
    Author

    @Cathaway Thanks for sharing. Just want to quickly confirm by "updating MNE" did you mean updating to v1.11 or the branch at #13555? (so that I know if which part of the code fixed the bug)

    This is very helpful for diagnosing the problem. I thought there might have been some data block parsing error but it seems the empty block was read in successfully. The bug actually occurred rather late when setting channel name-specific annotations (and you are right MNE might be confused about what channel names to use). The warning message is expected.

    I will simulate data like yours to make the codebase more robust :)

    in the original report I had core mne package v1.10.1, I updated to v1.11 and got the warning message after reading the problematic file

    I did not use the branch at #13555 since I used the pip install -U mne command

  6. qian-chu commented on Jan 5, 2026

    @qian-chu
    Contributor

    Since upgrading to v1.11 works, I suspect this issue has been fixed in #12847 (which aims to handle binocular/monocular switch, but should also work for your case where the tracked eye changed). Maybe @scott-huberty can confirm my hypothesis.

  7. scott-huberty commented on Jan 21, 2026

    @scott-huberty
    Contributor

    Since upgrading to v1.11 works, I suspect this issue has been fixed in #12847 (which aims to handle binocular/monocular switch, but should also work for your case where the tracked eye changed). Maybe @scott-huberty can confirm my hypothesis.

    Yes this also is my working hypothesis... Now the question is do we still need #1357 ? I vote yes if we can still make read_raw_eyelink fail, by simulating an ASCII file where one of the acquisition blocks does not contain any SAMPLES lines. What do you think @qian-chu ?

  8. qian-chu commented on Jan 28, 2026

    @qian-chu
    Contributor

    Since upgrading to v1.11 works, I suspect this issue has been fixed in #12847 (which aims to handle binocular/monocular switch, but should also work for your case where the tracked eye changed). Maybe @scott-huberty can confirm my hypothesis.

    Yes this also is my working hypothesis... Now the question is do we still need #1357 ? I vote yes if we can still make read_raw_eyelink fail, by simulating an ASCII file where one of the acquisition blocks does not contain any SAMPLES lines. What do you think @qian-chu ?

    I absolutely agree. It should be useful to extend the simulation and along with it solve the problem mentioned in #13567. I will refine the description of #13571 to reflect the scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions