code: def plot_bem(
      subject,
      subjects_dir=None,
      orientation="coronal",
      slices=None,
      brain_surfaces=None,
      src=None,
      show=True,
      show_indices=True,
      mri="T1.mgz",
      show_orientation=True,
  ):
      """Plot BEM contours on anatomical MRI slices.
  
      Parameters
      ----------
      %(subject)s
      %(subjects_dir)s
      orientation : str
          'coronal' or 'axial' or 'sagittal'.
      slices : list of int | None
          The indices of the MRI slices to plot. If ``None``, automatically
          pick 12 equally-spaced slices.
      brain_surfaces : str | list of str | None
          One or more brain surface to plot (optional). Entries should correspond
          to files in the subject's ``surf`` directory (e.g. ``"white"``).
      src : SourceSpaces | path-like | None
          SourceSpaces instance or path to a source space to plot individual
          sources as scatter-plot. Sources will be shown on exactly one slice
          (whichever slice is closest to each source in the given orientation
          plane). Path can be absolute or relative to the subject's ``bem``
          folder.
  
          .. versionchanged:: 0.20
             All sources are shown on the nearest slice rather than some
             being omitted.
      show : bool
          Show figure if True.
      show_indices : bool
          Show slice indices if True.
  
          .. versionadded:: 0.20
      mri : str
          The name of the MRI to use. Can be a standard FreeSurfer MRI such as
          ``'T1.mgz'``, or a full path to a custom MRI file.
  
          .. versionadded:: 0.21
      show_orientation : bool | str
          Show the orientation (L/R, P/A, I/S) of the data slices.
          True (default) will only show it on the outside most edges of the
          figure, False will never show labels, and "always" will label each
          plot.
  
          .. versionadded:: 0.21
          .. versionchanged:: 0.24
             Added support for "always".
  
      Returns
      -------
      fig : instance of matplotlib.figure.Figure
          The figure.
  
      See Also
      --------
      mne.viz.plot_alignment
  
      Notes
      -----
      Images are plotted in MRI voxel coordinates.
  
      If ``src`` is not None, for a given slice index, all source points are
      shown that are halfway between the previous slice and the given slice,
      and halfway between the given slice and the next slice.
      For large slice decimations, this can
      make some source points appear outside the BEM contour, which is shown
      for the given slice index. For example, in the case where the single
      midpoint slice is used ``slices=[128]``, all source points will be shown
      on top of the midpoint MRI slice with the BEM boundary drawn for that
      slice.
      """
      from ..source_space import SourceSpaces, read_source_spaces
  
      subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
      mri_fname = _check_mri(mri, subject, subjects_dir)
  
      # Get the BEM surface filenames
      bem_path = subjects_dir / subject / "bem"
  
      if not bem_path.is_dir():
          raise OSError(
              f'Subject bem directory "{bem_path}" does not exist'
          )
  
      surfaces = _get_bem_plotting_surfaces(bem_path)
      if brain_surfaces is not None:
          if isinstance(brain_surfaces, str):
              brain_surfaces = (brain_surfaces,)
          for surf_name in brain_surfaces:
              for hemi in ("lh", "rh"):
                  surf_fname = (
                      subjects_dir
                      / subject
                      / "surf"
                      / f"{hemi}.{surf_name}"
                  )
                  if surf_fname.exists():
                      surfaces.append((surf_fname, "#00DD00"))
                  else:
                      raise OSError(
                          "Surface %s does not exist." % surf_fname
                      )
  
      # TODO: Refactor with / improve _ensure_src to do this
      if isinstance(src, (str, Path, os.PathLike)):
          src = Path(src)
          if not src.exists():
              # convert to Path until get_subjects_dir returns a Path object
              src_ = Path(subjects_dir) / subject / "bem" / src
              if not src_.exists():
                  raise OSError(f"{src} does not exist")
              src = src_
          src = read_source_spaces(src)
      elif src is not None and not isinstance(src, SourceSpaces):
          raise TypeError(
              "src needs to be None, path-like or SourceSpaces instance, "
              "not %s" % repr(src)
          )
  
      if len(surfaces) == 0:
          raise OSError(
              "No surface files found. Surface files must end with "
              "inner_skull.surf, outer_skull.surf or outer_skin.surf"
          )
  
      # Plot the contours
      fig = _plot_mri_contours(
          mri_fname=mri_fname,
          surfaces=surfaces,
          src=src,
          orientation=orientation,
          slices=slices,
          show=show,
          show_indices=show_indices,
          show_orientation=show_orientation,
          slices_as_subplots=True,
      )
      return fig
  
imports: import copy
  import io
  import os
  import os.path
  import warnings
  from collections import defaultdict
  from glob import glob
  from itertools import cycle
  from pathlib import Path
  import numpy
  from scipy.signal import filtfilt, freqz, group_delay, lfilter, sosfilt, sosfiltfilt
  from .._fiff.constants import FIFF
  from .._fiff.pick import _DATA_CH_TYPES_SPLIT, _picks_by_type, pick_channels, pick_info, pick_types
  from .._fiff.proj import make_projector
  from .._freesurfer import _check_mri, _mri_orientation, _read_mri_info, _reorient_image
  from ..defaults import DEFAULTS
  from ..filter import estimate_ringing_samples
  from ..fixes import _safe_svd
  from ..rank import compute_rank
  from ..surface import read_surface
  from ..transforms import _frame_to_str, apply_trans
  from ..utils import _check_option, _mask_to_onsets_offsets, _on_missing, _pl, fill_doc, get_subjects_dir, logger, verbose, warn
  from .utils import _figure_agg, _get_color_list, _prepare_trellis, _validate_type, plt_show
label_desc: Use image node_id 5 for calling a global function with example usage: plot_bem(subject, subjects_dir, orientation, slices, brain_surfaces, src, show, show_indices, mri, show_orientation) and returns: fig