code: def test_initial_fit_redo():
      """Test that initial fits can be redone based on moments."""
      raw = read_raw_fif(chpi_fif_fname, allow_maxshield="yes")
      slopes = np.array(
          [[c["slopes"] for c in raw.info["hpi_meas"][0]["hpi_coils"]]]
      )
      amps = np.linalg.norm(slopes, axis=-1)
      amps /= slopes.shape[-1]
      assert_array_less(amps, 5e-11)
      assert_array_less(1e-12, amps)
      proj, _, _ = _setup_ext_proj(raw.info, ext_order=1)
      chpi_amplitudes = dict(
          times=np.zeros(1), slopes=slopes, proj=proj
      )
      chpi_locs = compute_chpi_locs(raw.info, chpi_amplitudes)
  
      # check GOF
      coil_gof = raw.info["hpi_results"][0]["goodness"]
      assert_allclose(
          chpi_locs["gofs"][0], coil_gof, atol=0.3
      )  # XXX not good
  
      # check moment
      # XXX our forward and theirs differ by an extra mult by _MAG_FACTOR
      coil_moment = raw.info["hpi_results"][0]["moments"] / _MAG_FACTOR
      py_moment = chpi_locs["moments"][0]
      coil_amp = np.linalg.norm(coil_moment, axis=-1, keepdims=True)
      py_amp = np.linalg.norm(py_moment, axis=-1, keepdims=True)
      assert_allclose(coil_amp, py_amp, rtol=0.2)
      coil_ori = coil_moment / coil_amp
      py_ori = py_moment / py_amp
      angles = np.rad2deg(
          np.arccos(np.abs(np.sum(coil_ori * py_ori, axis=1)))
      )
      assert_array_less(angles, 20)
  
      # check resulting dev_head_t
      head_pos = compute_head_pos(raw.info, chpi_locs)
      assert head_pos.shape == (1, 10)
      nm_pos = raw.info["dev_head_t"]["trans"]
      dist = 1000 * np.linalg.norm(nm_pos[:3, 3] - head_pos[0, 4:7])
      assert 0.1 < dist < 2
      angle = np.rad2deg(
          _angle_between_quats(
              rot_to_quat(nm_pos[:3, :3]), head_pos[0, 1:4]
          )
      )
      assert 0.1 < angle < 2
      gof = head_pos[0, 7]
      assert_allclose(gof, 0.9999, atol=1e-4)
  
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from scipy.interpolate import interp1d
  from scipy.spatial.distance import cdist
  from mne import pick_info, pick_types
  from mne._fiff.constants import FIFF
  from mne.chpi import _chpi_locs_to_times_dig, _compute_good_distances, _get_hpi_initial_fit, _setup_ext_proj, compute_chpi_amplitudes, compute_chpi_locs, compute_chpi_snr, compute_head_pos, extract_chpi_locs_ctf, extract_chpi_locs_kit, filter_chpi, get_active_chpi, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos, write_head_pos
  from mne.datasets import testing
  from mne.forward._compute_forward import _MAG_FACTOR
  from mne.io import RawArray, read_info, read_raw_artemis123, read_raw_ctf, read_raw_fif, read_raw_kit
  from mne.simulation import add_chpi
  from mne.transforms import _angle_between_quats, rot_to_quat
  from mne.utils import assert_meg_snr, catch_logging, object_diff, verbose
  from mne.viz import plot_head_positions
label_desc: Use image node_id 12 for calling a global function with example usage: test_initial_fit_redo() without return types