code: def tsdiffana(args):
      """Generate tsdiffana plots from command line params `args`
  
      Parameters
      ----------
      args : object
          object with attributes
  
          * filename : str - 4D image filename
          * out_file : str - graphics file to write to instead of leaving
            graphics on screen
          * time_axis : str - name or number of time axis in `filename`
          * slice_axis : str - name or number of slice axis in `filename`
          * write_results : bool - if True, write images and plots to files
          * out_path : None or str - path to which to write results
          * out_fname_label : None or filename - suffix of output results files
  
      Returns
      -------
      axes : Matplotlib axes
         Axes on which we have done the plots.
      """
      if args.out_file is not None and args.write_results:
          raise ValueError(
              "Cannot have OUT_FILE and WRITE_RESULTS options "
              "together"
          )
      img, time_axis, slice_axis = parse_fname_axes(
          args.filename, args.time_axis, args.slice_axis
      )
      results = time_slice_diffs_image(img, time_axis, slice_axis)
      axes = plot_tsdiffs(results)
      if args.out_file is None and not args.write_results:
          # interactive mode
          return axes
      if args.out_file is not None:
          # plot only mode
          axes[0].figure.savefig(args.out_file)
          return axes
      # plot and images mode
      froot, ext, addext = splitext_addext(args.filename)
      fpath, fbase = psplit(froot)
      fpath = fpath if args.out_path is None else args.out_path
      fbase = (
          fbase
          if args.out_fname_label is None
          else args.out_fname_label
      )
      axes[0].figure.savefig(pjoin(fpath, "tsdiff_" + fbase + ".png"))
      # Save image volumes
      for key, prefix in (
          ("slice_diff2_max_vol", "dv2_max_"),
          ("diff2_mean_vol", "dv2_mean_"),
      ):
          fname = pjoin(fpath, prefix + fbase + ext + addext)
          nipy.save_image(results[key], fname)
      # Save time courses into npz
      np.savez(
          pjoin(fpath, "tsdiff_" + fbase + ".npz"),
          volume_means=results["volume_means"],
          slice_mean_diff2=results["slice_mean_diff2"],
      )
      return axes
  
file_path: nipy/nipy/algorithms/diagnostics/commands.py
imports: from os.path import join
  from os.path import split
  import numpy
  from nibabel import AnalyzeHeader
  from nibabel.filename_parser import splitext_addext
  import nipy
  from .screens import screen, write_screen_res
  from .timediff import time_slice_diffs_image
  from .tsdiffplot import plot_tsdiffs
label_desc: Use image node_id 2 for calling a global function with example usage: tsdiffana(args) and returns: axes, axes, axes