Download This Notebook: Introduction.ipynb

Introduction

This is a brief introduction to scikit-rf (aka skrf). The intended audience are those who have a working python stack, and are somewhat familiar with python. If you are completely new to python, see scipy’s Getting Started. First, import the scikit-rf module skrf, as rf

In [1]:
import skrf as rf

If this produces an error, please see the installation tutorial.

Networks

The central object in skrf is a N-port microwave Network object. A Network can be created in a number of ways, one way is from data stored in a touchstone file.

In [2]:
ring_slot = rf.Network('data/ring slot.s2p')

If you cant find ring slot.s2p, then just import it from the skrf.data module.

In [3]:
from skrf.data import ring_slot

A short description of the network will be printed out if entered onto the command line

In [4]:
ring_slot
Out[4]:
2-Port Network: 'ring slot',  75.0-110.0 GHz, 201 pts, z0=[ 50.+0.j  50.+0.j]

The basic attributes of a microwave Network are provided by the following properties,

  • Network.s : Scattering Parameter matrix.
  • Network.z0 : Port Impedance matrix.
  • Network.frequency : Frequency Object.

The Network object has numerous other properties and methods which can found in it’s docstring. If you are using IPython/Jupyter, then these properties and methods can be ‘tabbed’ out on the command line.

In [1]: ring_slot.s<TAB>
ring_slot.s              ring_slot.s_arcl         ring_slot.s_im
ring_slot.s11            ring_slot.s_arcl_unwrap  ring_slot.s_mag
...

Linear Operations

Element-wise mathematical operations on the s-parameters are accessible through overloaded operators. To illustrate, we load a couple Networks stored in the skrf.data module.

In [5]:
short = rf.data.wr2p2_short
delayshort = rf.data.wr2p2_delayshort

The complex difference between their s-parameters is computed with

In [6]:
short - delayshort
Out[6]:
1-Port Network: 'wr2p2,short',  330.0-500.0 GHz, 201 pts, z0=[ 50.+0.j]

This returns a new Network. Other arrimetic operators are overloaded as well,

In [7]:
short/delayshort
Out[7]:
1-Port Network: 'wr2p2,short',  330.0-500.0 GHz, 201 pts, z0=[ 50.+0.j]

Cascading and De-embedding

Cascading and de-embeding 2-port Networks can also be done though operators. Cascading is done through the power operator, **.

In [8]:
short = rf.data.wr2p2_short
line = rf.data.wr2p2_line

delayshort = line ** short

De-embedding can be accomplished by cascading the inverse of a network. The inverse of a network is accessed through the property Network.inv.

In [9]:
short = line.inv ** delayshort

For more information on the functionality provided by the Network object, such as interpolation, stitching, n-port connections, and IO support see the Networks tutorial.

Plotting

skrf has a function which updates your matplotlib rcParams so that plots appear like the ones shown in these tutorials.

In [10]:
# display plots in notebook
%matplotlib inline
from pylab import *
rf.stylely()

The methods of the Network class provide convenient ways to plot components of the network parameters,

  • Network.plot_s_db() : plot magnitude of s-parameters in log scale
  • Network.plot_s_deg() : plot phase of s-parameters in degrees
  • Network.plot_s_smith() : plot complex s-parameters on Smith Chart

To plot all four s-parameters of the ring_slot in Mag, Phase, and on the Smith Chart.

In [11]:
ring_slot.plot_s_db()
../_images/tutorials_Introduction_33_0.png

Or plot the phase of \(S_{12}\)

In [12]:
ring_slot.plot_s_deg(m=0,n=1)
../_images/tutorials_Introduction_35_0.png
In [13]:
ring_slot.plot_s_smith(lw=2)
title('Big ole Smith Chart')
Out[13]:
<matplotlib.text.Text at 0x7f5bde3d2d68>
../_images/tutorials_Introduction_36_1.png

For more detailed information about plotting see the Plotting tutorial

NetworkSet

The NeworkSet object represents an unordered set of networks and provides methods for calculating statistical quantities and displaying uncertainty bounds.

A NeworkSet is created from a list or dict of Networks’s. This can be done quickly with rf.read_all() , which loads all skrf-readable objects in a directory. The argument contains is used to load only files which match a given substring.

In [14]:
rf.read_all('data/', contains='ro')
Out[14]:
{'ro,1': 1-Port Network: 'ro,1',  500.0-750.0 GHz, 201 pts, z0=[ 50.+0.j],
 'ro,2': 1-Port Network: 'ro,2',  500.0-750.0 GHz, 201 pts, z0=[ 50.+0.j],
 'ro,3': 1-Port Network: 'ro,3',  500.0-750.0 GHz, 201 pts, z0=[ 50.+0.j]}

This dictionary can be passed directly to the NeworkSet constructor,

In [15]:
from skrf import NetworkSet

ro_dict = rf.read_all('data/', contains='ro')
ro_ns = NetworkSet(ro_dict, name='ro set') # name is optional
ro_ns
Out[15]:
A NetworkSet of length 3

NeworkSet’s are list-like.

Statistical Properties

Statistical quantities can be calculated by accessing properties of the NeworkSet. For example, to calculate the complex average of the set, access the mean_s property

In [16]:
ro_ns.mean_s
Out[16]:
1-Port Network: 'ro set',  500.0-750.0 GHz, 201 pts, z0=[ 50.+0.j]

The returned results are stored in a Networks s-parameters, regardless of the type of the output. Similarly, to calculate the complex standard deviation of the set,

In [17]:
ro_ns.std_s
Out[17]:
1-Port Network: 'ro set',  500.0-750.0 GHz, 201 pts, z0=[ 50.+0.j]

Because these methods return a Network object the results can be saved or plotted in the same way as you would with a Network. To plot the magnitude of the standard deviation of the set,

In [18]:
ro_ns.std_s.plot_s_mag(label='S11')
ylabel('Standard Deviation')
title('Standard Deviation of RO');
../_images/tutorials_Introduction_51_0.png

Plotting Uncertainty Bounds

Uncertainty bounds on any network parameter can be plotted through the methods

In [19]:
ro_ns.plot_uncertainty_bounds_s_db(label='S11');
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/matplotlib/axes/_axes.py:4842: ComplexWarning: Casting complex values to real discards the imaginary part
  X[0] = start
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/matplotlib/axes/_axes.py:4843: ComplexWarning: Casting complex values to real discards the imaginary part
  X[N + 1] = end
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/matplotlib/axes/_axes.py:4846: ComplexWarning: Casting complex values to real discards the imaginary part
  X[1:N + 1, 1] = y1slice
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/matplotlib/axes/_axes.py:4848: ComplexWarning: Casting complex values to real discards the imaginary part
  X[N + 2:, 1] = y2slice[::-1]
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/numpy/core/numeric.py:531: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)
../_images/tutorials_Introduction_54_1.png

See the networkset tutorial for more information.

Virtual Instruments

Warning

To use the virtual instrument classes you must have some other modules installed, like PyVISA or python-ivi or both. See the [Virtual Instruments](virtualinstruments) tutorial for more information.

The skrf.vi module holds classes for GPIB/VISA instruments that are intricately related to skrf, mostly VNA’s. The VNA classes were created for the sole purpose of retrieving data so that calibration and analysis could be done offline by skrf, so most other VNA capabilities is neglected.

A list of VNA’s that are partially supported.

An example of using the PNA class to retrieve some s-parameter data

from skrf.vi import vna
my_vna = vna.PNA(address=16)

#if an error is thrown at this point there is most likely a problem with your visa setup

dut_1 = my_vna.s11
dut_2 = my_vna.s21
dut_3 = my_vna.two_port

See the Virtual Instruments tutorial for more information.

Calibration

Calibrations are performed through a Calibration class. In most cases, creating a Calibration object requires at least two pieces of information:

The Network elements in each list must all be similar (same #ports, frequency info, etc) and must be aligned to each other, meaning the first element of ideals list must correspond to the first element of measured list.

Below is an example script illustrating how to create a Calibration .

One Port Calibration

import skrf as rf
from skf.calibration import OnePort

my_ideals = rf.read_all('ideals/')
my_measured = rf.read_all('measured/')
duts = rf.read_all('measured/')

## create a Calibration instance
cal = rf.OnePort(
    ideals = [my_ideals[k] for k in ['short','open','load']],
    measured = [my_measured[k] for k in ['short','open','load']],
    )

caled_duts = [cal.apply_cal(dut) for dut in duts.values()]

See the Calibration tutorial for more details and examples.

Transmission Line Media

Simple transmission-line based networks can be created through methods of the Media class, which represents a transmission line object for a given medium. Once constructed, a Media object contains the neccesary properties such as propagation constant and characteristic impedance, that are needed to generate microwave circuits.

The basic usage looks something like this,

CPW

In [20]:
from skrf import Frequency
from skrf.media import CPW, Coaxial

freq = Frequency(75,110,101,'ghz')
cpw =  CPW(freq, w=10e-6, s=5e-6, ep_r=10.6)
cpw
Out[20]:
Coplanar Waveguide Media.  75-110 GHz.  101 points
 W= 1.00e-05m, S= 5.00e-06m
In [21]:
cpw.line(d=90,unit='deg', name='line')
Out[21]:
2-Port Network: 'line',  75.0-110.0 GHz, 101 pts, z0=[ 50.06074662+0.j  50.06074662+0.j]

Coax

In [22]:
freq = Frequency(1,10,101,'ghz')
coax = Coaxial(frequency=freq, Dint=1e-3, Dout=2e-3)
coax
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/scikit_rf-0.14.5-py3.5.egg/skrf/media/coaxial.py:154: ComplexWarning: Casting complex values to real discards the imaginary part
  '\nCharacteristic Impedance=%.1f-%.1f Ohm'%(self.Z0[0],self.Z0[-1]) +\
/home/docs/checkouts/readthedocs.org/user_builds/scikit-rf/conda/latest/lib/python3.5/site-packages/scikit_rf-0.14.5-py3.5.egg/skrf/media/coaxial.py:155: ComplexWarning: Casting complex values to real discards the imaginary part
  '\nPort impedance Z0=%.1f-%.1f Ohm'%(self.z0[0],self.z0[-1])
Out[22]:
Coaxial Transmission Line.  1-10 GHz.  101 points
Dint= 1.00 mm, Dout= 2.00 mm
Characteristic Impedance=41.6-41.6 Ohm
Port impedance Z0=41.6-41.6 Ohm
In [23]: