code: def test_tsdiffana(in_tmp_path):
      # Test tsdiffana command
      args = Args()
      img = load_image(funcfile)
      args.filename = funcfile
      args.time_axis = None
      args.slice_axis = None
      args.write_results = False
      args.out_path = None
      args.out_fname_label = None
      args.out_file = "test.png"
      check_axes(tsdiffana(args), img.shape, -1, -2)
      assert isfile("test.png")
      args.time_axis = "t"
      check_axes(tsdiffana(args), img.shape, -1, -2)
      args.time_axis = "3"
      check_axes(tsdiffana(args), img.shape, -1, -2)
      args.slice_axis = "k"
      check_axes(tsdiffana(args), img.shape, -1, -2)
      args.slice_axis = "2"
      check_axes(tsdiffana(args), img.shape, -1, -2)
      args.time_axis = "0"
      check_axes(tsdiffana(args), img.shape, 0, -2)
      args.slice_axis = "t"
      check_axes(tsdiffana(args), img.shape, 0, -1)
      # Check absolute path works
      args.slice_axis = "j"
      args.time_axis = "t"
      args.out_file = in_tmp_path / "test_again.png"
      check_axes(tsdiffana(args), img.shape, -1, -3)
      # Check that --out-images incompatible with --out-file
      args.write_results = True
      pytest.raises(ValueError, tsdiffana, args)
      args.out_file = None
      # Copy the functional file to a temporary writeable directory
      os.mkdir("mydata")
      tmp_funcfile = in_tmp_path / "mydata" / "myfunc.nii.gz"
      shutil.copy(funcfile, tmp_funcfile)
      args.filename = tmp_funcfile
      # Check write-results generates expected images
      check_axes(tsdiffana(args), img.shape, -1, -3)
      assert isfile(pjoin("mydata", "tsdiff_myfunc.png"))
      max_img = load_image(pjoin("mydata", "dv2_max_myfunc.nii.gz"))
      assert max_img.shape == img.shape[:-1]
      mean_img = load_image(pjoin("mydata", "dv2_max_myfunc.nii.gz"))
      assert mean_img.shape == img.shape[:-1]
      exp_results = time_slice_diffs_image(img, "t", "j")
      saved_results = np.load(pjoin("mydata", "tsdiff_myfunc.npz"))
      for key in ("volume_means", "slice_mean_diff2"):
          assert_array_equal(exp_results[key], saved_results[key])
      # That we can change out-path
      os.mkdir("myresults")
      args.out_path = "myresults"
      check_axes(tsdiffana(args), img.shape, -1, -3)
      assert isfile(pjoin("myresults", "tsdiff_myfunc.png"))
      max_img = load_image(pjoin("myresults", "dv2_max_myfunc.nii.gz"))
      assert max_img.shape == img.shape[:-1]
      # And out-fname-label
      args.out_fname_label = "vr2"
      check_axes(tsdiffana(args), img.shape, -1, -3)
      assert isfile(pjoin("myresults", "tsdiff_vr2.png"))
      max_img = load_image(pjoin("myresults", "dv2_max_vr2.nii.gz"))
      assert max_img.shape == img.shape[:-1]
      del max_img, mean_img, saved_results
  
imports: import os
  import shutil
  from os.path import dirname, isfile
  from os.path import join
  import nibabel
  import numpy
  import pytest
  from nibabel import AnalyzeImage, Nifti1Image, Nifti1Pair, Spm2AnalyzeImage
  from numpy.testing import assert_array_equal
  from nipy import load_image
  from nipy.io.nibcompat import get_header
  from nipy.io.nifti_ref import NiftiError
  from nipy.testing import funcfile
  from nipy.testing.decorators import needs_mpl_agg
  from ..commands import diagnose, parse_fname_axes, tsdiffana
  from ..timediff import time_slice_diffs_image
label_desc: Use image node_id 3 for calling a global function with example usage: test_tsdiffana(in_tmp_path) without return types