Trouble plotting EcoG electrodes

Hello,
I am trying to create a montage and plot the electrodes for a dataset I have. The dataset is in .nwb format. I extracted the information from .nwb file into a pandas data frame and I am trying to create a montage following the tutorials. An error is raised when I try to align the electrodes to the sample brain.
Error:
<ipython-input-155-20e522bc489e>:1: RuntimeWarning: Digitization points not found. Cannot plot digitization.

The relevant code :


montage = mne.channels.make_dig_montage(
    el_position, coord_frame='head')

info = mne.create_info(el_location, rate, ch_types ='ecog')

raw = mne.io.RawArray(data=df_paa['syllable_intervals'][0].T,
                          info=info).set_channel_types({ch_name: 'ecog' for ch_name in el_location})
raw.set_montage(montage)

fig = plot_alignment(raw.info, subject='sample', ecog=True, dig=True,surfaces = 'brain', subjects_dir=subjects_dir, coord_frame='mri')

Notes:
el_position is a dict type containing 256 electodes’ names and corresponding x,y,z coordinates
el_location is a list containing only electrodes’ names
df_paa['syllable_intervals'][0].T matrix of 256x (signal lenth) of the signals I’m working with
rate is sampling frequency

  • MNE version: 0.23.0, Python 3.8
  • operating system: Linux Mint

I would appreciate some guidelines. Thanks in advance.

ping @alexrockhill and @adam2392, they are most likely to be able to help with this.

Your electrodes are probably in coord_frame='mri_voxel' if you got them from a CT that was registered to the MRI. Also el_position has to be a dictionary with names and positions, not sure if that’s the case since it’s not in the code you shared but thought I’d mention it.

might be more accurate.

But now that I read your notes more carefully I see that everything looks in order as far as inputs. You don’t get any errors when you try to set the montage?

Also you may need to drop any channels that aren’t in the montage in order to plot.

Sorry, this error kinda slipped trough my eyes.
When I try to set the montage, when I execute the line of code
raw.set_montage(montage) it raises a warning.

RuntimeWarning: Fiducial point nasion not found, assuming identity unknown to head transformation

And it also raises an error :

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

I’m confused.

Looks like there might have actually been an error in the first line causing your montage to be None as well. From the error, it appears as though you’re trying to set a NoneType montage as the montage. So I would check the first line and maybe also plot the montage when you make it. (montage.plot())

The montage type is channel.montage.DigMontage and I did plot it, it is right. When I run raw.set_montage(montage) I get this in the console:

 In[12]: raw.set_montage(montage)
<ipython-input-12-1eda6b6b16a2>:1: RuntimeWarning: Fiducial point nasion not found, assuming identity unknown to head transformation
  raw.set_montage(montage)
Traceback (most recent call last):

  File "/home/mesecina6/.local/share/virtualenvs/braintospeech-sHitp4-c/lib/python3.8/site-packages/IPython/core/formatters.py", line 345, in _call_
    return method()

  File "/home/mesecina6/.local/share/virtualenvs/braintospeech-sHitp4-c/lib/python3.8/site-packages/mne/io/base.py", line 1763, in repr_html
    basenames = [os.path.basename(f) for f in self._filenames]

  File "/home/mesecina6/.local/share/virtualenvs/braintospeech-sHitp4-c/lib/python3.8/site-packages/mne/io/base.py", line 1763, in <listcomp>
    basenames = [os.path.basename(f) for f in self._filenames]

  File "/usr/lib/python3.8/posixpath.py", line 142, in basename
    p = os.fspath(p)

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

Out[12]: <RawArray | 256 x 5609 (1.8 s), ~11.3 MB, data loaded>

that error can be ignored and should only happen within Jupyter Notebook and maybe Jupyter Lab. It’s related to the way we do fancy printing of the Raw object in HTML contexts. The bug has already been reported here: filename issue with the new _repr_html_ when creating RawArray directly · Issue #9385 · mne-tools/mne-python · GitHub

For now, you could write raw = raw.set_montage(montage) to avoid getting the error.

I see, thank you. I am sill unable to plot the alignment of the electrodes. It doesn’t raise any kind of error. Only the brain mri is shown in pyVista, without aligned electrodes.

Does the montage plot without anything else?

I wonder if you’re encountering the same problem in this thread? We’ve had trouble replicating the problem in that thread… if it’s the same issue it would be helpful to know that you’re seeing it in Linux Mint too (the other user is on a mac). cc @larsoner


Here is what I get with montage.plot(). I explored the electrodes’ positions and it seems okay.

It seems to be the same thread. Although, to be honest,this is my first time working with ECoG, and I am not so familiar with the positioning systems, so there still might still be a chance that I’m just missing something trivial. :slight_smile:

I just noticed in your original code sample that you have el_position in the call to make_dig_montage, and el_location in the call to create_info. Are those supposed to be different (position vs location)?

If that’s not the problem, can you share a fully reproducible script (including a link to the electrode position data file, and code to load it in)? If necessary you can skip sharing the df_paa data if that’s not shareable, just add a line that creates fake data of the right dimensions instead.

Yes, el_position is a dict with electrodes names and x,y,z coordinate, el_ location is a list of electrodes’ names. Sure, I will create a shareable script and post it asp.

It could be a mm → m conversion, you could try following this tutorial with your points and surfaces substituted in Source alignment and coordinate frames — MNE 0.23.0 documentation

I did manage to plot the electrodes . It was trivial, I just divided the coordinates with 1000. Thank you for the help. :grinning_face_with_smiling_eyes:

2 Likes