

def grow_labels(subject, seeds, extents, hemis, subjects_dir=None, n_jobs=1, overlap=True, names=None, surface='white'):
    'Generate circular labels in source space with region growing\n\n    This function generates a number of labels in source space by growing\n    regions starting from the vertices defined in "seeds". For each seed, a\n    label is generated containing all vertices within a maximum geodesic\n    distance on the white matter surface from the seed.\n\n    Note: "extents" and "hemis" can either be arrays with the same length as\n          seeds, which allows using a different extent and hemisphere for each\n          label, or integers, in which case the same extent and hemisphere is\n          used for each label.\n\n    Parameters\n    ----------\n    subject : string\n        Name of the subject as in SUBJECTS_DIR.\n    seeds : int | list\n        Seed, or list of seeds. Each seed can be either a vertex number or\n        a list of vertex numbers.\n    extents : array | float\n        Extents (radius in mm) of the labels.\n    hemis : array | int\n        Hemispheres to use for the labels (0: left, 1: right).\n    subjects_dir : string\n        Path to SUBJECTS_DIR if not set in the environment.\n    n_jobs : int\n        Number of jobs to run in parallel. Likely only useful if tens\n        or hundreds of labels are being expanded simultaneously. Does not\n        apply with ``overlap=False``.\n    overlap : bool\n        Produce overlapping labels. If True (default), the resulting labels\n        can be overlapping. If False, each label will be grown one step at a\n        time, and occupied territory will not be invaded.\n    names : None | list of str\n        Assign names to the new labels (list needs to have the same length as\n        seeds).\n    surface : string\n        The surface used to grow the labels, defaults to the white surface.\n\n    Returns\n    -------\n    labels : list of Label\n        The labels\' ``comment`` attribute contains information on the seed\n        vertex and extent; the ``values``  attribute contains distance from the\n        seed in millimeters\n    '
    subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
    n_jobs = check_n_jobs(n_jobs)
    if np.isscalar(seeds):
        seeds = [seeds]
    seeds = np.atleast_1d([np.atleast_1d(seed) for seed in seeds])
    extents = np.atleast_1d(extents)
    hemis = np.atleast_1d(hemis)
    n_seeds = len(seeds)
    if ((len(extents) != 1) and (len(extents) != n_seeds)):
        raise ValueError('The extents parameter has to be of length 1 or len(seeds)')
    if ((len(hemis) != 1) and (len(hemis) != n_seeds)):
        raise ValueError('The hemis parameter has to be of length 1 or len(seeds)')
    if (len(extents) == 1):
        extents = np.tile(extents, n_seeds)
    if (len(hemis) == 1):
        hemis = np.tile(hemis, n_seeds)
    hemis = np.array([('lh' if (h == 0) else 'rh') for h in hemis])
    if (names is None):
        names = [('Label_%i-%s' % items) for items in enumerate(hemis)]
    else:
        if np.isscalar(names):
            names = [names]
        if (len(names) != n_seeds):
            raise ValueError('The names parameter has to be None or have length len(seeds)')
        for (i, hemi) in enumerate(hemis):
            if (not names[i].endswith(hemi)):
                names[i] = '-'.join((names[i], hemi))
    names = np.array(names)
    (tris, vert, dist) = ({
        
    }, {
        
    }, {
        
    })
    for hemi in set(hemis):
        surf_fname = op.join(subjects_dir, subject, 'surf', ((hemi + '.') + surface))
        (vert[hemi], tris[hemi]) = read_surface(surf_fname)
        dist[hemi] = mesh_dist(tris[hemi], vert[hemi])
    if overlap:
        (parallel, my_grow_labels, _) = parallel_func(_grow_labels, n_jobs)
        seeds = np.array_split(seeds, n_jobs)
        extents = np.array_split(extents, n_jobs)
        hemis = np.array_split(hemis, n_jobs)
        names = np.array_split(names, n_jobs)
        labels = sum(parallel((my_grow_labels(s, e, h, n, dist, vert, subject) for (s, e, h, n) in zip(seeds, extents, hemis, names))), [])
    else:
        labels = _grow_nonoverlapping_labels(subject, seeds, extents, hemis, vert, dist, names)
    colors = _n_colors(len(labels))
    for (label, color) in zip(labels, colors):
        label.color = color
    return labels

dataset/ETHPy150Open mne-tools/mne-python/mne/label.py grow_labels/original