code: def test_il_from_image():
      exp_shape = (17, 21, 3, 20)
      assert FIMG.shape == exp_shape
      # from_image construction
      imglst = ImageList.from_image(FIMG, axis=-1)
      # Test axis must be specified
      pytest.raises(ValueError, ImageList.from_image, FIMG)
      pytest.raises(ValueError, ImageList.from_image, FIMG, None)
      # check all the axes
      for i in range(4):
          order = list(range(4))
          order.remove(i)
          order.insert(0, i)
          img_re_i = FIMG.reordered_reference(order).reordered_axes(
              order
          )
          imglst_i = ImageList.from_image(FIMG, axis=i)
          assert imglst_i.list[0].shape == img_re_i.shape[1:]
          # check the affine as well
          assert_almost_equal(
              imglst_i.list[0].affine, img_re_i.affine[1:, 1:]
          )
      # length of image list should match number of frames
      assert len(imglst) == FIMG.shape[3]
      # check the affine
      A = np.identity(4)
      A[:3, :3] = FIMG.affine[:3, :3]
      A[:3, -1] = FIMG.affine[:3, -1]
      assert_almost_equal(imglst.list[0].affine, A)
      # Check other ways of naming axis
      assert len(ImageList.from_image(FIMG, axis="t")) == 20
      # Input and output axis names work
      new_cmap = AffineTransform(
          CoordinateSystem("ijkl"),
          FIMG.coordmap.function_range,
          FIMG.coordmap.affine,
      )
      fimg2 = Image(FIMG.get_fdata(), new_cmap)
      assert len(ImageList.from_image(fimg2, axis="t")) == 20
      assert len(ImageList.from_image(fimg2, axis="l")) == 20
      pytest.raises(AxisError, ImageList.from_image, FIMG, "q")
      # Check non-dropping case
      ndlist = ImageList.from_image(FIMG, axis="t", dropout=False)
      element = ndlist[1]
      assert element.coordmap == FIMG[..., 1].coordmap
  
file_path: nipy/nipy/core/image/tests/test_image_list.py
imports: import numpy
  import pytest
  from ....core.reference.coordinate_map import AffineTransform, AxisError, CoordinateSystem
  from ....io.api import load_image
  from ....testing import assert_almost_equal, funcfile
  from ..image import Image
  from ..image_list import ImageList, iter_axis
label_desc: Use image node_id 2 for calling a global function with example usage: test_il_from_image() without return types