code: def _as_coordinate_map(cmap):
      """Return CoordinateMap from AffineTransform
  
      Take a mapping AffineTransform and return a
      CoordinateMap with the appropriate functions.
      """
      if isinstance(cmap, CoordinateMap):
          return cmap
      elif isinstance(cmap, AffineTransform):
          affine_transform = cmap
          A, b = to_matvec(affine_transform.affine)
  
          def _function(x):
              value = np.dot(x, A.T)
              value += b
              return value
  
          # Preserve dtype check because the CoordinateMap expects to generate the
          # expected dtype and checks this on object creation
          affine_transform_inv = affine_transform.inverse(
              preserve_dtype=True
          )
          if affine_transform_inv:
              Ainv, binv = to_matvec(affine_transform_inv.affine)
  
              def _inverse_function(x):
                  value = np.dot(x, Ainv.T)
                  value += binv
                  return value
  
          else:
              _inverse_function = None
  
          return CoordinateMap(
              affine_transform.function_domain,
              affine_transform.function_range,
              _function,
              _inverse_function,
          )
      else:
          raise ValueError(
              "all mappings should be instances of "
              "either CoordinateMap or AffineTransform"
          )
  
imports: import warnings
  import numpy
  import numpy.linalg
  from nibabel import io_orientation
  from nibabel.affines import from_matvec, to_matvec
  from .coordinate_system import CoordinateSystem, is_coordsys, safe_dtype
  from .coordinate_system import product
label_desc: Use image node_id 10 for calling a global function with example usage: _as_coordinate_map(cmap) and returns: cmap, CoordinateMap, value, value