Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Trying to allow plotting SEEG activity in volumetric source space #8402

Merged
merged 52 commits into from Oct 26, 2020

Conversation

adam2392
Copy link
Member

@adam2392 adam2392 commented Oct 22, 2020

Reference issue

Fixes: #8364
Closes #8388

What does this implement/fix?

  1. Adds a plot_seeg.py tutorial for working w/ SEEG data analogous to plot_ecog.py.

  2. Attempts to refactor stc_near_sensors to show volumetric SEEG activity with either stc.plot or stc.plot_3d

Additional information

Opening up PR to start iterating.

Ideally want to allow SEEG activity to be visualized as such: https://mne.tools/dev/auto_tutorials/source-modeling/plot_beamformer_lcmv.html#volumetric-rendering-3d
Assumes user has:

  • electrode locations
  • raw SEEG activity

Apologies if the code is nowhere where it should be. Never worked with the source API on mne, but now am eager to learn it if it'll help produce these nice viz of SEEG.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start!

mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
adam2392 and others added 2 commits October 22, 2020 10:25
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@adam2392
Copy link
Member Author

adam2392 commented Oct 22, 2020

I keep on getting this error, and I'm not sure how to trace this down. It seems that there is no data getting attached to stc.data?

Traceback (most recent call last):
  File "/Users/adam2392/Documents/mne-python/tutorials/misc/plot_seeg.py", line 142, in <module>
    brain = stc.plot(src=src, mode='stat_map', initial_time=0.68,
  File "/Users/adam2392/Documents/mne-python/mne/source_estimate.py", line 1943, in plot
    return plot_volume_source_estimates(
  File "<decorator-gen-140>", line 24, in plot_volume_source_estimates
  File "/Users/adam2392/Documents/mne-python/mne/viz/_3d.py", line 2104, in plot_volume_source_estimates
    img = stc.as_volume(src, mri_resolution=False)
  File "/Users/adam2392/Documents/mne-python/mne/source_estimate.py", line 2106, in as_volume
    return _interpolate_data(data, src, mri_resolution=mri_resolution,
  File "/Users/adam2392/Documents/mne-python/mne/morph.py", line 823, in _interpolate_data
    vols[this_inuse] = stc.data[stc_slice]
ValueError: shape mismatch: value array of shape (0,2001) could not be broadcast to indexing result of shape (24303,2001)

Do you think this is a problem with the seeg coordinates, or possibly something with the stc_near_sensors function?

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it help if I pulled your changes and fixed the problem you're having with not having any data?

mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
tutorials/misc/plot_ecog.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
tutorials/misc/plot_seeg.py Outdated Show resolved Hide resolved
@larsoner
Copy link
Member

Do you think this is a problem with the seeg coordinates, or possibly something with the stc_near_sensors function?

I suspect that your evoked.data.shape[1] == 0 so your stc.data.shape[1] == 0 and the volume morphing and stc plotting functions don't handle this case properly.

adam2392 and others added 9 commits October 22, 2020 23:08
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@adam2392
Copy link
Member Author

Okay a few updates:

  1. it turned out that channel coords for the misc-data was in 'mm', so needed to divide by 1000 before setting to montage.
  2. In addition, if channels have nan coordinates, we need to remove to make sure pdist(pos) doesn't return nan.
  3. I added a bunch of inline comments to help navigate a bit better.
  4. I added a bunch of print statements to debug, but I can remove them once I figure out why the following error is occuring.
Traceback (most recent call last):
  File "/Users/adam2392/Documents/mne-python/tutorials/misc/plot_seeg.py", line 129, in <module>
    brain = stc.plot(src=vol_src, mode='stat_map', initial_time=0.68,
  File "/Users/adam2392/Documents/mne-python/mne/source_estimate.py", line 1943, in plot
    return plot_volume_source_estimates(
  File "<decorator-gen-140>", line 24, in plot_volume_source_estimates
  File "/Users/adam2392/Documents/mne-python/mne/viz/_3d.py", line 2104, in plot_volume_source_estimates
    img = stc.as_volume(src, mri_resolution=False)
  File "/Users/adam2392/Documents/mne-python/mne/source_estimate.py", line 2106, in as_volume
    return _interpolate_data(data, src, mri_resolution=mri_resolution,
  File "/Users/adam2392/Documents/mne-python/mne/morph.py", line 823, in _interpolate_data
    vols[this_inuse] = stc.data[stc_slice]
ValueError: shape mismatch: value array of shape (1638,2001) could not be broadcast to indexing result of shape (14629,2001)

It's trying to get 14629 vertices, which I'm guessing is coming from the vol_src for fsaverage, but I don't see anyway of limiting the amount of vertices there. In stc_near_sensors, we only grab 1638 vertices within our "epsilon-ball" parametrized by distance=0.01? Any idea how I should proceed? I don't think it seems to be a bug anymore on my end...

@adam2392
Copy link
Member Author

Anything else left to do from your end @adam2392 or are you happy with this now?

No this looks really good to me so far and honestly really useful for someone in the iEEG world to use mne-python in conjunction w/ freesurfer + neuroimaging viz.

I updated the docstring of stc_near_sensors. lmk wyt?

mne/source_estimate.py Outdated Show resolved Hide resolved
@adam2392
Copy link
Member Author

/home/circleci/project/mne/source_estimate.py:docstring of mne.stc_near_sensors:55: WARNING: Unexpected indentation.

I think this is occurring in the addition I made under Notes. I think(?) I fixed it?

@adam2392
Copy link
Member Author

Another small thing: do you happen to know how one would do this if you don't have BEM? My understanding is you only have BEM from flash MRI data. I've never worked w/ BEM and it never gets output from my freesurfer recon-all.

# get standard fsaverage volume (5mm grid) source space
fname_src = op.join(subjects_dir, 'fsaverage', 'bem',
                    'fsaverage-vol-5-src.fif')
vol_src = mne.read_source_spaces(fname_src)

E.g. what if the above someone wanted to just use the parcellated MRI? Is that possible?

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge

Let's see if @drammock and/or @agramfort are happy. Here is the rendered example:

https://22968-1301584-gh.circle-artifacts.com/0/dev/auto_tutorials/misc/plot_seeg.html

Just pushed a tiny commit to make the thumbnail the rendered movie.

@larsoner
Copy link
Member

larsoner commented Oct 25, 2020

Another small thing: do you happen to know how one would do this if you don't have BEM? My understanding is you only have BEM from flash MRI data. I've never worked w/ BEM and it never gets output from my freesurfer recon-all.

This is another thing that we should make clearer somewhere in the docs. You only need a BEM if you want to do some forward modeling.

What you really probably want is to constrain your volumetric sources to be within the brain volume. One way to do this is by passing a BEM, but really this just uses the inner_skull surface. Instead of doing this, you can use the brain surface EDIT: by using the surf argument of setup_volume_source_space, which you can extract from the brainmask.mgz file using a few FreeSurfer commands -- this is done in the process of mne watershed_bem, so this is a convenient way to get this surface. This does not require FLASH scans -- it uses only the T1.mgz image.

Alternatively, you can tell it to use aseg.mgz or aseg+aparc.mgz with single_volume=True, which will only include volumetric sources that are in the brain volume / brainmask.mgz. Maybe open a separate issue about how to create and work with volumetric source spaces so that we can discuss this stuff there?

@zhengliuer
Copy link

Hi, is there any way that we can set different parts of depth electrodes into different colors, for example, which may be useful, if the contacts of this electrode is out of the skull, it's green, otherwise yellow.

@larsoner
Copy link
Member

Hi, is there any way that we can set different parts of depth electrodes into different colors, for example, which may be useful, if the contacts of this electrode is out of the skull, it's green, otherwise yellow.

This is really an issue for / part of #8382

@larsoner larsoner merged commit cdeb443 into mne-tools:master Oct 26, 2020
5 checks passed
@larsoner
Copy link
Member

Thanks for working through this @adam2392 !

@adam2392 adam2392 deleted the seeg branch October 30, 2020 16:06
@zhengliuer
Copy link

Hi, recently I've been thinking that showing some info about the SEEG electrodes may be very useful when you move your mouse to the electrode in the figure produced by plot_alignment, for example, the name, the MNI coordinates, and which brain area the electrode is in. I have figured out how
to calculate the brain area of each electrode, but I don't know how to add it to this.

@zhengliuer
Copy link

image

@zhengliuer
Copy link

This is the info of the electrodes I calculated using python.
image

@drammock
Copy link
Member

drammock commented Dec 2, 2020

@BarryLiu-97 please open a new issue for new feature requests. This PR is already merged and closed.

@zhengliuer
Copy link

please open a new issue for new feature requests. This PR is already merged and closed.

Got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plotting MNI transformed ECoG Adding Source Visualization for SEEG data Using stc_near_sensors
5 participants