code: def test_image_xyz_affine():
      # Test getting the image xyz affines
      arr = np.arange(24).reshape((2, 3, 4)).astype(float)
      aff = np.diag([2, 3, 4, 1])
      img = Image(arr, vox2mni(aff))
      assert is_xyz_affable(img)
      assert_array_equal(xyz_affine(img), aff)
      arr4 = np.arange(24).reshape((1, 2, 3, 4))
      img4 = Image(arr4, vox2mni(np.diag([2, 3, 4, 5, 1])))
      assert is_xyz_affable(img4)
      img4_r = img4.reordered_axes([3, 2, 0, 1])
      assert not is_xyz_affable(img4_r)
      pytest.raises(AxesError, xyz_affine, img4_r)
      nimg = nib.Nifti1Image(arr, aff)
      assert is_xyz_affable(nimg)
      assert_array_equal(xyz_affine(nimg), aff)
      # Any dimensions not spatial, AxesError
      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, xyz_affine, 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, xyz_affine, img)
      assert_array_equal(xyz_affine(img, my_valtor), aff)
  
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 1 for calling a global function with example usage: test_image_xyz_affine() without return types