code: def diagnose(args):
      """Calculate, write results from diagnostic screen
  
      Parameters
      ----------
      args : object
          object with attributes:
  
          * filename : str - 4D image filename
          * time_axis : str - name or number of time axis in `filename`
          * slice_axis : str - name or number of slice axis in `filename`
          * out_path : None or str - path to which to write results
          * out_fname_label : None or filename - suffix of output results files
          * ncomponents : int - number of PCA components to write images for
  
      Returns
      -------
      res : dict
          Results of running :func:`screen` on `filename`
      """
      img, time_axis, slice_axis = parse_fname_axes(
          args.filename, args.time_axis, args.slice_axis
      )
      res = screen(img, args.ncomponents, time_axis, slice_axis)
      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
      )
      write_screen_res(res, fpath, fbase, ext + addext)
      return res
  
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 3 for calling a global function with example usage: diagnose(args) and returns: res