code: def test_calculate_head_pos_ctf(tmp_path):
      """Test extracting of cHPI positions from CTF data."""
      raw = read_raw_ctf(ctf_chpi_fname)
      chpi_locs = extract_chpi_locs_ctf(raw)
      quats = compute_head_pos(raw.info, chpi_locs)
      mc_quats = read_head_pos(ctf_chpi_pos_fname)
      mc_quats[
          :, 9
      ] /= 10000  # had old factor in there twice somehow...
      _assert_quats(
          quats,
          mc_quats,
          dist_tol=0.004,
          angle_tol=2.5,
          err_rtol=1.0,
          vel_atol=7e-3,
      )  # 7 mm/s
      plot_head_positions(quats, info=raw.info)
  
      with pytest.raises(RuntimeError, match="Could not find"):
          extract_chpi_locs_ctf(read_raw_fif(ctf_fname))
  
      # save-load should not affect result
      fname_temp = tmp_path / "test_ctf_raw.fif"
      raw.save(fname_temp)
      raw_read = read_raw_fif(fname_temp)
      # the two attributes used by compute_head_pos
      assert_allclose(
          raw.info["dev_head_t"]["trans"],
          raw_read.info["dev_head_t"]["trans"],
      )
      with pytest.warns(RuntimeWarning, match="is poor"):
          head_rrs = _get_hpi_initial_fit(raw.info, verbose="debug")
      with pytest.warns(RuntimeWarning, match="is poor"):
          head_rrs_2 = _get_hpi_initial_fit(
              raw_read.info, verbose="debug"
          )
      assert_allclose(head_rrs, head_rrs_2, atol=1e-5)
      quats_2 = compute_head_pos(raw_read.info, chpi_locs)
      _assert_quats(quats, quats_2, dist_tol=1e-5, angle_tol=0.1)
      chpi_locs_2 = extract_chpi_locs_ctf(raw_read)
      assert_allclose(chpi_locs["rrs"], chpi_locs_2["rrs"], atol=1e-5)
      quats_3 = compute_head_pos(raw_read.info, chpi_locs_2)
      _assert_quats(quats, quats_3, dist_tol=1e-5, angle_tol=0.1)
  
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 21 for calling a global function with example usage: test_calculate_head_pos_ctf(tmp_path) without return types