code: def check_data(
      output_data=None,
      data_collection=None,
      batch_size=4,
      merge_batch=True,
      show_output=True,
      output_filepath=None,
      viz_rows=None,
      viz_mode_2d=None,
      viz_mode_3d="2d_slice",
      color_range=None,
      output_groups=None,
      combine_outputs=False,
      rgb_output=True,
      colorbar=True,
      subplot_rows=None,
      title=None,
      subplot_titles=None,
      output_directory=None,
      case_name=None,
      **kwargs,
  ):
      if data_collection is not None:
          if (
              batch_size
              > data_collection.total_cases * data_collection.multiplier
          ):
              batch_size = (
                  data_collection.total_cases
                  * data_collection.multiplier
              )
  
          generator = data_collection.data_generator(
              perpetual=True, verbose=False, batch_size=batch_size
          )
          case_name = data_collection.current_case
          output_data = next(generator)
  
      if type(output_data) is not dict:
          output_data = {"output_data": output_data}
  
      # Very bad, reformat.
      output_data = {
          label: data
          for label, data in list(output_data.items())
          if "_affine" not in label
          and "_augmentation_string" not in label
          and "casename" not in label
      }
  
      for label, data in list(output_data.items()):
          if type(data) is str:
              output_data[label] = read_image_files(data)[
                  np.newaxis, ...
              ]
  
      if color_range is None:
          color_range = {
              label: [np.min(data), np.max(data)]
              for label, data in list(output_data.items())
          }
  
      if output_groups is not None:
          output_data = {
              label: data
              for label, data in list(output_data.items())
              if label in output_groups
          }
  
      if not show_output:
          subplot_titles = None
  
      output_images = OrderedDict()
  
      if data_collection is None:
          reference_key = list(output_data)[0]
          batch_size = output_data[reference_key].shape[0]
  
      if viz_rows is None:
          viz_rows = int(np.ceil(np.sqrt(batch_size)))
      else:
          viz_rows = min(viz_rows, batch_size)
  
      viz_columns = int(np.ceil(batch_size / float(viz_rows)))
  
      for label, data in list(output_data.items()):
          if (
              "_affine" in label
              or "_augmentation_string" in label
              or "casename" in label
          ):
              continue
  
          if data.ndim == 5:
              output_images, color_range = display_3d_data(
                  data,
                  color_range,
                  viz_mode_3d,
                  label,
                  output_images,
                  viz_rows,
                  viz_columns,
                  subplot_titles=subplot_titles,
                  **kwargs,
              )
  
          elif data.ndim == 4:
              if data.shape[-1] == 2:
                  for i in range(data.shape[-1]):
                      if subplot_titles is None:
                          subplot_title = label + "_" + str(i)
                      else:
                          subplot_title = subplot_titles[label][i]
  
                      output_images[subplot_title] = merge_data(
                          data[..., i][..., np.newaxis],
                          [viz_rows, viz_columns],
                          1,
                      )
                      color_range[subplot_title] = color_range[label]
  
              if data.shape[-1] not in [1, 3]:
                  output_images[label + "_RGB"] = merge_data(
                      data[..., 0:3], [viz_rows, viz_columns], 3
                  )
                  color_range[label + "_RGB"] = color_range[label]
                  for i in range(3, data.shape[-1]):
                      output_images[label + "_" + str(i)] = merge_data(
                          data[..., i][..., np.newaxis],
                          [viz_rows, viz_columns],
                          1,
                      )
                      color_range[label + "_" + str(i)] = color_range[
                          label
                      ]
              else:
                  output_images[label] = merge_data(
                      data, [viz_rows, viz_columns], data.shape[-1]
                  )
  
          elif data.ndim == 3:
              output_images[label] = merge_data(
                  data, [viz_rows, viz_columns], data.shape[-1]
              )
  
          # elif data.ndim == 2:
  
          #     output_images[label] = display_1d_data(data, [viz_rows, viz_columns])
  
      if show_output:
          plots = len(list(output_images.keys()))
          if subplot_rows is None:
              subplot_rows = int(np.ceil(np.sqrt(plots)))
          plot_columns = int(np.ceil(plots / float(subplot_rows)))
          fig, axarr = plt.subplots(plot_columns, subplot_rows)
  
          # matplotlib is so annoying
          if subplot_rows == 1 and plot_columns == 1:
              axarr = np.array([axarr]).reshape(1, 1)
          elif subplot_rows == 1 or plot_columns == 1:
              axarr = axarr.reshape(plot_columns, subplot_rows)
  
          for plot_idx, (label, data) in enumerate(
              output_images.items()
          ):
              image_row = plot_idx % plot_columns
              image_column = plot_idx // plot_columns
  
              if data.shape[-1] == 3:
                  # Weird matplotlib bug/feature:
                  if np.min(data) < 0:
                      data = (data - np.min(data)) / (
                          np.max(data) - np.min(data)
                      )
  
                  plt_image = axarr[image_row, image_column].imshow(
                      np.squeeze(data),
                      cmap=plt.get_cmap("hot"),
                      vmin=color_range[label][0],
                      vmax=color_range[label][1],
                      interpolation="none",
                  )
  
                  if colorbar:
                      fig.colorbar(
                          plt_image, ax=axarr[image_row, image_column]
                      )
  
              elif data.shape[-1] == 1:
                  plt_image = axarr[image_row, image_column].imshow(
                      np.squeeze(data),
                      cmap="gray",
                      vmin=color_range[label][0],
                      vmax=color_range[label][1],
                      interpolation="none",
                  )
  
                  if colorbar:
                      fig.colorbar(
                          plt_image,
                          ax=axarr[image_row, image_column],
                          cmap="gray",
                      )
  
              axarr[image_row, image_column].set_title(label)
  
          for plot_idx in range(
              len(output_images), subplot_rows * plot_columns
          ):
              image_row = plot_idx % plot_columns
              image_column = plot_idx // plot_columns
              fig.delaxes(axarr[image_row, image_column])
  
          if title is not None:
              fig.suptitle(title, fontsize=28)
  
          plt.show()
  
      output_filepaths = {}
      if output_directory is not None or output_filepath is not None:
          for label, data in list(output_images.items()):
              output_images[label] = image_preprocess(data)
              if output_filepath is not None:
                  output_filepaths[label] = save_data(
                      output_images[label],
                      replace_suffix(output_filepath, "", "_" + label),
                  )
                  continue
              if output_directory is not None and case_name is not None:
                  output_filepaths[label] = save_data(
                      output_images[label],
                      os.path.join(
                          output_directory,
                          nifti_splitext(
                              replace_suffix(
                                  os.path.basename(case_name),
                                  "",
                                  "_" + label,
                              )
                          )[0],
                      )
                      + ".png",
                  )
  
      return output_filepaths, output_images
  
file_path: DeepNeuro/deepneuro/utilities/visualize.py
imports: import numpy
  import matplotlib.pyplot
  import os
  from collections import OrderedDict
  from deepneuro.utilities.conversion import save_data, read_image_files
  from deepneuro.utilities.util import replace_suffix, nifti_splitext
label_desc: Use image node_id 1 for calling a global function with example usage: check_data(output_data, data_collection, batch_size, merge_batch, show_output, output_filepath, viz_rows, viz_mode_2d, viz_mode_3d, color_range, output_groups, combine_outputs, rgb_output, colorbar, subplot_rows, title, subplot_titles, output_directory, case_name) and returns: output_filepaths,  output_images