twpasolver.twoport module#
Two-port network module.
This module provides classes and methods for representing and manipulating two-port RF networks. It includes functionality for handling frequency-dependent network parameters, converting between different representations (such as ABCD matrices and S-parameters), and performing common operations on two-port networks.
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:
objectClass 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:
- Returns:
Instance of TwoPortCell.
- Return type:
- classmethod from_z(freqs: ndarray, z_mat: ndarray, Z0: float | int = 50) TwoPortCell[source]#
Instantiate from array of Z-parameters.
- Parameters:
- Returns:
Instance of TwoPortCell.
- Return type:
- classmethod from_file(filename: str, writer='hdf5') TwoPortCell[source]#
Load model from file.
- Parameters:
- Returns:
Instance of TwoPortCell.
- Return type:
- property freqs: ndarray#
Get the frequencies array.
- Returns:
Frequencies array.
- Return type:
numpy.ndarray
- property Z0: complex | float#
Get the reference line impedance.
- Returns:
Reference line impedance.
- Return type:
Impedance
- to_network() Network[source]#
Convert to scikit-rf Network.
- Returns:
scikit-rf Network.
- Return type:
rf.Network
- property s: SMatrixArray#
Get the S-parameter matrix.
- Returns:
S-parameter matrix.
- Return type:
- property z: ZMatrixArray#
Get the Z-parameter matrix.
- Returns:
Z-parameter matrix.
- Return type:
- as_dict() dict[source]#
Return cell contents as dictionary.
- Returns:
Dictionary containing cell contents.
- Return type:
- interpolate(freqs: ndarray, polar: bool = True) TwoPortCell[source]#
Return abcd matrix of internal cell interpolating the given frequencies.
- Parameters:
freqs (numpy.ndarray) – Frequencies array to interpolate.
polar (bool) – Interpolate magnitude and phase instead of real and imaginary part.
- Returns:
Interpolated instance of TwoPortCell.
- Return type:
- pydantic model twpasolver.twoport.TwoPortModel[source]#
-
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 0x7f42bdabe5f0>)>, ‘__get_pydantic_json_schema__’: <classmethod(<function _Impedance2PydanticAnnotation.__get_pydantic_json_schema__ at 0x7f42bdabe680>)>, ‘__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 0x7f42bdabe4d0>
json_schema_input_type = PydanticUndefined
- field N: NonNegativeInt = 1#
Number of repetitions of the model in the computed abcd matrix.
- Constraints:
ge = 0
- update(**kwargs) None[source]#
Update multiple attributes of the model.
- Parameters:
**kwargs – Attributes to update.
- abstract single_abcd(freqs: ndarray) ABCDArray[source]#
Compute the abcd matrix of a single iteration of the model.
- Parameters:
freqs (numpy.ndarray) – Frequencies array.
- Returns:
ABCD matrix for a single iteration.
- Return type:
- get_abcd(freqs: ndarray) ABCDArray[source]#
Compute the abcd matrix of the model.
- Parameters:
freqs (numpy.ndarray) – Frequencies array.
- Returns:
Computed ABCD matrix of the model.
- Return type:
- get_cell(freqs: ndarray) TwoPortCell[source]#
Return the two-port cell of the model.
- Parameters:
freqs (numpy.ndarray) – Frequencies array.
- Returns:
Two-port cell of the model.
- Return type: