code: def renamed_domain(mapping, newnames, name=""):
      """New coordmap with the coordinates of function_domain renamed
  
      Parameters
      ----------
      newnames: dict
         A dictionary whose keys are integers or are in
         mapping.function_range.coord_names and whose values are the new
         names.
  
      Returns
      -------
      newmapping : CoordinateMap or AffineTransform
         A new mapping with renamed function_domain. If
         isinstance(mapping, AffineTransform), newmapping is also an
         AffineTransform. Otherwise, it is a CoordinateMap.
  
      Examples
      --------
      >>> affine_domain = CoordinateSystem('ijk')
      >>> affine_range = CoordinateSystem('xyz')
      >>> affine_matrix = np.identity(4)
      >>> affine_mapping = AffineTransform(affine_domain, affine_range, affine_matrix)
  
      >>> new_affine_mapping = affine_mapping.renamed_domain({'i':'phase','k':'freq','j':'slice'})
      >>> new_affine_mapping.function_domain
      CoordinateSystem(coord_names=('phase', 'slice', 'freq'), name='', coord_dtype=float64)
  
      >>> new_affine_mapping = affine_mapping.renamed_domain({'i':'phase','k':'freq','l':'slice'})
      Traceback (most recent call last):
         ...
      ValueError: no domain coordinate named l
      """
      for key in list(newnames):
          if type(key) == int:
              newnames[
                  mapping.function_domain.coord_names[key]
              ] = newnames[key]
              del newnames[key]
  
      for key in list(newnames):
          if key not in mapping.function_domain.coord_names:
              raise ValueError(f"no domain coordinate named {str(key)}")
  
      new_coord_names = []
      for n in mapping.function_domain.coord_names:
          if n in newnames:
              new_coord_names.append(newnames[n])
          else:
              new_coord_names.append(n)
  
      new_function_domain = CoordinateSystem(
          new_coord_names,
          mapping.function_domain.name,
          coord_dtype=mapping.function_domain.coord_dtype,
      )
  
      ndim = mapping.ndims[0]
      ident_map = AffineTransform(
          new_function_domain,
          mapping.function_domain,
          np.identity(ndim + 1),
      )
  
      if isinstance(mapping, AffineTransform):
          return _compose_affines(mapping, ident_map)
      else:
          return _compose_cmaps(mapping, _as_coordinate_map(ident_map))
  
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 6 for calling a global function with example usage: renamed_domain(mapping, newnames, name) and returns: _compose_affines, _compose_cmaps