code: def _check_sphere(sphere, info=None, sphere_units="m"):
      from ..bem import (
          ConductorModel,
          fit_sphere_to_headshape,
          get_fitting_dig,
      )
  
      if sphere is None:
          sphere = HEAD_SIZE_DEFAULT
          if info is not None:
              # Decide if we have enough dig points to do the auto fit
              try:
                  get_fitting_dig(info, "extra", verbose="error")
              except (RuntimeError, ValueError):
                  pass
              else:
                  sphere = "auto"
  
      if isinstance(sphere, str):
          if sphere not in ("auto", "eeglab"):
              raise ValueError(
                  f'sphere, if str, must be "auto" or "eeglab", got {sphere}'
              )
          assert info is not None
  
          if sphere == "auto":
              R, r0, _ = fit_sphere_to_headshape(
                  info, verbose=_verbose_safe_false(), units="m"
              )
              sphere = tuple(r0) + (R,)
              sphere_units = "m"
          elif sphere == "eeglab":
              # We need coordinates for the 2D plane formed by
              # Fpz<->Oz and T7<->T8, as this plane will be the horizon (i.e. it
              # will determine the location of the head circle).
              #
              # We implement some special-handling in case Fpz is missing, as
              # this seems to be a quite common situation in numerous EEG labs.
              montage = info.get_montage()
              if montage is None:
                  raise ValueError(
                      'No montage was set on your data, but sphere="eeglab" '
                      "can only work if digitization points for the EEG "
                      "channels are available. Consider calling set_montage() "
                      "to apply a montage."
                  )
              ch_pos = montage.get_positions()["ch_pos"]
              horizon_ch_names = ("Fpz", "Oz", "T7", "T8")
  
              if "FPz" in ch_pos:  # "fix" naming
                  ch_pos["Fpz"] = ch_pos["FPz"]
                  del ch_pos["FPz"]
              elif "Fpz" not in ch_pos and "Oz" in ch_pos:
                  logger.info(
                      "Approximating Fpz location by mirroring Oz along "
                      "the X and Y axes."
                  )
                  # This assumes Fpz and Oz have the same Z coordinate
                  ch_pos["Fpz"] = ch_pos["Oz"] * [-1, -1, 1]
  
              for ch_name in horizon_ch_names:
                  if ch_name not in ch_pos:
                      msg = (
                          f'sphere="eeglab" requires digitization points of '
                          f"the following electrode locations in the data: "
                          f'{", ".join(horizon_ch_names)}, but could not find: '
                          f"{ch_name}"
                      )
                      if ch_name == "Fpz":
                          msg += (
                              ", and was unable to approximate its location "
                              "from Oz"
                          )
                      raise ValueError(msg)
  
              # Calculate the radius from: T7<->T8, Fpz<->Oz
              radius = np.abs(
                  [
                      ch_pos["T7"][0],  # X axis
                      ch_pos["T8"][0],  # X axis
                      ch_pos["Fpz"][1],  # Y axis
                      ch_pos["Oz"][1],  # Y axis
                  ]
              ).mean()
  
              # Calculate the center of the head sphere
              # Use 4 digpoints for each of the 3 axes to hopefully get a better
              # approximation than when using just 2 digpoints.
              sphere_locs = dict()
              for idx, axis in enumerate(("X", "Y", "Z")):
                  sphere_locs[axis] = np.mean(
                      [
                          ch_pos["T7"][idx],
                          ch_pos["T8"][idx],
                          ch_pos["Fpz"][idx],
                          ch_pos["Oz"][idx],
                      ]
                  )
              sphere = (
                  sphere_locs["X"],
                  sphere_locs["Y"],
                  sphere_locs["Z"],
                  radius,
              )
              sphere_units = "m"
              del sphere_locs, radius, montage, ch_pos
      elif isinstance(sphere, ConductorModel):
          if not sphere["is_sphere"] or len(sphere["layers"]) == 0:
              raise ValueError(
                  "sphere, if a ConductorModel, must be spherical "
                  "with multiple layers, not a BEM or single-layer "
                  "sphere (got %s)" % (sphere,)
              )
          sphere = tuple(sphere["r0"]) + (sphere["layers"][0]["rad"],)
          sphere_units = "m"
      sphere = np.array(sphere, dtype=float)
      if sphere.shape == ():
          sphere = np.concatenate([[0.0] * 3, [sphere]])
      if sphere.shape != (4,):
          raise ValueError(
              "sphere must be float or 1D array of shape (4,), got "
              "array-like of shape %s" % (sphere.shape,)
          )
      _check_option("sphere_units", sphere_units, ("m", "mm"))
      if sphere_units == "mm":
          sphere /= 1000.0
  
      sphere = np.array(sphere, float)
      return sphere
  
imports: import numbers
  import operator
  import os
  import re
  from builtins import input
  from difflib import get_close_matches
  from importlib import import_module
  from pathlib import Path
  import numpy
  from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
  from ..fixes import _compare_version, _median_complex
  from ._logging import _record_warnings, _verbose_safe_false, logger, verbose, warn
label_desc: Use image node_id 43 for calling a global function with example usage: _check_sphere(sphere, info, sphere_units) and returns: sphere