code: def save_nifti(fname, data, affine, hdr=None, dtype=None):
      """Save a data array into a nifti file.
  
      Parameters
      ----------
      fname : str
          The full path to the file to be saved.
  
      data : ndarray
          The array with the data to save.
  
      affine : 4x4 array
          The affine transform associated with the file.
  
      hdr : nifti header, optional
          May contain additional information to store in the file header.
  
      Returns
      -------
      None
  
      """
      NIBABEL_4_0_0_PLUS = Version(nib.__version__) >= Version("4.0.0")
      # See GitHub issues
      #  * https://github.com/nipy/nibabel/issues/1046
      #  * https://github.com/nipy/nibabel/issues/1089
      # This only applies to NIfTI because the parent Analyze formats did
      # not support 64-bit integer data, so `set_data_dtype(int64)` would
      # already fail.
      danger_dts = (np.dtype("int64"), np.dtype("uint64"))
      if (
          hdr is None
          and dtype is None
          and data.dtype in danger_dts
          and NIBABEL_4_0_0_PLUS
      ):
          msg = f"Image data has type {data.dtype}, which may cause "
          msg += "incompatibilities with other tools. Indeed, Analyze formats "
          msg += "did not support 64-bit integer data.\n\n"
          msg += (
              "To silent this, please specify the `header` or `dtype` "
          )
          msg += (
              "You could also use `np.asarray(data, dtype=np.int32)`. "
          )
          msg += "This cast will make sure that you data is compatible with "
          msg += "other software."
  
          raise ValueError(msg)
  
      kwargs = {"dtype": dtype} if NIBABEL_4_0_0_PLUS else {}
      result_img = nib.Nifti1Image(data, affine, header=hdr, **kwargs)
      result_img.to_filename(fname)
  
imports: from packaging.version import Version
  import nibabel
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: save_nifti(fname, data, affine, hdr, dtype) without return types