code: def _compute_chpi_amp_or_snr(
      raw,
      t_step_min=0.01,
      t_window="auto",
      ext_order=1,
      tmin=0,
      tmax=None,
      verbose=None,
      snr=False,
  ):
      """Compute cHPI amplitude or SNR.
  
      See compute_chpi_amplitudes for parameter descriptions. One additional
      boolean parameter ``snr`` signals whether to return SNR instead of
      amplitude.
      """
      hpi = _setup_hpi_amplitude_fitting(
          raw.info, t_window, ext_order=ext_order
      )
      tmin, tmax = raw._tmin_tmax_to_start_stop(tmin, tmax)
      tmin = tmin / raw.info["sfreq"]
      tmax = tmax / raw.info["sfreq"]
      need_win = hpi["t_window"] / 2.0
      fit_idxs = raw.time_as_index(
          np.arange(tmin + need_win, tmax, t_step_min),
          use_rounding=True,
      )
      logger.info(
          "Fitting %d HPI coil locations at up to %s time points "
          "(%0.1f s duration)"
          % (len(hpi["freqs"]), len(fit_idxs), tmax - tmin)
      )
      del tmin, tmax
      sin_fits = dict()
      sin_fits["proj"] = hpi["proj"]
      sin_fits["times"] = (
          np.round(fit_idxs + raw.first_samp - hpi["n_window"] / 2.0)
          / raw.info["sfreq"]
      )
      n_times = len(sin_fits["times"])
      n_freqs = len(hpi["freqs"])
      n_chans = len(sin_fits["proj"]["data"]["col_names"])
      if snr:
          del sin_fits["proj"]
          sin_fits["freqs"] = hpi["freqs"]
          ch_types = raw.get_channel_types()
          grad_offset = 3 if "mag" in ch_types else 0
          for ch_type in ("mag", "grad"):
              if ch_type in ch_types:
                  for key in ("snr", "power", "resid"):
                      cols = 1 if key == "resid" else n_freqs
                      sin_fits[f"{ch_type}_{key}"] = np.empty(
                          (n_times, cols)
                      )
      else:
          sin_fits["slopes"] = np.empty((n_times, n_freqs, n_chans))
      message = f"cHPI {'SNRs' if snr else 'amplitudes'}"
      for mi, midpt in enumerate(ProgressBar(fit_idxs, mesg=message)):
          #
          # 0. determine samples to fit.
          #
          time_sl = midpt - hpi["n_window"] // 2
          time_sl = slice(
              max(time_sl, 0),
              min(time_sl + hpi["n_window"], len(raw.times)),
          )
  
          #
          # 1. Fit amplitudes for each channel from each of the N sinusoids
          #
          amps_or_snrs = _fit_chpi_amplitudes(raw, time_sl, hpi, snr)
          if snr:
              if amps_or_snrs is None:
                  amps_or_snrs = np.full(
                      (n_freqs, grad_offset + 3), np.nan
                  )
              # unpack the SNR estimates. mag & grad are returned in one array
              # (because of Numba) so take care with which column is which.
              # note that mean residual is a scalar (same for all HPI freqs) but
              # is returned as a (tiled) vector (again, because Numba) so that's
              # why below we take amps_or_snrs[0, 2] instead of [:, 2]
              ch_types = raw.get_channel_types()
              if "mag" in ch_types:
                  sin_fits["mag_snr"][mi] = amps_or_snrs[:, 0]  # SNR
                  sin_fits["mag_power"][mi] = amps_or_snrs[
                      :, 1
                  ]  # mean power
                  sin_fits["mag_resid"][mi] = amps_or_snrs[
                      0, 2
                  ]  # mean resid
              if "grad" in ch_types:
                  sin_fits["grad_snr"][mi] = amps_or_snrs[
                      :, grad_offset
                  ]
                  sin_fits["grad_power"][mi] = amps_or_snrs[
                      :, grad_offset + 1
                  ]
                  sin_fits["grad_resid"][mi] = amps_or_snrs[
                      0, grad_offset + 2
                  ]
          else:
              sin_fits["slopes"][mi] = amps_or_snrs
      return sin_fits
  
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 29 for calling a global function with example usage: _compute_chpi_amp_or_snr(raw, t_step_min, t_window, ext_order, tmin, tmax, verbose, snr) and returns: sin_fits