code: def test_xhemi_morph():
      """Test cross-hemisphere morphing."""
      stc = read_source_estimate(fname_stc, subject="sample")
      # smooth 1 for speed where possible
      smooth = 4
      spacing = 4
      n_grade_verts = 2562
      stc = compute_source_morph(
          stc,
          "sample",
          "fsaverage_sym",
          smooth=smooth,
          warn=False,
          spacing=spacing,
          subjects_dir=subjects_dir,
      ).apply(stc)
      morph = compute_source_morph(
          stc,
          "fsaverage_sym",
          "fsaverage_sym",
          smooth=1,
          xhemi=True,
          warn=False,
          spacing=[stc.vertices[0], []],
          subjects_dir=subjects_dir,
      )
      stc_xhemi = morph.apply(stc)
      assert stc_xhemi.data.shape[0] == n_grade_verts
      assert stc_xhemi.rh_data.shape[0] == 0
      assert len(stc_xhemi.vertices[1]) == 0
      assert stc_xhemi.lh_data.shape[0] == n_grade_verts
      assert len(stc_xhemi.vertices[0]) == n_grade_verts
      # complete reversal mapping
      morph = compute_source_morph(
          stc,
          "fsaverage_sym",
          "fsaverage_sym",
          smooth=smooth,
          xhemi=True,
          warn=False,
          spacing=stc.vertices,
          subjects_dir=subjects_dir,
      )
      mm = morph.morph_mat
      assert mm.shape == (n_grade_verts * 2,) * 2
      assert mm.size > n_grade_verts * 2
      assert mm[:n_grade_verts, :n_grade_verts].size == 0  # L to L
      assert mm[n_grade_verts:, n_grade_verts:].size == 0  # R to L
      assert (
          mm[n_grade_verts:, :n_grade_verts].size > n_grade_verts
      )  # L to R
      assert (
          mm[:n_grade_verts, n_grade_verts:].size > n_grade_verts
      )  # R to L
      # more complicated reversal mapping
      vertices_use = [stc.vertices[0], np.arange(10242)]
      n_src_verts = len(vertices_use[1])
      assert vertices_use[0].shape == (n_grade_verts,)
      assert vertices_use[1].shape == (n_src_verts,)
      # ensure it's sufficiently diffirent to manifest round-trip errors
      assert np.isin(vertices_use[1], stc.vertices[1]).mean() < 0.3
      morph = compute_source_morph(
          stc,
          "fsaverage_sym",
          "fsaverage_sym",
          smooth=smooth,
          xhemi=True,
          warn=False,
          spacing=vertices_use,
          subjects_dir=subjects_dir,
      )
      mm = morph.morph_mat
      assert mm.shape == (
          n_grade_verts + n_src_verts,
          n_grade_verts * 2,
      )
      assert mm[:n_grade_verts, :n_grade_verts].size == 0
      assert mm[n_grade_verts:, n_grade_verts:].size == 0
      assert mm[:n_grade_verts, n_grade_verts:].size > n_grade_verts
      assert mm[n_grade_verts:, :n_grade_verts].size > n_src_verts
      # morph forward then back
      stc_xhemi = morph.apply(stc)
      morph = compute_source_morph(
          stc_xhemi,
          "fsaverage_sym",
          "fsaverage_sym",
          smooth=smooth,
          xhemi=True,
          warn=False,
          spacing=stc.vertices,
          subjects_dir=subjects_dir,
      )
      stc_return = morph.apply(stc_xhemi)
      for hi in range(2):
          assert_array_equal(stc_return.vertices[hi], stc.vertices[hi])
      correlation = np.corrcoef(
          stc.data.ravel(), stc_return.data.ravel()
      )[0, 1]
      assert correlation > 0.9
  
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 4 for calling a global function with example usage: test_xhemi_morph() without return types