code: def rollaxis(img, axis, inverse=False):
      """Roll `axis` backwards, until it lies in the first position.
  
      It also reorders the reference coordinates by the same ordering.
      This is done to preserve a diagonal affine matrix if image.affine
      is diagonal. It also makes it possible to unambiguously specify
      an axis to roll along in terms of either a reference name (i.e. 'z')
      or an axis name (i.e. 'slice').
  
      This function is deprecated; please use ``rollimg`` instead.
  
      Parameters
      ----------
      img : Image
         Image whose axes and reference coordinates are to be reordered
         by rolling.
      axis : str or int
         Axis to be rolled, can be specified by name or as an integer.
      inverse : bool, optional
         If inverse is True, then axis must be an integer and the first axis is
         returned to the position axis.  This keyword is deprecated and we'll
         remove it in a future version of nipy.
  
      Returns
      -------
      newimg : Image
         Image with reordered axes and reference coordinates.
  
      Examples
      --------
      >>> data = np.zeros((30,40,50,5))
      >>> affine_transform = AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,2,3,4,1]))
      >>> im = Image(data, affine_transform)
      >>> im.coordmap
      AffineTransform(
         function_domain=CoordinateSystem(coord_names=('i', 'j', 'k', 'l'), name='', coord_dtype=float64),
         function_range=CoordinateSystem(coord_names=('x', 'y', 'z', 't'), name='', coord_dtype=float64),
         affine=array([[ 1.,  0.,  0.,  0.,  0.],
                       [ 0.,  2.,  0.,  0.,  0.],
                       [ 0.,  0.,  3.,  0.,  0.],
                       [ 0.,  0.,  0.,  4.,  0.],
                       [ 0.,  0.,  0.,  0.,  1.]])
      )
      >>> im_t_first = rollaxis(im, 't')
      >>> np.diag(im_t_first.affine)
      array([ 4.,  1.,  2.,  3.,  1.])
      >>> im_t_first.shape
      (5, 30, 40, 50)
      >>> im_t_first.coordmap
      AffineTransform(
         function_domain=CoordinateSystem(coord_names=('l', 'i', 'j', 'k'), name='', coord_dtype=float64),
         function_range=CoordinateSystem(coord_names=('t', 'x', 'y', 'z'), name='', coord_dtype=float64),
         affine=array([[ 4.,  0.,  0.,  0.,  0.],
                       [ 0.,  1.,  0.,  0.,  0.],
                       [ 0.,  0.,  2.,  0.,  0.],
                       [ 0.,  0.,  0.,  3.,  0.],
                       [ 0.,  0.,  0.,  0.,  1.]])
      )
      """
      if inverse not in (True, False):
          raise ValueError(
              "Inverse should be True or False; did you mean to "
              "use the ``rollimg` function instead?"
          )
      if isinstance(axis, int) and axis < 0:
          axis = img.ndim + axis
      if inverse:
          if type(axis) != int:
              raise ValueError(
                  "If carrying out inverse rolling, "
                  "axis must be an integer"
              )
          order = list(range(1, img.ndim))
          order.insert(axis, 0)
          return img.reordered_axes(order).reordered_reference(order)
      if axis not in chain(
          range(img.axes.ndim),
          img.axes.coord_names,
          img.reference.coord_names,
      ):
          raise ValueError(
              "axis must be an axis number,"
              "an axis name or a reference name"
          )
      # Find out which index axis corresponds to
      in_index = out_index = -1
      if type(axis) == str:
          try:
              in_index = img.axes.index(axis)
          except:
              pass
          try:
              out_index = img.reference.index(axis)
          except:
              pass
          if in_index > 0 and out_index > 0 and in_index != out_index:
              raise ValueError(
                  "ambiguous choice of axis -- it exists "
                  "both in as an axis name and a "
                  "reference name"
              )
          if in_index >= 0:
              axis = in_index
          else:
              axis = out_index
      if axis == -1:
          axis += img.axes.ndim
      order = list(range(img.ndim))
      order.remove(axis)
      order.insert(0, axis)
      return img.reordered_axes(order).reordered_reference(order)
  
imports: import warnings
  from copy import copy
  from itertools import chain
  import numpy
  from nibabel.onetime import auto_attr
  from ..reference.array_coords import ArrayCoordMap
  from ..reference.coordinate_map import AffineTransform, CoordinateSystem, input_axis_index
label_desc: Use image node_id 3 for calling a global function with example usage: rollaxis(img, axis, inverse) and returns: img, img