Repository navigation
Error reading big CNT file #6535
Description
Activity
Since the CNT file is huge, which means the samples section in the CNT file (ref this: Structure of CNT file ) is also huge.
And mne choose to read the event table position from the SETUP section, which read as a long (32 bit) integer.
with open(fname, 'rb') as fid: .... fid.seek(SETUP_EVENTTABLEPOS_OFFSET) (event_table_pos,) = np.frombuffer(fid.read(4), dtype='<i4')`
As a result, the maximum length of the CNT file mne supports is equals to :
maximum_seconds = (np.iinfo(np.int32).max - 900 - 75 * n_channels) / sfreq / n_channels / 4
"900" is the size of the SETUP section, 75*n_channels is the size of ELECTLOC, and "4" is the bytes each sample point takes.
For the situation n_channels=62 and sfreq=1000, the result is 8659 seconds (about 2.4 hours). When the length of your CNT file is too long that the value of EVENT_TABLE_POS will overflow.
To solve this problem, you need to change the way to obtain the value of EVENT_TABLE_POS: calculate it using follow formula instead of read it from SETUP section:
-- # fid.seek(SETUP_EVENTTABLEPOS_OFFSET) # Line 66 -- # (event_table_pos,) = np.frombuffer(fid.read(4), dtype='<i4') # Line 67 ++ fid.seek(864) ++ (n_samples,) = np.frombuffer(fid.read(4), dtype='<i4') ++ event_table_pos = 900 + 75 * int(n_channels) + 4 * int(n_channels) * int(n_samples) -- event_offset = np.fromfile(fid, dtype='<i4', count=1)[0] # Line 242 ++ event_offset = 900 + 75 * int(n_channels) + 4 * int(n_channels) * int(n_samples)
Reacted by Joan MassichThank you all. It works!
However, the author said in his code that '# Header has a field for number of samples, but it does not seem to be too reliable. That's why we have option for setting n_bytes manually.' So I want to know if this update is stable. Because you use the nsamples in header to calculate the correct event_offset.can anyone share (privately or publicly) one of those long CNT files ??
When trying these large files, the code I'm reading in
Teegfield ofTEEGis not 1 or 2 is a random number (usually 129 or 116) our codebase allows for 3 as well. Is there any extension that I'm not aware of with different structures or am I doing something wrong?typedef struct { char Teeg; /* Either 1 or 2 */ long Size; /* Total length of all the events */ long Offset; /* Hopefully always 0 */ } TEEG;@massich Please download the cnt file from the following link:
https://bcmi.cloud:5001/sharing/ezXci1zax
The size of the cnt file is 2.23G. And it has multiple triggers of integer types named 1, 11, 2, 22.@LM-thinking thx for sharing the file, #6537 seems to be working, can you double check?
Hi all, It seems that I'm still getting this error reading cnt files.
Any idea why ?
Thanks !@sKinreich are you sure you are using the latest mne version ? Is so can you share the file privately ?
Hi agramfort,
Thank you for your reply !!!
I’m using version 0.22 of MNE.
How can I share the file privately ? can you send me your email address ? ([email protected])
Thanks you again for any help.Sivan
MNE Group:
I tried to read several cnt files of different sizes using
mne.io.read_raw_cnt.If the cnt file is lower than 2G, the file can be successfully loaded.
However, if the file size exceeds 2G, I will receive the following error:
Also:
If I use:
I got different error:
Here is my mne info