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. Since scipy.optimize.minimize minimizes its objective, the cost is the negated S21 in dB, so maximizing S21 corresponds to minimizing the cost. If target_freq is given it takes precedence over freq_band (and mode is 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 freqs closest to this value, ignoring freq_band/mode.

  • freq_band (tuple of (float, float), optional) – Frequency band (f_min, f_max) in Hz over which to evaluate S21 when target_freq is 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 mode is not "mean" or "worst", or if neither target_freq nor freq_band is provided.