The NetworkSet object represents an unordered set of networks. It provides methods for calculating statistical quantities and displaying uncertainty bounds on such a set.

Creating a NetworkSet

For this example, assume that numerous measurements of a single network are made. These measurements have been retrieved from a VNA and are in the form of touchstone files. A set of example data can be found in scikit-rf/skrf/data/, with naming convention ro,*.s1p,

In [4]: import skrf as rf

In [5]: ls $*

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. This can be done quickly with 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 [6]: rf.read_all(, contains='ro')
{'ro,1': 1-Port Network: 'ro,1',  500-750 GHz, 201 pts, z0=[ 50.+0.j],
 'ro,2': 1-Port Network: 'ro,2',  500-750 GHz, 201 pts, z0=[ 50.+0.j],
 'ro,3': 1-Port Network: 'ro,3',  500-750 GHz, 201 pts, z0=[ 50.+0.j]}

This can be passed directly to the NetworkSet constructor,

In [7]: ro_dict = rf.read_all(, contains='ro')

In [8]: ro_ns = rf.NetworkSet(ro_dict, name='ro set') #name is optional

In [9]: ro_ns
 Out[9]: A NetworkSet of length 3

A NetworkSet can also be constructed from 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 [10]: ro_ns[0]
Out[10]: 1-Port Network: 'ro,1',  500-750 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, (see Plotting for details on Network ploting methods).

In [11]: rf.stylely()
In [12]: ro_ns.plot_s_db(label='Mean Response')
Out[12]: [None, None, None]

Statistical Properties

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

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


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 [14]: figure();

In [15]: ro_ns.mean_s.plot_s_db(label='ro')

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

In [16]: figure();

In [17]: 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,

In [18]: figure();

In [19]: ro_ns.mean_s_deg.plot_s_re()

Plotting Uncertainty Bounds

Uncertainty bounds can be plotted through the methods

In [20]: figure();

In [21]: ro_ns.plot_uncertainty_bounds_s_db()

In [22]: figure();

In [23]: ro_ns.plot_uncertainty_bounds_s_deg()
../_images/ns_plot_uncertainty_bounds_s_db.png ../_images/ns_plot_uncertainty_bounds_s_deg.png


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

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

In [24]: rf.write('ro set.ns', ro_ns)

In [25]: ro_ns ='ro set.ns')