code: def _find_centroid_sphere(ch_pos, group_names):
      """Compute the centroid position between N electrodes.
  
      The centroid should be determined in spherical "head" coordinates which is
      more accurante than cutting through the scalp by averaging in cartesian
      coordinates.
  
      A simple way is to average the location in cartesian coordinate, convert
      to spehrical coordinate and replace the radius with the average radius of
      the N points in spherical coordinates.
  
      Parameters
      ----------
      ch_pos : OrderedDict
          The position of all channels in cartesian coordinates.
      group_names : list | tuple
          The name of the N electrodes used to determine the centroid.
  
      Returns
      -------
      pos_centroid : array of shape (3,)
          The position of the centroid in cartesian coordinates.
      """
      cartesian_positions = np.array(
          [ch_pos[ch_name] for ch_name in group_names]
      )
      sphere_positions = _cart_to_sph(cartesian_positions)
      cartesian_pos_centroid = np.average(cartesian_positions, axis=0)
      sphere_pos_centroid = _cart_to_sph(cartesian_pos_centroid)
      # average the radius and overwrite it
      avg_radius = np.average(sphere_positions, axis=0)[0]
      sphere_pos_centroid[0, 0] = avg_radius
      # convert back to cartesian
      pos_centroid = _sph_to_cart(sphere_pos_centroid)[0, :]
      return pos_centroid
  
file_path: mne-python/mne/preprocessing/interpolate.py
imports: from itertools import chain
  import numpy
  from scipy.sparse.csgraph import connected_components
  from .._fiff.meas_info import create_info
  from ..epochs import BaseEpochs, EpochsArray
  from ..evoked import Evoked, EvokedArray
  from ..io import BaseRaw, RawArray
  from ..transforms import _cart_to_sph, _sph_to_cart
  from ..utils import _ensure_int, _validate_type
label_desc: Use image node_id 3 for calling a global function with example usage: _find_centroid_sphere(ch_pos, group_names) and returns: pos_centroid