code: def test_rollaxis():
      data = np.random.standard_normal((3, 4, 7, 5))
      im = Image(
          data,
          AffineTransform.from_params(
              "ijkl", "xyzt", np.diag([1, 2, 3, 4, 1])
          ),
      )
      with pytest.deprecated_call():
          image.rollaxis(im, 1)
      # for the inverse we must specify an integer
      pytest.raises(ValueError, image.rollaxis, im, "i", True)
      # Check that rollaxis preserves diagonal affines, as claimed
      assert_almost_equal(
          image.rollaxis(im, 1).affine, np.diag([2, 1, 3, 4, 1])
      )
      assert_almost_equal(
          image.rollaxis(im, 2).affine, np.diag([3, 1, 2, 4, 1])
      )
      assert_almost_equal(
          image.rollaxis(im, 3).affine, np.diag([4, 1, 2, 3, 1])
      )
      # Check that ambiguous axes raise an exception
      # 'l' appears both as an axis and a reference coord name
      # and in different places
      im_amb = Image(
          data,
          AffineTransform.from_params(
              "ijkl", "xylt", np.diag([1, 2, 3, 4, 1])
          ),
      )
      pytest.raises(ValueError, image.rollaxis, im_amb, "l")
      # But if it's unambiguous, then
      # 'l' can appear both as an axis and a reference coord name
      im_unamb = Image(
          data,
          AffineTransform.from_params(
              "ijkl", "xyzl", np.diag([1, 2, 3, 4, 1])
          ),
      )
      im_rolled = image.rollaxis(im_unamb, "l")
      assert_almost_equal(
          im_rolled.get_fdata(),
          im_unamb.get_fdata().transpose([3, 0, 1, 2]),
      )
      for i, o, n in zip("ijkl", "xyzt", range(4)):
          im_i = image.rollaxis(im, i)
          im_o = image.rollaxis(im, o)
          im_n = image.rollaxis(im, n)
          assert_almost_equal(im_i.get_fdata(), im_o.get_fdata())
          assert_almost_equal(im_i.affine, im_o.affine)
          assert_almost_equal(im_n.get_fdata(), im_o.get_fdata())
          for _im in [im_n, im_o, im_i]:
              im_n_inv = image.rollaxis(_im, n, inverse=True)
              assert_almost_equal(im_n_inv.affine, im.affine)
              assert_almost_equal(im_n_inv.get_fdata(), im.get_fdata())
  
imports: import warnings
  from itertools import chain
  import nibabel
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from ...api import data_generator, parcels, write_data
  from ...reference.coordinate_map import AffineTransform, AxisError
  from ...reference.coordinate_system import CoordinateSystem
  from ..None import image
  from ..image import Image, is_image, iter_axis, rollimg
label_desc: Use image node_id 20 for calling a global function with example usage: test_rollaxis() without return types