code: def _ensure_cmap(cmap):
      """
      Ensure that we have a `.Colormap` object.
  
      For internal use to preserve type stability of errors.
  
      Parameters
      ----------
      cmap : None, str, Colormap
  
          - if a `Colormap`, return it
          - if a string, look it up in mpl.colormaps
          - if None, look up the default color map in mpl.colormaps
  
      Returns
      -------
      Colormap
  
      """
      if isinstance(cmap, colors.Colormap):
          return cmap
      cmap_name = (
          cmap if cmap is not None else mpl.rcParams["image.cmap"]
      )
      # use check_in_list to ensure type stability of the exception raised by
      # the internal usage of this (ValueError vs KeyError)
      if cmap_name not in _colormaps:
          _api.check_in_list(sorted(_colormaps), cmap=cmap_name)
      return mpl.colormaps[cmap_name]
  
imports: from collections.abc import Mapping
  import functools
  import numpy
  from numpy import ma
  import matplotlib
  from matplotlib import _api, colors, cbook, scale
  from matplotlib._cm import datad
  from matplotlib._cm_listed import cmaps
label_desc: Use image node_id 6 for calling a global function with example usage: _ensure_cmap(cmap) and returns: mpl, cmap