code: def _fast_fit_snr(
      this_data, n_freqs, model, inv_model, mag_picks, grad_picks
  ):
      # first or last window
      if this_data.shape[1] != model.shape[0]:
          model = model[: this_data.shape[1]]
          inv_model = np.linalg.pinv(model)
      coefs = np.ascontiguousarray(inv_model) @ np.ascontiguousarray(
          this_data.T
      )
      # average sin & cos terms (special property of sinusoids: power=A²/2)
      hpi_power = (
          coefs[:n_freqs] ** 2 + coefs[n_freqs : (2 * n_freqs)] ** 2
      ) / 2
      resid = this_data - np.ascontiguousarray((model @ coefs).T)
      # can't use np.var(..., axis=1) with Numba, so do it manually:
      resid_mean = np.atleast_2d(resid.sum(axis=1) / resid.shape[1]).T
      squared_devs = np.abs(resid - resid_mean) ** 2
      resid_var = squared_devs.sum(axis=1) / squared_devs.shape[1]
      # output array will be (n_freqs, 3 * n_ch_types). The 3 columns for each
      # channel type are the SNR, the mean cHPI power and the residual variance
      # (which gets tiled to shape (n_freqs,) because it's a scalar).
      snrs = np.empty((n_freqs, 0))
      # average power & compute residual variance separately for each ch type
      for _picks in (mag_picks, grad_picks):
          if len(_picks):
              avg_power = hpi_power[:, _picks].sum(axis=1) / len(_picks)
              avg_resid = resid_var[_picks].mean() * np.ones(n_freqs)
              snr = 10 * np.log10(avg_power / avg_resid)
              snrs = np.hstack(
                  (snrs, np.stack((snr, avg_power, avg_resid), 1))
              )
      return snrs
  
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 22 for calling a global function with example usage: _fast_fit_snr(this_data, n_freqs, model, inv_model, mag_picks, grad_picks) and returns: snrs