code: def extract_chpi_locs_kit(
      raw, stim_channel="MISC 064", *, verbose=None
  ):
      """Extract cHPI locations from KIT data.
  
      Parameters
      ----------
      raw : instance of RawKIT
          Raw data with KIT cHPI information.
      stim_channel : str
          The stimulus channel that encodes HPI measurement intervals.
      %(verbose)s
  
      Returns
      -------
      %(chpi_locs)s
  
      Notes
      -----
      .. versionadded:: 0.23
      """
      _validate_type(raw, (_RawKIT,), "raw")
      stim_chs = [
          raw.info["ch_names"][pick]
          for pick in pick_types(
              raw.info, stim=True, misc=True, ref_meg=False
          )
      ]
      _validate_type(stim_channel, str, "stim_channel")
      _check_option("stim_channel", stim_channel, stim_chs)
      idx = raw.ch_names.index(stim_channel)
      safe_false = _verbose_safe_false()
      events_on = find_events(
          raw,
          stim_channel=raw.ch_names[idx],
          output="onset",
          verbose=safe_false,
      )[:, 0]
      events_off = find_events(
          raw,
          stim_channel=raw.ch_names[idx],
          output="offset",
          verbose=safe_false,
      )[:, 0]
      bad = False
      if len(events_on) == 0 or len(events_off) == 0:
          bad = True
      else:
          if events_on[-1] > events_off[-1]:
              events_on = events_on[:-1]
          if (
              events_on.size != events_off.size
              or not (events_on < events_off).all()
          ):
              bad = True
      if bad:
          raise RuntimeError(
              f"Could not find appropriate cHPI intervals from {stim_channel}"
          )
      # use the midpoint for times
      times = (events_on + events_off) / (2 * raw.info["sfreq"])
      del events_on, events_off
      # XXX remove first two rows. It is unknown currently if there is a way to
      # determine from the con file the number of initial pulses that
      # indicate the start of reading. The number is shown by opening the con
      # file in MEG160, but I couldn't find the value in the .con file, so it
      # may just always be 2...
      times = times[2:]
      n_coils = 5  # KIT always has 5 (hard-coded in reader)
      header = raw._raw_extras[0]["dirs"][KIT.DIR_INDEX_CHPI_DATA]
      dtype = np.dtype([("good", "<u4"), ("data", "<f8", (4,))])
      assert dtype.itemsize == header["size"], (
          dtype.itemsize,
          header["size"],
      )
      all_data = list()
      for fname in raw._filenames:
          with open(fname) as fid:
              fid.seek(header["offset"])
              all_data.append(
                  np.fromfile(
                      fid, dtype, count=header["count"]
                  ).reshape(-1, n_coils)
              )
      data = np.concatenate(all_data)
      extra = ""
      if len(times) < len(data):
          extra = f", truncating to {len(times)} based on events"
      logger.info(
          f"Found {len(data)} cHPI measurement{_pl(len(data))}{extra}"
      )
      data = data[: len(times)]
      # good is not currently used, but keep this in case we want it later
      # good = data['good'] == 1
      data = data["data"]
      rrs, gofs = data[:, :, :3], data[:, :, 3]
      rrs = apply_trans(als_ras_trans, rrs)
      moments = np.zeros(rrs.shape)  # not encoded, set all zero
      return dict(rrs=rrs, gofs=gofs, times=times, moments=moments)
  
imports: import copy
  import itertools
  from functools import partial
  import numpy
  from scipy.linalg import orth
  from scipy.optimize import fmin_cobyla
  from scipy.spatial.distance import cdist
  from ._fiff.constants import FIFF
  from ._fiff.meas_info import Info, _simplify_info
  from ._fiff.pick import _picks_to_idx, pick_channels, pick_channels_regexp, pick_info, pick_types
  from ._fiff.proj import Projection, setup_proj
  from .channels.channels import _get_meg_system
  from .cov import compute_whitener, make_ad_hoc_cov
  from .dipole import _make_guesses
  from .event import find_events
  from .fixes import jit
  from .forward import _concatenate_coils, _create_meg_coils, _magnetic_dipole_field_vec
  from .io import BaseRaw
  from .io.ctf.trans import _make_ctf_coord_trans_set
  from .io.kit.constants import KIT
  from .io.kit.kit import RawKIT
  from .preprocessing.maxwell import _get_mf_picks_fix_mags, _prep_mf_coils, _regularize_out, _sss_basis
  from .transforms import _angle_between_quats, _fit_matched_points, _quat_to_affine, als_ras_trans, apply_trans, invert_transform, quat_to_rot, rot_to_quat
  from .utils import ProgressBar, _check_fname, _check_option, _on_missing, _pl, _validate_type, _verbose_safe_false, logger, use_log_level, verbose, warn
label_desc: Use image node_id 5 for calling a global function with example usage: extract_chpi_locs_kit(raw, stim_channel) and returns: dict