code: def test_image_as_xyz_image():
      # Test getting xyz affable version of the image
      arr = np.arange(24, dtype="float32").reshape((1, 2, 3, 4))
      aff = np.diag([2, 3, 4, 5, 1])
      img = Image(arr, vox2mni(aff))
      img_r = as_xyz_image(img)
      assert img is img_r
      # Reorder, reverse reordering, test != and ==
      for order in ((3, 0, 1, 2), (0, 3, 1, 2)):
          img_ro_out = img.reordered_reference(order)
          img_ro_in = img.reordered_axes(order)
          img_ro_both = img_ro_out.reordered_axes(order)
          for tmap in (img_ro_out, img_ro_in, img_ro_both):
              assert not is_xyz_affable(tmap)
              img_r = as_xyz_image(tmap)
              assert not tmap is img_r
              assert img == img_r
              assert_array_equal(img.get_fdata(), img_r.get_fdata())
      img_t0 = rollimg(img, "t")
      assert not is_xyz_affable(img_t0)
      img_t0_r = as_xyz_image(img_t0)
      assert not img_t0 is img_t0_r
      assert_array_equal(img.get_fdata(), img_t0_r.get_fdata())
      assert img.coordmap == img_t0_r.coordmap
      # Test against nibabel image
      nimg = nib.Nifti1Image(arr, np.diag([2, 3, 4, 1]))
      nimg_r = as_xyz_image(nimg)
      assert nimg is nimg_r
      # It's sometimes impossible to make an xyz affable image
      # If the xyz coordinates depend on the time coordinate
      aff = np.array(
          [
              [2, 0, 0, 2, 20],
              [0, 3, 0, 0, 21],
              [0, 0, 4, 0, 22],
              [0, 0, 0, 5, 23],
              [0, 0, 0, 0, 1],
          ]
      )
      img = Image(arr, vox2mni(aff))
      pytest.raises(AffineError, as_xyz_image, img)
      # If any dimensions not spatial, AxesError
      arr = np.arange(24, dtype="float32").reshape((2, 3, 4))
      aff = np.diag([2, 3, 4, 1])
      d_cs = CS("ijk", "voxels")
      r_cs = CS(("mni-x=L->R", "mni-y=P->A", "mni-q"), "mni")
      cmap = AffineTransform(d_cs, r_cs, aff)
      img = Image(arr, cmap)
      pytest.raises(AxesError, as_xyz_image, img)
      # Can pass in own validator
      my_valtor = {"blind": "x", "leading": "y", "ditch": "z"}
      r_cs = CS(("blind", "leading", "ditch"), "fall")
      cmap = AffineTransform(d_cs, r_cs, aff)
      img = Image(arr, cmap)
      pytest.raises(AxesError, as_xyz_image, img)
      assert as_xyz_image(img, my_valtor) is img
  
file_path: nipy/nipy/core/image/tests/test_image_spaces.py
imports: import nibabel
  import numpy
  import pytest
  from nibabel.affines import from_matvec
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ...reference.coordinate_map import AffineTransform
  from ...reference.coordinate_system import CoordinateSystem
  from ...reference.spaces import AffineError, AxesError, SpaceError, XYZSpace, mni_space, talairach_space, vox2mni, vox2talairach, voxel_csm
  from ..image import Image, rollimg
  from ..image_spaces import as_xyz_image, is_xyz_affable, make_xyz_image, xyz_affine
label_desc: Use image node_id 2 for calling a global function with example usage: test_image_as_xyz_image() without return types