code: def save_volume_5d(img_data, filename, save_path, affine=np.eye(4)):
      """
      Save the img_data to nifti image, if the final dimensions of the 5D array
      are 1's, save the lower dimensional image to disk by squeezing the trailing
      single dimensional spaces away.
  
      :param img_data: 5d img to save
      :param filename: filename under which to save the img_data
      :param save_path:
      :param affine: an affine matrix.
      :return:
      """
      if img_data is None:
          return
      # 5D images are not well supported by many image processing tools
      # (or are assumed to be time series)
      # Squeeze 5d processing space into smaller image spatial size (3d or 2d)
      # for improved compatibility with
      # external visualization/processing tools like Slicer3D, ITK,
      # SimpleITK, etc ...
      sqeezed_shape = img_data.shape
      while sqeezed_shape[-1] == 1:
          sqeezed_shape = sqeezed_shape[0:-1]
      img_data.shape = sqeezed_shape
      touch_folder(save_path)
      img_nii = nib.Nifti1Image(img_data, affine)
      # img_nii.set_data_dtype(np.dtype(np.float32))
      output_name = os.path.join(save_path, filename)
      try:
          if os.path.isfile(output_name):
              tf.logging.warning(
                  "File %s exists, overwriting the file.", output_name
              )
          nib.save(img_nii, output_name)
      except OSError:
          tf.logging.fatal("writing failed {}".format(output_name))
          raise
      tf.logging.info("Saved {}".format(output_name))
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 14 for calling a global function with example usage: save_volume_5d(img_data, filename, save_path, affine) without return types