code: def create_sphere_around_elec(xyz, template_mri, distance=8, freesurfer=None):
      
      if freesurfer is None:
          shift = 0
      else:
          shift = freesurfer.surface_ras_shift
  
      if isinstance(template_mri, str) or isinstance(template_mri, Path):
          template_mri = nload(str(template_mri))
  
      mask = zeros(template_mri.shape, dtype='bool')
      for vox in ndindex(template_mri.shape):
          vox_ras = apply_affine(template_mri.affine, vox) - shift
          if norm(xyz - vox_ras) <= distance:
              mask[vox] = True
  
      return mask
docs: Create an MRI mask around an electrode location,
  
      Parameters
      ----------
      xyz : ndarray
          3x0 array
      template_mri : path or str (as path) or nibabel.Nifti
          (path to) MRI to be used as template
      distance : float
          distance in mm between electrode and selected voxels
      freesurfer : instance of Freesurfer
          to adjust RAS coordinates, see Notes
  
      Returns
      -------
      3d bool ndarray
          mask where True voxels are within selected distance to the electrode
  
      Notes
      -----
      Freesurfer uses two coordinate systems: one for volumes ("RAS") and one for
      surfaces ("tkReg", "tkRAS", and "Surface RAS"), so the electrodes might be
      stored in one of the two systems. If the electrodes are in surface
      coordinates (f.e. if you can plot surface and electrodes in the same space),
      then you need to convert the coordinate system. This is done by passing an
      instance of Freesurfer.