code: def save_numpy_2_nifti(
      image_numpy,
      output_filepath=None,
      reference_data=None,
      metadata=None,
      **kwargs,
  ):
      """This is a bit convoluted."""
  
      if reference_data is not None:
          if isinstance(reference_data, str):
              nifti_image = nib.load(reference_data)
              image_affine = nifti_image.affine
          else:
              image_affine = reference_data
      else:
          image_affine = np.eye(4)
  
      output_nifti = nib.Nifti1Image(image_numpy, image_affine)
  
      if output_filepath is None:
          return output_nifti
      else:
          nib.save(output_nifti, output_filepath)
          return output_filepath
  
imports: import os
  import numpy
  import nibabel
  import nrrd
  import pydicom
  import subprocess
  from collections import defaultdict
  from imageio import imwrite, imread
  from deepneuro.utilities.util import grab_files_recursive, quotes
label_desc: Use image node_id 14 for calling a global function with example usage: save_numpy_2_nifti(image_numpy, output_filepath, reference_data, metadata) and returns: output_nifti, output_filepath