code: def test_calculate_chpi_snr():
      """Test cHPI SNR calculation."""
      raw = read_raw_fif(chpi_fif_fname, allow_maxshield="yes")
      # include handling of NaN (when cHPI was off at the beginning)
      raw.load_data()
      raw.info["bads"] = ["MEG0342", "MEG1443"]
      stop = int(round(raw.info["sfreq"])) * 2
      raw._data[raw.ch_names.index("STI201"), :stop] = 0
  
      result = compute_chpi_snr(raw)
      # make sure all the entries are there
      keys = {
          f"{ch_type}_{key}"
          for ch_type in ("mag", "grad")
          for key in ("snr", "power", "resid")
      }
      assert set(result) == keys.union({"times", "freqs"})
      # make sure the values are plausible, given the sample data file
      n_pts = len(raw.times) // int(round(raw.info["sfreq"] * 0.01))
      # our logic in this test for this length is not perfect
      assert_allclose(result["mag_snr"].shape[0], n_pts, atol=5)
      n_nan = np.where(result["times"] <= raw.first_time + 2)[0][-1]
      assert_allclose(result["mag_snr"][:n_nan], np.nan)
      assert result["mag_snr"][n_nan:].min() > 1
      assert result["mag_snr"][n_nan:].max() < 40
      assert result["grad_snr"][n_nan:].min() > 1
      assert result["grad_snr"][n_nan:].max() < 40
  
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 9 for calling a global function with example usage: test_calculate_chpi_snr() without return types