code: def test_scale_mri(tmp_path, few_surfaces, scale):
      """Test creating fsaverage and scaling it."""
      pytest.importorskip("nibabel")
      # create fsaverage using the testing "fsaverage" instead of the FreeSurfer
      # one
      fake_home = data_path
      create_default_subject(
          subjects_dir=tmp_path, fs_home=fake_home, verbose=True
      )
      assert _is_mri_subject(
          "fsaverage", tmp_path
      ), "Creating fsaverage failed"
  
      fid_path = (
          tmp_path / "fsaverage" / "bem" / "fsaverage-fiducials.fif"
      )
      os.remove(fid_path)
      create_default_subject(
          update=True, subjects_dir=tmp_path, fs_home=fake_home
      )
      assert fid_path.exists(), "Updating fsaverage"
  
      # copy MRI file from sample data (shouldn't matter that it's incorrect,
      # so here choose a small one)
      path_from = fake_home / "subjects" / "sample" / "mri" / "T1.mgz"
      path_to = tmp_path / "fsaverage" / "mri" / "orig.mgz"
      copyfile(path_from, path_to)
  
      # remove redundant label files
      label_temp = tmp_path / "fsaverage" / "label" / "*.label"
      label_paths = glob(str(label_temp))
      for label_path in label_paths[1:]:
          os.remove(label_path)
  
      # create source space
      bem_path = tmp_path / "fsaverage" / "bem"
      bem_fname = "fsaverage-%s-src.fif"
      src = mne.setup_source_space(
          "fsaverage", "ico0", subjects_dir=tmp_path, add_dist=False
      )
      mri = tmp_path / "fsaverage" / "mri" / "orig.mgz"
      vsrc = mne.setup_volume_source_space(
          "fsaverage",
          pos=50,
          mri=mri,
          subjects_dir=tmp_path,
          add_interpolator=False,
      )
      write_source_spaces(bem_path / (bem_fname % "vol-50"), vsrc)
  
      # scale fsaverage
      write_source_spaces(
          bem_path / (bem_fname % "ico-0"), src, overwrite=True
      )
      scale_mri(
          "fsaverage",
          "flachkopf",
          scale,
          True,
          subjects_dir=tmp_path,
          verbose="debug",
      )
      assert _is_mri_subject("flachkopf", tmp_path), "Scaling failed"
      spath = tmp_path / "flachkopf" / "bem"
      spath_fname = "flachkopf-%s-src.fif"
  
      assert (spath / (spath_fname % "ico-0")).exists()
      assert (
          tmp_path / "flachkopf" / "surf" / "lh.sphere.reg"
      ).is_file()
      vsrc_s = mne.read_source_spaces(spath / (spath_fname % "vol-50"))
      for vox in (
          [0, 0, 0],
          [1, 0, 0],
          [0, 1, 0],
          [0, 0, 1],
          [1, 2, 3],
      ):
          idx = np.ravel_multi_index(vox, vsrc[0]["shape"], order="F")
          err_msg = f"idx={idx} @ {vox}, scale={scale}"
          assert_allclose(
              apply_trans(vsrc[0]["src_mri_t"], vox),
              vsrc[0]["rr"][idx],
              err_msg=err_msg,
          )
          assert_allclose(
              apply_trans(vsrc_s[0]["src_mri_t"], vox),
              vsrc_s[0]["rr"][idx],
              err_msg=err_msg,
          )
      scale_labels("flachkopf", subjects_dir=tmp_path)
  
      # add distances to source space after hacking the properties to make
      # it run *much* faster
      src_dist = src.copy()
      for s in src_dist:
          s.update(
              rr=s["rr"][s["vertno"]],
              nn=s["nn"][s["vertno"]],
              tris=s["use_tris"],
          )
          s.update(
              np=len(s["rr"]),
              ntri=len(s["tris"]),
              vertno=np.arange(len(s["rr"])),
              inuse=np.ones(len(s["rr"]), int),
          )
      mne.add_source_space_distances(src_dist)
      write_source_spaces(
          bem_path / (bem_fname % "ico-0"), src_dist, overwrite=True
      )
  
      # scale with distances
      os.remove(spath / (spath_fname % "ico-0"))
      scale_source_space("flachkopf", "ico-0", subjects_dir=tmp_path)
      ssrc = mne.read_source_spaces(spath / (spath_fname % "ico-0"))
      assert ssrc[0]["dist"] is not None
      assert ssrc[0]["nearest"] is not None
  
      # check patch info computation (only if SciPy is new enough to be fast)
      for s in src_dist:
          for key in ("dist", "dist_limit"):
              s[key] = None
      write_source_spaces(
          bem_path / (bem_fname % "ico-0"), src_dist, overwrite=True
      )
  
      # scale with distances
      os.remove(spath / (spath_fname % "ico-0"))
      scale_source_space("flachkopf", "ico-0", subjects_dir=tmp_path)
      ssrc = mne.read_source_spaces(spath / (spath_fname % "ico-0"))
      assert ssrc[0]["dist"] is None
      assert ssrc[0]["nearest"] is not None
  
imports: import os
  from functools import reduce
  from glob import glob
  from shutil import copyfile
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less
  import mne
  from mne._fiff.constants import FIFF
  from mne.channels import DigMontage
  from mne.coreg import Coregistration, _is_mri_subject, coregister_fiducials, create_default_subject, fit_matched_points, get_mni_fiducials, scale_labels, scale_mri, scale_source_space
  from mne.datasets import testing
  from mne.io import read_fiducials, read_info
  from mne.source_space import write_source_spaces
  from mne.transforms import Transform, _angle_between_quats, apply_trans, invert_transform, read_trans, rot_to_quat, rotation, scaling, translation
  from mne.utils import catch_logging
label_desc: Use image node_id 3 for calling a global function with example usage: test_scale_mri(tmp_path, few_surfaces, scale) without return types