'Compute the center of mass of the label.
This function computes the spatial center of mass on the surface
as in [1]_.
Parameters
subject : string | None
The subject the label is defined for.
restrict_vertices : bool | array of int | instance of SourceSpaces
If True, returned vertex will be one from the label. Otherwise,
it could be any vertex from surf. If an array of int, the
returned vertex will come from that array. If instance of
SourceSpaces (as of 0.13), the returned vertex will be from
the given source space. For most accuruate estimates, do not
restrict vertices.
subjects_dir : str, or None
Path to the SUBJECTS_DIR. If None, the path is obtained by using
the environment variable SUBJECTS_DIR.
surf : str
The surface to use for Euclidean distance center of mass
finding. The default here is "sphere", which finds the center
of mass on the spherical surface to help avoid potential issues
with cortical folding.
Returns
vertex : int
Vertex of the spatial center of mass for the inferred hemisphere,
with each vertex weighted by its label value.
See Also
SourceEstimate.center_of_mass
vertex_to_mni
Notes
.. versionadded: 0.13
References
.. [1] Larson and Lee, "The cortical dynamics underlying effective
switching of auditory spatial attention", NeuroImage 2012.'

def center_of_mass(self, subject=None, restrict_vertices=False, subjects_dir=None, surf='sphere'):

    if (not isinstance(surf, string_types)):
        raise TypeError(('surf    must    be    a    string,    got    %s' % (type(surf),)))
    subject = _check_subject(self.subject, subject)
    if np.any((self.values < 0)):
        raise ValueError('Cannot    compute    COM    with    negative    values')
    if np.all((self.values == 0)):
        raise ValueError('Cannot    compute    COM    with    all    values    ==    0.    For    structural    labels,    consider    setting    to    ones    via    label.values[:]    =    1.')
    vertex = _center_of_mass(self.vertices, self.values, self.hemi, surf, subject, subjects_dir, restrict_vertices)
    return vertex
