code: def test_calculate_chpi_positions_vv():
      """Test calculation of cHPI positions."""
      # Check to make sure our fits match MF decently
      mf_quats = read_head_pos(pos_fname)
      raw = read_raw_fif(chpi_fif_fname, allow_maxshield="yes")
      raw.crop(0, 5).load_data()
      # check "auto" t_window estimation at full sampling rate
      with catch_logging() as log:
          compute_chpi_amplitudes(
              raw,
              t_step_min=0.1,
              t_window="auto",
              tmin=0,
              tmax=2,
              verbose=True,
          )
      assert "83.3 ms" in log.getvalue()
      # This is a little hack (aliasing while decimating) to make it much faster
      # for testing purposes only. We can relax this later if we find it breaks
      # something.
      raw_dec = _decimate_chpi(raw, 15)
      with catch_logging() as log:
          with pytest.warns(RuntimeWarning, match="cannot determine"):
              py_quats = _calculate_chpi_positions(
                  raw_dec, t_window=0.2, verbose="debug"
              )
      log = log.getvalue()
      assert "\nHPIFIT" in log
      assert "Computing 4385 HPI location guesses" in log
      _assert_quats(py_quats, mf_quats, dist_tol=0.001, angle_tol=0.7)
      # degenerate conditions
      raw_no_chpi = read_raw_fif(sample_fname)
      with pytest.raises(
          ValueError, match="No appropriate cHPI information"
      ):
          _calculate_chpi_positions(raw_no_chpi)
      raw_bad = raw.copy()
      del raw_bad.info["hpi_meas"][0]["hpi_coils"][0]["coil_freq"]
      with pytest.raises(
          ValueError, match="No appropriate cHPI information"
      ):
          _calculate_chpi_positions(raw_bad)
      raw_bad = raw.copy()
      for d in raw_bad.info["dig"]:
          if d["kind"] == FIFF.FIFFV_POINT_HPI:
              d["coord_frame"] = FIFF.FIFFV_COORD_UNKNOWN
              break
      with pytest.raises(
          RuntimeError, match="coordinate frame incorrect"
      ):
          _calculate_chpi_positions(raw_bad)
      for d in raw_bad.info["dig"]:
          if d["kind"] == FIFF.FIFFV_POINT_HPI:
              d["coord_frame"] = FIFF.FIFFV_COORD_HEAD
              d["r"] = np.ones(3)
      raw_bad.crop(0, 1.0)
      picks = np.concatenate(
          [
              np.arange(306, len(raw_bad.ch_names)),
              pick_types(raw_bad.info, meg=True)[::16],
          ]
      )
      raw_bad.pick([raw_bad.ch_names[pick] for pick in picks])
      with pytest.warns(RuntimeWarning, match="Discrepancy"):
          with catch_logging() as log_file:
              _calculate_chpi_positions(
                  raw_bad, t_step_min=1.0, verbose=True
              )
      # ignore HPI info header and [done] footer
      assert "0/5 good HPI fits" in log_file.getvalue()
  
      # half the rate cuts off cHPI coils
      with raw.info._unlock():
          raw.info["lowpass"] /= 2.0
      with pytest.raises(RuntimeError, match="above the"):
          _calculate_chpi_positions(raw)
  
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 8 for calling a global function with example usage: test_calculate_chpi_positions_vv() without return types