optimize_s21#
- simpleEMS.sim_tools.optimize_s21(freqs: ndarray[tuple[Any, ...], dtype[_ScalarT]], s21: ndarray[tuple[Any, ...], dtype[_ScalarT]], target_freq: float | None = None, freq_band: tuple[float, float] | None = None, mode: str = 'worst') floating#
Objective function for S21 (transmission) optimization. Higher S21 is better.
Computes a scalar cost from S21 data for use with
optimize_s_params. Sincescipy.optimize.minimizeminimizes its objective, the cost is the negated S21 in dB, so maximizing S21 corresponds to minimizing the cost. Iftarget_freqis given it takes precedence overfreq_band(andmodeis ignored).- Parameters:
freqs (NDArray) – Array of frequencies in Hz, matching
s21.s21 (NDArray) – Complex S21 parameter array across the frequency range.
target_freq (float, optional) – If given, evaluate S21 (in dB) at the frequency in
freqsclosest to this value, ignoringfreq_band/mode.freq_band (tuple of (float, float), optional) – Frequency band
(f_min, f_max)in Hz over which to evaluate S21 whentarget_freqis not given.mode (str, optional) –
Evaluation mode within the frequency band:
"mean": negative mean of S21 in dB across the band."worst": negative minimum of S21 in dB across the band (worst-case transmission).
Default is
"worst".
- Returns:
Scalar cost value (negated S21 in dB); lower means higher transmission.
- Return type:
float
- Raises:
ValueError – If
modeis not"mean"or"worst", or if neithertarget_freqnorfreq_bandis provided.