code: def _setup_hpi_amplitude_fitting(
      info,
      t_window,
      remove_aliased=False,
      ext_order=1,
      allow_empty=False,
      verbose=None,
  ):
      """Generate HPI structure for HPI localization."""
      # grab basic info.
      on_missing = "raise" if not allow_empty else "ignore"
      hpi_freqs, hpi_pick, hpi_ons = get_chpi_info(
          info, on_missing=on_missing
      )
  
      # check for maxwell filtering
      for ent in info["proc_history"]:
          for key in ("sss_info", "max_st"):
              if len(ent["max_info"]["sss_info"]) > 0:
                  warn(
                      "Fitting cHPI amplitudes after Maxwell filtering may not work, "
                      "consider fitting on the original data."
                  )
                  break
  
      _validate_type(t_window, (str, "numeric"), "t_window")
      if info["line_freq"] is not None:
          line_freqs = np.arange(
              info["line_freq"], info["sfreq"] / 3.0, info["line_freq"]
          )
      else:
          line_freqs = np.zeros([0])
      logger.info(
          "Line interference frequencies: {} Hz".format(
              " ".join([f"{lf}" for lf in line_freqs])
          )
      )
      # worry about resampled/filtered data.
      # What to do e.g. if Raw has been resampled and some of our
      # HPI freqs would now be aliased
      highest = info.get("lowpass")
      highest = info["sfreq"] / 2.0 if highest is None else highest
      keepers = hpi_freqs <= highest
      if remove_aliased:
          hpi_freqs = hpi_freqs[keepers]
          hpi_ons = hpi_ons[keepers]
      elif not keepers.all():
          raise RuntimeError(
              f"Found HPI frequencies {hpi_freqs[~keepers].tolist()} above the lowpass ("
              f"or Nyquist) frequency {highest:0.1f}"
          )
      # calculate optimal window length.
      if isinstance(t_window, str):
          _check_option(
              "t_window", t_window, ("auto",), extra="if a string"
          )
          if len(hpi_freqs):
              all_freqs = np.concatenate((hpi_freqs, line_freqs))
              delta_freqs = np.diff(np.unique(all_freqs))
              t_window = max(
                  5.0 / all_freqs.min(), 1.0 / delta_freqs.min()
              )
          else:
              t_window = 0.2
      t_window = float(t_window)
      if t_window <= 0:
          raise ValueError(f"t_window ({t_window}) must be > 0")
      logger.info(f"Using time window: {1000 * t_window:0.1f} ms")
      window_nsamp = np.rint(t_window * info["sfreq"]).astype(int)
      model = _setup_hpi_glm(
          hpi_freqs, line_freqs, info["sfreq"], window_nsamp
      )
      inv_model = np.linalg.pinv(model)
      inv_model_reord = _reorder_inv_model(inv_model, len(hpi_freqs))
      proj, proj_op, meg_picks = _setup_ext_proj(info, ext_order)
      # include mag and grad picks separately, for SNR computations
      mag_subpicks = _picks_to_idx(info, "mag", allow_empty=True)
      mag_subpicks = np.searchsorted(meg_picks, mag_subpicks)
      grad_subpicks = _picks_to_idx(info, "grad", allow_empty=True)
      grad_subpicks = np.searchsorted(meg_picks, grad_subpicks)
      # Set up magnetic dipole fits
      hpi = dict(
          meg_picks=meg_picks,
          mag_subpicks=mag_subpicks,
          grad_subpicks=grad_subpicks,
          hpi_pick=hpi_pick,
          model=model,
          inv_model=inv_model,
          t_window=t_window,
          inv_model_reord=inv_model_reord,
          on=hpi_ons,
          n_window=window_nsamp,
          proj=proj,
          proj_op=proj_op,
          freqs=hpi_freqs,
          line_freqs=line_freqs,
      )
      return hpi
  
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 15 for calling a global function with example usage: _setup_hpi_amplitude_fitting(info, t_window, remove_aliased, ext_order, allow_empty, verbose) and returns: hpi