# Average Source Estimate for each label region

**URL:** <https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization, eeg\
**Created:** [January 25, 2021, 8:49am UTC](https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567 "2021-01-25T08:49:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinhyon](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/justinhyon/32/118_2.png) [@justinhyon](https://mne.discourse.group/u/justinhyon)\
**Post date:** [January 25, 2021, 8:49am UTC](https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567/1 "2021-01-25T08:49:41Z")

</div>

- 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!

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [January 25, 2021, 4:28pm UTC](https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567/2 "2021-01-25T16:28:08Z")

</div>

This was answered on GitHub [here](https://github.com/mne-tools/mne-python/issues/8693#issuecomment-766798302). The short version is: use the `extract_label_time_course` function.

---

<div class="post-metadata">

**Author:** ![justinhyon](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/justinhyon/32/118_2.png) [@justinhyon](https://mne.discourse.group/u/justinhyon)\
**Post date:** [January 25, 2021, 7:02pm UTC](https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567/3 "2021-01-25T19:02:29Z")

</div>

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

```python
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:

```python
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.

---

<div class="post-metadata">

**Author:** ![justinhyon](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/justinhyon/32/118_2.png) [@justinhyon](https://mne.discourse.group/u/justinhyon)\
**Post date:** [February 17, 2021, 12:15pm UTC](https://mne.discourse.group/t/average-source-estimate-for-each-label-region/2567/4 "2021-02-17T12:15:23Z")

</div>

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?
