code: def renamed_range(mapping, newnames):
      """New coordmap with the coordinates of function_range renamed
  
      Parameters
      ----------
      newnames : dict
         A dictionary whose keys are integers or in
         mapping.function_range.coord_names and whose values are the new
         names.
  
      Returns
      -------
      newmapping : CoordinateMap or AffineTransform
         A new CoordinateMap with the coordinates of function_range
         renamed.  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_range({'x':'u'})
      >>> new_affine_mapping.function_range
      CoordinateSystem(coord_names=('u', 'y', 'z'), name='', coord_dtype=float64)
  
      >>> new_affine_mapping = affine_mapping.renamed_range({'w':'u'})
      Traceback (most recent call last):
         ...
      ValueError: no range coordinate named w
      """
      for key in list(newnames):
          if type(key) == int:
              newnames[
                  mapping.function_range.coord_names[key]
              ] = newnames[key]
              del newnames[key]
  
      for key in list(newnames):
          if key not in mapping.function_range.coord_names:
              raise ValueError(f"no range coordinate named {str(key)}")
  
      new_coord_names = []
      for n in mapping.function_range.coord_names:
          if n in newnames:
              new_coord_names.append(newnames[n])
          else:
              new_coord_names.append(n)
  
      new_function_range = CoordinateSystem(
          new_coord_names,
          mapping.function_range.name,
          coord_dtype=mapping.function_range.coord_dtype,
      )
  
      ndim = mapping.ndims[1]
      ident_map = AffineTransform(
          mapping.function_range,
          new_function_range,
          np.identity(ndim + 1),
      )
  
      if isinstance(mapping, AffineTransform):
          return _compose_affines(ident_map, mapping)
      else:
          return _compose_cmaps(_as_coordinate_map(ident_map), mapping)
  
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 7 for calling a global function with example usage: renamed_range(mapping, newnames) and returns: _compose_affines, _compose_cmaps