code: def test_morph_stc_dense():
      """Test morphing stc."""
      subject_from = "sample"
      subject_to = "fsaverage"
      stc_from = read_source_estimate(fname_smorph, subject="sample")
      stc_to = read_source_estimate(fname_fmorph)
      # make sure we can specify grade
      stc_from.crop(0.09, 0.1)  # for faster computation
      stc_to.crop(0.09, 0.1)  # for faster computation
      assert_array_equal(
          stc_to.time_as_index([0.09, 0.1], use_rounding=True),
          [0, len(stc_to.times) - 1],
      )
  
      # After dep change this to:
      morph = compute_source_morph(
          subject_to=subject_to,
          spacing=3,
          smooth=12,
          src=stc_from,
          subjects_dir=subjects_dir,
          precompute=True,
      )
      assert morph.vol_morph_mat is None  # a no-op for surface
      stc_to1 = morph.apply(stc_from)
      assert_allclose(stc_to.data, stc_to1.data, atol=1e-5)
  
      mean_from = stc_from.data.mean(axis=0)
      mean_to = stc_to1.data.mean(axis=0)
      assert np.corrcoef(mean_to, mean_from).min() > 0.999
  
      vertices_to = grade_to_vertices(
          subject_to, grade=3, subjects_dir=subjects_dir
      )
  
      # make sure we can fill by morphing
      with pytest.warns(RuntimeWarning, match="consider increasing"):
          morph = compute_source_morph(
              stc_from,
              subject_from,
              subject_to,
              spacing=None,
              smooth=1,
              subjects_dir=subjects_dir,
          )
      stc_to5 = morph.apply(stc_from)
      assert stc_to5.data.shape[0] == 163842 + 163842
  
      # Morph vector data
      stc_vec = _real_vec_stc()
      stc_vec_to1 = compute_source_morph(
          stc_vec,
          subject_from,
          subject_to,
          subjects_dir=subjects_dir,
          spacing=vertices_to,
          smooth=1,
          warn=False,
      ).apply(stc_vec)
      assert stc_vec_to1.subject == subject_to
      assert stc_vec_to1.tmin == stc_vec.tmin
      assert stc_vec_to1.tstep == stc_vec.tstep
      assert len(stc_vec_to1.lh_vertno) == 642
      assert len(stc_vec_to1.rh_vertno) == 642
  
      # Degenerate conditions
  
      # Morphing to a density that is too high should raise an informative error
      # (here we need to push to grade=6, but for some subjects even grade=5
      # will break)
      with pytest.raises(
          ValueError, match="Cannot use icosahedral grade 6 "
      ):
          compute_source_morph(
              stc_to1,
              subject_from=subject_to,
              subject_to=subject_from,
              spacing=6,
              subjects_dir=subjects_dir,
          )
      del stc_to1
  
      with pytest.raises(
          ValueError, match="smooth.* has to be at least 0"
      ):
          compute_source_morph(
              stc_from,
              subject_from,
              subject_to,
              spacing=5,
              smooth=-1,
              subjects_dir=subjects_dir,
          )
  
      # subject from mismatch
      with pytest.raises(
          ValueError, match="subject_from does not match"
      ):
          compute_source_morph(
              stc_from, subject_from="foo", subjects_dir=subjects_dir
          )
  
      # only one set of vertices
      with pytest.raises(
          ValueError, match="grade.*list must have two elements"
      ):
          compute_source_morph(
              stc_from,
              subject_from=subject_from,
              spacing=[vertices_to[0]],
              subjects_dir=subjects_dir,
          )
  
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 11 for calling a global function with example usage: test_morph_stc_dense() without return types