code: def filter_chpi(
      raw,
      include_line=True,
      t_step=0.01,
      t_window="auto",
      ext_order=1,
      allow_line_only=False,
      verbose=None,
  ):
      """Remove cHPI and line noise from data.
  
      .. note:: This function will only work properly if cHPI was on
                during the recording.
  
      Parameters
      ----------
      raw : instance of Raw
          Raw data with cHPI information. Must be preloaded. Operates in-place.
      include_line : bool
          If True, also filter line noise.
      t_step : float
          Time step to use for estimation, default is 0.01 (10 ms).
      %(t_window_chpi_t)s
      %(ext_order_chpi)s
      allow_line_only : bool
          If True, allow filtering line noise only. The default is False,
          which only allows the function to run when cHPI information is present.
  
          .. versionadded:: 0.20
      %(verbose)s
  
      Returns
      -------
      raw : instance of Raw
          The raw data.
  
      Notes
      -----
      cHPI signals are in general not stationary, because head movements act
      like amplitude modulators on cHPI signals. Thus it is recommended to
      use this procedure, which uses an iterative fitting method, to
      remove cHPI signals, as opposed to notch filtering.
  
      .. versionadded:: 0.12
      """
      _validate_type(raw, BaseRaw, "raw")
      if not raw.preload:
          raise RuntimeError("raw data must be preloaded")
      t_step = float(t_step)
      if t_step <= 0:
          raise ValueError(f"t_step ({t_step}) must be > 0")
      n_step = int(np.ceil(t_step * raw.info["sfreq"]))
      if include_line and raw.info["line_freq"] is None:
          raise RuntimeError(
              'include_line=True but raw.info["line_freq"] is '
              "None, consider setting it to the line frequency"
          )
      hpi = _setup_hpi_amplitude_fitting(
          raw.info,
          t_window,
          remove_aliased=True,
          ext_order=ext_order,
          allow_empty=allow_line_only,
          verbose=_verbose_safe_false(),
      )
  
      fit_idxs = np.arange(
          0, len(raw.times) + hpi["n_window"] // 2, n_step
      )
      n_freqs = len(hpi["freqs"])
      n_remove = 2 * n_freqs
      meg_picks = pick_types(
          raw.info, meg=True, exclude=()
      )  # filter all chs
      n_times = len(raw.times)
  
      msg = "Removing %s cHPI" % n_freqs
      if include_line:
          n_remove += 2 * len(hpi["line_freqs"])
          msg += " and %s line harmonic" % len(hpi["line_freqs"])
      msg += " frequencies from %s MEG channels" % len(meg_picks)
  
      recon = np.dot(
          hpi["model"][:, :n_remove], hpi["inv_model"][:n_remove]
      ).T
      logger.info(msg)
      chunks = list()  # the chunks to subtract
      last_endpt = 0
      pb = ProgressBar(fit_idxs, mesg="Filtering")
      for ii, midpt in enumerate(pb):
          left_edge = midpt - hpi["n_window"] // 2
          time_sl = slice(
              max(left_edge, 0),
              min(left_edge + hpi["n_window"], len(raw.times)),
          )
          this_len = time_sl.stop - time_sl.start
          if this_len == hpi["n_window"]:
              this_recon = recon
          else:  # first or last window
              model = hpi["model"][:this_len]
              inv_model = np.linalg.pinv(model)
              this_recon = np.dot(
                  model[:, :n_remove], inv_model[:n_remove]
              ).T
          this_data = raw._data[meg_picks, time_sl]
          subt_pt = min(midpt + n_step, n_times)
          if last_endpt != subt_pt:
              fit_left_edge = (
                  left_edge - time_sl.start + hpi["n_window"] // 2
              )
              fit_sl = slice(
                  fit_left_edge, fit_left_edge + (subt_pt - last_endpt)
              )
              chunks.append(
                  (subt_pt, np.dot(this_data, this_recon[:, fit_sl]))
              )
          last_endpt = subt_pt
  
          # Consume (trailing) chunks that are now safe to remove because
          # our windows will no longer touch them
          if ii < len(fit_idxs) - 1:
              next_left_edge = fit_idxs[ii + 1] - hpi["n_window"] // 2
          else:
              next_left_edge = np.inf
          while len(chunks) > 0 and chunks[0][0] <= next_left_edge:
              right_edge, chunk = chunks.pop(0)
              raw._data[
                  meg_picks, right_edge - chunk.shape[1] : right_edge
              ] -= chunk
      return raw
  
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 32 for calling a global function with example usage: filter_chpi(raw, include_line, t_step, t_window, ext_order, allow_line_only, verbose) and returns: raw