code: def test_tsd_image():
      # Test image version of time slice diff
      fimg = load_image(funcfile)
      data = fimg.get_fdata()
      tsda = tsd.time_slice_diffs
      tsdi = tsd.time_slice_diffs_image
      arr_results = tsda(data)
      # image routine insists on named slice axis, no default
      pytest.raises(AxisError, tsdi, fimg)
      # Works when specifying slice axis as keyword argument
      img_results = tsdi(fimg, slice_axis="k")
      assert_arr_img_res(arr_results, img_results)
      ax_names = fimg.coordmap.function_domain.coord_names
      # Test against array version
      for time_ax in range(4):
          time_name = ax_names[time_ax]
          for slice_ax in range(4):
              slice_name = ax_names[slice_ax]
              if time_ax == slice_ax:
                  pytest.raises(
                      ValueError, tsda, data, time_ax, slice_ax
                  )
                  pytest.raises(
                      ValueError, tsdi, fimg, time_ax, slice_ax
                  )
                  pytest.raises(
                      ValueError, tsdi, fimg, time_name, slice_ax
                  )
                  pytest.raises(
                      ValueError, tsdi, fimg, time_ax, slice_name
                  )
                  pytest.raises(
                      ValueError, tsdi, fimg, time_name, slice_name
                  )
                  continue
              arr_res = tsda(data, time_ax, slice_ax)
              assert_arr_img_res(arr_res, tsdi(fimg, time_ax, slice_ax))
              assert_arr_img_res(
                  arr_res, tsdi(fimg, time_name, slice_ax)
              )
              assert_arr_img_res(
                  arr_res, tsdi(fimg, time_ax, slice_name)
              )
              img_results = tsdi(fimg, time_name, slice_name)
              assert_arr_img_res(arr_res, img_results)
              exp_ax_names = tuple(
                  n for n in ax_names if n != time_name
              )
              for key in ("slice_diff2_max_vol", "diff2_mean_vol"):
                  img = img_results[key]
                  assert (
                      img.coordmap.function_domain.coord_names
                      == exp_ax_names
                  )
      # Test defaults on rolled image
      fimg_rolled = rollimg(fimg, "t")
      # Still don't have a slice axis specified
      pytest.raises(AxisError, tsdi, fimg_rolled)
      # Test default time axis
      assert_arr_img_res(arr_results, tsdi(fimg_rolled, slice_axis="k"))
      # Test axis named slice overrides default guess
      time_ax = -1
      for sa_no, sa_name in ((0, "i"), (1, "j"), (2, "k")):
          fimg_renamed = fimg.renamed_axes(**{sa_name: "slice"})
          arr_res = tsda(data, time_ax, sa_no)
          assert_arr_img_res(arr_res, tsdi(fimg_renamed, time_ax))
  
file_path: nipy/nipy/algorithms/diagnostics/tests/test_time_difference.py
imports: from os.path import dirname
  from os.path import join
  import numpy
  import pytest
  import scipy.io
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from nipy import load_image
  from nipy.testing import funcfile
  from ....core.api import rollimg
  from ....core.reference.coordinate_map import AxisError
  from ..None import timediff
label_desc: Use image node_id 5 for calling a global function with example usage: test_tsd_image() without return types