Hi everyone!
I’m working with MEG ctf data and I’m having trouble loading it.
Here’s an example:
file_path = r'C:/Users/joaco/OneDrive - The University of Nottingham/MEGEYEHS/DATA/CTF_DATA/15909001/15909001_MatiasIson_20220530_02.ds'
raw = mne.io.read_raw_ctf(file_path)
OUTPUT:
ds directory : C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds
res4 data read.
hc data read.
Separate EEG position data file read.
Quaternion matching (desired vs. transformed):
0.42 68.31 0.00 mm <-> 0.42 68.31 0.00 mm (orig : -53.00 45.90 -248.52 mm) diff = 0.000 mm
-0.42 -68.31 0.00 mm <-> -0.42 -68.31 0.00 mm (orig : 45.10 -49.18 -246.57 mm) diff = 0.000 mm
83.73 0.00 0.00 mm <-> 83.73 -0.00 0.00 mm (orig : 53.82 58.80 -242.95 mm) diff = 0.000 mm
Coordinate transformations established.
Polhemus data for 3 HPI coils added
Device coordinate locations for 3 HPI coils added
2 extra points added to Polhemus data.
Measurement info composed.
Finding samples for C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds\15909001_MatiasIson_20220530_02.meg4:
System clock channel is available, checking which samples are valid.
C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py:230: RuntimeWarning: overflow encountered in long_scalars
offset = CTF.HEADER_SIZE + (samp_offset * res4['nchan'] +
Traceback (most recent call last):
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\IPython\core\interactiveshell.py", line 3398, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-20-208af92d7217>", line 1, in <cell line: 1>
raw = mne.io.read_raw_ctf(file_path)
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py", line 66, in read_raw_ctf
return RawCTF(directory, system_clock, preload=preload,
File "<decorator-gen-223>", line 12, in __init__
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py", line 131, in __init__
sample_info = _get_sample_info(meg4_name, res4, system_clock)
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py", line 232, in _get_sample_info
fid.seek(offset, 0)
OSError: [Errno 22] Invalid argument
It encounters a long scalar overflow. I could get past this with:
raw = mne.io.read_raw_ctf(file_path, system_clock='ignore')
OUTPUT:
ds directory : C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds
res4 data read.
hc data read.
Separate EEG position data file read.
Quaternion matching (desired vs. transformed):
0.42 68.31 0.00 mm <-> 0.42 68.31 0.00 mm (orig : -53.00 45.90 -248.52 mm) diff = 0.000 mm
-0.42 -68.31 0.00 mm <-> -0.42 -68.31 0.00 mm (orig : 45.10 -49.18 -246.57 mm) diff = 0.000 mm
83.73 0.00 0.00 mm <-> 83.73 -0.00 0.00 mm (orig : 53.82 58.80 -242.95 mm) diff = 0.000 mm
Coordinate transformations established.
Polhemus data for 3 HPI coils added
Device coordinate locations for 3 HPI coils added
2 extra points added to Polhemus data.
Measurement info composed.
Finding samples for C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds\15909001_MatiasIson_20220530_02.meg4:
System clock channel is available, but ignored.
290 x 6000 = 1740000 samples from 422 chs
Current compensation grade : 3
At this point I can plot the data with raw.plot() but I cannot apply any filters or so.
When I run raw.load_data()
raw.load_data()
OUTPUT:
ds directory : C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds
res4 data read.
hc data read.
Separate EEG position data file read.
Quaternion matching (desired vs. transformed):
0.42 68.31 0.00 mm <-> 0.42 68.31 0.00 mm (orig : -53.00 45.90 -248.52 mm) diff = 0.000 mm
-0.42 -68.31 0.00 mm <-> -0.42 -68.31 0.00 mm (orig : 45.10 -49.18 -246.57 mm) diff = 0.000 mm
83.73 0.00 0.00 mm <-> 83.73 -0.00 0.00 mm (orig : 53.82 58.80 -242.95 mm) diff = 0.000 mm
Coordinate transformations established.
Polhemus data for 3 HPI coils added
Device coordinate locations for 3 HPI coils added
2 extra points added to Polhemus data.
Measurement info composed.
Finding samples for C:\Users\joaco\OneDrive - The University of Nottingham\MEGEYEHS\DATA\CTF_DATA\15909001\15909001_MatiasIson_20220530_02.ds\15909001_MatiasIson_20220530_02.meg4:
System clock channel is available, but ignored.
290 x 6000 = 1740000 samples from 422 chs
Current compensation grade : 3
Reading 0 ... 1739999 = 0.000 ... 1449.999 secs...
C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py:176: RuntimeWarning: overflow encountered in long_scalars
pos += samp_offset * si['n_chan'] * 4
Traceback (most recent call last):
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\IPython\core\interactiveshell.py", line 3398, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-23-72a37d28be67>", line 1, in <cell line: 1>
raw.load_data()
File "<decorator-gen-206>", line 12, in load_data
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\base.py", line 557, in load_data
self._preload_data(True)
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\base.py", line 567, in _preload_data
self._data = self._read_segment(
File "<decorator-gen-205>", line 12, in _read_segment
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\base.py", line 452, in _read_segment
_ReadSegmentFileProtector(self)._read_segment_file(
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\base.py", line 2158, in _read_segment_file
return self.__raw.__class__._read_segment_file(
File "C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\lib\site-packages\mne\io\ctf\ctf.py", line 177, in _read_segment_file
fid.seek(pos, 0)
OSError: [Errno 22] Invalid argument
I get a similar error. This also happens if I run the read_raw_ctf(preload=True). So I’m guessing the issue is when actually loading the data.
I tried tis in two different computers, and with 3 different datasets (one of them from an other experiment) and the error persisted.
I also tried to load the data in Matlab and it worked… So I’m not sure what the problem could be.
Here’s my specs:
mne.sys_info()
OUTPUT:
Platform: Windows-10-10.0.19044-SP0
Python: 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\joaco\anaconda3\envs\MEGEYEHS_Python\python.exe
CPU: AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD: 16 cores
Memory: 15.4 GB
mne: 1.0.3
numpy: 1.21.5 {blas=mkl_rt, lapack=mkl_rt}
scipy: 1.7.3
matplotlib: 3.5.1 {backend=QtAgg}
sklearn: 1.0.2
numba: 0.55.1
nibabel: 3.2.2
nilearn: 0.9.1
dipy: 1.5.0
cupy: Not found
pandas: 1.4.2
pyvista: 0.34.0 {OpenGL 4.5.13596 Core Profile Context 20.10.20.14 27.20.11020.14001 via AMD Radeon(TM) Graphics}
pyvistaqt: 0.9.0
ipyvtklink: 0.2.2
vtk: 9.0.3
PyQt5: 5.12.3
ipympl: Not found
pooch: v1.6.0
mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: 0.3.1
mne_connectivity: Not found
Thanks for your help!