code: def test_make_xyz_image():
      # Standard neuro image creator
      arr = np.arange(24, dtype="float32").reshape((1, 2, 3, 4))
      aff = np.diag([2, 3, 4, 1])
      img = make_xyz_image(arr, aff, "mni")
      assert img.coordmap == vox2mni(aff, 1.0)
      assert_array_equal(img.get_fdata(), arr)
      img = make_xyz_image(arr, aff, "talairach")
      assert img.coordmap == vox2talairach(aff, 1.0)
      assert_array_equal(img.get_fdata(), arr)
      img = make_xyz_image(arr, aff, talairach_space)
      assert img.coordmap == vox2talairach(aff, 1.0)
      # Unknown space as string raises SpaceError
      pytest.raises(
          SpaceError, make_xyz_image, arr, aff, "unlikely space name"
      )
      funky_space = XYZSpace("hija")
      img = make_xyz_image(arr, aff, funky_space)
      csm = funky_space.to_coordsys_maker("t")
      in_cs = CS("ijkl", "voxels")
      exp_cmap = AffineTransform(
          in_cs, csm(4), np.diag([2, 3, 4, 1, 1])
      )
      assert img.coordmap == exp_cmap
      # Affine must be 4, 4
      bad_aff = np.diag([2, 3, 4, 2, 1])
      pytest.raises(ValueError, make_xyz_image, arr, bad_aff, "mni")
      # Can pass added zooms
      img = make_xyz_image(arr, (aff, (2.0,)), "mni")
      assert img.coordmap == vox2mni(aff, 2.0)
      # Also as scalar
      img = make_xyz_image(arr, (aff, 2.0), "mni")
      assert img.coordmap == vox2mni(aff, 2.0)
      # Must match length of needed zooms
      arr5 = arr[..., None]
      pytest.raises(ValueError, make_xyz_image, arr5, (aff, 2.0), "mni")
      img = make_xyz_image(arr5, (aff, (2.0, 3.0)), "mni")
      assert img.coordmap == vox2mni(aff, (2.0, 3.0))
      # Always xyz affable after creation
      assert_array_equal(xyz_affine(img), aff)
      assert is_xyz_affable(img)
      # Need at least 3 dimensions in data
      pytest.raises(
          ValueError, make_xyz_image, np.zeros((2, 3)), aff, "mni"
      )
      # Check affines don't round / floor floating point
      aff = np.diag([2.1, 3, 4, 1])
      img = make_xyz_image(np.zeros((2, 3, 4)), aff, "scanner")
      assert_array_equal(img.coordmap.affine, aff)
      img = make_xyz_image(np.zeros((2, 3, 4, 5)), aff, "scanner")
      assert_array_equal(
          img.coordmap.affine, np.diag([2.1, 3, 4, 1, 1])
      )
  
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 4 for calling a global function with example usage: test_make_xyz_image() without return types