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

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

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

Here is my code for forward solution:


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 tutorialhttps://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:

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

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

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



help.

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.
HTH
Kam

2 Likes