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.
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.
[1]:
import skrf as rf
rf.read_all(rf.data.pwd, contains='ro')
[1]:
{'ro,1': 1-Port Network: 'ro,1', 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],
'ro,2': 1-Port Network: 'ro,2', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j]}
This can be passed directly to the NetworkSet constructor,
[2]:
from skrf import NetworkSet
ro_dict = rf.read_all(rf.data.pwd, contains='ro')
ro_ns = NetworkSet(ro_dict, name='ro set')
ro_ns
[2]:
[1-Port Network: 'ro,1', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j], 1-Port Network: 'ro,3', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j], 1-Port Network: 'ro,2', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j]]
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().
Accessing Network Methods¶
The Network elements in a NetworkSet can be accessed like the elements of list,
[3]:
ro_ns[0]
[3]:
1-Port Network: 'ro,1', 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.
[4]:
%matplotlib inline
from pylab import *
import skrf as rf
rf.stylely()
ro_ns.plot_s_db()
[4]:
[None, None, None]
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
[5]:
ro_ns.mean_s
[5]:
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
[6]:
ro_ns.mean_s.plot_s_db(label='ro')
Or to plot the standard deviation of the complex s-parameters,
[7]:
ro_ns.std_s.plot_s_re(y_label='Standard Deviations')
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,
[8]:
ro_ns.mean_s_deg.plot_s_re()
Plotting Uncertainty Bounds¶
Uncertainty bounds can be plotted through the methods
[9]:
ro_ns.plot_uncertainty_bounds_s_db()
[10]:
ro_ns.plot_uncertainty_bounds_s_deg()
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 uncertainty in the magnitude component only.
Reading and Writing¶
To write all Networks of a NetworkSet out to individual touchstones,
[11]:
ro_ns.write_touchstone(dir='data/')
[11]:
[None, None, None]
For temporary data storage, NetworkSets can be saved and read from disk using the functions rf.read and rf.write
[12]:
rf.write('ro set.ns', ro_ns)
[13]:
ro_ns = rf.read('ro set.ns')
ro_ns
[13]:
[1-Port Network: 'ro,1', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j], 1-Port Network: 'ro,3', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j], 1-Port Network: 'ro,2', 500.0-750.0 GHz, 201 pts, z0=[50.+0.j]]
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]
[14]:
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
[ ]: