code: def add_chpi(
      raw, head_pos=None, interp="cos2", n_jobs=None, verbose=None
  ):
      """Add cHPI activations to raw data.
  
      Parameters
      ----------
      raw : instance of Raw
          The raw instance to be modified.
      %(head_pos)s
      %(interp)s
      %(n_jobs)s
      %(verbose)s
  
      Returns
      -------
      raw : instance of Raw
          The instance, modified in place.
  
      Notes
      -----
      .. versionadded:: 0.18
      """
      _validate_type(raw, BaseRaw, "raw")
      _check_preload(raw, "Adding cHPI signals ")
      info, first_samp, times = raw.info, raw.first_samp, raw.times
      meg_picks = pick_types(
          info, meg=True, eeg=False, exclude=[]
      )  # for CHPI
      if len(meg_picks) == 0:
          raise RuntimeError(
              "Cannot add cHPI if no MEG picks are present"
          )
      dev_head_ts, offsets = _check_head_pos(
          head_pos, info, first_samp, times
      )
      hpi_freqs, hpi_pick, hpi_ons = get_chpi_info(
          info, on_missing="raise"
      )
      hpi_rrs = _get_hpi_initial_fit(info, verbose="error")
      hpi_nns = (
          hpi_rrs
          / np.sqrt(np.sum(hpi_rrs * hpi_rrs, axis=1))[:, np.newaxis]
      )
      # turn on cHPI in file
      data = raw._data
      data[hpi_pick, :] = hpi_ons.sum()
      _log_ch("cHPI status bits enabled and", info, hpi_pick)
      sinusoids = 70e-9 * np.sin(
          2
          * np.pi
          * hpi_freqs[:, np.newaxis]
          * (np.arange(len(times)) / info["sfreq"])
      )
      info = pick_info(info, meg_picks)
      with info._unlock():
          info.update(projs=[], bads=[])  # Ensure no 'projs' or 'bads'
      megcoils = _prep_meg_channels(info, ignore_ref=True)["defs"]
      used = np.zeros(len(raw.times), bool)
      dev_head_ts.append(dev_head_ts[-1])  # ZOH after time ends
      get_fwd = _HPIForwards(
          offsets, dev_head_ts, megcoils, hpi_rrs, hpi_nns
      )
      interper = _Interp2(offsets, get_fwd, interp)
      lims = np.concatenate([offsets, [len(raw.times)]])
      for start, stop in zip(lims[:-1], lims[1:]):
          (fwd,) = interper.feed(stop - start)
          data[meg_picks, start:stop] += np.einsum(
              "svt,vt->st", fwd, sinusoids[:, start:stop]
          )
          assert not used[start:stop].any()
          used[start:stop] = True
      assert used.all()
      return raw
  
imports: import os
  from collections.abc import Iterable
  from pathlib import Path
  import numpy
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._ola import _Interp2
  from ..bem import fit_sphere_to_headshape, make_sphere_model, read_bem_solution
  from ..chpi import _get_hpi_initial_fit, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos
  from ..cov import Covariance, make_ad_hoc_cov, read_cov
  from ..event import _get_stim_channel
  from ..forward import _compute_forwards, _magnetic_dipole_field_vec, _merge_fwds, _prep_meg_channels, _prepare_for_forward, _stc_src_sel, _to_forward_dict, _transform_orig_meg_coils, convert_forward_solution, restrict_forward_to_stc
  from ..io import BaseRaw, RawArray
  from ..source_estimate import _BaseSourceEstimate
  from ..source_space._source_space import _ensure_src, _set_source_space_vertices, setup_volume_source_space
  from ..surface import _CheckInside
  from ..transforms import _get_trans, transform_surface_to
  from ..utils import _check_preload, _pl, _validate_type, check_random_state, logger, verbose
  from .source import SourceSimulator
label_desc: Use image node_id 9 for calling a global function with example usage: add_chpi(raw, head_pos, interp, n_jobs, verbose) and returns: raw