# Cannot extract source estimated data of each brain region using HCP parcellation (ValueError: No vertices match the label in the stc file)

**URL:** <https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210>\
**Category:** Support & Discussions\
**Created:** [June 5, 2021, 1:57pm UTC](https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210 "2021-06-05T13:57:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shirinV](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@shirinV](https://mne.discourse.group/u/shirinV)\
**Post date:** [June 5, 2021, 1:57pm UTC](https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210/1 "2021-06-05T13:57:27Z")

</div>

**If you have a question or issue with MNE-Python, please include the following info:**

- MNE-Python version: 0.23.0
- operating system:

So I am now calculating source estimated data, and I want to save the source estimated data for each epoch and each label (labels are extracted from the hcp parcellation).

Which attribute defines the number of vertices in the final stc file? Because, my stc files contain 516 vertices. However, I remember in one of the tutorials, the number of vertices were around 7498.

I think that is a problem because in my final step, when I call the function `stc_data.in_label(lbl)`, I receive this error:

> ValueError: No vertices match the label in the stc file

So I think my stc\_data file lacks many vertices.  
I am putting my codes after the inverse solution. However, if needed, please let me know what else I should provide.

#Inverse solution

from mne.connectivity import envelope\_correlation  
from mne.minimum\_norm import make\_inverse\_operator, apply\_inverse\_epochs  
from mne.preprocessing import compute\_proj\_ecg, compute\_proj\_eog

```python
cov = noise_cov_reg
inv = make_inverse_operator(epochs.info, fwd, cov)

snr = 3.0
stcs = apply_inverse_epochs(epochs, inv,
                            lambda2=1.0 / snr ** 2, verbose=False,
                            method="dSPM", pick_ori="normal")

stcs[0].shape --> answer: 516*551

```

---

<div class="post-metadata">

**Author:** ![shirinV](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@shirinV](https://mne.discourse.group/u/shirinV)\
**Post date:** [June 7, 2021, 12:34pm UTC](https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210/2 "2021-06-07T12:34:31Z")

</div>

Here is my code for forward solution:

```python

src = mne.setup_source_space(subject, spacing='all', add_dist='patch',
                             subjects_dir=subjects_dir)
print(src)

import os.path as op
#https://mne.tools/stable/auto_tutorials/forward/30_forward.html
surface = op.join(subjects_dir, subject, 'bem', 'inner_skull.surf')
vol_src = mne.setup_volume_source_space(subject, subjects_dir=subjects_dir,
                                        surface=surface)
print(vol_src)

model = mne.make_bem_model(subject='SV', ico=4,
                           conductivity=conductivity,
                           subjects_dir=subjects_dir)
bem = mne.make_bem_solution(model)

fwd = mne.make_forward_solution(info, trans=trans, src=src, bem=bem,
                                meg=True, eeg=False, mindist=5.0, n_jobs=1,
                                verbose=True, ignore_ref=True)
print(fwd)

```

And here are the results of “forward\_solution”:

> Source space : \<SourceSpaces: [\<surface (lh), n\_vertices=142069, n\_used=258\>, \<surface (rh), n\_vertices=145134, n\_used=258\>] MRI (surface RAS) coords, subject ‘SV’, ~26.4 MB\>  
> MRI → head transform : /Users/shirinvafaei/Documents/Datasets/sentences\_word\_by\_word/MEG\_raw/Shirin\_20201021/train0\_20201021-trans.fif  
> Measurement data : instance of Info  
> Conductor model : instance of ConductorModel  
> Accurate field computations  
> Do computations in head coordinates  
> Free source orientations
> 
> Read 2 source spaces a total of 516 active source locations
> 
> Coordinate transformation: MRI (surface RAS) → head  
> 0.995143 -0.095295 0.024692 -4.36 mm  
> 0.086552 0.966476 0.241728 11.86 mm  
> -0.046900 -0.238417 0.970030 20.61 mm  
> 0.000000 0.000000 0.000000 1.00
> 
> Read 160 MEG channels from info  
> 99 coil definitions read  
> Coordinate transformation: MEG device → head  
> -1.000000 -0.000000 0.000000 0.14 mm  
> 0.000000 -1.000000 0.000000 57.11 mm  
> 0.000000 0.000000 1.000000 15.90 mm  
> 0.000000 0.000000 0.000000 1.00  
> MEG coil definitions created in head coordinates.  
> Source spaces are now in head coordinates.
> 
> Employing the head-\>MRI coordinate transform with the BEM model.  
> BEM model instance of ConductorModel is now set up
> 
> Source spaces are in head coordinates.  
> Checking that the sources are inside the surface and at least 5.0 mm away (will take a few…)  
> Skipping interior check for 113 sources that fit inside a sphere of radius 53.9 mm  
> Skipping solid angle check for 0 points using Qhull  
> Skipping interior check for 110 sources that fit inside a sphere of radius 53.9 mm  
> Skipping solid angle check for 0 points using Qhull
> 
> Setting up compensation data…  
> No compensation set. Nothing more to do.
> 
> Composing the field computation matrix…  
> Computing MEG at 516 source locations (free orientations)…
> 
> Finished.  
> \<Forward | MEG channels: 160 | EEG channels: 0 | Source space: Surface with 516 vertices | Source orientation: Free\>

However, in this tutorial[https://mne.tools/dev/auto\_tutorials/inverse/10\_stc\_class.html](https://mne.tools/dev/auto_tutorials/inverse/10_stc_class.html) (as an example), the number of vertices is arund 7498.

The main reason that I am asking this is when I wan to get the source estimated data related to the labels of various brain regions (obtained from hcp parcellation), I receive this error:

> * * *
> 
> ValueError Traceback (most recent call last)  
> in   
> 3  
> 4 for stc\_data in stcs:  
> ----\> 5 stc\_label = stc\_data.in\_label(lbl)  
> 6
> 
> ~/opt/anaconda3/lib/python3.7/site-packages/mne/source\_estimate.py in in\_label(self, label)  
> 1405  
> 1406 if sum([len(v) for v in vertices]) == 0:  
> → 1407 raise ValueError(‘No vertices match the label in the stc file’)  
> 1408  
> 1409 label\_stc = self. **class** (values, vertices=vertices, tmin=self.tmin,
> 
> ValueError: No vertices match the label in the stc file

Here is my code for the later part:

```python
#using HCP parcellation
labels_parc = mne.read_labels_from_annot(subject, parc='HCPMMP1',
                                         subjects_dir=fs_dir_local)

```

```python

for lbl in labels_parc:
    lbl_name = lbl.name
    
    for stc_data in stcs:
        stc_label = stc_data.in_label(lbl)

```

stcs are a list of source estimated data. Length of stcs is equal to number of epochs and each element has the shape (516, 551), which I think can be interpolated as 516 vertices and 551 time points.

However, I have difficulty when want to extract the data for each brain region using the HCP parcellation.

I sincerely appreciate your help.

Shirin

---

<div class="post-metadata">

**Author:** ![shirinV](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@shirinV](https://mne.discourse.group/u/shirinV)\
**Post date:** [June 7, 2021, 12:52pm UTC](https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210/3 "2021-06-07T12:52:01Z")

</div>

So I have realized it seems I am able to extract the stc data of some brain regions, however, not all of them.

I have attached two screenshots of the success/failed labels (labels that I was able to extract the source estimated data from that label or no).

I hope it will

 ![Screen Shot 2021-06-07 at 21.47.21](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/bc72dab44d589d19306820dd41e1116e1b1c99c3.png)  
 ![Screen Shot 2021-06-07 at 21.46.23](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/2a7736bccd41b8d3b289129500aa7454a4fe9a09.png)  
help.

---

<div class="post-metadata">

**Author:** ![Kam](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kam/32/280_2.png) [@Kam](https://mne.discourse.group/u/Kam)\
**Post date:** [June 11, 2021, 7:24pm UTC](https://mne.discourse.group/t/cannot-extract-source-estimated-data-of-each-brain-region-using-hcp-parcellation-valueerror-no-vertices-match-the-label-in-the-stc-file/3210/4 "2021-06-11T19:24:15Z")

</div>

Hi Shirin,  
According to docs, your source space should contain a **lot** more than 516 source locations. Was the MRI prepped properly?  
Your data should pass the sanity checks illustrated in [here](https://mne.tools/stable/auto_tutorials/forward/30_forward.html).  
HTH  
Kam
