cbrnr/mnelab

Error reading XDF file: invalid variable-length integer encountered.

Closed this issue · 2 comments

Apologies if this has been posted before. I'm using functions from mnelab to import .xdf files from an EEG experiment (recorded using LabRecorder):

from mnelab.io.xdf import read_raw_xdf

# Define file name
raw_fname = 'file_name.xdf''

# Identify which stream in the xdf file holds the EEG channels (can vary between datasets)
streams = pyxdf.resolve_streams(str(raw_fname))
stream_id = pyxdf.match_streaminfos(streams, [{"type": "signal"}])

# Load in the raw data and drop the (empty) trigger channel
raw = read_raw_xdf(raw_fname, stream_ids = stream_id)

I have a few xdf files from a few different participants. Some files load just fine, but others cause the following error:


RuntimeError Traceback (most recent call last)
Cell In[26], line 2
1 # Identify which stream in the xdf file holds the EEG channels (can vary between datasets)
----> 2 streams = pyxdf.resolve_streams(str(raw_fname))
3 stream_id = pyxdf.match_streaminfos(streams, [{"type": "signal"}])
5 # Load in the raw data and drop the (empty) trigger channel

File ~\anaconda3\Lib\site-packages\pyxdf\pyxdf.py:777, in resolve_streams(fname)
764 def resolve_streams(fname):
765 """Resolve streams in given XDF file.
766
767 Parameters
(...)
775 List of dicts containing information on each stream.
776 """
--> 777 return parse_chunks(parse_xdf(fname))

File ~\anaconda3\Lib\site-packages\pyxdf\pyxdf.py:795, in parse_xdf(fname)
793 chunks = []
794 with open_xdf(fname) as f:
--> 795 for chunk in _read_chunks(f):
796 chunks.append(chunk)
797 return chunks

File ~\anaconda3\Lib\site-packages\pyxdf\pyxdf.py:841, in _read_chunks(f)
839 chunk = dict()
840 try:
--> 841 chunk["nbytes"] = _read_varlen_int(f)
842 except EOFError:
843 return

File ~\anaconda3\Lib\site-packages\pyxdf\pyxdf.py:490, in _read_varlen_int(f)
488 return struct.unpack("<Q", f.read(8))[0]
489 else:
--> 490 raise RuntimeError("invalid variable-length integer encountered.")

RuntimeError: invalid variable-length integer encountered.

I read in another post (xdf-modules/pyxdf#83) that this could be due to corrputed chunks, and that one can examine the chunks using the MNELAB GUI. However, trying to load in the problematic file using the GUI fails, and I again get an error saying: "invalid variable-length integer encountered."

Does anyone know what might be causing this problem, and/or if there is a way to resolve it?

You cannot import a corrupted file, but it should be possible to inspect its chunks using "File" – "Show XDF chunks..." (and not "File" – "Open"). If you still get an error, please let me know.

Thanks @cbrnr, that worked. The files were indeed corrupted. I discovered that they had been corrupted as they were moved from one computer to another via an online storage cloud. Not sure exactly how/why that happened, but when I moved them with a USB instead, they imported just fine.