Package empro :: Package toolkit :: Package results :: Module network
[frames] | no frames]

Source Code for Module empro.toolkit.results.network

 1  from empro.toolkit import Bunch 
 2  from empro.toolkit.results import UnavailableError, excitation_based 
 3   
 4  INTERPOLATION_UNDEFINED, INTERPOLATION_NONE, INTERPOLATION_CLOSEST_VALUE = 0,1,2 
 5   
6 -class Network(object):
7 - def __init__(self, results):
8 import empro.toolkit 9 self._results = results 10 self._zRefs = None 11 self._circuitMatrix = empro.toolkit._getCircuitMatrix(sim=self._results._sim) 12 self._availableExcitations = self._results.availableExcitations()
13
14 - def availableFrequencies(self):
15 # availableFrequencies -> list of available frequencies 16 return self._circuitMatrix.frequencies().data
17
18 - def S(self,frequency,interpolation=INTERPOLATION_CLOSEST_VALUE):
19 # S(frequency, interpolation) -> returns the S matrix 20 if interpolation==INTERPOLATION_CLOSEST_VALUE: 21 index, freq = min(enumerate(self.availableFrequencies()),key=lambda x:abs(x[1]-frequency)) 22 elif interpolation==INTERPOLATION_NONE: 23 freq = frequency 24 else: 25 raise RuntimeError("Unsupported interpolation scheme") 26 return self._circuitMatrix.Smatrix(freq)
27
28 - def Z(self,frequency,interpolation=INTERPOLATION_CLOSEST_VALUE):
29 # Z(frequency, interpolation) -> returns the Z matrix 30 s = self._S(frequency, interpolation) 31 return s.stoz()
32
33 - def Y(self,frequency,interpolation=INTERPOLATION_CLOSEST_VALUE):
34 # Y(frequency, interpolation) -> returns the Y matrix 35 s = self._S(frequency, interpolation) 36 return s.stoy()
37
38 - def Zref(self):
39 # Zref -> the reference impedances 40 return [self._circuitMatrix.Zref(i) for i in range(self._circuitMatrix.size())]
41
42 - def activeSparam(self, frequency, excitation, interpolation=INTERPOLATION_CLOSEST_VALUE):
43 """ 44 activeSparam(frequency, excitation) 45 @type frequency: double 46 @param frequency: frequency of interest 47 @type excitation: map from string to to voltage or current excitation 48 @param excitation: a map from port name to voltage or current excitation (example: {"p1": excitation.VoltageSource(V=1,load=excitation.ParallelRLC(50))} 49 @rtype: list of complex numbers 50 @return: list of active S params for each port under given excitation 51 """ 52 s = self.S(frequency, interpolation) 53 activeS = [] 54 excitationBase = self._results.excitationBased( excitation = excitation, frequencies = frequency ) 55 excitationWeights = excitationBase.weights(frequency) 56 voltage = [] 57 voltageId = 0 58 for i in range(len(self._availableExcitations)): 59 portName = self._availableExcitations[i] 60 if portName in excitationWeights: 61 value = excitationWeights[portName] 62 voltage.append(value) 63 else: 64 raise RuntimeError("The port %s does not excist in the excitation map"%(portName)) 65 for i in range(s.size()): 66 thisS = 0.0 67 for j in range(s.size()): 68 thisS += s(i,j)*voltage[ j ] 69 if ( voltage[i] != 0 ): 70 activeS.append( thisS/voltage[ i ] ) 71 else: 72 raise RuntimeError("The voltage of the port is equal to zero!") 73 return activeS
74