Issues generating functional labels for RH

Hi all,

I have been attempting to generate functional labels from source estimates for a data set as outlined here: https://martinos.org/mne/stable/auto_examples/inverse/plot_label_from_stc.html#sphx-glr-auto-examples-inverse-plot-label-from-stc-py

This works beautifully for all the left hemisphere parcellations I try, but whenever I try a right hemisphere counter-part, the list of func_labels return empty, causing the below indexing error:

I've recently run my own code based on this example and it works for both
hemispheres. Just guessing here, but what does stc_mean.vertices look like?
Does it have vertices in the correct hemisphere?

Hm, well the problem must be with me somewhere then. If I run the code for a right hemi parc, I get:

In [50]: stc_mean.vertices
Out[50]:
[array([ 12, 68, 76, ..., 132204, 132241, 132257]),
array([ 7, 38, 43, ..., 134417, 134419, 134449])]

If I run it on the left hemisphere, I get the exact same thing. Do those two arrays represent vertices for each hemisphere? Or is that telling me its looking at the same vertices (only in the lh) when looking for rh activation?

My guess is stc_to_label doesn't like 'connected=True' when you have
vertices in both hemispheres but I have not looked at the source code. You
could try 'connected=False' which should return labels in each hemisphere
according to the documentation. Either that, or try to figure out why your
parcellation labels are resulting in vertices in both hemispheres and
change that. (The ROIs I used to restrict the stc were hand drawn in
Freesurfer, so when I use 'stc.in_label(label)', I only get vertices in one
hemisphere; 'stc.vertices' returns a list in which one of the arrays is
empty.)

Hi Natalie and others,

It was actually just my failure to understand the syntax of the output. I needed to change this line:

func_labels,_ = mne.stc_to_label(stc_mean_label, src=src, smooth=True,
                                  subjects_dir=subjects_dir, connected=True)
to:

_,func_labels = mne.stc_to_label(stc_mean_label, src=src, smooth=True,
                                  subjects_dir=subjects_dir, connected=True)

in order to get my list of rh labels. Thus the emptiness of my list of right hemisphere labels. Thanks to Ivan on the martinos-python list for pointing that out. So (in case it helps anyone else), something like:

func_labels_lh, func_labels_rh = mne.stc_to_label(stc_mean_label, src=src, smooth=True,
                                  subjects_dir=subjects_dir, connected=True)

would get me two lists, each containing the respective lh and rh labels (as I'm imagining is obvious to anyone with more than a week's worth of python experience).

Thanks for trying to help Natalie!