Download This Notebook: NetworkSet.ipynb

NetworkSet

Introduction

The NetworkSet object represents an unordered set of networks. It provides methods iterating and slicing the set, sorting by datetime, calculating statistical quantities, and displaying uncertainty bounds on plots.

Creating a NetworkSet

Lets take a look in the data/ folder, there are some redundant measurements of a network called ro, which is a radiating open waveguide.

In [1]:
ls data/ro*
data/ro,1.s1p  data/ro,2.s1p  data/ro,3.s1p

The files ro,1.s1p , ro,2.s1p, … are redundant measurements on which we would like to calculate statistics using the NetworkSet class.

A NetworkSet is created from a list or dict of Network’s. So first we need to load all of the touchstone files into Networks. This can be done quickly with rf.read_all, The argument contains is used to load only files which match a given substring.

In [2]:
import skrf as rf

rf.read_all(rf.data.pwd, contains='ro')
Out[2]:
{'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 can be passed directly to the NetworkSet constructor,

In [3]:
from skrf import NetworkSet

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

A NetworkSet can also be constructed directly from a dir with NetworkSet.from_dir() or from a zipfile of touchstones through the class method NetworkSet.from_zip().

Accesing Network Methods

The Network elements in a NetworkSet can be accessed like the elements of list,

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

Most Network methods are also methods of NetworkSet. These methods are called on each Network element individually. For example to plot the log-magnitude of the s-parameters of each Network.

In [5]:
%matplotlib inline
from pylab import *
import skrf as rf
rf.stylely()

ro_ns.plot_s_db()
Out[5]:
[None, None, None]
../_images/tutorials_NetworkSet_12_1.png

Statistical Properties

Statistical quantities can be calculated by accessing properties of the NetworkSet. To calculate the complex average of the set, access the mean_s property

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

Note

Because the statistical operator methods are generated upon initialization their API is not explicitly documented in this manual.

The naming convention of the statistical operator properties are NetworkSet.{function}_{parameter}, where function is the name of the statistical function, and parameter is the Network parameter to operate on. These methods return a Network object, so they can be saved or plotted in the same way as you would with a Network. To plot the log-magnitude of the complex mean response

In [7]:
ro_ns.mean_s.plot_s_db(label='ro')
../_images/tutorials_NetworkSet_17_0.png

Or to plot the standard deviation of the complex s-parameters,

In [8]:
ro_ns.std_s.plot_s_re(y_label='Standard Deviations')
../_images/tutorials_NetworkSet_19_0.png

Using these properties it is possible to calculate statistical quantities on the scalar components of the complex network parameters. To calculate the mean of the phase component,

In [9]:
ro_ns.mean_s_deg.plot_s_re()
../_images/tutorials_NetworkSet_21_0.png

Plotting Uncertainty Bounds

Uncertainty bounds can be plotted through the methods

In [10]:
ro_ns.plot_uncertainty_bounds_s_db()
/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_NetworkSet_23_1.png
In [11]:
ro_ns.plot_uncertainty_bounds_s_deg()
/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_NetworkSet_24_1.png

Note

The uncertainty bounds plotted above are calculated after the complex number has been projected onto the specified scalar component. Thus, the first plot represents uncerainty in the magnitude component only.

Reading and Writing

To write all Networks of a NetworkSet out to individual touchstones,

In [12]:
ro_ns.write_touchstone(dir='data/')
Out[12]:
[None, None, None]

For temporary data storage, NetworkSets can be saved and read from disk using the functions rf.read and rf.write

In [13]:
rf.write('ro set.ns', ro_ns)
In [14]:
ro_ns = rf.read('ro set.ns')
ro_ns
Out[14]:
A NetworkSet of length 3

Export to Excel, csv, or html

NetworkSets can also be exported to other filetypes. The format of the output; real/imag, mag/phase is adjustable, as is the output type; csv, excel, html. For example to export mag/phase for each network into an Excel spreadsheet for your boss[s]

In [15]:
ro_ns.write_spreadsheet('data/ro_spreadsheet.xls', form='db')

More info on this can be found in the function, skrf.io.general.network_2_spreadsheet

In [16]: