code: def test_xyz_affines():
      fimg = copy_of(funcfile)
      data = fimg.get_fdata()
      # Check conversion to xyz affable
      # Roll time to front in array
      fimg_t0 = fimg.reordered_axes((3, 0, 1, 2))
      # Nifti conversion rolls it back
      assert_array_equal(nipy2nifti(fimg_t0).get_fdata(), data)
      # Roll time to position 1
      fimg_t0 = fimg.reordered_axes((0, 3, 1, 2))
      assert_array_equal(nipy2nifti(fimg_t0).get_fdata(), data)
      # Check bad names cause NiftiError
      out_coords = fimg.reference.coord_names
      bad_img = fimg.renamed_reference(
          **{out_coords[0]: "not a known axis"}
      )
      pytest.raises(NiftiError, nipy2nifti, bad_img)
      # Check xyz works for not strict
      bad_img = fimg.renamed_reference(**dict(zip(out_coords, "xyz")))
      assert_array_equal(
          nipy2nifti(bad_img, strict=False).get_fdata(), data
      )
      # But fails for strict
      pytest.raises(NiftiError, nipy2nifti, bad_img, strict=True)
      # 3D is OK
      aimg = copy_of(anatfile)
      adata = aimg.get_fdata()
      assert_array_equal(nipy2nifti(aimg).get_fdata(), adata)
      # For now, always error on 2D (this depends on as_xyz_image)
      pytest.raises(NiftiError, nipy2nifti, aimg[:, :, 1])
      pytest.raises(NiftiError, nipy2nifti, aimg[:, 1, :])
      pytest.raises(NiftiError, nipy2nifti, aimg[1, :, :])
      # Do not allow spaces not in the NIFTI canon
      for i in range(3):
          displaced_img = fimg.renamed_reference(
              **{out_coords[i]: "obscure"}
          )
          pytest.raises(NiftiError, nipy2nifti, displaced_img)
  
imports: import warnings
  from copy import copy
  import nibabel
  import numpy
  import pytest
  from nibabel.affines import from_matvec
  from nibabel.spatialimages import HeaderDataError
  from numpy.testing import assert_array_equal
  from ...core.api import AffineTransform
  from ...core.api import CoordinateSystem
  from ...core.api import Image
  from ...core.reference.spaces import aligned_csm, mni_csm, scanner_csm, talairach_csm, unknown_csm, unknown_space, vox2mni
  from ...testing import anatfile, funcfile
  from ..files import load
  from ..nibcompat import get_affine, get_header
  from ..nifti_ref import NiftiError, nifti2nipy, nipy2nifti
label_desc: Use image node_id 3 for calling a global function with example usage: test_xyz_affines() without return types