code: def _assert_quats(
      actual,
      desired,
      dist_tol=0.003,
      angle_tol=5.0,
      err_rtol=0.5,
      gof_rtol=0.001,
      vel_atol=2e-3,
  ):  # 2 mm/s
      """Compare estimated cHPI positions."""
      __tracebackhide__ = True
      trans_est, rot_est, t_est = head_pos_to_trans_rot_t(actual)
      trans, rot, t = head_pos_to_trans_rot_t(desired)
      quats_est = rot_to_quat(rot_est)
      gofs, errs, vels = desired[:, 7:].T
      gofs_est, errs_est, vels_est = actual[:, 7:].T
      del actual, desired
  
      # maxfilter produces some times that are implausibly large (weird)
      if not np.isclose(t[0], t_est[0], atol=1e-1):  # within 100 ms
          raise AssertionError(
              "Start times not within 100 ms: %0.3f != %0.3f"
              % (t[0], t_est[0])
          )
      use_mask = (t >= t_est[0]) & (t <= t_est[-1])
      t = t[use_mask]
      trans = trans[use_mask]
      quats = rot_to_quat(rot)
      quats = quats[use_mask]
      gofs, errs, vels = gofs[use_mask], errs[use_mask], vels[use_mask]
  
      # double-check our angle function
      for q in (quats, quats_est):
          angles = _angle_between_quats(q, q)
          assert_allclose(angles, 0.0, atol=1e-5)
  
      # limit translation difference between MF and our estimation
      trans_est_interp = interp1d(t_est, trans_est, axis=0)(t)
      distances = np.sqrt(
          np.sum((trans - trans_est_interp) ** 2, axis=1)
      )
      assert np.isfinite(distances).all()
      arg_worst = np.argmax(distances)
      assert (
          distances[arg_worst] <= dist_tol
      ), "@ %0.3f seconds: %0.3f > %0.3f mm" % (
          t[arg_worst],
          1000 * distances[arg_worst],
          1000 * dist_tol,
      )
  
      # limit rotation difference between MF and our estimation
      # (note that the interpolation will make this slightly worse)
      quats_est_interp = interp1d(t_est, quats_est, axis=0)(t)
      angles = (
          180 * _angle_between_quats(quats_est_interp, quats) / np.pi
      )
      arg_worst = np.argmax(angles)
      assert (
          angles[arg_worst] <= angle_tol
      ), "@ %0.3f seconds: %0.3f > %0.3f deg" % (
          t[arg_worst],
          angles[arg_worst],
          angle_tol,
      )
  
      # error calculation difference
      errs_est_interp = interp1d(t_est, errs_est)(t)
      assert_allclose(
          errs_est_interp, errs, rtol=err_rtol, atol=1e-3, err_msg="err"
      )  # 1 mm
  
      # gof calculation difference
      gof_est_interp = interp1d(t_est, gofs_est)(t)
      assert_allclose(
          gof_est_interp, gofs, rtol=gof_rtol, atol=1e-7, err_msg="gof"
      )
  
      # velocity calculation difference
      vel_est_interp = interp1d(t_est, vels_est)(t)
      assert_allclose(
          vel_est_interp, vels, atol=vel_atol, err_msg="velocity"
      )
  
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 4 for calling a global function with example usage: _assert_quats(actual, desired, dist_tol, angle_tol, err_rtol, gof_rtol, vel_atol) without return types