Potential bug with grow_labels()

Hello MNE-forum,

I have a potential bug or otherwise an issue that I’m unable to solve with MNE-python 0.22.0 on Ubuntu 18.04.

I would like to combine MEG source estimates of 24 visual stimuli to form a retinotopic map of the visual cortex. My approach is to find peaks of each response to use as a starting location and then extend them outwards a few millimeters without overlapping neighbouring patches.

I attempted doing it with the mne.grow_labels-function, but setting the overlap=False parameter crashes the code with all datasets. The error is as follows:

Traceback (most recent call last):

  File "/m/nbe/scratch/megci/MFinverse/Code/grow_labels_bugtest.py", line 16, in <module>
    labels =  mne.grow_labels('fsaverage', stc.get_peak(hemi = 'lh')[0], 1, 1, overlap = False)

  File "/work/modules/Ubuntu/14.04/amd64/common/anaconda3/latest/envs/neuroimaging_test/lib/python3.8/site-packages/mne/label.py", line 1635, in grow_labels
    labels = _grow_nonoverlapping_labels(subject, seeds, extents, hemis,

  File "/work/modules/Ubuntu/14.04/amd64/common/anaconda3/latest/envs/neuroimaging_test/lib/python3.8/site-packages/mne/label.py", line 1673, in _grow_nonoverlapping_labels
    if np.any(parc[seed] >= 0):

IndexError: arrays used as indices must be of integer (or boolean) type

I suspect this is due to the grow_labels function in label.py typecasting the seed vertex array to dtype object before passing it to _grow_nonoverlapping_labels(), which tries to use it as an array index. As far as I know, object arrays can’t be used this way hence the crash. Shouldn’t it be fixed by changing the array datatype to int or am I doing something terribly wrong here?

A simple example code which can reproduce this issue:

import mne
from mne.datasets import sample

data_path = sample.data_path()
fname = data_path + '/MEG/sample/sample_audvis-meg'

stc = mne.read_source_estimate(fname)

labels =  mne.grow_labels('fsaverage', stc.get_peak(hemi = 'lh')[0], 1, 1, overlap = False)

Thank you in advance!

I opened an issue

ALex

Thank you! I created an identical anaconda environment to try and fix it, it indeed seems to be only the data type which has to be changed for the function to work.