code: def test_coregistration(
      scale_mode, ref_scale, grow_hair, fiducials, fid_match
  ):
      """Test automated coregistration."""
      pytest.importorskip("nibabel")
      subject = "sample"
      if fiducials is None:
          fiducials, coord_frame = read_fiducials(fid_fname)
          assert coord_frame == FIFF.FIFFV_COORD_MRI
      info = read_info(raw_fname)
      for d in info["dig"]:
          d["r"] = d["r"] * ref_scale
      trans = read_trans(trans_fname)
      coreg = Coregistration(
          info,
          subject=subject,
          subjects_dir=subjects_dir,
          fiducials=fiducials,
      )
      assert np.allclose(coreg._last_parameters, coreg._parameters)
      assert len(coreg.fiducials.dig) == 3
      for dig_point in coreg.fiducials.dig:
          assert dig_point["coord_frame"] == FIFF.FIFFV_COORD_MRI
          assert dig_point["kind"] == FIFF.FIFFV_POINT_CARDINAL
  
      coreg.set_fid_match(fid_match)
      default_params = list(coreg._default_parameters)
      coreg.set_rotation(default_params[:3])
      coreg.set_translation(default_params[3:6])
      coreg.set_scale(default_params[6:9])
      coreg.set_grow_hair(grow_hair)
      coreg.set_scale_mode(scale_mode)
      # Identity transform
      errs_id = coreg.compute_dig_mri_distances()
      is_scaled = ref_scale != [1.0, 1.0, 1.0]
      id_max = 0.03 if is_scaled and scale_mode == "3-axis" else 0.02
      assert 0.005 < np.median(errs_id) < id_max
      # Fiducial transform + scale
      coreg.fit_fiducials(verbose=True)
      assert coreg._extra_points_filter is None
      coreg.omit_head_shape_points(distance=0.02)
      assert coreg._extra_points_filter is not None
      errs_fid = coreg.compute_dig_mri_distances()
      assert_array_less(0, errs_fid)
      if is_scaled or scale_mode is not None:
          fid_max = 0.05
          fid_med = 0.02
      else:
          fid_max = 0.03
          fid_med = 0.01
      assert_array_less(errs_fid, fid_max)
      assert 0.001 < np.median(errs_fid) < fid_med
      assert not np.allclose(coreg._parameters, default_params)
      coreg.omit_head_shape_points(distance=-1)
      coreg.omit_head_shape_points(distance=5.0 / 1000)
      assert coreg._extra_points_filter is not None
      # ICP transform + scale
      coreg.fit_icp(verbose=True)
      assert isinstance(coreg.trans, Transform)
      errs_icp = coreg.compute_dig_mri_distances()
      assert_array_less(0, errs_icp)
      if is_scaled or scale_mode == "3-axis":
          icp_max = 0.015
      else:
          icp_max = 0.01
      assert_array_less(errs_icp, icp_max)
      assert 0.001 < np.median(errs_icp) < 0.004
      assert (
          np.rad2deg(
              _angle_between_quats(
                  rot_to_quat(coreg.trans["trans"][:3, :3]),
                  rot_to_quat(trans["trans"][:3, :3]),
              )
          )
          < 13
      )
      if scale_mode is None:
          atol = 1e-7
      else:
          atol = 0.35
      assert_allclose(coreg._scale, ref_scale, atol=atol)
      coreg.reset()
      assert_allclose(coreg._parameters, default_params)
  
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 7 for calling a global function with example usage: test_coregistration(scale_mode, ref_scale, grow_hair, fiducials, fid_match) without return types