code: def _get_head_surface(
      surf, subject, subjects_dir, bem=None, verbose=None
  ):
      """Get a head surface from the Freesurfer subject directory.
  
      Parameters
      ----------
      surf : str
          The name of the surface 'auto', 'head', 'outer_skin', 'head-dense'
          or 'seghead'.
      %(subject)s
      %(subjects_dir)s
      bem : mne.bem.ConductorModel | None
          The conductor model that stores information about the head surface.
      %(verbose)s
  
      Returns
      -------
      head_surf : dict | None
          A dictionary with keys 'rr', 'tris', 'ntri', 'use_tris', 'np'
          and 'coord_frame' that store information for mesh plotting and other
          useful information about the head surface.
  
      Notes
      -----
      .. versionadded: 0.24
      """
      from .bem import _bem_find_surface, read_bem_surfaces
  
      _check_option(
          "surf",
          surf,
          ("auto", "head", "outer_skin", "head-dense", "seghead"),
      )
      if surf in ("auto", "head", "outer_skin"):
          if bem is not None:
              try:
                  return _bem_find_surface(bem, "head")
              except RuntimeError:
                  logger.info(
                      "Could not find the surface for "
                      "head in the provided BEM model, "
                      "looking in the subject directory."
                  )
      if subject is None:
          if surf == "auto":
              return
          raise ValueError(
              "To plot the head surface, the BEM/sphere"
              " model must contain a head surface "
              'or "subject" must be provided (got '
              "None)"
          )
      subject_dir = op.join(
          get_subjects_dir(subjects_dir, raise_error=True), subject
      )
      if surf in ("head-dense", "seghead"):
          try_fnames = [
              op.join(subject_dir, "bem", f"{subject}-head-dense.fif"),
              op.join(subject_dir, "surf", "lh.seghead"),
          ]
      else:
          try_fnames = [
              op.join(subject_dir, "bem", "outer_skin.surf"),
              op.join(subject_dir, "bem", "flash", "outer_skin.surf"),
              op.join(subject_dir, "bem", f"{subject}-head-sparse.fif"),
              op.join(subject_dir, "bem", f"{subject}-head.fif"),
          ]
      for fname in try_fnames:
          if op.exists(fname):
              logger.info(
                  f"Using {op.basename(fname)} for head surface."
              )
              if op.splitext(fname)[-1] == ".fif":
                  return read_bem_surfaces(fname, on_defects="warn")[0]
              else:
                  return _read_mri_surface(fname)
      raise OSError(
          "No head surface found for subject "
          f"{subject} after trying:\n" + "\n".join(try_fnames)
      )
  
imports: import os.path
  from gzip import GzipFile
  from pathlib import Path
  import numpy
  from ._fiff.constants import FIFF
  from ._fiff.meas_info import read_fiducials
  from .surface import _read_mri_surface, read_surface
  from .transforms import Transform, _ensure_trans, apply_trans, combine_transforms, invert_transform, read_ras_mni_t
  from .utils import _check_fname, _check_option, _import_nibabel, _validate_type, get_subjects_dir, logger, verbose
label_desc: Use image node_id 22 for calling a global function with example usage: _get_head_surface(surf, subject, subjects_dir, bem, verbose) and returns: _bem_find_surface, read_bem_surfaces, _read_mri_surface