twpasolver.twoport module#

Two-port RF networks: frequency-dependent ABCD matrices, conversion to S/Z parameters, interpolation and file I/O.

Examples

Create a TwoPortCell from ABCD parameters:

freqs = np.array([1e9, 2e9, 3e9])
abcd = np.array([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]],
    [[9, 10], [11, 12]]
])
cell = TwoPortCell(freqs, abcd)

Convert to S-parameters:

s_params = cell.s

Interpolate to new frequencies:

new_freqs = np.array([1.5e9, 2.5e9])
interpolated_cell = cell.interpolate(new_freqs)

Save and load from file:

cell.dump_to_file('cell_data.hdf5')
loaded_cell = TwoPortCell.from_file('cell_data.hdf5')
class twpasolver.twoport.TwoPortCell(freqs: ndarray, abcd: ndarray | ABCDArray, Z0: complex | float = 50)[source]#

Bases: object

Class representing a two-port RF cell.

classmethod from_s(freqs: ndarray, s_mat: ndarray, Z0: float | int = 50) → TwoPortCell[source]#

Instantiate from array of S-parameters.

Parameters:
  • freqs (numpy.ndarray) – Frequencies in Hz, shape (N,).

  • s_mat (numpy.ndarray) – S-parameter matrices, shape (N, 2, 2).

  • Z0 (float | int) – Reference line impedance.

classmethod from_file(filename: str, writer='hdf5') → TwoPortCell[source]#

Load cell from file written by dump_to_file() (writer is the file format).

property freqs: ndarray#

Frequencies in Hz.

property Z0: complex | float#

Reference line impedance.

to_network() → Network[source]#

Convert to scikit-rf Network.

property s: SMatrixArray#

S-parameter matrices (pseudo-waves, referenced to Z0).

property z: ZMatrixArray#

Z-parameter matrices.

as_dict() → dict[source]#

Return cell contents as dictionary with keys freqs, abcd, Z0.

dump_to_file(filename: str, writer='hdf5') → None[source]#

Dump cell to file (writer is the file format; complex matrices need "hdf5").

interpolate(freqs: ndarray, polar: bool = False) → TwoPortCell[source]#

Return a cell with ABCD matrices linearly interpolated at the given frequencies.

Parameters:
  • freqs (numpy.ndarray) – Frequencies in Hz.

  • polar (bool) – Interpolate magnitude and unwrapped phase instead of real and imaginary part.

pydantic model twpasolver.twoport.TwoPortModel[source]#

Bases: BaseModel, ABC

Base class for models of two-port networks.

Show JSON schema
{
   "title": "TwoPortModel",
   "description": "Base class for models of two-port networks.",
   "type": "object",
   "properties": {
      "Z0_ref": {
         "default": 50.0,
         "description": "Reference line impedance of the two-port component.",
         "title": "Z0 Ref",
         "type": "number"
      },
      "N": {
         "default": 1,
         "description": "Number of repetitions of the model in the computed abcd matrix.",
         "minimum": 0,
         "title": "N",
         "type": "integer"
      }
   }
}

Fields:
field Z0_ref: Impedance = 50.0#

Reference line impedance of the two-port component.

Constraints:
  • __module__ = twpasolver.bonus_types

  • __get_pydantic_core_schema__ = <bound method _Impedance2PydanticAnnotation.__get_pydantic_core_schema__ of <class ‘twpasolver.bonus_types._Impedance2PydanticAnnotation’>>

  • __get_pydantic_json_schema__ = <bound method _Impedance2PydanticAnnotation.__get_pydantic_json_schema__ of <class ‘twpasolver.bonus_types._Impedance2PydanticAnnotation’>>

  • __dict__ = {‘__module__’: ‘twpasolver.bonus_types’, ‘__get_pydantic_core_schema__’: <classmethod(<function _Impedance2PydanticAnnotation.__get_pydantic_core_schema__ at 0x7f3d60b565c0>)>, ‘__get_pydantic_json_schema__’: <classmethod(<function _Impedance2PydanticAnnotation.__get_pydantic_json_schema__ at 0x7f3d60b56660>)>, ‘__dict__’: <attribute ‘__dict__’ of ‘_Impedance2PydanticAnnotation’ objects>, ‘__weakref__’: <attribute ‘__weakref__’ of ‘_Impedance2PydanticAnnotation’ objects>, ‘__doc__’: None}

  • __weakref__ = <attribute ‘__weakref__’ of ‘_Impedance2PydanticAnnotation’ objects>

  • func = <function validate_impedance at 0x7f3d61bee160>

  • json_schema_input_type = PydanticUndefined

field N: NonNegativeInt = 1#

Number of repetitions of the model in the computed abcd matrix.

Constraints:
  • ge = 0

registry: ClassVar[dict[str, type[TwoPortModel]]] = {'Capacitance': <class 'twpasolver.models.oneport.Capacitance'>, 'Inductance': <class 'twpasolver.models.oneport.Inductance'>, 'LCLfBaseCell': <class 'twpasolver.models.twpa_cells.LCLfBaseCell'>, 'LosslessTL': <class 'twpasolver.models.transmission_lines.LosslessTL'>, 'OnePortArray': <class 'twpasolver.models.oneport.OnePortArray'>, 'Resistance': <class 'twpasolver.models.oneport.Resistance'>, 'Stub': <class 'twpasolver.models.oneport.Stub'>, 'StubBaseCell': <class 'twpasolver.models.twpa_cells.StubBaseCell'>, 'TWPA': <class 'twpasolver.models.twoportarrays.TWPA'>, 'TwoPortArray': <class 'twpasolver.models.twoportarrays.TwoPortArray'>}#
static validate_cell(cell: Any, base: type) → TwoPortModel[source]#

A copy of cell (a model instance, or a dict with a registered name), checked to be a base.

update(**kwargs) → None[source]#

Update multiple attributes of the model; unknown names raise RuntimeError.

abstract single_abcd(freqs: ndarray) → ABCDArray[source]#

Compute the ABCD matrix of a single iteration of the model.

Parameters:

freqs (numpy.ndarray) – Frequencies in Hz.

get_abcd(freqs: ndarray) → ABCDArray[source]#

Compute the ABCD matrix of the model repeated N times; freqs in Hz.

get_cell(freqs: ndarray) → TwoPortCell[source]#

Return the two-port cell of the model; freqs in Hz.

get_network(freqs: ndarray) → Network[source]#

Return the two-port cell of the model as a scikit-rf Network; freqs in Hz.