

def __add__(self, other):
    if isinstance(other, BiHemiLabel):
        return (other + self)
    elif isinstance(other, Label):
        if (self.subject != other.subject):
            raise ValueError(('Label subject parameters must match, got "%s" and "%s". Consider setting the subject parameter on initialization, or setting label.subject manually before combining labels.' % (self.subject, other.subject)))
        if (self.hemi != other.hemi):
            name = ('%s + %s' % (self.name, other.name))
            if (self.hemi == 'lh'):
                (lh, rh) = (self.copy(), other.copy())
            else:
                (lh, rh) = (other.copy(), self.copy())
            color = _blend_colors(self.color, other.color)
            return BiHemiLabel(lh, rh, name, color)
    else:
        raise TypeError(('Need: Label or BiHemiLabel. Got: %r' % other))
    duplicates = np.intersect1d(self.vertices, other.vertices)
    n_dup = len(duplicates)
    if n_dup:
        self_dup = [np.where((self.vertices == d))[0][0] for d in duplicates]
        other_dup = [np.where((other.vertices == d))[0][0] for d in duplicates]
        if (not np.all((self.pos[self_dup] == other.pos[other_dup]))):
            err = ('Labels %r and %r: vertices overlap but differ in position values' % (self.name, other.name))
            raise ValueError(err)
        isnew = np.array([(v not in duplicates) for v in other.vertices])
        vertices = np.hstack((self.vertices, other.vertices[isnew]))
        pos = np.vstack((self.pos, other.pos[isnew]))
        tgt_idx = [np.where((vertices == v))[0][0] for v in other.vertices]
        n_self = len(self.values)
        n_other = len(other.values)
        new_len = ((n_self + n_other) - n_dup)
        values = np.zeros(new_len, dtype=self.values.dtype)
        values[:n_self] += self.values
        values[tgt_idx] += other.values
    else:
        vertices = np.hstack((self.vertices, other.vertices))
        pos = np.vstack((self.pos, other.pos))
        values = np.hstack((self.values, other.values))
    indcs = np.argsort(vertices)
    (vertices, pos, values) = (vertices[indcs], pos[indcs, :], values[indcs])
    comment = ('%s + %s' % (self.comment, other.comment))
    name0 = (self.name if self.name else 'unnamed')
    name1 = (other.name if other.name else 'unnamed')
    name = ('%s + %s' % (name0, name1))
    color = _blend_colors(self.color, other.color)
    verbose = (self.verbose or other.verbose)
    label = Label(vertices, pos, values, self.hemi, comment, name, None, self.subject, color, verbose)
    return label

dataset/ETHPy150Open mne-tools/mne-python/mne/label.py Label.__add__/original