Average Source Estimate for each label region

  • MNE-Python version: 0.22.0
  • operating system: OSX 10.15.6
    Hello,
    I want to get an average source estimate for each brain region in the atlas I use for my volume source space. I was wondering if there was a way to do this automatically, or if there was a way to output the indices of sources that correspond to each label region, so that using these numbers and the order of labels in the atlas I could average groups of rows in the final source estimate matrix. The goal is to obtain a very rough picture of which regions in the atlas are most active.
    Thank You!

This was answered on GitHub here. The short version is: use the extract_label_time_course function.

1 Like

thanks for the suggestion! I tried to run the example code, but I got the following error:

Traceback (most recent call last):
  File "/Users/user/Desktop/source_loc_use_saved.py", line 816, in <module>
    label_tc = stc.extract_label_time_course(labels=[fname_aseg, label_names], src=src)
  File "<decorator-gen-254>", line 24, in extract_label_time_course
  File "/Users/user/.pyenv/versions/3.8.3/lib/python3.8/site-packages/mne/source_estimate.py", line 2011, in extract_label_time_course
    return extract_label_time_course(
  File "<decorator-gen-267>", line 24, in extract_label_time_course
  File "/Users/user/.pyenv/versions/3.8.3/lib/python3.8/site-packages/mne/source_estimate.py", line 3214, in extract_label_time_course
    label_tc = list(label_tc)
  File "/Users/user/.pyenv/versions/3.8.3/lib/python3.8/site-packages/mne/source_estimate.py", line 3140, in _gen_extract_label_time_course
    assert vertidx.shape[1] == stc.data.shape[0]
AssertionError

stc.data.shape[0] is 592, the total number of sources in the regions that are in the source space. vertidx.shape[1] is 5, and I’m not sure where this number came from. The code I used is:

src = inv['src']
fname_aseg = op.join(subjects_dir, 'EM', 'mri', 'aparc.a2009s+aseg.mgz')
label_tc = stc.extract_label_time_course(labels=[fname_aseg, labels_used], src=src)

labels_used is a list of the regions currently in the source space.

Hello! I still have not been able to figure out the issue in the last reply and am wondering if anyone has any suggestions on what could be wrong?