code: def reordered_range(mapping, order=None):
      """New coordmap with the coordinates of function_range reordered
  
      Defaults to reversing the coordinates of function_range.
  
      Parameters
      ----------
      order: sequence
         Order to use, defaults to reverse. The elements can be integers,
         strings or 2-tuples of strings.  If they are strings, they should
         be in mapping.function_range.coord_names.
  
      Returns
      -------
      newmapping : CoordinateMap or AffineTransform
         A new CoordinateMap with the coordinates of function_range
         reordered.  If isinstance(mapping, AffineTransform), newmapping
         is also an AffineTransform. Otherwise, it is a CoordinateMap.
  
      Examples
      --------
      >>> input_cs = CoordinateSystem('ijk')
      >>> output_cs = CoordinateSystem('xyz')
      >>> cm = AffineTransform(input_cs, output_cs, np.identity(4))
      >>> cm.reordered_range('xzy').function_range
      CoordinateSystem(coord_names=('x', 'z', 'y'), name='', coord_dtype=float64)
      >>> cm.reordered_range([0,2,1]).function_range.coord_names
      ('x', 'z', 'y')
  
      >>> newcm = cm.reordered_range('yzx')
      >>> newcm.function_range.coord_names
      ('y', 'z', 'x')
  
      Notes
      -----
      If no reordering is to be performed, it returns a copy of mapping.
      """
      ndim = mapping.ndims[1]
      if order is None:
          order = list(range(ndim))[::-1]
      elif type(order[0]) == str:
          order = [mapping.function_range.index(s) for s in order]
  
      newaxes = [mapping.function_range.coord_names[i] for i in order]
      newoutcoords = CoordinateSystem(
          newaxes,
          mapping.function_range.name,
          mapping.function_range.coord_dtype,
      )
  
      perm = np.zeros((ndim + 1,) * 2)
      perm[-1, -1] = 1.0
  
      for i, j in enumerate(order):
          perm[j, i] = 1.0
  
      if np.allclose(perm, np.identity(perm.shape[0])):
          import copy
  
          return copy.copy(mapping)
  
      perm = perm.astype(mapping.function_range.coord_dtype)
  
      A = AffineTransform(mapping.function_range, newoutcoords, perm.T)
  
      if isinstance(mapping, AffineTransform):
          return _compose_affines(A, mapping)
      else:
          return _compose_cmaps(_as_coordinate_map(A), 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 8 for calling a global function with example usage: reordered_range(mapping, order) and returns: copy, _compose_affines, _compose_cmaps