code: def _interpolate_data(stc, morph, mri_resolution, mri_space, output):
      """Interpolate source estimate data to MRI."""
      _check_dep(nibabel="2.1.0", dipy=False)
      NiftiImage, NiftiHeader = _triage_output(output)
      _validate_type(
          stc, _BaseVolSourceEstimate, "stc", "volume source estimate"
      )
      assert morph.kind in ("volume", "mixed")
  
      voxel_size_defined = False
  
      if isinstance(mri_resolution, (int, float)) and not isinstance(
          mri_resolution, bool
      ):
          # use iso voxel size
          mri_resolution = (float(mri_resolution),) * 3
  
      if isinstance(mri_resolution, tuple):
          _check_dep(
              nibabel=False, dipy="0.10.1"
          )  # nibabel was already checked
          from dipy.align.reslice import reslice
  
          voxel_size = mri_resolution
          voxel_size_defined = True
          mri_resolution = True
  
      # if data wasn't morphed yet - necessary for call of
      # stc_unmorphed.as_volume. Since only the shape of src is known, it cannot
      # be resliced to a given voxel size without knowing the original.
      if isinstance(morph, SourceSpaces):
          assert morph.kind in ("volume", "mixed")
          offset = 2 if morph.kind == "mixed" else 0
          if voxel_size_defined:
              raise ValueError(
                  "Cannot infer original voxel size for reslicing... "
                  "set mri_resolution to boolean value or apply morph first."
              )
          # Now deal with the fact that we may have multiple sub-volumes
          inuse = [s["inuse"] for s in morph[offset:]]
          src_shape = [s["shape"] for s in morph[offset:]]
          assert len(set(map(tuple, src_shape))) == 1
          src_subject = morph._subject
          morph = BunchConst(
              src_data=_get_src_data(morph, mri_resolution)[0]
          )
      else:
          # Make a list as we may have many inuse when using multiple sub-volumes
          inuse = morph.src_data["inuse"]
          src_subject = morph.subject_from
      assert isinstance(inuse, list)
      if stc.subject is not None:
          _check_subject_src(stc.subject, src_subject, "stc.subject")
  
      n_times = stc.data.shape[1]
      shape = morph.src_data["src_shape"][::-1] + (
          n_times,
      )  # SAR->RAST
      dtype = np.complex128 if np.iscomplexobj(stc.data) else np.float64
      # order='F' so that F-order flattening is faster
      vols = np.zeros(
          (np.prod(shape[:3]), shape[3]), dtype=dtype, order="F"
      )
      n_vertices_seen = 0
      for this_inuse in inuse:
          this_inuse = this_inuse.astype(bool)
          n_vertices = np.sum(this_inuse)
          stc_slice = slice(
              n_vertices_seen, n_vertices_seen + n_vertices
          )
          vols[this_inuse] = stc.data[stc_slice]
          n_vertices_seen += n_vertices
  
      # use mri resolution as represented in src
      if mri_resolution:
          if morph.src_data["interpolator"] is None:
              raise RuntimeError(
                  "Cannot morph with mri_resolution when add_interpolator=False "
                  "was used with setup_volume_source_space"
              )
          shape = morph.src_data["src_shape_full"][::-1] + (n_times,)
          vols = morph.src_data["interpolator"] @ vols
  
      # reshape back to proper shape
      vols = np.reshape(vols, shape, order="F")
  
      # set correct space
      if mri_resolution:
          affine = morph.src_data["src_affine_vox"]
      else:
          affine = morph.src_data["src_affine_src"]
  
      if mri_space:
          affine = np.dot(morph.src_data["src_affine_ras"], affine)
  
      affine[:3] *= 1e3
  
      # pre-define header
      header = NiftiHeader()
      header.set_xyzt_units("mm", "msec")
      header["pixdim"][4] = 1e3 * stc.tstep
  
      # if a specific voxel size was targeted (only possible after morphing)
      if voxel_size_defined:
          # reslice mri
          vols, affine = reslice(
              vols, affine, _get_zooms_orig(morph), voxel_size
          )
  
      with warnings.catch_warnings():  # nibabel<->numpy warning
          vols = NiftiImage(vols, affine, header=header)
  
      return vols
  
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 12 for calling a global function with example usage: _interpolate_data(stc, morph, mri_resolution, mri_space, output) and returns: vols