Comments for z0 setter/getter
@@ -765,8 +765,10 @@ class Network(object):
else:
name = self.name
- if self.z0.ndim < 2:
- z0 = self.z0
+ _z0 = self.z0
+
+ if _z0.ndim < 2:
+ z0 = _z0
else:
z0 = self.z0[0, :]
@@ -1110,38 +1112,50 @@ class Network(object):
characteristic impedance for network
"""
+ # if we are unable to determine the s-matrix shape we return an scalar
if not hasattr(self, '_s'):
return self._z0
+ # _z0 is an scalar, so a npy.array with shape fxn is filled with _z0
if self._z0.ndim == 0:
return npy.full(self._s.shape[:2], self._z0)
elif self._z0.ndim == 1:
- z0 = npy.ones(self._s.shape[:2], dtype=complex)
+ # _z0 is a vector, either of length nports or frequency.npoints.
+ # Create a npy.array with shape fxn and broadcast vector to array.
+ z0 = npy.zeros(self._s.shape[:2], dtype=complex)
if len(self._z0) == self.nports:
z0[:] = self._z0[None, :]
- #elif len(self._z0) == self.frequency.npoints:
else:
z0[:] = self._z0[:,None]
return z0
elif self._z0.ndim == 2:
+ # _z0 is a matrix of correct shape, so we can return directly
return self._z0
@z0.setter
def z0(self, z0):
- if isinstance(z0, Number):
- self._z0 = npy.array(z0, dtype=complex)
- return
-
- z0 = npy.array(z0, dtype=complex)
+ # cast any array like type (tuple, list) to a npy.array
+ z0 = npy.squeeze(npy.array(z0, dtype=complex))
+ # assign _z0 directly if z0 is a scalar
if z0.ndim == 0:
self._z0 = z0
return
+
+ # if _z0 is a vector or matrix, we check if _s is already assigned.
+ # If not, we cannot proof the correct dimensions and silently accept
+ # any vector or fxn array
if not hasattr(self, '_s'):
if 1 <= z0.ndim <= 2:
self._z0 = z0
return
+ # if _z0 is a vector, we check if the dimension matches with either
+ # nports or frequency.npoints. If yes, we accept the value.
+ # Note that there can be an ambiguity in theory, if nports == npoints
+ #
+ # if _z0 is a matrix, we check if the shape matches with _s
+ # In any other case raise an Exception
if z0.ndim == 1:
if len(z0) in (self.frequency.npoints, self.nports):
self._z0 = z0
@@ -6297,3 +6311,4 @@ def s2vswr_active(s, a):
+
