This notebook demonstrates the new design of skrf's Network Class. The new class utilizes a more object-oriented approach which is cleaner and more scalable. The draw-back is that it breaks backward compatibility.
Creating a new style Network from an old
In [ ]:
import skrf as rf
%matplotlib inline
from pylab import *
rf.stylely()
from skrf import network2
a = network2.Network.from_ntwkv1(rf.data.ring_slot)
The new Network class employs nested objects, which makes for a cleaner and more logical namespace. The basic structure is:
Accessing a Network's parameters like s
,z
,or y
returns a Parameters object,
In [ ]:
type(a.s)
You can get at the array by accessing the property val
.
In [ ]:
a.s.val[:3]
You can also slice the parameter directly. This can be used as an alternative way to access the values.
In [ ]:
a.s[:2]
This nested-object desgin allows for more concise function calls. For example, plot functions become members of the parameters, which behave like you expect
In [ ]:
a.s.plot()
In [ ]:
a.z.plot()
axis('equal')
Each parameter has members for various scalar projections.
In [ ]:
type(a.s.db)
In [ ]:
type(a.s.deg)
Their numerical values may be accessed through val
attribute or by direct slicing, just like a Parameter
In [ ]:
a.s.db[:2]
Projections also plot()
as you expect
In [ ]:
a.s.db.plot();
In [ ]:
a.s.deg.plot(1,0);
One interesting advantage of using an object-oriented model for parameters and projections is that we can create custom display logic for the ipython notebook. This allows us to define graphical representations for an object, removing the need to call any plot method.
In [ ]:
a.s.db
In [ ]:
a.z.im
Numpy ndarray properties are accessable on both Parameters and Projections . These are implemented using python __getattr__()
operator so they wont tab out, but you can still use em.
In [ ]:
a.s.db.plot()
axhline(a.s.db.min(),color='k')
axhline(a.s.db.max(),color='k')
Networks can sliced by an index on the frequency axis or by a human readable frequency selections,
In [ ]:
a[40:100] #slice by frequency index
In [ ]:
a['82-92ghz'] # slice by a human readable string
In [ ]:
a['82-92ghz'].s.db
Individual s-parameters can be accessed by calling a Network with the desired port indecies (index starting from 0)
In [ ]:
s11 = a(0,0) # s11
s22 = a(1,1) # s22
s12 = a(0,1) # s12
s21 = a(1,1) # s21
s11
Time domain transform is implemented as a Parameter named s_time
. Note that accessing this parameter implicitly windows the s-parameters before taking the FFT. For finer control over the transform, use the functions s2time
and windowed
.
In [ ]:
b = network2.Network.from_ntwkv1(rf.data.ring_slot_meas)
b.s_time.db