Scikit-RF
Scikit-RF is an object-oriented Python library for microwave engineering. It provides tools for network analysis, circuit simulation, calibration, and visualization of S-parameters and other RF components. The current version is 1.11.0, and it maintains an active, though not strictly time-bound, release cadence.
Common errors
-
AttributeError: module 'skrf' has no attribute 'Network'
cause Attempting to access `Network` directly as `skrf.Network` after using `from skrf import Network` or similar, or vice-versa, or due to a partial/incorrect import.fixThe canonical way to use `Network` is `import skrf as rf; ntwk = rf.Network(...)`. Ensure you are consistently using `rf.Network` after `import skrf as rf` or `from skrf import Network` if you prefer direct import. -
ValueError: Frequency unit must be one of ['hz', 'khz', 'mhz', 'ghz', 'thz']
cause An invalid string was provided for the `unit` argument when creating a `Frequency` object.fixCorrect the `unit` string to one of the accepted values: 'hz', 'khz', 'mhz', 'ghz', or 'thz'. For example: `rf.Frequency(1, 10, 101, 'ghz')`. -
FileNotFoundError: [Errno 2] No such file or directory: 'my_file.s2p'
cause The specified Touchstone file path is incorrect, or the file does not exist at the given location.fixDouble-check the file path. Ensure the file exists, the path is absolute or correct relative to your script's execution directory, and that you have read permissions. Use `os.path.exists()` for debugging. -
IndexError: index 0 is out of bounds for axis 1 with size 0
cause This often occurs when trying to access elements of an S-parameter matrix (e.g., `ntwk.s[:,0,0]`) on a `Network` object that hasn't been properly initialized with S-parameter data or has zero ports/frequencies.fixEnsure the `Network` object has valid S-parameter data and dimensions. If creating from scratch, provide `s` (S-parameters array) and `frequency` to the `Network` constructor. If loading, verify the source file's integrity.
Warnings
- gotcha Scikit-RF handles frequency units internally, but users often confuse input units (Hz, kHz, MHz, GHz) leading to incorrect calculations or plots. Always be explicit.
- breaking Prior to version 0.16, the `skrf.network.Network` class and other components had different constructors or attribute names. Code written for older versions might fail due to these changes.
- gotcha When loading Touchstone files, scikit-rf automatically determines the number of ports. If the file is malformed or unusual, this can lead to incorrect network dimensions or parsing errors.
- gotcha Default plotting styles might not always be ideal for publication or specific analysis. Matplotlib's default may hide details or look unpolished.
Install
-
pip install scikit-rf
Imports
- Network
from scikit_rf import Network
import skrf as rf ntwk = rf.Network(...)
- Frequency
from skrf.frequency import Frequency
import skrf as rf freq = rf.Frequency(...)
- Circuit
from skrf.circuit import Circuit
import skrf as rf cir = rf.Circuit(...)
Quickstart
import skrf as rf
import matplotlib.pyplot as plt
# Create a dummy 2-port network for demonstration
f = rf.Frequency(1, 10, 101, 'ghz') # 1-10 GHz, 101 points
s = rf.Touchstone(f, name='my_network')
# Populate with some dummy S-parameters (e.g., ideal thru) for 2-port
s.s[:,0,0] = 0 # S11
s.s[:,1,1] = 0 # S22
s.s[:,0,1] = 1 # S12
s.s[:,1,0] = 1 # S21
# Create a Network object from the Touchstone data
ntwk = rf.Network(s=s.s, frequency=f, name='Dummy Thru')
# Plot S21 magnitude in dB
ntwk.plot_s_db(m=1, n=0)
plt.title(f'{ntwk.name} S21 Magnitude')
plt.xlabel('Frequency (GHz)')
plt.ylabel('S21 Magnitude (dB)')
# plt.show() # Uncomment to display plot
print(f"Network name: {ntwk.name}")
print(f"Network frequency range: {ntwk.frequency.f_ghz[0]:.2f} GHz to {ntwk.frequency.f_ghz[-1]:.2f} GHz")