code: def _morphed_stc_as_volume(
      morph, stc, mri_resolution, mri_space, output
  ):
      """Return volume source space as Nifti1Image and/or save to disk."""
      assert isinstance(
          stc, _BaseVolSourceEstimate
      )  # should be guaranteed
      if stc._data_ndim == 3:
          stc = stc.magnitude()
      _check_dep(nibabel="2.1.0", dipy=False)
  
      NiftiImage, NiftiHeader = _triage_output(output)
  
      # if MRI resolution is set manually as a single value, convert to tuple
      if isinstance(mri_resolution, (int, float)):
          # use iso voxel size
          new_zooms = (float(mri_resolution),) * 3
      elif isinstance(mri_resolution, tuple):
          new_zooms = mri_resolution
      # if full MRI resolution, compute zooms from shape and MRI zooms
      if isinstance(mri_resolution, bool):
          new_zooms = _get_zooms_orig(morph) if mri_resolution else None
  
      # create header
      hdr = NiftiHeader()
      hdr.set_xyzt_units("mm", "msec")
      hdr["pixdim"][4] = 1e3 * stc.tstep
  
      # setup empty volume
      if morph.src_data["to_vox_map"] is not None:
          shape = morph.src_data["to_vox_map"][0]
          affine = morph.src_data["to_vox_map"][1]
      else:
          shape = morph.shape
          affine = morph.affine
      assert stc.data.ndim == 2
      n_times = stc.data.shape[1]
      img = np.zeros((np.prod(shape), n_times))
      img[stc.vertices[0], :] = stc.data
      img = img.reshape(
          shape + (n_times,), order="F"
      )  # match order='F' above
      del shape
  
      # make nifti from data
      with warnings.catch_warnings():  # nibabel<->numpy warning
          img = NiftiImage(img, affine, header=hdr)
  
      # reslice in case of manually defined voxel size
      zooms = morph.zooms[:3]
      if new_zooms is not None:
          from dipy.align.reslice import reslice
  
          new_zooms = new_zooms[:3]
          img, affine = reslice(
              _get_img_fdata(img),
              img.affine,  # MRI to world registration
              zooms,  # old voxel size in mm
              new_zooms,
          )  # new voxel size in mm
          with warnings.catch_warnings():  # nibabel<->numpy warning
              img = NiftiImage(img, affine)
          zooms = new_zooms
  
      #  set zooms in header
      img.header.set_zooms(tuple(zooms) + (1,))
      return img
  
imports: import copy
  import os.path
  import warnings
  import numpy
  from scipy import sparse
  from .fixes import _get_img_fdata
  from .morph_map import read_morph_map
  from .parallel import parallel_func
  from .source_estimate import _BaseSourceEstimate, _BaseSurfaceSourceEstimate, _BaseVolSourceEstimate, _get_ico_tris
  from .source_space._source_space import SourceSpaces, _ensure_src, _grid_interp
  from .surface import _compute_nearest, mesh_edges, read_surface
  from .utils import BunchConst, ProgressBar, _check_fname, _check_option, _custom_lru_cache, _ensure_int, _import_h5io_funcs, _import_nibabel, _validate_type, check_version, fill_doc, get_subjects_dir, logger, use_log_level, verbose, warn
  from .utils import warn
label_desc: Use image node_id 9 for calling a global function with example usage: _morphed_stc_as_volume(morph, stc, mri_resolution, mri_space, output) and returns: img