@@ -1,505 +1,505 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
9 |
|
9 | |||
10 | class Header: |
|
10 | class Header: | |
11 |
|
11 | |||
12 | def __init__(self): |
|
12 | def __init__(self): | |
13 | raise |
|
13 | raise | |
14 |
|
14 | |||
15 | def copy(self): |
|
15 | def copy(self): | |
16 | return copy.deepcopy(self) |
|
16 | return copy.deepcopy(self) | |
17 |
|
17 | |||
18 | def read(): |
|
18 | def read(): | |
19 | pass |
|
19 | pass | |
20 |
|
20 | |||
21 | def write(): |
|
21 | def write(): | |
22 | pass |
|
22 | pass | |
23 |
|
23 | |||
24 | class BasicHeader(Header): |
|
24 | class BasicHeader(Header): | |
25 |
|
25 | |||
26 | size = None |
|
26 | size = None | |
27 | version = None |
|
27 | version = None | |
28 | dataBlock = None |
|
28 | dataBlock = None | |
29 | utc = None |
|
29 | utc = None | |
30 | miliSecond = None |
|
30 | miliSecond = None | |
31 | timeZone = None |
|
31 | timeZone = None | |
32 | dstFlag = None |
|
32 | dstFlag = None | |
33 | errorCount = None |
|
33 | errorCount = None | |
34 | struct = None |
|
34 | struct = None | |
35 |
|
35 | |||
36 | def __init__(self): |
|
36 | def __init__(self): | |
37 |
|
37 | |||
38 | self.size = 0 |
|
38 | self.size = 0 | |
39 | self.version = 0 |
|
39 | self.version = 0 | |
40 | self.dataBlock = 0 |
|
40 | self.dataBlock = 0 | |
41 | self.utc = 0 |
|
41 | self.utc = 0 | |
42 | self.miliSecond = 0 |
|
42 | self.miliSecond = 0 | |
43 | self.timeZone = 0 |
|
43 | self.timeZone = 0 | |
44 | self.dstFlag = 0 |
|
44 | self.dstFlag = 0 | |
45 | self.errorCount = 0 |
|
45 | self.errorCount = 0 | |
46 | self.struct = numpy.dtype([ |
|
46 | self.struct = numpy.dtype([ | |
47 | ('nSize','<u4'), |
|
47 | ('nSize','<u4'), | |
48 | ('nVersion','<u2'), |
|
48 | ('nVersion','<u2'), | |
49 | ('nDataBlockId','<u4'), |
|
49 | ('nDataBlockId','<u4'), | |
50 | ('nUtime','<u4'), |
|
50 | ('nUtime','<u4'), | |
51 | ('nMilsec','<u2'), |
|
51 | ('nMilsec','<u2'), | |
52 | ('nTimezone','<i2'), |
|
52 | ('nTimezone','<i2'), | |
53 | ('nDstflag','<i2'), |
|
53 | ('nDstflag','<i2'), | |
54 | ('nErrorCount','<u4') |
|
54 | ('nErrorCount','<u4') | |
55 | ]) |
|
55 | ]) | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def read(self, fp): |
|
58 | def read(self, fp): | |
59 | try: |
|
59 | try: | |
60 | header = numpy.fromfile(fp, self.struct,1) |
|
60 | header = numpy.fromfile(fp, self.struct,1) | |
61 | self.size = header['nSize'][0] |
|
61 | self.size = int(header['nSize'][0]) | |
62 | self.version = header['nVersion'][0] |
|
62 | self.version = int(header['nVersion'][0]) | |
63 | self.dataBlock = header['nDataBlockId'][0] |
|
63 | self.dataBlock = int(header['nDataBlockId'][0]) | |
64 | self.utc = header['nUtime'][0] |
|
64 | self.utc = int(header['nUtime'][0]) | |
65 | self.miliSecond = header['nMilsec'][0] |
|
65 | self.miliSecond = int(header['nMilsec'][0]) | |
66 | self.timeZone = header['nTimezone'][0] |
|
66 | self.timeZone = int(header['nTimezone'][0]) | |
67 | self.dstFlag = header['nDstflag'][0] |
|
67 | self.dstFlag = int(header['nDstflag'][0]) | |
68 | self.errorCount = header['nErrorCount'][0] |
|
68 | self.errorCount = int(header['nErrorCount'][0]) | |
69 | except: |
|
69 | except: | |
70 | return 0 |
|
70 | return 0 | |
71 |
|
71 | |||
72 | return 1 |
|
72 | return 1 | |
73 |
|
73 | |||
74 | def write(self, fp): |
|
74 | def write(self, fp): | |
75 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
75 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) | |
76 | header = numpy.array(headerTuple,self.struct) |
|
76 | header = numpy.array(headerTuple,self.struct) | |
77 | header.tofile(fp) |
|
77 | header.tofile(fp) | |
78 |
|
78 | |||
79 | return 1 |
|
79 | return 1 | |
80 |
|
80 | |||
81 | class SystemHeader(Header): |
|
81 | class SystemHeader(Header): | |
82 |
|
82 | |||
83 | size = None |
|
83 | size = None | |
84 | nSamples = None |
|
84 | nSamples = None | |
85 | nProfiles = None |
|
85 | nProfiles = None | |
86 | nChannels = None |
|
86 | nChannels = None | |
87 | adcResolution = None |
|
87 | adcResolution = None | |
88 | pciDioBusWidth = None |
|
88 | pciDioBusWidth = None | |
89 | struct = None |
|
89 | struct = None | |
90 |
|
90 | |||
91 | def __init__(self): |
|
91 | def __init__(self): | |
92 | self.size = 0 |
|
92 | self.size = 0 | |
93 | self.nSamples = 0 |
|
93 | self.nSamples = 0 | |
94 | self.nProfiles = 0 |
|
94 | self.nProfiles = 0 | |
95 | self.nChannels = 0 |
|
95 | self.nChannels = 0 | |
96 | self.adcResolution = 0 |
|
96 | self.adcResolution = 0 | |
97 | self.pciDioBusWidth = 0 |
|
97 | self.pciDioBusWidth = 0 | |
98 | self.struct = numpy.dtype([ |
|
98 | self.struct = numpy.dtype([ | |
99 | ('nSize','<u4'), |
|
99 | ('nSize','<u4'), | |
100 | ('nNumSamples','<u4'), |
|
100 | ('nNumSamples','<u4'), | |
101 | ('nNumProfiles','<u4'), |
|
101 | ('nNumProfiles','<u4'), | |
102 | ('nNumChannels','<u4'), |
|
102 | ('nNumChannels','<u4'), | |
103 | ('nADCResolution','<u4'), |
|
103 | ('nADCResolution','<u4'), | |
104 | ('nPCDIOBusWidth','<u4'), |
|
104 | ('nPCDIOBusWidth','<u4'), | |
105 | ]) |
|
105 | ]) | |
106 |
|
106 | |||
107 |
|
107 | |||
108 | def read(self, fp): |
|
108 | def read(self, fp): | |
109 | try: |
|
109 | try: | |
110 | header = numpy.fromfile(fp,self.struct,1) |
|
110 | header = numpy.fromfile(fp,self.struct,1) | |
111 | self.size = header['nSize'][0] |
|
111 | self.size = header['nSize'][0] | |
112 | self.nSamples = header['nNumSamples'][0] |
|
112 | self.nSamples = header['nNumSamples'][0] | |
113 | self.nProfiles = header['nNumProfiles'][0] |
|
113 | self.nProfiles = header['nNumProfiles'][0] | |
114 | self.nChannels = header['nNumChannels'][0] |
|
114 | self.nChannels = header['nNumChannels'][0] | |
115 | self.adcResolution = header['nADCResolution'][0] |
|
115 | self.adcResolution = header['nADCResolution'][0] | |
116 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
116 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
117 | except: |
|
117 | except: | |
118 | return 0 |
|
118 | return 0 | |
119 |
|
119 | |||
120 | return 1 |
|
120 | return 1 | |
121 |
|
121 | |||
122 | def write(self, fp): |
|
122 | def write(self, fp): | |
123 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
123 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) | |
124 | header = numpy.array(headerTuple,self.struct) |
|
124 | header = numpy.array(headerTuple,self.struct) | |
125 | header.tofile(fp) |
|
125 | header.tofile(fp) | |
126 |
|
126 | |||
127 | return 1 |
|
127 | return 1 | |
128 |
|
128 | |||
129 | class RadarControllerHeader(Header): |
|
129 | class RadarControllerHeader(Header): | |
130 |
|
130 | |||
131 | size = None |
|
131 | size = None | |
132 | expType = None |
|
132 | expType = None | |
133 | nTx = None |
|
133 | nTx = None | |
134 | ipp = None |
|
134 | ipp = None | |
135 | txA = None |
|
135 | txA = None | |
136 | txB = None |
|
136 | txB = None | |
137 | nWindows = None |
|
137 | nWindows = None | |
138 | numTaus = None |
|
138 | numTaus = None | |
139 | codeType = None |
|
139 | codeType = None | |
140 | line6Function = None |
|
140 | line6Function = None | |
141 | line5Function = None |
|
141 | line5Function = None | |
142 | fClock = None |
|
142 | fClock = None | |
143 | prePulseBefore = None |
|
143 | prePulseBefore = None | |
144 | prePulserAfter = None |
|
144 | prePulserAfter = None | |
145 | rangeIpp = None |
|
145 | rangeIpp = None | |
146 | rangeTxA = None |
|
146 | rangeTxA = None | |
147 | rangeTxB = None |
|
147 | rangeTxB = None | |
148 | struct = None |
|
148 | struct = None | |
149 |
|
149 | |||
150 | def __init__(self): |
|
150 | def __init__(self): | |
151 | self.size = 0 |
|
151 | self.size = 0 | |
152 | self.expType = 0 |
|
152 | self.expType = 0 | |
153 | self.nTx = 0 |
|
153 | self.nTx = 0 | |
154 | self.ipp = 0 |
|
154 | self.ipp = 0 | |
155 | self.txA = 0 |
|
155 | self.txA = 0 | |
156 | self.txB = 0 |
|
156 | self.txB = 0 | |
157 | self.nWindows = 0 |
|
157 | self.nWindows = 0 | |
158 | self.numTaus = 0 |
|
158 | self.numTaus = 0 | |
159 | self.codeType = 0 |
|
159 | self.codeType = 0 | |
160 | self.line6Function = 0 |
|
160 | self.line6Function = 0 | |
161 | self.line5Function = 0 |
|
161 | self.line5Function = 0 | |
162 | self.fClock = 0 |
|
162 | self.fClock = 0 | |
163 | self.prePulseBefore = 0 |
|
163 | self.prePulseBefore = 0 | |
164 | self.prePulserAfter = 0 |
|
164 | self.prePulserAfter = 0 | |
165 | self.rangeIpp = 0 |
|
165 | self.rangeIpp = 0 | |
166 | self.rangeTxA = 0 |
|
166 | self.rangeTxA = 0 | |
167 | self.rangeTxB = 0 |
|
167 | self.rangeTxB = 0 | |
168 | self.struct = numpy.dtype([ |
|
168 | self.struct = numpy.dtype([ | |
169 | ('nSize','<u4'), |
|
169 | ('nSize','<u4'), | |
170 | ('nExpType','<u4'), |
|
170 | ('nExpType','<u4'), | |
171 | ('nNTx','<u4'), |
|
171 | ('nNTx','<u4'), | |
172 | ('fIpp','<f4'), |
|
172 | ('fIpp','<f4'), | |
173 | ('fTxA','<f4'), |
|
173 | ('fTxA','<f4'), | |
174 | ('fTxB','<f4'), |
|
174 | ('fTxB','<f4'), | |
175 | ('nNumWindows','<u4'), |
|
175 | ('nNumWindows','<u4'), | |
176 | ('nNumTaus','<u4'), |
|
176 | ('nNumTaus','<u4'), | |
177 | ('nCodeType','<u4'), |
|
177 | ('nCodeType','<u4'), | |
178 | ('nLine6Function','<u4'), |
|
178 | ('nLine6Function','<u4'), | |
179 | ('nLine5Function','<u4'), |
|
179 | ('nLine5Function','<u4'), | |
180 | ('fClock','<f4'), |
|
180 | ('fClock','<f4'), | |
181 | ('nPrePulseBefore','<u4'), |
|
181 | ('nPrePulseBefore','<u4'), | |
182 | ('nPrePulseAfter','<u4'), |
|
182 | ('nPrePulseAfter','<u4'), | |
183 | ('sRangeIPP','<a20'), |
|
183 | ('sRangeIPP','<a20'), | |
184 | ('sRangeTxA','<a20'), |
|
184 | ('sRangeTxA','<a20'), | |
185 | ('sRangeTxB','<a20'), |
|
185 | ('sRangeTxB','<a20'), | |
186 | ]) |
|
186 | ]) | |
187 |
|
187 | |||
188 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
188 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
189 |
|
189 | |||
190 | self.samplingWindow = None |
|
190 | self.samplingWindow = None | |
191 | self.nHeights = None |
|
191 | self.nHeights = None | |
192 | self.firstHeight = None |
|
192 | self.firstHeight = None | |
193 | self.deltaHeight = None |
|
193 | self.deltaHeight = None | |
194 | self.samplesWin = None |
|
194 | self.samplesWin = None | |
195 |
|
195 | |||
196 | self.nCode = None |
|
196 | self.nCode = None | |
197 | self.nBaud = None |
|
197 | self.nBaud = None | |
198 | self.code = None |
|
198 | self.code = None | |
199 | self.flip1 = None |
|
199 | self.flip1 = None | |
200 | self.flip2 = None |
|
200 | self.flip2 = None | |
201 |
|
201 | |||
202 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
202 | self.dynamic = numpy.array([],numpy.dtype('byte')) | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | def read(self, fp): |
|
205 | def read(self, fp): | |
206 | try: |
|
206 | try: | |
207 | startFp = fp.tell() |
|
207 | startFp = fp.tell() | |
208 | header = numpy.fromfile(fp,self.struct,1) |
|
208 | header = numpy.fromfile(fp,self.struct,1) | |
209 | self.size = header['nSize'][0] |
|
209 | self.size = int(header['nSize'][0]) | |
210 | self.expType = header['nExpType'][0] |
|
210 | self.expType = int(header['nExpType'][0]) | |
211 | self.nTx = header['nNTx'][0] |
|
211 | self.nTx = int(header['nNTx'][0]) | |
212 | self.ipp = header['fIpp'][0] |
|
212 | self.ipp = float(header['fIpp'][0]) | |
213 | self.txA = header['fTxA'][0] |
|
213 | self.txA = float(header['fTxA'][0]) | |
214 | self.txB = header['fTxB'][0] |
|
214 | self.txB = float(header['fTxB'][0]) | |
215 | self.nWindows = header['nNumWindows'][0] |
|
215 | self.nWindows = int(header['nNumWindows'][0]) | |
216 | self.numTaus = header['nNumTaus'][0] |
|
216 | self.numTaus = int(header['nNumTaus'][0]) | |
217 | self.codeType = header['nCodeType'][0] |
|
217 | self.codeType = int(header['nCodeType'][0]) | |
218 | self.line6Function = header['nLine6Function'][0] |
|
218 | self.line6Function = int(header['nLine6Function'][0]) | |
219 | self.line5Function = header['nLine5Function'][0] |
|
219 | self.line5Function = int(header['nLine5Function'][0]) | |
220 | self.fClock = header['fClock'][0] |
|
220 | self.fClock = float(header['fClock'][0]) | |
221 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
221 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
222 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
222 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) | |
223 | self.rangeIpp = header['sRangeIPP'][0] |
|
223 | self.rangeIpp = header['sRangeIPP'][0] | |
224 | self.rangeTxA = header['sRangeTxA'][0] |
|
224 | self.rangeTxA = header['sRangeTxA'][0] | |
225 | self.rangeTxB = header['sRangeTxB'][0] |
|
225 | self.rangeTxB = header['sRangeTxB'][0] | |
226 | # jump Dynamic Radar Controller Header |
|
226 | # jump Dynamic Radar Controller Header | |
227 | jumpFp = self.size - 116 |
|
227 | jumpFp = self.size - 116 | |
228 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
228 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) | |
229 | #pointer backward to dynamic header and read |
|
229 | #pointer backward to dynamic header and read | |
230 | backFp = fp.tell() - jumpFp |
|
230 | backFp = fp.tell() - jumpFp | |
231 | fp.seek(backFp) |
|
231 | fp.seek(backFp) | |
232 |
|
232 | |||
233 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
233 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) | |
234 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
234 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
235 | self.firstHeight = self.samplingWindow['h0'] |
|
235 | self.firstHeight = self.samplingWindow['h0'] | |
236 | self.deltaHeight = self.samplingWindow['dh'] |
|
236 | self.deltaHeight = self.samplingWindow['dh'] | |
237 | self.samplesWin = self.samplingWindow['nsa'] |
|
237 | self.samplesWin = self.samplingWindow['nsa'] | |
238 |
|
238 | |||
239 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
239 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) | |
240 |
|
240 | |||
241 | if self.codeType != 0: |
|
241 | if self.codeType != 0: | |
242 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
242 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
243 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
243 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
244 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
244 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') | |
245 | tempList = [] |
|
245 | tempList = [] | |
246 | for ic in range(self.nCode): |
|
246 | for ic in range(self.nCode): | |
247 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.)) |
|
247 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.)) | |
248 | tempList.append(temp) |
|
248 | tempList.append(temp) | |
249 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
249 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] | |
250 | self.code = 2.0*self.code - 1.0 |
|
250 | self.code = 2.0*self.code - 1.0 | |
251 |
|
251 | |||
252 | if self.line5Function == RCfunction.FLIP: |
|
252 | if self.line5Function == RCfunction.FLIP: | |
253 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
253 | self.flip1 = numpy.fromfile(fp,'<u4',1) | |
254 |
|
254 | |||
255 | if self.line6Function == RCfunction.FLIP: |
|
255 | if self.line6Function == RCfunction.FLIP: | |
256 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
256 | self.flip2 = numpy.fromfile(fp,'<u4',1) | |
257 |
|
257 | |||
258 | endFp = self.size + startFp |
|
258 | endFp = self.size + startFp | |
259 | jumpFp = endFp - fp.tell() |
|
259 | jumpFp = endFp - fp.tell() | |
260 | if jumpFp > 0: |
|
260 | if jumpFp > 0: | |
261 | fp.seek(jumpFp) |
|
261 | fp.seek(jumpFp) | |
262 |
|
262 | |||
263 | except: |
|
263 | except: | |
264 | return 0 |
|
264 | return 0 | |
265 |
|
265 | |||
266 | return 1 |
|
266 | return 1 | |
267 |
|
267 | |||
268 | def write(self, fp): |
|
268 | def write(self, fp): | |
269 | headerTuple = (self.size, |
|
269 | headerTuple = (self.size, | |
270 | self.expType, |
|
270 | self.expType, | |
271 | self.nTx, |
|
271 | self.nTx, | |
272 | self.ipp, |
|
272 | self.ipp, | |
273 | self.txA, |
|
273 | self.txA, | |
274 | self.txB, |
|
274 | self.txB, | |
275 | self.nWindows, |
|
275 | self.nWindows, | |
276 | self.numTaus, |
|
276 | self.numTaus, | |
277 | self.codeType, |
|
277 | self.codeType, | |
278 | self.line6Function, |
|
278 | self.line6Function, | |
279 | self.line5Function, |
|
279 | self.line5Function, | |
280 | self.fClock, |
|
280 | self.fClock, | |
281 | self.prePulseBefore, |
|
281 | self.prePulseBefore, | |
282 | self.prePulserAfter, |
|
282 | self.prePulserAfter, | |
283 | self.rangeIpp, |
|
283 | self.rangeIpp, | |
284 | self.rangeTxA, |
|
284 | self.rangeTxA, | |
285 | self.rangeTxB) |
|
285 | self.rangeTxB) | |
286 |
|
286 | |||
287 | header = numpy.array(headerTuple,self.struct) |
|
287 | header = numpy.array(headerTuple,self.struct) | |
288 | header.tofile(fp) |
|
288 | header.tofile(fp) | |
289 |
|
289 | |||
290 | dynamic = self.dynamic |
|
290 | dynamic = self.dynamic | |
291 | dynamic.tofile(fp) |
|
291 | dynamic.tofile(fp) | |
292 |
|
292 | |||
293 | return 1 |
|
293 | return 1 | |
294 |
|
294 | |||
295 |
|
295 | |||
296 |
|
296 | |||
297 | class ProcessingHeader(Header): |
|
297 | class ProcessingHeader(Header): | |
298 |
|
298 | |||
299 | size = None |
|
299 | size = None | |
300 | dtype = None |
|
300 | dtype = None | |
301 | blockSize = None |
|
301 | blockSize = None | |
302 | profilesPerBlock = None |
|
302 | profilesPerBlock = None | |
303 | dataBlocksPerFile = None |
|
303 | dataBlocksPerFile = None | |
304 | nWindows = None |
|
304 | nWindows = None | |
305 | processFlags = None |
|
305 | processFlags = None | |
306 | nCohInt = None |
|
306 | nCohInt = None | |
307 | nIncohInt = None |
|
307 | nIncohInt = None | |
308 | totalSpectra = None |
|
308 | totalSpectra = None | |
309 | struct = None |
|
309 | struct = None | |
310 | flag_dc = None |
|
310 | flag_dc = None | |
311 | flag_cspc = None |
|
311 | flag_cspc = None | |
312 |
|
312 | |||
313 | def __init__(self): |
|
313 | def __init__(self): | |
314 | self.size = 0 |
|
314 | self.size = 0 | |
315 | self.dtype = 0 |
|
315 | self.dtype = 0 | |
316 | self.blockSize = 0 |
|
316 | self.blockSize = 0 | |
317 | self.profilesPerBlock = 0 |
|
317 | self.profilesPerBlock = 0 | |
318 | self.dataBlocksPerFile = 0 |
|
318 | self.dataBlocksPerFile = 0 | |
319 | self.nWindows = 0 |
|
319 | self.nWindows = 0 | |
320 | self.processFlags = 0 |
|
320 | self.processFlags = 0 | |
321 | self.nCohInt = 0 |
|
321 | self.nCohInt = 0 | |
322 | self.nIncohInt = 0 |
|
322 | self.nIncohInt = 0 | |
323 | self.totalSpectra = 0 |
|
323 | self.totalSpectra = 0 | |
324 | self.struct = numpy.dtype([ |
|
324 | self.struct = numpy.dtype([ | |
325 | ('nSize','<u4'), |
|
325 | ('nSize','<u4'), | |
326 | ('nDataType','<u4'), |
|
326 | ('nDataType','<u4'), | |
327 | ('nSizeOfDataBlock','<u4'), |
|
327 | ('nSizeOfDataBlock','<u4'), | |
328 | ('nProfilesperBlock','<u4'), |
|
328 | ('nProfilesperBlock','<u4'), | |
329 | ('nDataBlocksperFile','<u4'), |
|
329 | ('nDataBlocksperFile','<u4'), | |
330 | ('nNumWindows','<u4'), |
|
330 | ('nNumWindows','<u4'), | |
331 | ('nProcessFlags','<u4'), |
|
331 | ('nProcessFlags','<u4'), | |
332 | ('nCoherentIntegrations','<u4'), |
|
332 | ('nCoherentIntegrations','<u4'), | |
333 | ('nIncoherentIntegrations','<u4'), |
|
333 | ('nIncoherentIntegrations','<u4'), | |
334 | ('nTotalSpectra','<u4') |
|
334 | ('nTotalSpectra','<u4') | |
335 | ]) |
|
335 | ]) | |
336 | self.samplingWindow = 0 |
|
336 | self.samplingWindow = 0 | |
337 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
337 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
338 | self.nHeights = 0 |
|
338 | self.nHeights = 0 | |
339 | self.firstHeight = 0 |
|
339 | self.firstHeight = 0 | |
340 | self.deltaHeight = 0 |
|
340 | self.deltaHeight = 0 | |
341 | self.samplesWin = 0 |
|
341 | self.samplesWin = 0 | |
342 | self.spectraComb = 0 |
|
342 | self.spectraComb = 0 | |
343 | self.nCode = None |
|
343 | self.nCode = None | |
344 | self.code = None |
|
344 | self.code = None | |
345 | self.nBaud = None |
|
345 | self.nBaud = None | |
346 | self.shif_fft = False |
|
346 | self.shif_fft = False | |
347 | self.flag_dc = False |
|
347 | self.flag_dc = False | |
348 | self.flag_cspc = False |
|
348 | self.flag_cspc = False | |
349 |
|
349 | |||
350 | def read(self, fp): |
|
350 | def read(self, fp): | |
351 | try: |
|
351 | try: | |
352 | header = numpy.fromfile(fp,self.struct,1) |
|
352 | header = numpy.fromfile(fp,self.struct,1) | |
353 | self.size = header['nSize'][0] |
|
353 | self.size = int(header['nSize'][0]) | |
354 | self.dtype = header['nDataType'][0] |
|
354 | self.dtype = int(header['nDataType'][0]) | |
355 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
355 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
356 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
356 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
357 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
357 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
358 | self.nWindows = header['nNumWindows'][0] |
|
358 | self.nWindows = int(header['nNumWindows'][0]) | |
359 | self.processFlags = header['nProcessFlags'] |
|
359 | self.processFlags = int(header['nProcessFlags']) | |
360 | self.nCohInt = header['nCoherentIntegrations'][0] |
|
360 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
361 | self.nIncohInt = header['nIncoherentIntegrations'][0] |
|
361 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
362 | self.totalSpectra = header['nTotalSpectra'][0] |
|
362 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
363 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) |
|
363 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) | |
364 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
364 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
365 | self.firstHeight = self.samplingWindow['h0'][0] |
|
365 | self.firstHeight = int(self.samplingWindow['h0'][0]) | |
366 | self.deltaHeight = self.samplingWindow['dh'][0] |
|
366 | self.deltaHeight = int(self.samplingWindow['dh'][0]) | |
367 | self.samplesWin = self.samplingWindow['nsa'] |
|
367 | self.samplesWin = self.samplingWindow['nsa'] | |
368 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
368 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
369 |
|
369 | |||
370 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
370 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
371 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
371 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
372 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
372 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
373 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) |
|
373 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) | |
374 |
|
374 | |||
375 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
375 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
376 | self.shif_fft = True |
|
376 | self.shif_fft = True | |
377 | else: |
|
377 | else: | |
378 | self.shif_fft = False |
|
378 | self.shif_fft = False | |
379 |
|
379 | |||
380 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
380 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
381 | self.flag_dc = True |
|
381 | self.flag_dc = True | |
382 |
|
382 | |||
383 | nChannels = 0 |
|
383 | nChannels = 0 | |
384 | nPairs = 0 |
|
384 | nPairs = 0 | |
385 | pairList = [] |
|
385 | pairList = [] | |
386 |
|
386 | |||
387 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
387 | for i in range( 0, self.totalSpectra*2, 2 ): | |
388 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
388 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
389 | nChannels = nChannels + 1 #par de canales iguales |
|
389 | nChannels = nChannels + 1 #par de canales iguales | |
390 | else: |
|
390 | else: | |
391 | nPairs = nPairs + 1 #par de canales diferentes |
|
391 | nPairs = nPairs + 1 #par de canales diferentes | |
392 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
392 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
393 |
|
393 | |||
394 | self.flag_cspc = False |
|
394 | self.flag_cspc = False | |
395 | if nPairs > 0: |
|
395 | if nPairs > 0: | |
396 | self.flag_cspc = True |
|
396 | self.flag_cspc = True | |
397 |
|
397 | |||
398 | except: |
|
398 | except: | |
399 | return 0 |
|
399 | return 0 | |
400 |
|
400 | |||
401 | return 1 |
|
401 | return 1 | |
402 |
|
402 | |||
403 | def write(self, fp): |
|
403 | def write(self, fp): | |
404 | headerTuple = (self.size, |
|
404 | headerTuple = (self.size, | |
405 | self.dtype, |
|
405 | self.dtype, | |
406 | self.blockSize, |
|
406 | self.blockSize, | |
407 | self.profilesPerBlock, |
|
407 | self.profilesPerBlock, | |
408 | self.dataBlocksPerFile, |
|
408 | self.dataBlocksPerFile, | |
409 | self.nWindows, |
|
409 | self.nWindows, | |
410 | self.processFlags, |
|
410 | self.processFlags, | |
411 | self.nCohInt, |
|
411 | self.nCohInt, | |
412 | self.nIncohInt, |
|
412 | self.nIncohInt, | |
413 | self.totalSpectra) |
|
413 | self.totalSpectra) | |
414 |
|
414 | |||
415 | header = numpy.array(headerTuple,self.struct) |
|
415 | header = numpy.array(headerTuple,self.struct) | |
416 | header.tofile(fp) |
|
416 | header.tofile(fp) | |
417 |
|
417 | |||
418 | if self.nWindows != 0: |
|
418 | if self.nWindows != 0: | |
419 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
419 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
420 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
420 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) | |
421 | samplingWindow.tofile(fp) |
|
421 | samplingWindow.tofile(fp) | |
422 |
|
422 | |||
423 |
|
423 | |||
424 | if self.totalSpectra != 0: |
|
424 | if self.totalSpectra != 0: | |
425 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
425 | spectraComb = numpy.array([],numpy.dtype('u1')) | |
426 | spectraComb = self.spectraComb |
|
426 | spectraComb = self.spectraComb | |
427 | spectraComb.tofile(fp) |
|
427 | spectraComb.tofile(fp) | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
430 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
431 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
431 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
432 | nCode.tofile(fp) |
|
432 | nCode.tofile(fp) | |
433 |
|
433 | |||
434 | nBaud = self.nBaud |
|
434 | nBaud = self.nBaud | |
435 | nBaud.tofile(fp) |
|
435 | nBaud.tofile(fp) | |
436 |
|
436 | |||
437 | code = self.code.reshape(nCode*nBaud) |
|
437 | code = self.code.reshape(nCode*nBaud) | |
438 | code.tofile(fp) |
|
438 | code.tofile(fp) | |
439 |
|
439 | |||
440 | return 1 |
|
440 | return 1 | |
441 |
|
441 | |||
442 | class RCfunction: |
|
442 | class RCfunction: | |
443 | NONE=0 |
|
443 | NONE=0 | |
444 | FLIP=1 |
|
444 | FLIP=1 | |
445 | CODE=2 |
|
445 | CODE=2 | |
446 | SAMPLING=3 |
|
446 | SAMPLING=3 | |
447 | LIN6DIV256=4 |
|
447 | LIN6DIV256=4 | |
448 | SYNCHRO=5 |
|
448 | SYNCHRO=5 | |
449 |
|
449 | |||
450 | class nCodeType: |
|
450 | class nCodeType: | |
451 | NONE=0 |
|
451 | NONE=0 | |
452 | USERDEFINE=1 |
|
452 | USERDEFINE=1 | |
453 | BARKER2=2 |
|
453 | BARKER2=2 | |
454 | BARKER3=3 |
|
454 | BARKER3=3 | |
455 | BARKER4=4 |
|
455 | BARKER4=4 | |
456 | BARKER5=5 |
|
456 | BARKER5=5 | |
457 | BARKER7=6 |
|
457 | BARKER7=6 | |
458 | BARKER11=7 |
|
458 | BARKER11=7 | |
459 | BARKER13=8 |
|
459 | BARKER13=8 | |
460 | AC128=9 |
|
460 | AC128=9 | |
461 | COMPLEMENTARYCODE2=10 |
|
461 | COMPLEMENTARYCODE2=10 | |
462 | COMPLEMENTARYCODE4=11 |
|
462 | COMPLEMENTARYCODE4=11 | |
463 | COMPLEMENTARYCODE8=12 |
|
463 | COMPLEMENTARYCODE8=12 | |
464 | COMPLEMENTARYCODE16=13 |
|
464 | COMPLEMENTARYCODE16=13 | |
465 | COMPLEMENTARYCODE32=14 |
|
465 | COMPLEMENTARYCODE32=14 | |
466 | COMPLEMENTARYCODE64=15 |
|
466 | COMPLEMENTARYCODE64=15 | |
467 | COMPLEMENTARYCODE128=16 |
|
467 | COMPLEMENTARYCODE128=16 | |
468 | CODE_BINARY28=17 |
|
468 | CODE_BINARY28=17 | |
469 |
|
469 | |||
470 | class PROCFLAG: |
|
470 | class PROCFLAG: | |
471 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
471 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
472 | DECODE_DATA = numpy.uint32(0x00000002) |
|
472 | DECODE_DATA = numpy.uint32(0x00000002) | |
473 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
473 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
474 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
474 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
475 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
475 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
476 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
476 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
477 |
|
477 | |||
478 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
478 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
479 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
479 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
480 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
480 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
481 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
481 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
482 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
482 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
483 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
483 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
484 |
|
484 | |||
485 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
485 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
486 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
486 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
487 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
487 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
488 |
|
488 | |||
489 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
489 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
490 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
490 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
491 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
491 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
492 |
|
492 | |||
493 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
493 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
494 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
494 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
495 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
495 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
496 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
496 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
497 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
497 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
498 |
|
498 | |||
499 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
499 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
500 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
500 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
501 |
|
501 | |||
502 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
502 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
503 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
503 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
504 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
504 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
505 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
|
505 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
@@ -1,903 +1,903 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 |
|
10 | |||
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | class ProcessingUnit: |
|
15 | class ProcessingUnit: | |
16 |
|
16 | |||
17 | """ |
|
17 | """ | |
18 | Esta es la clase base para el procesamiento de datos. |
|
18 | Esta es la clase base para el procesamiento de datos. | |
19 |
|
19 | |||
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
21 | - Metodos internos (callMethod) |
|
21 | - Metodos internos (callMethod) | |
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
23 | tienen que ser agreagados con el metodo "add". |
|
23 | tienen que ser agreagados con el metodo "add". | |
24 |
|
24 | |||
25 | """ |
|
25 | """ | |
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
27 | dataIn = None |
|
27 | dataIn = None | |
28 |
|
28 | |||
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
30 | dataOut = None |
|
30 | dataOut = None | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | objectDict = None |
|
33 | objectDict = None | |
34 |
|
34 | |||
35 | def __init__(self): |
|
35 | def __init__(self): | |
36 |
|
36 | |||
37 | self.objectDict = {} |
|
37 | self.objectDict = {} | |
38 |
|
38 | |||
39 | def init(self): |
|
39 | def init(self): | |
40 |
|
40 | |||
41 | raise ValueError, "Not implemented" |
|
41 | raise ValueError, "Not implemented" | |
42 |
|
42 | |||
43 | def addOperation(self, object, objId): |
|
43 | def addOperation(self, object, objId): | |
44 |
|
44 | |||
45 | """ |
|
45 | """ | |
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
47 | identificador asociado a este objeto. |
|
47 | identificador asociado a este objeto. | |
48 |
|
48 | |||
49 | Input: |
|
49 | Input: | |
50 |
|
50 | |||
51 | object : objeto de la clase "Operation" |
|
51 | object : objeto de la clase "Operation" | |
52 |
|
52 | |||
53 | Return: |
|
53 | Return: | |
54 |
|
54 | |||
55 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
55 | objId : identificador del objeto, necesario para ejecutar la operacion | |
56 | """ |
|
56 | """ | |
57 |
|
57 | |||
58 | self.objectDict[objId] = object |
|
58 | self.objectDict[objId] = object | |
59 |
|
59 | |||
60 | return objId |
|
60 | return objId | |
61 |
|
61 | |||
62 | def operation(self, **kwargs): |
|
62 | def operation(self, **kwargs): | |
63 |
|
63 | |||
64 | """ |
|
64 | """ | |
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los |
|
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los | |
66 | atributos del objeto dataOut |
|
66 | atributos del objeto dataOut | |
67 |
|
67 | |||
68 | Input: |
|
68 | Input: | |
69 |
|
69 | |||
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
71 | """ |
|
71 | """ | |
72 |
|
72 | |||
73 | raise ValueError, "ImplementedError" |
|
73 | raise ValueError, "ImplementedError" | |
74 |
|
74 | |||
75 | def callMethod(self, name, **kwargs): |
|
75 | def callMethod(self, name, **kwargs): | |
76 |
|
76 | |||
77 | """ |
|
77 | """ | |
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
79 |
|
79 | |||
80 | Input: |
|
80 | Input: | |
81 | name : nombre del metodo a ejecutar |
|
81 | name : nombre del metodo a ejecutar | |
82 |
|
82 | |||
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
84 |
|
84 | |||
85 | """ |
|
85 | """ | |
86 | if name != 'run': |
|
86 | if name != 'run': | |
87 |
|
87 | |||
88 | if name == 'init' and self.dataIn.isEmpty(): |
|
88 | if name == 'init' and self.dataIn.isEmpty(): | |
89 | self.dataOut.flagNoData = True |
|
89 | self.dataOut.flagNoData = True | |
90 | return False |
|
90 | return False | |
91 |
|
91 | |||
92 | if name != 'init' and self.dataOut.isEmpty(): |
|
92 | if name != 'init' and self.dataOut.isEmpty(): | |
93 | return False |
|
93 | return False | |
94 |
|
94 | |||
95 | methodToCall = getattr(self, name) |
|
95 | methodToCall = getattr(self, name) | |
96 |
|
96 | |||
97 | methodToCall(**kwargs) |
|
97 | methodToCall(**kwargs) | |
98 |
|
98 | |||
99 | if name != 'run': |
|
99 | if name != 'run': | |
100 | return True |
|
100 | return True | |
101 |
|
101 | |||
102 | if self.dataOut.isEmpty(): |
|
102 | if self.dataOut.isEmpty(): | |
103 | return False |
|
103 | return False | |
104 |
|
104 | |||
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | def callObject(self, objId, **kwargs): |
|
107 | def callObject(self, objId, **kwargs): | |
108 |
|
108 | |||
109 | """ |
|
109 | """ | |
110 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
110 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
111 |
|
111 | |||
112 | Input: |
|
112 | Input: | |
113 |
|
113 | |||
114 | objId : identificador del objeto a ejecutar |
|
114 | objId : identificador del objeto a ejecutar | |
115 |
|
115 | |||
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
117 |
|
117 | |||
118 | Return: |
|
118 | Return: | |
119 |
|
119 | |||
120 | None |
|
120 | None | |
121 | """ |
|
121 | """ | |
122 |
|
122 | |||
123 | if self.dataOut.isEmpty(): |
|
123 | if self.dataOut.isEmpty(): | |
124 | return False |
|
124 | return False | |
125 |
|
125 | |||
126 | object = self.objectDict[objId] |
|
126 | object = self.objectDict[objId] | |
127 |
|
127 | |||
128 | object.run(self.dataOut, **kwargs) |
|
128 | object.run(self.dataOut, **kwargs) | |
129 |
|
129 | |||
130 | return True |
|
130 | return True | |
131 |
|
131 | |||
132 | def call(self, operationConf, **kwargs): |
|
132 | def call(self, operationConf, **kwargs): | |
133 |
|
133 | |||
134 | """ |
|
134 | """ | |
135 | Return True si ejecuta la operacion "operationConf.name" con los |
|
135 | Return True si ejecuta la operacion "operationConf.name" con los | |
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
137 | La operacion puede ser de dos tipos: |
|
137 | La operacion puede ser de dos tipos: | |
138 |
|
138 | |||
139 | 1. Un metodo propio de esta clase: |
|
139 | 1. Un metodo propio de esta clase: | |
140 |
|
140 | |||
141 | operation.type = "self" |
|
141 | operation.type = "self" | |
142 |
|
142 | |||
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
144 | operation.type = "other". |
|
144 | operation.type = "other". | |
145 |
|
145 | |||
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
147 | "addOperation" e identificado con el operation.id |
|
147 | "addOperation" e identificado con el operation.id | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | con el id de la operacion. |
|
150 | con el id de la operacion. | |
151 |
|
151 | |||
152 | Input: |
|
152 | Input: | |
153 |
|
153 | |||
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
155 |
|
155 | |||
156 | """ |
|
156 | """ | |
157 |
|
157 | |||
158 | if operationConf.type == 'self': |
|
158 | if operationConf.type == 'self': | |
159 | sts = self.callMethod(operationConf.name, **kwargs) |
|
159 | sts = self.callMethod(operationConf.name, **kwargs) | |
160 |
|
160 | |||
161 | if operationConf.type == 'other': |
|
161 | if operationConf.type == 'other': | |
162 | sts = self.callObject(operationConf.id, **kwargs) |
|
162 | sts = self.callObject(operationConf.id, **kwargs) | |
163 |
|
163 | |||
164 | return sts |
|
164 | return sts | |
165 |
|
165 | |||
166 | def setInput(self, dataIn): |
|
166 | def setInput(self, dataIn): | |
167 |
|
167 | |||
168 | self.dataIn = dataIn |
|
168 | self.dataIn = dataIn | |
169 |
|
169 | |||
170 | def getOutput(self): |
|
170 | def getOutput(self): | |
171 |
|
171 | |||
172 | return self.dataOut |
|
172 | return self.dataOut | |
173 |
|
173 | |||
174 | class Operation(): |
|
174 | class Operation(): | |
175 |
|
175 | |||
176 | """ |
|
176 | """ | |
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
179 | acumulacion dentro de esta clase |
|
179 | acumulacion dentro de esta clase | |
180 |
|
180 | |||
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
182 |
|
182 | |||
183 | """ |
|
183 | """ | |
184 |
|
184 | |||
185 | __buffer = None |
|
185 | __buffer = None | |
186 | __isConfig = False |
|
186 | __isConfig = False | |
187 |
|
187 | |||
188 | def __init__(self): |
|
188 | def __init__(self): | |
189 |
|
189 | |||
190 | pass |
|
190 | pass | |
191 |
|
191 | |||
192 | def run(self, dataIn, **kwargs): |
|
192 | def run(self, dataIn, **kwargs): | |
193 |
|
193 | |||
194 | """ |
|
194 | """ | |
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
196 |
|
196 | |||
197 | Input: |
|
197 | Input: | |
198 |
|
198 | |||
199 | dataIn : objeto del tipo JROData |
|
199 | dataIn : objeto del tipo JROData | |
200 |
|
200 | |||
201 | Return: |
|
201 | Return: | |
202 |
|
202 | |||
203 | None |
|
203 | None | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | __buffer : buffer de recepcion de datos. |
|
206 | __buffer : buffer de recepcion de datos. | |
207 |
|
207 | |||
208 | """ |
|
208 | """ | |
209 |
|
209 | |||
210 | raise ValueError, "ImplementedError" |
|
210 | raise ValueError, "ImplementedError" | |
211 |
|
211 | |||
212 | class VoltageProc(ProcessingUnit): |
|
212 | class VoltageProc(ProcessingUnit): | |
213 |
|
213 | |||
214 |
|
214 | |||
215 | def __init__(self): |
|
215 | def __init__(self): | |
216 |
|
216 | |||
217 | self.objectDict = {} |
|
217 | self.objectDict = {} | |
218 | self.dataOut = Voltage() |
|
218 | self.dataOut = Voltage() | |
219 |
|
219 | |||
220 | def init(self): |
|
220 | def init(self): | |
221 |
|
221 | |||
222 | self.dataOut.copy(self.dataIn) |
|
222 | self.dataOut.copy(self.dataIn) | |
223 | # No necesita copiar en cada init() los atributos de dataIn |
|
223 | # No necesita copiar en cada init() los atributos de dataIn | |
224 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
224 | # la copia deberia hacerse por cada nuevo bloque de datos | |
225 |
|
225 | |||
226 | def selectChannels(self, channelList): |
|
226 | def selectChannels(self, channelList): | |
227 |
|
227 | |||
228 | channelIndexList = [] |
|
228 | channelIndexList = [] | |
229 |
|
229 | |||
230 | for channel in channelList: |
|
230 | for channel in channelList: | |
231 | index = self.dataOut.channelList.index(channel) |
|
231 | index = self.dataOut.channelList.index(channel) | |
232 | channelIndexList.append(index) |
|
232 | channelIndexList.append(index) | |
233 |
|
233 | |||
234 | self.selectChannelsByIndex(channelIndexList) |
|
234 | self.selectChannelsByIndex(channelIndexList) | |
235 |
|
235 | |||
236 | def selectChannelsByIndex(self, channelIndexList): |
|
236 | def selectChannelsByIndex(self, channelIndexList): | |
237 | """ |
|
237 | """ | |
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
239 |
|
239 | |||
240 | Input: |
|
240 | Input: | |
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
242 |
|
242 | |||
243 | Affected: |
|
243 | Affected: | |
244 | self.dataOut.data |
|
244 | self.dataOut.data | |
245 | self.dataOut.channelIndexList |
|
245 | self.dataOut.channelIndexList | |
246 | self.dataOut.nChannels |
|
246 | self.dataOut.nChannels | |
247 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
247 | self.dataOut.m_ProcessingHeader.totalSpectra | |
248 | self.dataOut.systemHeaderObj.numChannels |
|
248 | self.dataOut.systemHeaderObj.numChannels | |
249 | self.dataOut.m_ProcessingHeader.blockSize |
|
249 | self.dataOut.m_ProcessingHeader.blockSize | |
250 |
|
250 | |||
251 | Return: |
|
251 | Return: | |
252 | None |
|
252 | None | |
253 | """ |
|
253 | """ | |
254 |
|
254 | |||
255 | for channelIndex in channelIndexList: |
|
255 | for channelIndex in channelIndexList: | |
256 | if channelIndex not in self.dataOut.channelIndexList: |
|
256 | if channelIndex not in self.dataOut.channelIndexList: | |
257 | print channelIndexList |
|
257 | print channelIndexList | |
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
259 |
|
259 | |||
260 | nChannels = len(channelIndexList) |
|
260 | nChannels = len(channelIndexList) | |
261 |
|
261 | |||
262 | data = self.dataOut.data[channelIndexList,:] |
|
262 | data = self.dataOut.data[channelIndexList,:] | |
263 |
|
263 | |||
264 | self.dataOut.data = data |
|
264 | self.dataOut.data = data | |
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
266 | # self.dataOut.nChannels = nChannels |
|
266 | # self.dataOut.nChannels = nChannels | |
267 |
|
267 | |||
268 | return 1 |
|
268 | return 1 | |
269 |
|
269 | |||
270 | class CohInt(Operation): |
|
270 | class CohInt(Operation): | |
271 |
|
271 | |||
272 | __profIndex = 0 |
|
272 | __profIndex = 0 | |
273 | __withOverapping = False |
|
273 | __withOverapping = False | |
274 |
|
274 | |||
275 | __byTime = False |
|
275 | __byTime = False | |
276 | __initime = None |
|
276 | __initime = None | |
277 | __lastdatatime = None |
|
277 | __lastdatatime = None | |
278 | __integrationtime = None |
|
278 | __integrationtime = None | |
279 |
|
279 | |||
280 | __buffer = None |
|
280 | __buffer = None | |
281 |
|
281 | |||
282 | __dataReady = False |
|
282 | __dataReady = False | |
283 |
|
283 | |||
284 | n = None |
|
284 | n = None | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | def __init__(self): |
|
287 | def __init__(self): | |
288 |
|
288 | |||
289 | self.__isConfig = False |
|
289 | self.__isConfig = False | |
290 |
|
290 | |||
291 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
291 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
292 | """ |
|
292 | """ | |
293 | Set the parameters of the integration class. |
|
293 | Set the parameters of the integration class. | |
294 |
|
294 | |||
295 | Inputs: |
|
295 | Inputs: | |
296 |
|
296 | |||
297 | n : Number of coherent integrations |
|
297 | n : Number of coherent integrations | |
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
299 | overlapping : |
|
299 | overlapping : | |
300 |
|
300 | |||
301 | """ |
|
301 | """ | |
302 |
|
302 | |||
303 | self.__initime = None |
|
303 | self.__initime = None | |
304 | self.__lastdatatime = 0 |
|
304 | self.__lastdatatime = 0 | |
305 | self.__buffer = None |
|
305 | self.__buffer = None | |
306 | self.__dataReady = False |
|
306 | self.__dataReady = False | |
307 |
|
307 | |||
308 |
|
308 | |||
309 | if n == None and timeInterval == None: |
|
309 | if n == None and timeInterval == None: | |
310 | raise ValueError, "n or timeInterval should be specified ..." |
|
310 | raise ValueError, "n or timeInterval should be specified ..." | |
311 |
|
311 | |||
312 | if n != None: |
|
312 | if n != None: | |
313 | self.n = n |
|
313 | self.n = n | |
314 | self.__byTime = False |
|
314 | self.__byTime = False | |
315 | else: |
|
315 | else: | |
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
317 | self.n = 9999 |
|
317 | self.n = 9999 | |
318 | self.__byTime = True |
|
318 | self.__byTime = True | |
319 |
|
319 | |||
320 | if overlapping: |
|
320 | if overlapping: | |
321 | self.__withOverapping = True |
|
321 | self.__withOverapping = True | |
322 | self.__buffer = None |
|
322 | self.__buffer = None | |
323 | else: |
|
323 | else: | |
324 | self.__withOverapping = False |
|
324 | self.__withOverapping = False | |
325 | self.__buffer = 0 |
|
325 | self.__buffer = 0 | |
326 |
|
326 | |||
327 | self.__profIndex = 0 |
|
327 | self.__profIndex = 0 | |
328 |
|
328 | |||
329 | def putData(self, data): |
|
329 | def putData(self, data): | |
330 |
|
330 | |||
331 | """ |
|
331 | """ | |
332 | Add a profile to the __buffer and increase in one the __profileIndex |
|
332 | Add a profile to the __buffer and increase in one the __profileIndex | |
333 |
|
333 | |||
334 | """ |
|
334 | """ | |
335 |
|
335 | |||
336 | if not self.__withOverapping: |
|
336 | if not self.__withOverapping: | |
337 | self.__buffer += data.copy() |
|
337 | self.__buffer += data.copy() | |
338 | self.__profIndex += 1 |
|
338 | self.__profIndex += 1 | |
339 | return |
|
339 | return | |
340 |
|
340 | |||
341 | #Overlapping data |
|
341 | #Overlapping data | |
342 | nChannels, nHeis = data.shape |
|
342 | nChannels, nHeis = data.shape | |
343 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
343 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
344 |
|
344 | |||
345 | #If the buffer is empty then it takes the data value |
|
345 | #If the buffer is empty then it takes the data value | |
346 | if self.__buffer == None: |
|
346 | if self.__buffer == None: | |
347 | self.__buffer = data |
|
347 | self.__buffer = data | |
348 | self.__profIndex += 1 |
|
348 | self.__profIndex += 1 | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 | #If the buffer length is lower than n then stakcing the data value |
|
351 | #If the buffer length is lower than n then stakcing the data value | |
352 | if self.__profIndex < self.n: |
|
352 | if self.__profIndex < self.n: | |
353 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
353 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
354 | self.__profIndex += 1 |
|
354 | self.__profIndex += 1 | |
355 | return |
|
355 | return | |
356 |
|
356 | |||
357 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
357 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
359 | self.__buffer[self.n-1] = data |
|
359 | self.__buffer[self.n-1] = data | |
360 | self.__profIndex = self.n |
|
360 | self.__profIndex = self.n | |
361 | return |
|
361 | return | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | def pushData(self): |
|
364 | def pushData(self): | |
365 | """ |
|
365 | """ | |
366 | Return the sum of the last profiles and the profiles used in the sum. |
|
366 | Return the sum of the last profiles and the profiles used in the sum. | |
367 |
|
367 | |||
368 | Affected: |
|
368 | Affected: | |
369 |
|
369 | |||
370 | self.__profileIndex |
|
370 | self.__profileIndex | |
371 |
|
371 | |||
372 | """ |
|
372 | """ | |
373 |
|
373 | |||
374 | if not self.__withOverapping: |
|
374 | if not self.__withOverapping: | |
375 | data = self.__buffer |
|
375 | data = self.__buffer | |
376 | n = self.__profIndex |
|
376 | n = self.__profIndex | |
377 |
|
377 | |||
378 | self.__buffer = 0 |
|
378 | self.__buffer = 0 | |
379 | self.__profIndex = 0 |
|
379 | self.__profIndex = 0 | |
380 |
|
380 | |||
381 | return data, n |
|
381 | return data, n | |
382 |
|
382 | |||
383 | #Integration with Overlapping |
|
383 | #Integration with Overlapping | |
384 | data = numpy.sum(self.__buffer, axis=0) |
|
384 | data = numpy.sum(self.__buffer, axis=0) | |
385 | n = self.__profIndex |
|
385 | n = self.__profIndex | |
386 |
|
386 | |||
387 | return data, n |
|
387 | return data, n | |
388 |
|
388 | |||
389 | def byProfiles(self, data): |
|
389 | def byProfiles(self, data): | |
390 |
|
390 | |||
391 | self.__dataReady = False |
|
391 | self.__dataReady = False | |
392 | avgdata = None |
|
392 | avgdata = None | |
393 | n = None |
|
393 | n = None | |
394 |
|
394 | |||
395 | self.putData(data) |
|
395 | self.putData(data) | |
396 |
|
396 | |||
397 | if self.__profIndex == self.n: |
|
397 | if self.__profIndex == self.n: | |
398 |
|
398 | |||
399 | avgdata, n = self.pushData() |
|
399 | avgdata, n = self.pushData() | |
400 | self.__dataReady = True |
|
400 | self.__dataReady = True | |
401 |
|
401 | |||
402 | return avgdata |
|
402 | return avgdata | |
403 |
|
403 | |||
404 | def byTime(self, data, datatime): |
|
404 | def byTime(self, data, datatime): | |
405 |
|
405 | |||
406 | self.__dataReady = False |
|
406 | self.__dataReady = False | |
407 | avgdata = None |
|
407 | avgdata = None | |
408 | n = None |
|
408 | n = None | |
409 |
|
409 | |||
410 | self.putData(data) |
|
410 | self.putData(data) | |
411 |
|
411 | |||
412 | if (datatime - self.__initime) >= self.__integrationtime: |
|
412 | if (datatime - self.__initime) >= self.__integrationtime: | |
413 | avgdata, n = self.pushData() |
|
413 | avgdata, n = self.pushData() | |
414 | self.n = n |
|
414 | self.n = n | |
415 | self.__dataReady = True |
|
415 | self.__dataReady = True | |
416 |
|
416 | |||
417 | return avgdata |
|
417 | return avgdata | |
418 |
|
418 | |||
419 | def integrate(self, data, datatime=None): |
|
419 | def integrate(self, data, datatime=None): | |
420 |
|
420 | |||
421 | if self.__initime == None: |
|
421 | if self.__initime == None: | |
422 | self.__initime = datatime |
|
422 | self.__initime = datatime | |
423 |
|
423 | |||
424 | if self.__byTime: |
|
424 | if self.__byTime: | |
425 | avgdata = self.byTime(data, datatime) |
|
425 | avgdata = self.byTime(data, datatime) | |
426 | else: |
|
426 | else: | |
427 | avgdata = self.byProfiles(data) |
|
427 | avgdata = self.byProfiles(data) | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | self.__lastdatatime = datatime |
|
430 | self.__lastdatatime = datatime | |
431 |
|
431 | |||
432 | if avgdata == None: |
|
432 | if avgdata == None: | |
433 | return None, None |
|
433 | return None, None | |
434 |
|
434 | |||
435 | avgdatatime = self.__initime |
|
435 | avgdatatime = self.__initime | |
436 |
|
436 | |||
437 | deltatime = datatime -self.__lastdatatime |
|
437 | deltatime = datatime -self.__lastdatatime | |
438 |
|
438 | |||
439 | if not self.__withOverapping: |
|
439 | if not self.__withOverapping: | |
440 | self.__initime = datatime |
|
440 | self.__initime = datatime | |
441 | else: |
|
441 | else: | |
442 | self.__initime += deltatime |
|
442 | self.__initime += deltatime | |
443 |
|
443 | |||
444 | return avgdata, avgdatatime |
|
444 | return avgdata, avgdatatime | |
445 |
|
445 | |||
446 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
446 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
447 |
|
447 | |||
448 | if not self.__isConfig: |
|
448 | if not self.__isConfig: | |
449 | self.setup(n, timeInterval, overlapping) |
|
449 | self.setup(n, timeInterval, overlapping) | |
450 | self.__isConfig = True |
|
450 | self.__isConfig = True | |
451 |
|
451 | |||
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
453 |
|
453 | |||
454 | # dataOut.timeInterval *= n |
|
454 | # dataOut.timeInterval *= n | |
455 | dataOut.flagNoData = True |
|
455 | dataOut.flagNoData = True | |
456 |
|
456 | |||
457 | if self.__dataReady: |
|
457 | if self.__dataReady: | |
458 | dataOut.data = avgdata |
|
458 | dataOut.data = avgdata | |
459 | dataOut.nCohInt *= self.n |
|
459 | dataOut.nCohInt *= self.n | |
460 | dataOut.utctime = avgdatatime |
|
460 | dataOut.utctime = avgdatatime | |
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
462 | dataOut.flagNoData = False |
|
462 | dataOut.flagNoData = False | |
463 |
|
463 | |||
464 |
|
464 | |||
465 | class SpectraProc(ProcessingUnit): |
|
465 | class SpectraProc(ProcessingUnit): | |
466 |
|
466 | |||
467 | def __init__(self): |
|
467 | def __init__(self): | |
468 |
|
468 | |||
469 | self.objectDict = {} |
|
469 | self.objectDict = {} | |
470 | self.buffer = None |
|
470 | self.buffer = None | |
471 | self.firstdatatime = None |
|
471 | self.firstdatatime = None | |
472 | self.profIndex = 0 |
|
472 | self.profIndex = 0 | |
473 | self.dataOut = Spectra() |
|
473 | self.dataOut = Spectra() | |
474 |
|
474 | |||
475 | def __updateObjFromInput(self): |
|
475 | def __updateObjFromInput(self): | |
476 |
|
476 | |||
477 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
477 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
478 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
478 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
479 | self.dataOut.channelList = self.dataIn.channelList |
|
479 | self.dataOut.channelList = self.dataIn.channelList | |
480 | self.dataOut.heightList = self.dataIn.heightList |
|
480 | self.dataOut.heightList = self.dataIn.heightList | |
481 | self.dataOut.dtype = self.dataIn.dtype |
|
481 | self.dataOut.dtype = self.dataIn.dtype | |
482 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
482 | # self.dataOut.nHeights = self.dataIn.nHeights | |
483 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
483 | # self.dataOut.nChannels = self.dataIn.nChannels | |
484 | self.dataOut.nBaud = self.dataIn.nBaud |
|
484 | self.dataOut.nBaud = self.dataIn.nBaud | |
485 | self.dataOut.nCode = self.dataIn.nCode |
|
485 | self.dataOut.nCode = self.dataIn.nCode | |
486 | self.dataOut.code = self.dataIn.code |
|
486 | self.dataOut.code = self.dataIn.code | |
487 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
487 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
488 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
488 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
489 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
489 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
490 | self.dataOut.utctime = self.firstdatatime |
|
490 | self.dataOut.utctime = self.firstdatatime | |
491 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
491 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
492 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
492 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
493 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
493 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
494 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
494 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
495 | self.dataOut.nIncohInt = 1 |
|
495 | self.dataOut.nIncohInt = 1 | |
496 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
496 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
497 |
self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints* |
|
497 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nConInt*self.dataOut.nIncohInt | |
498 |
|
498 | |||
499 | def __getFft(self): |
|
499 | def __getFft(self): | |
500 | """ |
|
500 | """ | |
501 | Convierte valores de Voltaje a Spectra |
|
501 | Convierte valores de Voltaje a Spectra | |
502 |
|
502 | |||
503 | Affected: |
|
503 | Affected: | |
504 | self.dataOut.data_spc |
|
504 | self.dataOut.data_spc | |
505 | self.dataOut.data_cspc |
|
505 | self.dataOut.data_cspc | |
506 | self.dataOut.data_dc |
|
506 | self.dataOut.data_dc | |
507 | self.dataOut.heightList |
|
507 | self.dataOut.heightList | |
508 | self.dataOut.m_BasicHeader |
|
508 | self.dataOut.m_BasicHeader | |
509 | self.dataOut.m_ProcessingHeader |
|
509 | self.dataOut.m_ProcessingHeader | |
510 | self.dataOut.radarControllerHeaderObj |
|
510 | self.dataOut.radarControllerHeaderObj | |
511 | self.dataOut.systemHeaderObj |
|
511 | self.dataOut.systemHeaderObj | |
512 | self.profIndex |
|
512 | self.profIndex | |
513 | self.buffer |
|
513 | self.buffer | |
514 | self.dataOut.flagNoData |
|
514 | self.dataOut.flagNoData | |
515 | self.dataOut.dtype |
|
515 | self.dataOut.dtype | |
516 | self.dataOut.nPairs |
|
516 | self.dataOut.nPairs | |
517 | self.dataOut.nChannels |
|
517 | self.dataOut.nChannels | |
518 | self.dataOut.nProfiles |
|
518 | self.dataOut.nProfiles | |
519 | self.dataOut.systemHeaderObj.numChannels |
|
519 | self.dataOut.systemHeaderObj.numChannels | |
520 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
520 | self.dataOut.m_ProcessingHeader.totalSpectra | |
521 | self.dataOut.m_ProcessingHeader.profilesPerBlock |
|
521 | self.dataOut.m_ProcessingHeader.profilesPerBlock | |
522 | self.dataOut.m_ProcessingHeader.numHeights |
|
522 | self.dataOut.m_ProcessingHeader.numHeights | |
523 | self.dataOut.m_ProcessingHeader.spectraComb |
|
523 | self.dataOut.m_ProcessingHeader.spectraComb | |
524 | self.dataOut.m_ProcessingHeader.shif_fft |
|
524 | self.dataOut.m_ProcessingHeader.shif_fft | |
525 | """ |
|
525 | """ | |
526 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
526 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
527 | dc = fft_volt[:,0,:] |
|
527 | dc = fft_volt[:,0,:] | |
528 |
|
528 | |||
529 | #calculo de self-spectra |
|
529 | #calculo de self-spectra | |
530 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
530 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
531 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
531 | spc = fft_volt * numpy.conjugate(fft_volt) | |
532 | spc = spc.real |
|
532 | spc = spc.real | |
533 |
|
533 | |||
534 | blocksize = 0 |
|
534 | blocksize = 0 | |
535 | blocksize += dc.size |
|
535 | blocksize += dc.size | |
536 | blocksize += spc.size |
|
536 | blocksize += spc.size | |
537 |
|
537 | |||
538 | cspc = None |
|
538 | cspc = None | |
539 | pairIndex = 0 |
|
539 | pairIndex = 0 | |
540 | if self.dataOut.pairsList != None: |
|
540 | if self.dataOut.pairsList != None: | |
541 | #calculo de cross-spectra |
|
541 | #calculo de cross-spectra | |
542 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
542 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
543 | for pair in self.dataOut.pairsList: |
|
543 | for pair in self.dataOut.pairsList: | |
544 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
544 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
545 | pairIndex += 1 |
|
545 | pairIndex += 1 | |
546 | blocksize += cspc.size |
|
546 | blocksize += cspc.size | |
547 |
|
547 | |||
548 | self.dataOut.data_spc = spc |
|
548 | self.dataOut.data_spc = spc | |
549 | self.dataOut.data_cspc = cspc |
|
549 | self.dataOut.data_cspc = cspc | |
550 | self.dataOut.data_dc = dc |
|
550 | self.dataOut.data_dc = dc | |
551 | self.dataOut.blockSize = blocksize |
|
551 | self.dataOut.blockSize = blocksize | |
552 |
|
552 | |||
553 | def init(self, nFFTPoints=None, pairsList=None): |
|
553 | def init(self, nFFTPoints=None, pairsList=None): | |
554 |
|
554 | |||
555 | if self.dataIn.type == "Spectra": |
|
555 | if self.dataIn.type == "Spectra": | |
556 | self.dataOut.copy(self.dataIn) |
|
556 | self.dataOut.copy(self.dataIn) | |
557 | return |
|
557 | return | |
558 |
|
558 | |||
559 | if self.dataIn.type == "Voltage": |
|
559 | if self.dataIn.type == "Voltage": | |
560 |
|
560 | |||
561 | if nFFTPoints == None: |
|
561 | if nFFTPoints == None: | |
562 |
raise ValueError, "This SpectraProc. |
|
562 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
563 |
|
563 | |||
564 | if pairsList == None: |
|
564 | if pairsList == None: | |
565 | nPairs = 0 |
|
565 | nPairs = 0 | |
566 | else: |
|
566 | else: | |
567 | nPairs = len(pairsList) |
|
567 | nPairs = len(pairsList) | |
568 |
|
568 | |||
569 | self.dataOut.nFFTPoints = nFFTPoints |
|
569 | self.dataOut.nFFTPoints = nFFTPoints | |
570 | self.dataOut.pairsList = pairsList |
|
570 | self.dataOut.pairsList = pairsList | |
571 | self.dataOut.nPairs = nPairs |
|
571 | self.dataOut.nPairs = nPairs | |
572 |
|
572 | |||
573 | if self.buffer == None: |
|
573 | if self.buffer == None: | |
574 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
574 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
575 | self.dataOut.nFFTPoints, |
|
575 | self.dataOut.nFFTPoints, | |
576 | self.dataIn.nHeights), |
|
576 | self.dataIn.nHeights), | |
577 | dtype='complex') |
|
577 | dtype='complex') | |
578 |
|
578 | |||
579 |
|
579 | |||
580 | self.buffer[:,self.profIndex,:] = self.dataIn.data |
|
580 | self.buffer[:,self.profIndex,:] = self.dataIn.data | |
581 | self.profIndex += 1 |
|
581 | self.profIndex += 1 | |
582 |
|
582 | |||
583 | if self.firstdatatime == None: |
|
583 | if self.firstdatatime == None: | |
584 | self.firstdatatime = self.dataIn.utctime |
|
584 | self.firstdatatime = self.dataIn.utctime | |
585 |
|
585 | |||
586 | if self.profIndex == self.dataOut.nFFTPoints: |
|
586 | if self.profIndex == self.dataOut.nFFTPoints: | |
587 | self.__updateObjFromInput() |
|
587 | self.__updateObjFromInput() | |
588 | self.__getFft() |
|
588 | self.__getFft() | |
589 |
|
589 | |||
590 | self.dataOut.flagNoData = False |
|
590 | self.dataOut.flagNoData = False | |
591 |
|
591 | |||
592 | self.buffer = None |
|
592 | self.buffer = None | |
593 | self.firstdatatime = None |
|
593 | self.firstdatatime = None | |
594 | self.profIndex = 0 |
|
594 | self.profIndex = 0 | |
595 |
|
595 | |||
596 | return |
|
596 | return | |
597 |
|
597 | |||
598 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
598 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
599 |
|
599 | |||
600 | def selectChannels(self, channelList): |
|
600 | def selectChannels(self, channelList): | |
601 |
|
601 | |||
602 | channelIndexList = [] |
|
602 | channelIndexList = [] | |
603 |
|
603 | |||
604 | for channel in channelList: |
|
604 | for channel in channelList: | |
605 | index = self.dataOut.channelList.index(channel) |
|
605 | index = self.dataOut.channelList.index(channel) | |
606 | channelIndexList.append(index) |
|
606 | channelIndexList.append(index) | |
607 |
|
607 | |||
608 | self.selectChannelsByIndex(channelIndexList) |
|
608 | self.selectChannelsByIndex(channelIndexList) | |
609 |
|
609 | |||
610 | def selectChannelsByIndex(self, channelIndexList): |
|
610 | def selectChannelsByIndex(self, channelIndexList): | |
611 | """ |
|
611 | """ | |
612 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
612 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
613 |
|
613 | |||
614 | Input: |
|
614 | Input: | |
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
616 |
|
616 | |||
617 | Affected: |
|
617 | Affected: | |
618 | self.dataOut.data_spc |
|
618 | self.dataOut.data_spc | |
619 | self.dataOut.channelIndexList |
|
619 | self.dataOut.channelIndexList | |
620 | self.dataOut.nChannels |
|
620 | self.dataOut.nChannels | |
621 |
|
621 | |||
622 | Return: |
|
622 | Return: | |
623 | None |
|
623 | None | |
624 | """ |
|
624 | """ | |
625 |
|
625 | |||
626 | for channelIndex in channelIndexList: |
|
626 | for channelIndex in channelIndexList: | |
627 | if channelIndex not in self.dataOut.channelIndexList: |
|
627 | if channelIndex not in self.dataOut.channelIndexList: | |
628 | print channelIndexList |
|
628 | print channelIndexList | |
629 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
629 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
630 |
|
630 | |||
631 | nChannels = len(channelIndexList) |
|
631 | nChannels = len(channelIndexList) | |
632 |
|
632 | |||
633 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
633 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
634 |
|
634 | |||
635 | self.dataOut.data_spc = data_spc |
|
635 | self.dataOut.data_spc = data_spc | |
636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
637 | # self.dataOut.nChannels = nChannels |
|
637 | # self.dataOut.nChannels = nChannels | |
638 |
|
638 | |||
639 | return 1 |
|
639 | return 1 | |
640 |
|
640 | |||
641 |
|
641 | |||
642 | class IncohInt(Operation): |
|
642 | class IncohInt(Operation): | |
643 |
|
643 | |||
644 |
|
644 | |||
645 | __profIndex = 0 |
|
645 | __profIndex = 0 | |
646 | __withOverapping = False |
|
646 | __withOverapping = False | |
647 |
|
647 | |||
648 | __byTime = False |
|
648 | __byTime = False | |
649 | __initime = None |
|
649 | __initime = None | |
650 | __lastdatatime = None |
|
650 | __lastdatatime = None | |
651 | __integrationtime = None |
|
651 | __integrationtime = None | |
652 |
|
652 | |||
653 | __buffer_spc = None |
|
653 | __buffer_spc = None | |
654 | __buffer_cspc = None |
|
654 | __buffer_cspc = None | |
655 | __buffer_dc = None |
|
655 | __buffer_dc = None | |
656 |
|
656 | |||
657 | __dataReady = False |
|
657 | __dataReady = False | |
658 |
|
658 | |||
659 | n = None |
|
659 | n = None | |
660 |
|
660 | |||
661 |
|
661 | |||
662 | def __init__(self): |
|
662 | def __init__(self): | |
663 |
|
663 | |||
664 | self.__isConfig = False |
|
664 | self.__isConfig = False | |
665 |
|
665 | |||
666 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
666 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
667 | """ |
|
667 | """ | |
668 | Set the parameters of the integration class. |
|
668 | Set the parameters of the integration class. | |
669 |
|
669 | |||
670 | Inputs: |
|
670 | Inputs: | |
671 |
|
671 | |||
672 | n : Number of coherent integrations |
|
672 | n : Number of coherent integrations | |
673 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
673 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
674 | overlapping : |
|
674 | overlapping : | |
675 |
|
675 | |||
676 | """ |
|
676 | """ | |
677 |
|
677 | |||
678 | self.__initime = None |
|
678 | self.__initime = None | |
679 | self.__lastdatatime = 0 |
|
679 | self.__lastdatatime = 0 | |
680 | self.__buffer_spc = None |
|
680 | self.__buffer_spc = None | |
681 | self.__buffer_cspc = None |
|
681 | self.__buffer_cspc = None | |
682 | self.__buffer_dc = None |
|
682 | self.__buffer_dc = None | |
683 | self.__dataReady = False |
|
683 | self.__dataReady = False | |
684 |
|
684 | |||
685 |
|
685 | |||
686 | if n == None and timeInterval == None: |
|
686 | if n == None and timeInterval == None: | |
687 | raise ValueError, "n or timeInterval should be specified ..." |
|
687 | raise ValueError, "n or timeInterval should be specified ..." | |
688 |
|
688 | |||
689 | if n != None: |
|
689 | if n != None: | |
690 | self.n = n |
|
690 | self.n = n | |
691 | self.__byTime = False |
|
691 | self.__byTime = False | |
692 | else: |
|
692 | else: | |
693 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
693 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
694 | self.n = 9999 |
|
694 | self.n = 9999 | |
695 | self.__byTime = True |
|
695 | self.__byTime = True | |
696 |
|
696 | |||
697 | if overlapping: |
|
697 | if overlapping: | |
698 | self.__withOverapping = True |
|
698 | self.__withOverapping = True | |
699 | else: |
|
699 | else: | |
700 | self.__withOverapping = False |
|
700 | self.__withOverapping = False | |
701 | self.__buffer_spc = 0 |
|
701 | self.__buffer_spc = 0 | |
702 | self.__buffer_cspc = 0 |
|
702 | self.__buffer_cspc = 0 | |
703 | self.__buffer_dc = 0 |
|
703 | self.__buffer_dc = 0 | |
704 |
|
704 | |||
705 | self.__profIndex = 0 |
|
705 | self.__profIndex = 0 | |
706 |
|
706 | |||
707 | def putData(self, data_spc, data_cspc, data_dc): |
|
707 | def putData(self, data_spc, data_cspc, data_dc): | |
708 |
|
708 | |||
709 | """ |
|
709 | """ | |
710 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
710 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
711 |
|
711 | |||
712 | """ |
|
712 | """ | |
713 |
|
713 | |||
714 | if not self.__withOverapping: |
|
714 | if not self.__withOverapping: | |
715 | self.__buffer_spc += data_spc |
|
715 | self.__buffer_spc += data_spc | |
716 |
|
716 | |||
717 | if data_cspc == None: |
|
717 | if data_cspc == None: | |
718 | self.__buffer_cspc = None |
|
718 | self.__buffer_cspc = None | |
719 | else: |
|
719 | else: | |
720 | self.__buffer_cspc += data_cspc |
|
720 | self.__buffer_cspc += data_cspc | |
721 |
|
721 | |||
722 | if data_dc == None: |
|
722 | if data_dc == None: | |
723 | self.__buffer_dc = None |
|
723 | self.__buffer_dc = None | |
724 | else: |
|
724 | else: | |
725 | self.__buffer_dc += data_dc |
|
725 | self.__buffer_dc += data_dc | |
726 |
|
726 | |||
727 | self.__profIndex += 1 |
|
727 | self.__profIndex += 1 | |
728 | return |
|
728 | return | |
729 |
|
729 | |||
730 | #Overlapping data |
|
730 | #Overlapping data | |
731 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
731 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
732 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
732 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
733 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
733 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
734 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
734 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
735 |
|
735 | |||
736 | #If the buffer is empty then it takes the data value |
|
736 | #If the buffer is empty then it takes the data value | |
737 | if self.__buffer_spc == None: |
|
737 | if self.__buffer_spc == None: | |
738 | self.__buffer_spc = data_spc.copy() |
|
738 | self.__buffer_spc = data_spc.copy() | |
739 |
|
739 | |||
740 | if data_cspc == None: |
|
740 | if data_cspc == None: | |
741 | self.__buffer_cspc = None |
|
741 | self.__buffer_cspc = None | |
742 | else: |
|
742 | else: | |
743 | self.__buffer_cspc += data_cspc.copy() |
|
743 | self.__buffer_cspc += data_cspc.copy() | |
744 |
|
744 | |||
745 | if data_dc == None: |
|
745 | if data_dc == None: | |
746 | self.__buffer_dc = None |
|
746 | self.__buffer_dc = None | |
747 | else: |
|
747 | else: | |
748 | self.__buffer_dc += data_dc.copy() |
|
748 | self.__buffer_dc += data_dc.copy() | |
749 |
|
749 | |||
750 | self.__profIndex += 1 |
|
750 | self.__profIndex += 1 | |
751 | return |
|
751 | return | |
752 |
|
752 | |||
753 | #If the buffer length is lower than n then stakcing the data value |
|
753 | #If the buffer length is lower than n then stakcing the data value | |
754 | if self.__profIndex < self.n: |
|
754 | if self.__profIndex < self.n: | |
755 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
755 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
756 |
|
756 | |||
757 | if self.__buffer_cspc != None: |
|
757 | if self.__buffer_cspc != None: | |
758 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
758 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
759 |
|
759 | |||
760 | if self.__buffer_dc != None: |
|
760 | if self.__buffer_dc != None: | |
761 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
761 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
762 |
|
762 | |||
763 | self.__profIndex += 1 |
|
763 | self.__profIndex += 1 | |
764 | return |
|
764 | return | |
765 |
|
765 | |||
766 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
766 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
767 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
767 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
768 | self.__buffer_spc[self.n-1] = data_spc |
|
768 | self.__buffer_spc[self.n-1] = data_spc | |
769 |
|
769 | |||
770 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
770 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
771 | self.__buffer_cspc[self.n-1] = data_cspc |
|
771 | self.__buffer_cspc[self.n-1] = data_cspc | |
772 |
|
772 | |||
773 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
773 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
774 | self.__buffer_dc[self.n-1] = data_dc |
|
774 | self.__buffer_dc[self.n-1] = data_dc | |
775 |
|
775 | |||
776 | self.__profIndex = self.n |
|
776 | self.__profIndex = self.n | |
777 | return |
|
777 | return | |
778 |
|
778 | |||
779 |
|
779 | |||
780 | def pushData(self): |
|
780 | def pushData(self): | |
781 | """ |
|
781 | """ | |
782 | Return the sum of the last profiles and the profiles used in the sum. |
|
782 | Return the sum of the last profiles and the profiles used in the sum. | |
783 |
|
783 | |||
784 | Affected: |
|
784 | Affected: | |
785 |
|
785 | |||
786 | self.__profileIndex |
|
786 | self.__profileIndex | |
787 |
|
787 | |||
788 | """ |
|
788 | """ | |
789 | data_spc = None |
|
789 | data_spc = None | |
790 | data_cspc = None |
|
790 | data_cspc = None | |
791 | data_dc = None |
|
791 | data_dc = None | |
792 |
|
792 | |||
793 | if not self.__withOverapping: |
|
793 | if not self.__withOverapping: | |
794 | data_spc = self.__buffer_spc |
|
794 | data_spc = self.__buffer_spc | |
795 | data_cspc = self.__buffer_cspc |
|
795 | data_cspc = self.__buffer_cspc | |
796 | data_dc = self.__buffer_dc |
|
796 | data_dc = self.__buffer_dc | |
797 |
|
797 | |||
798 | n = self.__profIndex |
|
798 | n = self.__profIndex | |
799 |
|
799 | |||
800 | self.__buffer_spc = 0 |
|
800 | self.__buffer_spc = 0 | |
801 | self.__buffer_cspc = 0 |
|
801 | self.__buffer_cspc = 0 | |
802 | self.__buffer_dc = 0 |
|
802 | self.__buffer_dc = 0 | |
803 | self.__profIndex = 0 |
|
803 | self.__profIndex = 0 | |
804 |
|
804 | |||
805 | return data_spc, data_cspc, data_dc, n |
|
805 | return data_spc, data_cspc, data_dc, n | |
806 |
|
806 | |||
807 | #Integration with Overlapping |
|
807 | #Integration with Overlapping | |
808 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
808 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
809 |
|
809 | |||
810 | if self.__buffer_cspc != None: |
|
810 | if self.__buffer_cspc != None: | |
811 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
811 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
812 |
|
812 | |||
813 | if self.__buffer_dc != None: |
|
813 | if self.__buffer_dc != None: | |
814 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
814 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
815 |
|
815 | |||
816 | n = self.__profIndex |
|
816 | n = self.__profIndex | |
817 |
|
817 | |||
818 | return data_spc, data_cspc, data_dc, n |
|
818 | return data_spc, data_cspc, data_dc, n | |
819 |
|
819 | |||
820 | def byProfiles(self, *args): |
|
820 | def byProfiles(self, *args): | |
821 |
|
821 | |||
822 | self.__dataReady = False |
|
822 | self.__dataReady = False | |
823 | avgdata_spc = None |
|
823 | avgdata_spc = None | |
824 | avgdata_cspc = None |
|
824 | avgdata_cspc = None | |
825 | avgdata_dc = None |
|
825 | avgdata_dc = None | |
826 | n = None |
|
826 | n = None | |
827 |
|
827 | |||
828 | self.putData(*args) |
|
828 | self.putData(*args) | |
829 |
|
829 | |||
830 | if self.__profIndex == self.n: |
|
830 | if self.__profIndex == self.n: | |
831 |
|
831 | |||
832 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
832 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
833 | self.__dataReady = True |
|
833 | self.__dataReady = True | |
834 |
|
834 | |||
835 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
835 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
836 |
|
836 | |||
837 | def byTime(self, datatime, *args): |
|
837 | def byTime(self, datatime, *args): | |
838 |
|
838 | |||
839 | self.__dataReady = False |
|
839 | self.__dataReady = False | |
840 | avgdata_spc = None |
|
840 | avgdata_spc = None | |
841 | avgdata_cspc = None |
|
841 | avgdata_cspc = None | |
842 | avgdata_dc = None |
|
842 | avgdata_dc = None | |
843 | n = None |
|
843 | n = None | |
844 |
|
844 | |||
845 | self.putData(*args) |
|
845 | self.putData(*args) | |
846 |
|
846 | |||
847 | if (datatime - self.__initime) >= self.__integrationtime: |
|
847 | if (datatime - self.__initime) >= self.__integrationtime: | |
848 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
848 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
849 | self.n = n |
|
849 | self.n = n | |
850 | self.__dataReady = True |
|
850 | self.__dataReady = True | |
851 |
|
851 | |||
852 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
852 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
853 |
|
853 | |||
854 | def integrate(self, datatime, *args): |
|
854 | def integrate(self, datatime, *args): | |
855 |
|
855 | |||
856 | if self.__initime == None: |
|
856 | if self.__initime == None: | |
857 | self.__initime = datatime |
|
857 | self.__initime = datatime | |
858 |
|
858 | |||
859 | if self.__byTime: |
|
859 | if self.__byTime: | |
860 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
860 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
861 | else: |
|
861 | else: | |
862 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
862 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
863 |
|
863 | |||
864 | self.__lastdatatime = datatime |
|
864 | self.__lastdatatime = datatime | |
865 |
|
865 | |||
866 | if avgdata_spc == None: |
|
866 | if avgdata_spc == None: | |
867 | return None, None, None, None |
|
867 | return None, None, None, None | |
868 |
|
868 | |||
869 | avgdatatime = self.__initime |
|
869 | avgdatatime = self.__initime | |
870 |
|
870 | |||
871 | deltatime = datatime -self.__lastdatatime |
|
871 | deltatime = datatime -self.__lastdatatime | |
872 |
|
872 | |||
873 | if not self.__withOverapping: |
|
873 | if not self.__withOverapping: | |
874 | self.__initime = datatime |
|
874 | self.__initime = datatime | |
875 | else: |
|
875 | else: | |
876 | self.__initime += deltatime |
|
876 | self.__initime += deltatime | |
877 |
|
877 | |||
878 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
878 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
879 |
|
879 | |||
880 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
880 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
881 |
|
881 | |||
882 | if not self.__isConfig: |
|
882 | if not self.__isConfig: | |
883 | self.setup(n, timeInterval, overlapping) |
|
883 | self.setup(n, timeInterval, overlapping) | |
884 | self.__isConfig = True |
|
884 | self.__isConfig = True | |
885 |
|
885 | |||
886 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
886 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
887 | dataOut.data_spc, |
|
887 | dataOut.data_spc, | |
888 | dataOut.data_cspc, |
|
888 | dataOut.data_cspc, | |
889 | dataOut.data_dc) |
|
889 | dataOut.data_dc) | |
890 |
|
890 | |||
891 | # dataOut.timeInterval *= n |
|
891 | # dataOut.timeInterval *= n | |
892 | dataOut.flagNoData = True |
|
892 | dataOut.flagNoData = True | |
893 |
|
893 | |||
894 | if self.__dataReady: |
|
894 | if self.__dataReady: | |
895 | dataOut.data_spc = avgdata_spc |
|
895 | dataOut.data_spc = avgdata_spc | |
896 | dataOut.data_cspc = avgdata_cspc |
|
896 | dataOut.data_cspc = avgdata_cspc | |
897 | dataOut.data_dc = avgdata_dc |
|
897 | dataOut.data_dc = avgdata_dc | |
898 |
|
898 | |||
899 | dataOut.nIncohInt *= self.n |
|
899 | dataOut.nIncohInt *= self.n | |
900 | dataOut.utctime = avgdatatime |
|
900 | dataOut.utctime = avgdatatime | |
901 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
901 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
902 | dataOut.flagNoData = False |
|
902 | dataOut.flagNoData = False | |
903 | No newline at end of file |
|
903 |
General Comments 0
You need to be logged in to leave comments.
Login now