code: def test_volume_labels_morph(tmp_path, sl, n_real, n_mri, n_orig):
      """Test generating a source space from volume label."""
      nib = pytest.importorskip("nibabel")
      n_use = (sl.stop - sl.start) // (sl.step or 1)
      # see gh-5224
      evoked = mne.read_evokeds(fname_evoked)[0].crop(0, 0)
      evoked.pick(evoked.ch_names[:306:8])
      evoked.info.normalize_proj()
      n_ch = len(evoked.ch_names)
      lut, _ = read_freesurfer_lut()
      label_names = sorted(get_volume_labels_from_aseg(fname_aseg))
      use_label_names = label_names[sl]
      src = setup_volume_source_space(
          "sample",
          subjects_dir=subjects_dir,
          volume_label=use_label_names,
          mri=fname_aseg,
      )
      assert len(src) == n_use
      assert src.kind == "volume"
      n_src = sum(s["nuse"] for s in src)
      sphere = make_sphere_model("auto", "auto", evoked.info)
      fwd = make_forward_solution(evoked.info, fname_trans, src, sphere)
      assert fwd["sol"]["data"].shape == (n_ch, n_src * 3)
      inv = make_inverse_operator(
          evoked.info, fwd, make_ad_hoc_cov(evoked.info), loose=1.0
      )
      stc = apply_inverse(evoked, inv)
      assert stc.data.shape == (n_src, 1)
      img = stc.as_volume(src, mri_resolution=True)
      assert img.shape == (86, 86, 86, 1)
      n_on = np.array(img.dataobj).astype(bool).sum()
      aseg_img = _get_img_fdata(nib.load(fname_aseg))
      n_got_real = np.isin(
          aseg_img.ravel(), [lut[name] for name in use_label_names]
      ).sum()
      assert n_got_real == n_real
      # - This was 291 on `main` before gh-5590
      # - Refactoring transforms it became 279 with a < 1e-8 change in vox_mri_t
      # - Dropped to 123 once nearest-voxel was used in gh-7653
      # - Jumped back up to 330 with morphing fixes actually correctly
      #   interpolating across all volumes
      assert aseg_img.shape == img.shape[:3]
      assert n_on == n_mri
      for ii in range(2):
          # should work with (ii=0) or without (ii=1) the interpolator
          if ii:
              src[0]["interpolator"] = None
          img = stc.as_volume(src, mri_resolution=False)
          n_on = np.array(img.dataobj).astype(bool).sum()
          # was 20 on `main` before gh-5590
          # then 44 before gh-7653, which took it back to 20
          assert n_on == n_orig
      # without the interpolator, this should fail
      assert src[0]["interpolator"] is None
      with pytest.raises(
          RuntimeError, match=r".*src\[0\], .* mri_resolution"
      ):
          stc.as_volume(src, mri_resolution=True)
  
imports: from inspect import signature
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from scipy.sparse import csr_matrix
  from scipy.sparse import eye
  from scipy.spatial.distance import cdist
  import mne
  from mne import SourceEstimate, SourceMorph, VectorSourceEstimate, VolSourceEstimate, VolVectorSourceEstimate, compute_source_morph, get_volume_labels_from_aseg, grade_to_vertices, make_ad_hoc_cov, make_forward_solution, make_sphere_model, read_evokeds, read_forward_solution, read_freesurfer_lut, read_source_estimate, read_source_morph, setup_volume_source_space
  from mne._freesurfer import _get_atlas_values, _get_mri_info_data
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.minimum_norm import apply_inverse, make_inverse_operator, read_inverse_operator
  from mne.source_space._source_space import _add_interpolator, _grid_interp
  from mne.transforms import quat_to_rot
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 13 for calling a global function with example usage: test_volume_labels_morph(tmp_path, sl, n_real, n_mri, n_orig) without return types