type error to read sample data (MNE TUTORIAL)

  • MNE version: 0.24.0
  • operating system: Windows 10

hello, I’m new in MNE and i just wanted to try the first tutorial:

import numpy as np
import mne
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = (sample_data_folder,‘MEG’,‘sample’,
‘sample_audvis_filt-0-40_raw.fif’)

Until this point it’s working.
Then, this is the line that return an error:

raw = mne.io.read_raw_fif(sample_data_raw_file)

return:

TypeError Traceback (most recent call last)
Input In [2], in <cell line: 4>()
1 sample_data_folder = mne.datasets.sample.data_path()
2 sample_data_raw_file = (sample_data_folder,‘MEG’,‘sample’,
3 ‘sample_audvis_filt-0-40_raw.fif’)
----> 4 raw = mne.io.read_raw_fif(sample_data_raw_file)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:473, in read_raw_fif(fname, allow_maxshield, preload, on_split_missing, verbose)
438 @fill_doc
439 def read_raw_fif(fname, allow_maxshield=False, preload=False,
440 on_split_missing=‘raise’, verbose=None):
441 “”“Reader function for Raw FIF data.
442
443 Parameters
(…)
471 … versionadded:: 0.9.0
472 “””
→ 473 return Raw(fname=fname, allow_maxshield=allow_maxshield,
474 preload=preload, verbose=verbose,
475 on_split_missing=on_split_missing)

File :24, in init(self, fname, allow_maxshield, preload, on_split_missing, verbose)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:81, in Raw.init(self, fname, allow_maxshield, preload, on_split_missing, verbose)
78 next_fname = fname
79 while next_fname is not None:
80 raw, next_fname, buffer_size_sec =
—> 81 self._read_raw_file(next_fname, allow_maxshield,
82 preload, do_check_ext)
83 do_check_ext = False
84 raws.append(raw)

File :24, in _read_raw_file(self, fname, allow_maxshield, preload, do_check_ext, verbose)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:136, in Raw._read_raw_file(self, fname, allow_maxshield, preload, do_check_ext, verbose)
132 @verbose
133 def _read_raw_file(self, fname, allow_maxshield, preload,
134 do_check_ext=True, verbose=None):
135 “”“Read in header information from a raw file.”“”
→ 136 logger.info(‘Opening raw data file %s…’ % fname)
138 # Read in the whole file if preload is on and .fif.gz (saves time)
139 if not _file_like(fname):

TypeError: not all arguments converted during string formatting

I tried with others files from others tutorials but the issue is always the same.
I can’t find on the web others with this same issue… someone to help a biginner?

Thanks!

Clem

hi,

you passed sample_data_raw_file as a tuple not a string pointing to the file on disk.

I would suggest you start by copy pasting the examples and tutorials.

Alex

1 Like

to expand on what @agramfort said: this line

is incorrect, it should probably be something like

sample_data_raw_file = os.path.join(sample_data_folder,‘MEG’,‘sample’,
‘sample_audvis_filt-0-40_raw.fif’)

(the os.path.join was missing)

Ok it’s working now (juste needed to import os ). Actually it was missing on the tutorial page.

Thank you!

In fact the tutorial says

sample_data_raw_file = (sample_data_folder / 'MEG' / 'sample' /
                        'sample_audvis_filt-0-40_raw.fif')

which uses / instead of , in between each path element. That works because sample_data_folder is a pathlib.Path object, not a normal string. See pathlib — Object-oriented filesystem paths — Python 3.10.7 documentation

1 Like

Hi!

Thank you for your explanations.

I’m facing another issue, when I’m triying to read the dataset I have a File Not Found Error.
I printed my files path to be shure that it exist but the read_raw_fif function seems not found it.

thanks in advance!

printing the file path does not ensure that it exists. try os.path.exists()

ok I just tryed on colab and it’s working.

I’m usiing Anaconda and from anaconda I work on jupyterlab and spyder. I have the same issue on jupyterlab and on spyder. So the problem should come from my environment…

conda-build version : 3.22.0
python version : 3.9.12.final.0