code: def test_morph_stc_sparse():
      """Test morphing stc with sparse=True."""
      subject_from = "sample"
      subject_to = "fsaverage"
      # Morph sparse data
      # Make a sparse stc
      stc_from = read_source_estimate(fname_smorph, subject="sample")
      stc_from.vertices[0] = stc_from.vertices[0][[100, 500]]
      stc_from.vertices[1] = stc_from.vertices[1][[200]]
      stc_from._data = stc_from._data[:3]
  
      stc_to_sparse = compute_source_morph(
          stc_from,
          subject_from=subject_from,
          subject_to=subject_to,
          spacing=None,
          sparse=True,
          subjects_dir=subjects_dir,
      ).apply(stc_from)
  
      assert_allclose(
          np.sort(stc_from.data.sum(axis=1)),
          np.sort(stc_to_sparse.data.sum(axis=1)),
      )
      assert len(stc_from.rh_vertno) == len(stc_to_sparse.rh_vertno)
      assert len(stc_from.lh_vertno) == len(stc_to_sparse.lh_vertno)
      assert stc_to_sparse.subject == subject_to
      assert stc_from.tmin == stc_from.tmin
      assert stc_from.tstep == stc_from.tstep
  
      stc_from.vertices[0] = np.array([], dtype=np.int64)
      stc_from._data = stc_from._data[:1]
  
      stc_to_sparse = compute_source_morph(
          stc_from,
          subject_from,
          subject_to,
          spacing=None,
          sparse=True,
          subjects_dir=subjects_dir,
      ).apply(stc_from)
  
      assert_allclose(
          np.sort(stc_from.data.sum(axis=1)),
          np.sort(stc_to_sparse.data.sum(axis=1)),
      )
      assert len(stc_from.rh_vertno) == len(stc_to_sparse.rh_vertno)
      assert len(stc_from.lh_vertno) == len(stc_to_sparse.lh_vertno)
      assert stc_to_sparse.subject == subject_to
      assert stc_from.tmin == stc_from.tmin
      assert stc_from.tstep == stc_from.tstep
  
      # Degenerate cases
      with pytest.raises(
          ValueError, match="spacing must be set to None"
      ):
          compute_source_morph(
              stc_from,
              subject_from=subject_from,
              subject_to=subject_to,
              spacing=5,
              sparse=True,
              subjects_dir=subjects_dir,
          )
      with pytest.raises(
          ValueError, match="xhemi=True can only be used with"
      ):
          compute_source_morph(
              stc_from,
              subject_from=subject_from,
              subject_to=subject_to,
              spacing=None,
              sparse=True,
              xhemi=True,
              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 12 for calling a global function with example usage: test_morph_stc_sparse() without return types