1 import empro, os
2 from empro.toolkit import Bunch
3 from empro.toolkit.results import UnavailableError, excitation_based
4
5 -class Sar(excitation_based.ExcitationBased):
10
12 try:
13 import empro
14 rawResult = empro.toolkit.dataset.getResult(sim=self._results._sim, run='Run0001', object=fromWhat, timeDependence='SteadyState', result=whatValue)
15 self._results._extractAvailableExcitationToRun(rawResult.query)
16 self._availableExcitationsToRun = self._results._availableExcitationsToRun
17
18 except KeyError:
19 raise UnavailableError("")
20
21 outputObj = rawResult.query.getOutputObject()
22
23 scalarValues = {}
24
25 for portName, runIndex in self._availableExcitationsToRun.iteritems():
26 rawResult = empro.toolkit.dataset.getResult(sim=self._results._sim, run=runIndex+1, object=fromWhat, timeDependence='SteadyState', result=whatValue)
27 dim0 = rawResult.dimension(0)
28
29 if not self._frequencies:
30 freqIndexRange = range(dim0.size())
31 else:
32 freqIndexRange = [x for x in range(dim0.size()) if dim0.at(x) in self._frequencies]
33
34 for freqIndex in freqIndexRange:
35 frequency = rawResult.dimension(0).at(freqIndex)
36 excitationScaling = abs(self._excitationWeights.weight(portName, frequency))
37 value = rawResult.at(freqIndex)*excitationScaling
38 existingValue = scalarValues.get(frequency, Bunch(frequency=frequency, value=0.0)).value
39 scalarValues[frequency] = Bunch(frequency=frequency,value=max(value,existingValue))
40 return scalarValues
41
43 """
44 avg1gMax -> for each frequency of interest return the avg1gMax value under loaded conditions
45 """
46 if self._coherent:
47 return UnavailableError()
48 return self._scalarValue('SAR Averaging Sensor (1g Average)','MaxSar')
49
51 """
52 avg10gMax -> for each frequency of interest return the avg10gMax value under loaded conditions
53 """
54 if self._coherent:
55 return UnavailableError()
56 return self._scalarValue('SAR Averaging Sensor (10g Average)','MaxSar')
57
59 """
60 rawMax -> for each frequency of interest return the rawMax value under loaded conditions
61 """
62 if self._coherent:
63 return UnavailableError()
64 return self._scalarValue('SAR Sensor ( Raw )','MaxSar')
65
67 """
68 total1gMax -> takes the total of all 1g computations and sums them
69 """
70 if self._coherent:
71 return UnavailableError()
72 values = self.avg1gMax()
73 total = 0.0
74 for freq, val in values.iteritems():
75 total = total + val.value
76
77 return total
78
80 """
81 total10gMax -> takes the total of all 10g computations and sums them
82 """
83 if self._coherent:
84 return UnavailableError()
85
86 values = self.avg10gMax()
87 total = 0.0
88 for freq, val in values.iteritems():
89 total = total + val.value
90
91 return total
92
94 """
95 totalRawMax -> takes the total of all raw computations and sums them
96 """
97 if self._coherent:
98 return UnavailableError()
99
100 values = self.rawMax()
101 total = 0.0
102 for freq, val in values.iteritems():
103 total = total + val.value
104
105 return total
106
107
108 """
109 # example usage
110
111 sar1 = results.Sar(excitation = {'source1' : 1.0, 'source2' : (3.0, 1.0)}, freqs=[1.0, 3.0])
112 sar2 = results.Sar(excitation = {'source1' : 2.0, 'source2' : (1.0, 5.0)}, freqs=[1.0, 3.0])
113
114 sar1 += sar2
115
116 print sar1.total10gMax()
117 """
118