Issue with set_montage

  • MNE-Python version: 0.23.4
  • operating system: Mac OS 11.6

Hello,

I am working through the example:

Working with sEEG data β€” MNE 1.6.0 documentation

Instead of the lines:

raw = mne.io.read_raw_edf(misc_path + '/seeg/sample_seeg.edf')

raw.info['bads'].extend([ch for ch in raw.ch_names if ch not in ch_names])
raw.load_data()
raw.drop_channels(raw.info['bads'])
raw.crop(0, 2)  # just process 2 sec of data for speed

I put:

info = mne.create_info(ch_names=ch_names, sfreq=512)
raw = mne.io.RawArray(np.zeros((len(ch_names), 10)), info)

then, at the line:

raw.set_montage(montage)

I get the following error:

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

~/opt/anaconda3/envs/mne/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/opt/anaconda3/envs/mne/lib/python3.9/site-packages/mne/io/base.py in _repr_html_(self, caption)
   1761 
   1762     def _repr_html_(self, caption=None):
-> 1763         basenames = [os.path.basename(f) for f in self._filenames]
   1764         m, s = divmod(self._last_time - self.first_time, 60)
   1765         h, m = divmod(m, 60)

~/opt/anaconda3/envs/mne/lib/python3.9/site-packages/mne/io/base.py in <listcomp>(.0)
   1761 
   1762     def _repr_html_(self, caption=None):
-> 1763         basenames = [os.path.basename(f) for f in self._filenames]
   1764         m, s = divmod(self._last_time - self.first_time, 60)
   1765         h, m = divmod(m, 60)

~/opt/anaconda3/envs/mne/lib/python3.9/posixpath.py in basename(p)
    140 def basename(p):
    141     """Returns the final component of a pathname"""
--> 142     p = os.fspath(p)
    143     sep = _get_sep(p)
    144     i = p.rfind(sep) + 1

TypeError: expected str, bytes or os.PathLike object, not NoneType

Could someone help me understand what is going on? Thank you!

Hello @chapochn and welcome to the forum!

This behavior is a bug that has recently been fixed in the development version of MNE-Python; the bugfix will be included in MNE-Python 0.24, which will be released in a few days.

As a workaround for now, avoid having a function or method return a Raw object in the last line of a Jupyter cell / in the IPython interpreter. Specifically what you can do is, instead of:

raw.set_montage(montage)

do e.g.

raw.set_montage(montage)
print(raw)

Best wishes,
Richard

1 Like

Thank you very much for the quick and helpful answer!

1 Like