code: def test_scale_mri_xfm(tmp_path, few_surfaces, subjects_dir_tmp_few):
      """Test scale_mri transforms and MRI scaling."""
      pytest.importorskip("nibabel")
      # scale fsaverage
      sample_dir = subjects_dir_tmp_few / "sample"
      subject_to = "flachkopf"
      spacing = "oct2"
      for subject_from in ("fsaverage", "sample"):
          if subject_from == "fsaverage":
              scale = 1.0  # single dim
          else:
              scale = [0.9, 2, 0.8]  # separate
          src_from_fname = (
              subjects_dir_tmp_few
              / subject_from
              / "bem"
              / ("%s-%s-src.fif" % (subject_from, spacing))
          )
          src_from = mne.setup_source_space(
              subject_from,
              spacing,
              subjects_dir=subjects_dir_tmp_few,
              add_dist=False,
          )
          write_source_spaces(src_from_fname, src_from)
          vertices_from = np.concatenate(
              [s["vertno"] for s in src_from]
          )
          assert len(vertices_from) == 36
          hemis = [0] * len(src_from[0]["vertno"]) + [1] * len(
              src_from[0]["vertno"]
          )
          mni_from = mne.vertex_to_mni(
              vertices_from,
              hemis,
              subject_from,
              subjects_dir=subjects_dir_tmp_few,
          )
          if subject_from == "fsaverage":  # identity transform
              source_rr = (
                  np.concatenate(
                      [s["rr"][s["vertno"]] for s in src_from]
                  )
                  * 1e3
              )
              assert_allclose(mni_from, source_rr)
          if subject_from == "fsaverage":
              overwrite = skip_fiducials = False
          else:
              with pytest.raises(OSError, match="No fiducials file"):
                  scale_mri(
                      subject_from,
                      subject_to,
                      scale,
                      subjects_dir=subjects_dir_tmp_few,
                  )
              skip_fiducials = True
              with pytest.raises(OSError, match="already exists"):
                  scale_mri(
                      subject_from,
                      subject_to,
                      scale,
                      subjects_dir=subjects_dir_tmp_few,
                      skip_fiducials=skip_fiducials,
                  )
              overwrite = True
          if (
              subject_from == "sample"
          ):  # support for not needing all surf files
              os.remove(sample_dir / "surf" / "lh.curv")
          scale_mri(
              subject_from,
              subject_to,
              scale,
              subjects_dir=subjects_dir_tmp_few,
              verbose="debug",
              overwrite=overwrite,
              skip_fiducials=skip_fiducials,
          )
          if subject_from == "fsaverage":
              assert _is_mri_subject(subject_to, subjects_dir_tmp_few)
          src_to_fname = (
              subjects_dir_tmp_few
              / subject_to
              / "bem"
              / ("%s-%s-src.fif" % (subject_to, spacing))
          )
          assert src_to_fname.exists(), "Source space was not scaled"
          # Check MRI scaling
          fname_mri = (
              subjects_dir_tmp_few / subject_to / "mri" / "T1.mgz"
          )
          assert fname_mri.exists(), "MRI was not scaled"
          # Check MNI transform
          src = mne.read_source_spaces(src_to_fname)
          vertices = np.concatenate([s["vertno"] for s in src])
          assert_array_equal(vertices, vertices_from)
          mni = mne.vertex_to_mni(
              vertices,
              hemis,
              subject_to,
              subjects_dir=subjects_dir_tmp_few,
          )
          assert_allclose(mni, mni_from, atol=1e-3)  # 0.001 mm
          # Check head_to_mni (the `trans` here does not really matter)
          trans = rotation(0.001, 0.002, 0.003) @ translation(
              0.01, 0.02, 0.03
          )
          trans = Transform("head", "mri", trans)
          pos_head_from = np.random.RandomState(0).randn(4, 3)
          pos_mni_from = mne.head_to_mni(
              pos_head_from, subject_from, trans, subjects_dir_tmp_few
          )
          pos_mri_from = apply_trans(trans, pos_head_from)
          pos_mri = pos_mri_from * scale
          pos_head = apply_trans(invert_transform(trans), pos_mri)
          pos_mni = mne.head_to_mni(
              pos_head, subject_to, trans, subjects_dir_tmp_few
          )
          assert_allclose(pos_mni, pos_mni_from, atol=1e-3)
          # another way
          pos_mri_from_2 = mne.head_to_mri(
              pos_head_from, subject_from, trans, subjects_dir_tmp_few
          )
          pos_mri_from_ras = mne.head_to_mri(
              pos_head_from,
              subject_from,
              trans,
              subjects_dir_tmp_few,
              kind="ras",
          )
          mri_eq_ras = np.allclose(
              pos_mri_from_2, pos_mri_from_ras, atol=1e-1
          )
          if subject_from == "fsaverage":
              assert mri_eq_ras  # fsaverage is special this way
          else:
              assert not mri_eq_ras  # sample is not
          assert_allclose(pos_mri_from_2, 1e3 * pos_mri_from, atol=1e-3)
          with pytest.raises(OSError, match=r"parameters\.cfg"):
              mne.head_to_mri(
                  pos_head_from,
                  subject_from,
                  trans,
                  subjects_dir_tmp_few,
                  unscale=True,
                  kind="mri",
              )
          # yet another way
          pos_mri_from_3 = mne.head_to_mri(
              pos_head,
              subject_to,
              trans,
              subjects_dir_tmp_few,
              kind="mri",
              unscale=True,
          )
          assert_allclose(pos_mri_from_3, 1e3 * pos_mri_from, atol=1e-3)
  
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 4 for calling a global function with example usage: test_scale_mri_xfm(tmp_path, few_surfaces, subjects_dir_tmp_few) without return types