code: def write_screen_res(
      res, out_path, out_root, out_img_ext=".nii", pcnt_var_thresh=0.1
  ):
      """Write results from ``screen`` to disk as images
  
      Parameters
      ----------
      res : dict
         output from ``screen`` function
      out_path : str
         directory to which to write output images
      out_root : str
         part of filename between image-specific prefix and image-specific
         extension to use for writing images
      out_img_ext : str, optional
         extension (identifying image type) to which to write volume
         images.  Default is '.nii'
      pcnt_var_thresh : float, optional
         threshold below which we do not plot percent variance explained
         by components; default is 0.1.  This removes the long tail from
         percent variance plots.
  
      Returns
      -------
      None
      """
      import matplotlib.pyplot as plt
  
      # save volume images
      for key in ("mean", "min", "max", "std", "pca"):
          fname = pjoin(out_path, f"{key}_{out_root}{out_img_ext}")
          save_image(res[key], fname)
      # plot, save component time courses and some tsdiffana stuff
      pca_axis = res["pca_res"]["axis"]
      n_comp = res["pca_res"]["basis_projections"].shape[pca_axis]
      vectors = res["pca_res"]["basis_vectors"]
      pcnt_var = res["pca_res"]["pcnt_var"]
      np.savez(
          pjoin(out_path, f"vectors_components_{out_root}.npz"),
          basis_vectors=vectors,
          pcnt_var=pcnt_var,
          volume_means=res["ts_res"]["volume_means"],
          slice_mean_diff2=res["ts_res"]["slice_mean_diff2"],
      )
      plt.figure()
      for c in range(n_comp):
          plt.subplot(n_comp, 1, c + 1)
          plt.plot(vectors[:, c])
          plt.axis("tight")
      plt.suptitle(out_root + ": PCA basis vectors")
      plt.savefig(pjoin(out_path, f"components_{out_root}.png"))
      # plot percent variance
      plt.figure()
      plt.plot(pcnt_var[pcnt_var >= pcnt_var_thresh])
      plt.axis("tight")
      plt.suptitle(out_root + ": PCA percent variance")
      plt.savefig(pjoin(out_path, f"pcnt_var_{out_root}.png"))
      # plot tsdiffana
      plt.figure()
      axes = [plt.subplot(4, 1, i + 1) for i in range(4)]
      plot_tsdiffs(res["ts_res"], axes)
      plt.suptitle(out_root + ": tsdiffana")
      plt.savefig(pjoin(out_path, f"tsdiff_{out_root}.png"))
  
file_path: nipy/nipy/algorithms/diagnostics/screens.py
imports: import warnings
  from os.path import join
  import numpy
  from ...core.api import Image, drop_io_dim
  from ...core.reference.coordinate_map import AxisError, input_axis_index
  from ...io.api import save_image
  from ..utils import pca
  from .timediff import time_slice_diffs
  from .tsdiffplot import plot_tsdiffs
label_desc: Use image node_id 2 for calling a global function with example usage: write_screen_res(res, out_path, out_root, out_img_ext, pcnt_var_thresh) without return types