@@ -1,534 +1,534 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | import sys |
|
7 | 7 | import numpy |
|
8 | 8 | import copy |
|
9 | 9 | import datetime |
|
10 | 10 | |
|
11 | 11 | class Header: |
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | raise |
|
15 | 15 | |
|
16 | 16 | def copy(self): |
|
17 | 17 | return copy.deepcopy(self) |
|
18 | 18 | |
|
19 | 19 | def read(): |
|
20 | 20 | pass |
|
21 | 21 | |
|
22 | 22 | def write(): |
|
23 | 23 | pass |
|
24 | 24 | |
|
25 | 25 | def printInfo(self): |
|
26 | 26 | |
|
27 | 27 | print "#"*100 |
|
28 | 28 | print self.__class__.__name__.upper() |
|
29 | 29 | print "#"*100 |
|
30 | 30 | for key in self.__dict__.keys(): |
|
31 | 31 | print "%s = %s" %(key, self.__dict__[key]) |
|
32 | 32 | |
|
33 | 33 | class BasicHeader(Header): |
|
34 | 34 | |
|
35 | 35 | size = None |
|
36 | 36 | version = None |
|
37 | 37 | dataBlock = None |
|
38 | 38 | utc = None |
|
39 | 39 | ltc = None |
|
40 | 40 | miliSecond = None |
|
41 | 41 | timeZone = None |
|
42 | 42 | dstFlag = None |
|
43 | 43 | errorCount = None |
|
44 | 44 | struct = None |
|
45 | 45 | datatime = None |
|
46 | 46 | |
|
47 | 47 | __LOCALTIME = None |
|
48 | 48 | |
|
49 | 49 | def __init__(self, useLocalTime=True): |
|
50 | 50 | |
|
51 | 51 | self.size = 0 |
|
52 | 52 | self.version = 0 |
|
53 | 53 | self.dataBlock = 0 |
|
54 | 54 | self.utc = 0 |
|
55 | 55 | self.miliSecond = 0 |
|
56 | 56 | self.timeZone = 0 |
|
57 | 57 | self.dstFlag = 0 |
|
58 | 58 | self.errorCount = 0 |
|
59 | 59 | self.struct = numpy.dtype([ |
|
60 | 60 | ('nSize','<u4'), |
|
61 | 61 | ('nVersion','<u2'), |
|
62 | 62 | ('nDataBlockId','<u4'), |
|
63 | 63 | ('nUtime','<u4'), |
|
64 | 64 | ('nMilsec','<u2'), |
|
65 | 65 | ('nTimezone','<i2'), |
|
66 | 66 | ('nDstflag','<i2'), |
|
67 | 67 | ('nErrorCount','<u4') |
|
68 | 68 | ]) |
|
69 | 69 | |
|
70 | 70 | self.useLocalTime = useLocalTime |
|
71 | 71 | |
|
72 | 72 | def read(self, fp): |
|
73 | 73 | try: |
|
74 | 74 | header = numpy.fromfile(fp, self.struct,1) |
|
75 | 75 | self.size = int(header['nSize'][0]) |
|
76 | 76 | self.version = int(header['nVersion'][0]) |
|
77 | 77 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
78 | 78 | self.utc = int(header['nUtime'][0]) |
|
79 | 79 | self.miliSecond = int(header['nMilsec'][0]) |
|
80 | 80 | self.timeZone = int(header['nTimezone'][0]) |
|
81 | 81 | self.dstFlag = int(header['nDstflag'][0]) |
|
82 | 82 | self.errorCount = int(header['nErrorCount'][0]) |
|
83 | 83 | |
|
84 | 84 | self.ltc = self.utc |
|
85 | 85 | |
|
86 | 86 | if self.useLocalTime: |
|
87 | 87 | self.ltc -= self.timeZone*60 |
|
88 | 88 | |
|
89 | 89 | self.datatime = datetime.datetime.utcfromtimestamp(self.ltc) |
|
90 | 90 | |
|
91 | 91 | except Exception, e: |
|
92 | 92 | print "BasicHeader: " |
|
93 | 93 | print e |
|
94 | 94 | return 0 |
|
95 | 95 | |
|
96 | 96 | return 1 |
|
97 | 97 | |
|
98 | 98 | def write(self, fp): |
|
99 | 99 | |
|
100 | 100 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
101 | 101 | header = numpy.array(headerTuple,self.struct) |
|
102 | 102 | header.tofile(fp) |
|
103 | 103 | |
|
104 | 104 | return 1 |
|
105 | 105 | |
|
106 | 106 | class SystemHeader(Header): |
|
107 | 107 | |
|
108 | 108 | size = None |
|
109 | 109 | nSamples = None |
|
110 | 110 | nProfiles = None |
|
111 | 111 | nChannels = None |
|
112 | 112 | adcResolution = None |
|
113 | 113 | pciDioBusWidth = None |
|
114 | 114 | struct = None |
|
115 | 115 | |
|
116 | 116 | def __init__(self): |
|
117 | 117 | self.size = 0 |
|
118 | 118 | self.nSamples = 0 |
|
119 | 119 | self.nProfiles = 0 |
|
120 | 120 | self.nChannels = 0 |
|
121 | 121 | self.adcResolution = 0 |
|
122 | 122 | self.pciDioBusWidth = 0 |
|
123 | 123 | self.struct = numpy.dtype([ |
|
124 | 124 | ('nSize','<u4'), |
|
125 | 125 | ('nNumSamples','<u4'), |
|
126 | 126 | ('nNumProfiles','<u4'), |
|
127 | 127 | ('nNumChannels','<u4'), |
|
128 | 128 | ('nADCResolution','<u4'), |
|
129 | 129 | ('nPCDIOBusWidth','<u4'), |
|
130 | 130 | ]) |
|
131 | 131 | |
|
132 | 132 | |
|
133 | 133 | def read(self, fp): |
|
134 | 134 | try: |
|
135 | 135 | header = numpy.fromfile(fp,self.struct,1) |
|
136 | 136 | self.size = header['nSize'][0] |
|
137 | 137 | self.nSamples = header['nNumSamples'][0] |
|
138 | 138 | self.nProfiles = header['nNumProfiles'][0] |
|
139 | 139 | self.nChannels = header['nNumChannels'][0] |
|
140 | 140 | self.adcResolution = header['nADCResolution'][0] |
|
141 | 141 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
142 | 142 | |
|
143 | 143 | except Exception, e: |
|
144 | 144 | print "SystemHeader: " + e |
|
145 | 145 | return 0 |
|
146 | 146 | |
|
147 | 147 | return 1 |
|
148 | 148 | |
|
149 | 149 | def write(self, fp): |
|
150 | 150 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
151 | 151 | header = numpy.array(headerTuple,self.struct) |
|
152 | 152 | header.tofile(fp) |
|
153 | 153 | |
|
154 | 154 | return 1 |
|
155 | 155 | |
|
156 | 156 | class RadarControllerHeader(Header): |
|
157 | 157 | |
|
158 | 158 | size = None |
|
159 | 159 | expType = None |
|
160 | 160 | nTx = None |
|
161 | 161 | ipp = None |
|
162 | 162 | txA = None |
|
163 | 163 | txB = None |
|
164 | 164 | nWindows = None |
|
165 | 165 | numTaus = None |
|
166 | 166 | codeType = None |
|
167 | 167 | line6Function = None |
|
168 | 168 | line5Function = None |
|
169 | 169 | fClock = None |
|
170 | 170 | prePulseBefore = None |
|
171 | 171 | prePulserAfter = None |
|
172 | 172 | rangeIpp = None |
|
173 | 173 | rangeTxA = None |
|
174 | 174 | rangeTxB = None |
|
175 | 175 | struct = None |
|
176 | 176 | |
|
177 | 177 | def __init__(self): |
|
178 | 178 | self.size = 0 |
|
179 | 179 | self.expType = 0 |
|
180 | 180 | self.nTx = 0 |
|
181 | 181 | self.ipp = 0 |
|
182 | 182 | self.txA = 0 |
|
183 | 183 | self.txB = 0 |
|
184 | 184 | self.nWindows = 0 |
|
185 | 185 | self.numTaus = 0 |
|
186 | 186 | self.codeType = 0 |
|
187 | 187 | self.line6Function = 0 |
|
188 | 188 | self.line5Function = 0 |
|
189 | 189 | self.fClock = 0 |
|
190 | 190 | self.prePulseBefore = 0 |
|
191 | 191 | self.prePulserAfter = 0 |
|
192 | 192 | self.rangeIpp = 0 |
|
193 | 193 | self.rangeTxA = 0 |
|
194 | 194 | self.rangeTxB = 0 |
|
195 | 195 | self.struct = numpy.dtype([ |
|
196 | 196 | ('nSize','<u4'), |
|
197 | 197 | ('nExpType','<u4'), |
|
198 | 198 | ('nNTx','<u4'), |
|
199 | 199 | ('fIpp','<f4'), |
|
200 | 200 | ('fTxA','<f4'), |
|
201 | 201 | ('fTxB','<f4'), |
|
202 | 202 | ('nNumWindows','<u4'), |
|
203 | 203 | ('nNumTaus','<u4'), |
|
204 | 204 | ('nCodeType','<u4'), |
|
205 | 205 | ('nLine6Function','<u4'), |
|
206 | 206 | ('nLine5Function','<u4'), |
|
207 | 207 | ('fClock','<f4'), |
|
208 | 208 | ('nPrePulseBefore','<u4'), |
|
209 | 209 | ('nPrePulseAfter','<u4'), |
|
210 | 210 | ('sRangeIPP','<a20'), |
|
211 | 211 | ('sRangeTxA','<a20'), |
|
212 | 212 | ('sRangeTxB','<a20'), |
|
213 | 213 | ]) |
|
214 | 214 | |
|
215 | 215 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
216 | 216 | |
|
217 | 217 | self.samplingWindow = None |
|
218 | 218 | self.nHeights = None |
|
219 | 219 | self.firstHeight = None |
|
220 | 220 | self.deltaHeight = None |
|
221 | 221 | self.samplesWin = None |
|
222 | 222 | |
|
223 | 223 | self.nCode = None |
|
224 | 224 | self.nBaud = None |
|
225 | 225 | self.code = None |
|
226 | 226 | self.flip1 = None |
|
227 | 227 | self.flip2 = None |
|
228 | 228 | |
|
229 | 229 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
230 | 230 | |
|
231 | 231 | |
|
232 | 232 | def read(self, fp): |
|
233 | 233 | try: |
|
234 | 234 | startFp = fp.tell() |
|
235 | 235 | header = numpy.fromfile(fp,self.struct,1) |
|
236 | 236 | self.size = int(header['nSize'][0]) |
|
237 | 237 | self.expType = int(header['nExpType'][0]) |
|
238 | 238 | self.nTx = int(header['nNTx'][0]) |
|
239 | 239 | self.ipp = float(header['fIpp'][0]) |
|
240 | 240 | self.txA = float(header['fTxA'][0]) |
|
241 | 241 | self.txB = float(header['fTxB'][0]) |
|
242 | 242 | self.nWindows = int(header['nNumWindows'][0]) |
|
243 | 243 | self.numTaus = int(header['nNumTaus'][0]) |
|
244 | 244 | self.codeType = int(header['nCodeType'][0]) |
|
245 | 245 | self.line6Function = int(header['nLine6Function'][0]) |
|
246 | 246 | self.line5Function = int(header['nLine5Function'][0]) |
|
247 | 247 | self.fClock = float(header['fClock'][0]) |
|
248 | 248 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
249 | 249 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
250 | 250 | self.rangeIpp = header['sRangeIPP'][0] |
|
251 | 251 | self.rangeTxA = header['sRangeTxA'][0] |
|
252 | 252 | self.rangeTxB = header['sRangeTxB'][0] |
|
253 | 253 | # jump Dynamic Radar Controller Header |
|
254 | 254 | jumpFp = self.size - 116 |
|
255 | 255 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
256 | 256 | #pointer backward to dynamic header and read |
|
257 | 257 | backFp = fp.tell() - jumpFp |
|
258 | 258 | fp.seek(backFp) |
|
259 | 259 | |
|
260 | 260 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
261 | 261 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) |
|
262 | 262 | self.firstHeight = self.samplingWindow['h0'] |
|
263 | 263 | self.deltaHeight = self.samplingWindow['dh'] |
|
264 | 264 | self.samplesWin = self.samplingWindow['nsa'] |
|
265 | 265 | |
|
266 | 266 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
267 | 267 | |
|
268 | 268 | if self.codeType != 0: |
|
269 | 269 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
270 | 270 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
271 | 271 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
272 | 272 | tempList = [] |
|
273 | 273 | for ic in range(self.nCode): |
|
274 | 274 | temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.))) |
|
275 | 275 | tempList.append(temp) |
|
276 | 276 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
277 | 277 | self.code = 2.0*self.code - 1.0 |
|
278 | 278 | |
|
279 | 279 | if self.line5Function == RCfunction.FLIP: |
|
280 | 280 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
281 | 281 | |
|
282 | 282 | if self.line6Function == RCfunction.FLIP: |
|
283 | 283 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
284 | 284 | |
|
285 | 285 | endFp = self.size + startFp |
|
286 | 286 | jumpFp = endFp - fp.tell() |
|
287 | 287 | if jumpFp > 0: |
|
288 | 288 | fp.seek(jumpFp) |
|
289 | 289 | |
|
290 | 290 | except Exception, e: |
|
291 | 291 | print "RadarControllerHeader: " + e |
|
292 | 292 | return 0 |
|
293 | 293 | |
|
294 | 294 | return 1 |
|
295 | 295 | |
|
296 | 296 | def write(self, fp): |
|
297 | 297 | headerTuple = (self.size, |
|
298 | 298 | self.expType, |
|
299 | 299 | self.nTx, |
|
300 | 300 | self.ipp, |
|
301 | 301 | self.txA, |
|
302 | 302 | self.txB, |
|
303 | 303 | self.nWindows, |
|
304 | 304 | self.numTaus, |
|
305 | 305 | self.codeType, |
|
306 | 306 | self.line6Function, |
|
307 | 307 | self.line5Function, |
|
308 | 308 | self.fClock, |
|
309 | 309 | self.prePulseBefore, |
|
310 | 310 | self.prePulserAfter, |
|
311 | 311 | self.rangeIpp, |
|
312 | 312 | self.rangeTxA, |
|
313 | 313 | self.rangeTxB) |
|
314 | 314 | |
|
315 | 315 | header = numpy.array(headerTuple,self.struct) |
|
316 | 316 | header.tofile(fp) |
|
317 | 317 | |
|
318 | 318 | dynamic = self.dynamic |
|
319 | 319 | dynamic.tofile(fp) |
|
320 | 320 | |
|
321 | 321 | return 1 |
|
322 | 322 | |
|
323 | 323 | |
|
324 | 324 | |
|
325 | 325 | class ProcessingHeader(Header): |
|
326 | 326 | |
|
327 | 327 | size = None |
|
328 | 328 | dtype = None |
|
329 | 329 | blockSize = None |
|
330 | 330 | profilesPerBlock = None |
|
331 | 331 | dataBlocksPerFile = None |
|
332 | 332 | nWindows = None |
|
333 | 333 | processFlags = None |
|
334 | 334 | nCohInt = None |
|
335 | 335 | nIncohInt = None |
|
336 | 336 | totalSpectra = None |
|
337 | 337 | struct = None |
|
338 | 338 | flag_dc = None |
|
339 | 339 | flag_cspc = None |
|
340 | 340 | |
|
341 | 341 | def __init__(self): |
|
342 | 342 | self.size = 0 |
|
343 | 343 | self.dtype = 0 |
|
344 | 344 | self.blockSize = 0 |
|
345 | 345 | self.profilesPerBlock = 0 |
|
346 | 346 | self.dataBlocksPerFile = 0 |
|
347 | 347 | self.nWindows = 0 |
|
348 | 348 | self.processFlags = 0 |
|
349 | 349 | self.nCohInt = 0 |
|
350 | 350 | self.nIncohInt = 0 |
|
351 | 351 | self.totalSpectra = 0 |
|
352 | 352 | self.struct = numpy.dtype([ |
|
353 | 353 | ('nSize','<u4'), |
|
354 | 354 | ('nDataType','<u4'), |
|
355 | 355 | ('nSizeOfDataBlock','<u4'), |
|
356 | 356 | ('nProfilesperBlock','<u4'), |
|
357 | 357 | ('nDataBlocksperFile','<u4'), |
|
358 | 358 | ('nNumWindows','<u4'), |
|
359 | 359 | ('nProcessFlags','<u4'), |
|
360 | 360 | ('nCoherentIntegrations','<u4'), |
|
361 | 361 | ('nIncoherentIntegrations','<u4'), |
|
362 | 362 | ('nTotalSpectra','<u4') |
|
363 | 363 | ]) |
|
364 | 364 | self.samplingWindow = 0 |
|
365 | 365 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
366 | 366 | self.nHeights = 0 |
|
367 | 367 | self.firstHeight = 0 |
|
368 | 368 | self.deltaHeight = 0 |
|
369 | 369 | self.samplesWin = 0 |
|
370 | 370 | self.spectraComb = 0 |
|
371 | 371 | self.nCode = None |
|
372 | 372 | self.code = None |
|
373 | 373 | self.nBaud = None |
|
374 | 374 | self.shif_fft = False |
|
375 | 375 | self.flag_dc = False |
|
376 | 376 | self.flag_cspc = False |
|
377 | 377 | |
|
378 | 378 | def read(self, fp): |
|
379 | try: | |
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
|
379 | # try: | |
|
380 | header = numpy.fromfile(fp,self.struct,1) | |
|
381 | self.size = int(header['nSize'][0]) | |
|
382 | self.dtype = int(header['nDataType'][0]) | |
|
383 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
|
384 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
|
385 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
|
386 | self.nWindows = int(header['nNumWindows'][0]) | |
|
387 | self.processFlags = header['nProcessFlags'] | |
|
388 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
|
389 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
|
390 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
|
391 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) | |
|
392 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
|
393 | self.firstHeight = float(self.samplingWindow['h0'][0]) | |
|
394 | self.deltaHeight = float(self.samplingWindow['dh'][0]) | |
|
395 | self.samplesWin = self.samplingWindow['nsa'] | |
|
396 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
|
397 | ||
|
398 | # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
|
399 | # self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
|
400 | # self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
|
401 | # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) | |
|
402 | ||
|
403 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
|
404 | self.shif_fft = True | |
|
405 | else: | |
|
406 | self.shif_fft = False | |
|
402 | 407 | |
|
403 |
|
|
|
404 |
|
|
|
408 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
|
409 | self.flag_dc = True | |
|
410 | ||
|
411 | nChannels = 0 | |
|
412 | nPairs = 0 | |
|
413 | pairList = [] | |
|
414 | ||
|
415 | for i in range( 0, self.totalSpectra*2, 2 ): | |
|
416 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
|
417 | nChannels = nChannels + 1 #par de canales iguales | |
|
405 | 418 | else: |
|
406 | self.shif_fft = False | |
|
407 | ||
|
408 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 | nPairs = 0 | |
|
413 | pairList = [] | |
|
414 | ||
|
415 | for i in range( 0, self.totalSpectra*2, 2 ): | |
|
416 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
|
417 | nChannels = nChannels + 1 #par de canales iguales | |
|
418 | else: | |
|
419 | nPairs = nPairs + 1 #par de canales diferentes | |
|
420 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
|
421 | ||
|
422 | self.flag_cspc = False | |
|
423 | if nPairs > 0: | |
|
424 | self.flag_cspc = True | |
|
419 | nPairs = nPairs + 1 #par de canales diferentes | |
|
420 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
|
421 | ||
|
422 | self.flag_cspc = False | |
|
423 | if nPairs > 0: | |
|
424 | self.flag_cspc = True | |
|
425 | 425 | |
|
426 | except Exception, e: | |
|
427 |
print "ProcessingHeader: " |
|
|
428 | return 0 | |
|
426 | # except Exception, e: | |
|
427 | # print "Error ProcessingHeader: " | |
|
428 | # return 0 | |
|
429 | 429 | |
|
430 | 430 | return 1 |
|
431 | 431 | |
|
432 | 432 | def write(self, fp): |
|
433 | 433 | headerTuple = (self.size, |
|
434 | 434 | self.dtype, |
|
435 | 435 | self.blockSize, |
|
436 | 436 | self.profilesPerBlock, |
|
437 | 437 | self.dataBlocksPerFile, |
|
438 | 438 | self.nWindows, |
|
439 | 439 | self.processFlags, |
|
440 | 440 | self.nCohInt, |
|
441 | 441 | self.nIncohInt, |
|
442 | 442 | self.totalSpectra) |
|
443 | 443 | |
|
444 | 444 | header = numpy.array(headerTuple,self.struct) |
|
445 | 445 | header.tofile(fp) |
|
446 | 446 | |
|
447 | 447 | if self.nWindows != 0: |
|
448 | 448 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
449 | 449 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
450 | 450 | samplingWindow.tofile(fp) |
|
451 | 451 | |
|
452 | 452 | |
|
453 | 453 | if self.totalSpectra != 0: |
|
454 | 454 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
455 | 455 | spectraComb = self.spectraComb |
|
456 | 456 | spectraComb.tofile(fp) |
|
457 | 457 | |
|
458 | 458 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
459 | 459 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
460 | 460 | # nCode.tofile(fp) |
|
461 | 461 | # |
|
462 | 462 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
463 | 463 | # nBaud.tofile(fp) |
|
464 | 464 | # |
|
465 | 465 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
466 | 466 | # code = code.astype(numpy.dtype('<f4')) |
|
467 | 467 | # code.tofile(fp) |
|
468 | 468 | |
|
469 | 469 | return 1 |
|
470 | 470 | |
|
471 | 471 | class RCfunction: |
|
472 | 472 | NONE=0 |
|
473 | 473 | FLIP=1 |
|
474 | 474 | CODE=2 |
|
475 | 475 | SAMPLING=3 |
|
476 | 476 | LIN6DIV256=4 |
|
477 | 477 | SYNCHRO=5 |
|
478 | 478 | |
|
479 | 479 | class nCodeType: |
|
480 | 480 | NONE=0 |
|
481 | 481 | USERDEFINE=1 |
|
482 | 482 | BARKER2=2 |
|
483 | 483 | BARKER3=3 |
|
484 | 484 | BARKER4=4 |
|
485 | 485 | BARKER5=5 |
|
486 | 486 | BARKER7=6 |
|
487 | 487 | BARKER11=7 |
|
488 | 488 | BARKER13=8 |
|
489 | 489 | AC128=9 |
|
490 | 490 | COMPLEMENTARYCODE2=10 |
|
491 | 491 | COMPLEMENTARYCODE4=11 |
|
492 | 492 | COMPLEMENTARYCODE8=12 |
|
493 | 493 | COMPLEMENTARYCODE16=13 |
|
494 | 494 | COMPLEMENTARYCODE32=14 |
|
495 | 495 | COMPLEMENTARYCODE64=15 |
|
496 | 496 | COMPLEMENTARYCODE128=16 |
|
497 | 497 | CODE_BINARY28=17 |
|
498 | 498 | |
|
499 | 499 | class PROCFLAG: |
|
500 | 500 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
501 | 501 | DECODE_DATA = numpy.uint32(0x00000002) |
|
502 | 502 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
503 | 503 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
504 | 504 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
505 | 505 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
506 | 506 | |
|
507 | 507 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
508 | 508 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
509 | 509 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
510 | 510 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
511 | 511 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
512 | 512 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
513 | 513 | |
|
514 | 514 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
515 | 515 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
516 | 516 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
517 | 517 | |
|
518 | 518 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
519 | 519 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
520 | 520 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
521 | 521 | |
|
522 | 522 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
523 | 523 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
524 | 524 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
525 | 525 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
526 | 526 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
527 | 527 | |
|
528 | 528 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
529 | 529 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
530 | 530 | |
|
531 | 531 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
532 | 532 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
533 | 533 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
534 | 534 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
@@ -1,1355 +1,1363 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime, os |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | def isRealtime(utcdatatime): |
|
5 | 5 | utcnow = time.mktime(datetime.datetime.utcnow().timetuple()) |
|
6 | 6 | delta = utcnow - utcdatatime # abs |
|
7 | 7 | if delta >= 5*60.: |
|
8 | 8 | return False |
|
9 | 9 | return True |
|
10 | 10 | |
|
11 | 11 | class CrossSpectraPlot(Figure): |
|
12 | 12 | |
|
13 | 13 | __isConfig = None |
|
14 | 14 | __nsubplots = None |
|
15 | 15 | |
|
16 | 16 | WIDTH = None |
|
17 | 17 | HEIGHT = None |
|
18 | 18 | WIDTHPROF = None |
|
19 | 19 | HEIGHTPROF = None |
|
20 | 20 | PREFIX = 'cspc' |
|
21 | 21 | |
|
22 | 22 | def __init__(self): |
|
23 | 23 | |
|
24 | 24 | self.__isConfig = False |
|
25 | 25 | self.__nsubplots = 4 |
|
26 | 26 | |
|
27 | 27 | self.WIDTH = 250 |
|
28 | 28 | self.HEIGHT = 250 |
|
29 | 29 | self.WIDTHPROF = 0 |
|
30 | 30 | self.HEIGHTPROF = 0 |
|
31 | 31 | |
|
32 | 32 | def getSubplots(self): |
|
33 | 33 | |
|
34 | 34 | ncol = 4 |
|
35 | 35 | nrow = self.nplots |
|
36 | 36 | |
|
37 | 37 | return nrow, ncol |
|
38 | 38 | |
|
39 | 39 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
40 | 40 | |
|
41 | 41 | self.__showprofile = showprofile |
|
42 | 42 | self.nplots = nplots |
|
43 | 43 | |
|
44 | 44 | ncolspan = 1 |
|
45 | 45 | colspan = 1 |
|
46 | 46 | |
|
47 | 47 | self.createFigure(idfigure = idfigure, |
|
48 | 48 | wintitle = wintitle, |
|
49 | 49 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
50 | 50 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
51 | 51 | show=True) |
|
52 | 52 | |
|
53 | 53 | nrow, ncol = self.getSubplots() |
|
54 | 54 | |
|
55 | 55 | counter = 0 |
|
56 | 56 | for y in range(nrow): |
|
57 | 57 | for x in range(ncol): |
|
58 | 58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
59 | 59 | |
|
60 | 60 | counter += 1 |
|
61 | 61 | |
|
62 | 62 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
63 | 63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
64 | 64 | save=False, figpath='./', figfile=None, |
|
65 | 65 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
66 | 66 | |
|
67 | 67 | """ |
|
68 | 68 | |
|
69 | 69 | Input: |
|
70 | 70 | dataOut : |
|
71 | 71 | idfigure : |
|
72 | 72 | wintitle : |
|
73 | 73 | channelList : |
|
74 | 74 | showProfile : |
|
75 | 75 | xmin : None, |
|
76 | 76 | xmax : None, |
|
77 | 77 | ymin : None, |
|
78 | 78 | ymax : None, |
|
79 | 79 | zmin : None, |
|
80 | 80 | zmax : None |
|
81 | 81 | """ |
|
82 | 82 | |
|
83 | 83 | if pairsList == None: |
|
84 | 84 | pairsIndexList = dataOut.pairsIndexList |
|
85 | 85 | else: |
|
86 | 86 | pairsIndexList = [] |
|
87 | 87 | for pair in pairsList: |
|
88 | 88 | if pair not in dataOut.pairsList: |
|
89 | 89 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
90 | 90 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
91 | 91 | |
|
92 | 92 | if pairsIndexList == []: |
|
93 | 93 | return |
|
94 | 94 | |
|
95 | 95 | if len(pairsIndexList) > 4: |
|
96 | 96 | pairsIndexList = pairsIndexList[0:4] |
|
97 | 97 | factor = dataOut.normFactor |
|
98 | 98 | x = dataOut.getVelRange(1) |
|
99 | 99 | y = dataOut.getHeiRange() |
|
100 | 100 | z = dataOut.data_spc[:,:,:]/factor |
|
101 | 101 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
102 | 102 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
103 | 103 | noise = dataOut.getNoise()/factor |
|
104 | 104 | |
|
105 | 105 | zdB = 10*numpy.log10(z) |
|
106 | 106 | avgdB = 10*numpy.log10(avg) |
|
107 | 107 | noisedB = 10*numpy.log10(noise) |
|
108 | 108 | |
|
109 | 109 | |
|
110 | thisDatetime = dataOut.datatime | |
|
111 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
110 | #thisDatetime = dataOut.datatime | |
|
111 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
112 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
112 | 113 | xlabel = "Velocity (m/s)" |
|
113 | 114 | ylabel = "Range (Km)" |
|
114 | 115 | |
|
115 | 116 | if not self.__isConfig: |
|
116 | 117 | |
|
117 | 118 | nplots = len(pairsIndexList) |
|
118 | 119 | |
|
119 | 120 | self.setup(idfigure=idfigure, |
|
120 | 121 | nplots=nplots, |
|
121 | 122 | wintitle=wintitle, |
|
122 | 123 | showprofile=showprofile, |
|
123 | 124 | show=show) |
|
124 | 125 | |
|
125 | 126 | if xmin == None: xmin = numpy.nanmin(x) |
|
126 | 127 | if xmax == None: xmax = numpy.nanmax(x) |
|
127 | 128 | if ymin == None: ymin = numpy.nanmin(y) |
|
128 | 129 | if ymax == None: ymax = numpy.nanmax(y) |
|
129 | 130 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
130 | 131 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
131 | 132 | |
|
132 | 133 | self.__isConfig = True |
|
133 | 134 | |
|
134 | 135 | self.setWinTitle(title) |
|
135 | 136 | |
|
136 | 137 | for i in range(self.nplots): |
|
137 | 138 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
138 | 139 | |
|
139 | 140 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
140 | 141 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
141 | 142 | axes0 = self.axesList[i*self.__nsubplots] |
|
142 | 143 | axes0.pcolor(x, y, zdB, |
|
143 | 144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
144 | 145 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
145 | 146 | ticksize=9, colormap=power_cmap, cblabel='') |
|
146 | 147 | |
|
147 | 148 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
148 | 149 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
149 | 150 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
150 | 151 | axes0.pcolor(x, y, zdB, |
|
151 | 152 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
152 | 153 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
153 | 154 | ticksize=9, colormap=power_cmap, cblabel='') |
|
154 | 155 | |
|
155 | 156 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
156 | 157 | coherence = numpy.abs(coherenceComplex) |
|
157 | 158 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
158 | 159 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
159 | 160 | |
|
160 | 161 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
161 | 162 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
162 | 163 | axes0.pcolor(x, y, coherence, |
|
163 | 164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
164 | 165 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
165 | 166 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
166 | 167 | |
|
167 | 168 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
168 | 169 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
169 | 170 | axes0.pcolor(x, y, phase, |
|
170 | 171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
171 | 172 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
172 | 173 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
173 | 174 | |
|
174 | 175 | |
|
175 | 176 | |
|
176 | 177 | self.draw() |
|
177 | 178 | |
|
178 | 179 | if save: |
|
179 | 180 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
180 | 181 | if figfile == None: |
|
181 | 182 | figfile = self.getFilename(name = date) |
|
182 | 183 | |
|
183 | 184 | self.saveFigure(figpath, figfile) |
|
184 | 185 | |
|
185 | 186 | |
|
186 | 187 | class RTIPlot(Figure): |
|
187 | 188 | |
|
188 | 189 | __isConfig = None |
|
189 | 190 | __nsubplots = None |
|
190 | 191 | |
|
191 | 192 | WIDTHPROF = None |
|
192 | 193 | HEIGHTPROF = None |
|
193 | 194 | PREFIX = 'rti' |
|
194 | 195 | |
|
195 | 196 | def __init__(self): |
|
196 | 197 | |
|
197 | 198 | self.timerange = 2*60*60 |
|
198 | 199 | self.__isConfig = False |
|
199 | 200 | self.__nsubplots = 1 |
|
200 | 201 | |
|
201 | 202 | self.WIDTH = 800 |
|
202 | 203 | self.HEIGHT = 150 |
|
203 | 204 | self.WIDTHPROF = 120 |
|
204 | 205 | self.HEIGHTPROF = 0 |
|
205 | 206 | self.counterftp = 0 |
|
206 | 207 | |
|
207 | 208 | def getSubplots(self): |
|
208 | 209 | |
|
209 | 210 | ncol = 1 |
|
210 | 211 | nrow = self.nplots |
|
211 | 212 | |
|
212 | 213 | return nrow, ncol |
|
213 | 214 | |
|
214 | 215 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
215 | 216 | |
|
216 | 217 | self.__showprofile = showprofile |
|
217 | 218 | self.nplots = nplots |
|
218 | 219 | |
|
219 | 220 | ncolspan = 1 |
|
220 | 221 | colspan = 1 |
|
221 | 222 | if showprofile: |
|
222 | 223 | ncolspan = 7 |
|
223 | 224 | colspan = 6 |
|
224 | 225 | self.__nsubplots = 2 |
|
225 | 226 | |
|
226 | 227 | self.createFigure(idfigure = idfigure, |
|
227 | 228 | wintitle = wintitle, |
|
228 | 229 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
229 | 230 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
230 | 231 | show=show) |
|
231 | 232 | |
|
232 | 233 | nrow, ncol = self.getSubplots() |
|
233 | 234 | |
|
234 | 235 | counter = 0 |
|
235 | 236 | for y in range(nrow): |
|
236 | 237 | for x in range(ncol): |
|
237 | 238 | |
|
238 | 239 | if counter >= self.nplots: |
|
239 | 240 | break |
|
240 | 241 | |
|
241 | 242 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
242 | 243 | |
|
243 | 244 | if showprofile: |
|
244 | 245 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
245 | 246 | |
|
246 | 247 | counter += 1 |
|
247 | 248 | |
|
248 | 249 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
249 | 250 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
250 | 251 | timerange=None, |
|
251 | 252 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): |
|
252 | 253 | |
|
253 | 254 | """ |
|
254 | 255 | |
|
255 | 256 | Input: |
|
256 | 257 | dataOut : |
|
257 | 258 | idfigure : |
|
258 | 259 | wintitle : |
|
259 | 260 | channelList : |
|
260 | 261 | showProfile : |
|
261 | 262 | xmin : None, |
|
262 | 263 | xmax : None, |
|
263 | 264 | ymin : None, |
|
264 | 265 | ymax : None, |
|
265 | 266 | zmin : None, |
|
266 | 267 | zmax : None |
|
267 | 268 | """ |
|
268 | 269 | |
|
269 | 270 | if channelList == None: |
|
270 | 271 | channelIndexList = dataOut.channelIndexList |
|
271 | 272 | else: |
|
272 | 273 | channelIndexList = [] |
|
273 | 274 | for channel in channelList: |
|
274 | 275 | if channel not in dataOut.channelList: |
|
275 | 276 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
276 | 277 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
277 | 278 | |
|
278 | 279 | if timerange != None: |
|
279 | 280 | self.timerange = timerange |
|
280 | 281 | |
|
281 | 282 | tmin = None |
|
282 | 283 | tmax = None |
|
283 | 284 | factor = dataOut.normFactor |
|
284 | 285 | x = dataOut.getTimeRange() |
|
285 | 286 | y = dataOut.getHeiRange() |
|
286 | 287 | |
|
287 | 288 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
288 | 289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
289 | 290 | avg = numpy.average(z, axis=1) |
|
290 | 291 | |
|
291 | 292 | avgdB = 10.*numpy.log10(avg) |
|
292 | 293 | |
|
293 | 294 | |
|
294 | 295 | # thisDatetime = dataOut.datatime |
|
295 | 296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
296 |
title = wintitle |
|
|
297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
297 | 298 | xlabel = "" |
|
298 | 299 | ylabel = "Range (Km)" |
|
299 | 300 | |
|
300 | 301 | if not self.__isConfig: |
|
301 | 302 | |
|
302 | 303 | nplots = len(channelIndexList) |
|
303 | 304 | |
|
304 | 305 | self.setup(idfigure=idfigure, |
|
305 | 306 | nplots=nplots, |
|
306 | 307 | wintitle=wintitle, |
|
307 | 308 | showprofile=showprofile, |
|
308 | 309 | show=show) |
|
309 | 310 | |
|
310 | 311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
311 | 312 | if ymin == None: ymin = numpy.nanmin(y) |
|
312 | 313 | if ymax == None: ymax = numpy.nanmax(y) |
|
313 | 314 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
314 | 315 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
315 | 316 | |
|
316 | 317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
317 | 318 | self.__isConfig = True |
|
318 | 319 | |
|
319 | 320 | |
|
320 | 321 | self.setWinTitle(title) |
|
321 | 322 | |
|
322 | 323 | for i in range(self.nplots): |
|
323 | 324 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
324 | 325 | axes = self.axesList[i*self.__nsubplots] |
|
325 | 326 | zdB = avgdB[i].reshape((1,-1)) |
|
326 | 327 | axes.pcolorbuffer(x, y, zdB, |
|
327 | 328 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
328 | 329 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
329 | 330 | ticksize=9, cblabel='', cbsize="1%") |
|
330 | 331 | |
|
331 | 332 | if self.__showprofile: |
|
332 | 333 | axes = self.axesList[i*self.__nsubplots +1] |
|
333 | 334 | axes.pline(avgdB[i], y, |
|
334 | 335 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
335 | 336 | xlabel='dB', ylabel='', title='', |
|
336 | 337 | ytick_visible=False, |
|
337 | 338 | grid='x') |
|
338 | 339 | |
|
339 | 340 | self.draw() |
|
340 | 341 | |
|
341 | 342 | if save: |
|
342 | 343 | |
|
343 | 344 | if figfile == None: |
|
344 | 345 | figfile = self.getFilename(name = self.name) |
|
345 | 346 | |
|
346 | 347 | self.saveFigure(figpath, figfile) |
|
347 | 348 | |
|
348 | 349 | self.counterftp += 1 |
|
349 | 350 | if (ftp and (self.counterftp==ftpratio)): |
|
350 | 351 | figfilename = os.path.join(figpath,figfile) |
|
351 | 352 | self.sendByFTP(figfilename) |
|
352 | 353 | self.counterftp = 0 |
|
353 | 354 | |
|
354 | 355 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
355 | 356 | self.__isConfig = False |
|
356 | 357 | |
|
357 | 358 | class SpectraPlot(Figure): |
|
358 | 359 | |
|
359 | 360 | __isConfig = None |
|
360 | 361 | __nsubplots = None |
|
361 | 362 | |
|
362 | 363 | WIDTHPROF = None |
|
363 | 364 | HEIGHTPROF = None |
|
364 | 365 | PREFIX = 'spc' |
|
365 | 366 | |
|
366 | 367 | def __init__(self): |
|
367 | 368 | |
|
368 | 369 | self.__isConfig = False |
|
369 | 370 | self.__nsubplots = 1 |
|
370 | 371 | |
|
371 | 372 | self.WIDTH = 230 |
|
372 | 373 | self.HEIGHT = 250 |
|
373 | 374 | self.WIDTHPROF = 120 |
|
374 | 375 | self.HEIGHTPROF = 0 |
|
375 | 376 | |
|
376 | 377 | def getSubplots(self): |
|
377 | 378 | |
|
378 | 379 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
379 | 380 | nrow = int(self.nplots*1./ncol + 0.9) |
|
380 | 381 | |
|
381 | 382 | return nrow, ncol |
|
382 | 383 | |
|
383 | 384 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
384 | 385 | |
|
385 | 386 | self.__showprofile = showprofile |
|
386 | 387 | self.nplots = nplots |
|
387 | 388 | |
|
388 | 389 | ncolspan = 1 |
|
389 | 390 | colspan = 1 |
|
390 | 391 | if showprofile: |
|
391 | 392 | ncolspan = 3 |
|
392 | 393 | colspan = 2 |
|
393 | 394 | self.__nsubplots = 2 |
|
394 | 395 | |
|
395 | 396 | self.createFigure(idfigure = idfigure, |
|
396 | 397 | wintitle = wintitle, |
|
397 | 398 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
398 | 399 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
399 | 400 | show=show) |
|
400 | 401 | |
|
401 | 402 | nrow, ncol = self.getSubplots() |
|
402 | 403 | |
|
403 | 404 | counter = 0 |
|
404 | 405 | for y in range(nrow): |
|
405 | 406 | for x in range(ncol): |
|
406 | 407 | |
|
407 | 408 | if counter >= self.nplots: |
|
408 | 409 | break |
|
409 | 410 | |
|
410 | 411 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
411 | 412 | |
|
412 | 413 | if showprofile: |
|
413 | 414 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
414 | 415 | |
|
415 | 416 | counter += 1 |
|
416 | 417 | |
|
417 | 418 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
418 | 419 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
419 | 420 | save=False, figpath='./', figfile=None, show=True): |
|
420 | 421 | |
|
421 | 422 | """ |
|
422 | 423 | |
|
423 | 424 | Input: |
|
424 | 425 | dataOut : |
|
425 | 426 | idfigure : |
|
426 | 427 | wintitle : |
|
427 | 428 | channelList : |
|
428 | 429 | showProfile : |
|
429 | 430 | xmin : None, |
|
430 | 431 | xmax : None, |
|
431 | 432 | ymin : None, |
|
432 | 433 | ymax : None, |
|
433 | 434 | zmin : None, |
|
434 | 435 | zmax : None |
|
435 | 436 | """ |
|
436 | 437 | |
|
437 | 438 | if channelList == None: |
|
438 | 439 | channelIndexList = dataOut.channelIndexList |
|
439 | 440 | else: |
|
440 | 441 | channelIndexList = [] |
|
441 | 442 | for channel in channelList: |
|
442 | 443 | if channel not in dataOut.channelList: |
|
443 | 444 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
444 | 445 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
445 | 446 | factor = dataOut.normFactor |
|
446 | 447 | x = dataOut.getVelRange(1) |
|
447 | 448 | y = dataOut.getHeiRange() |
|
448 | 449 | |
|
449 | 450 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
450 | 451 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
451 | 452 | avg = numpy.average(z, axis=1) |
|
452 | 453 | noise = dataOut.getNoise()/factor |
|
453 | 454 | |
|
454 | 455 | zdB = 10*numpy.log10(z) |
|
455 | 456 | avgdB = 10*numpy.log10(avg) |
|
456 | 457 | noisedB = 10*numpy.log10(noise) |
|
457 | 458 | |
|
458 | thisDatetime = dataOut.datatime | |
|
459 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
459 | #thisDatetime = dataOut.datatime | |
|
460 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
461 | title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
460 | 462 | xlabel = "Velocity (m/s)" |
|
461 | 463 | ylabel = "Range (Km)" |
|
462 | 464 | |
|
463 | 465 | if not self.__isConfig: |
|
464 | 466 | |
|
465 | 467 | nplots = len(channelIndexList) |
|
466 | 468 | |
|
467 | 469 | self.setup(idfigure=idfigure, |
|
468 | 470 | nplots=nplots, |
|
469 | 471 | wintitle=wintitle, |
|
470 | 472 | showprofile=showprofile, |
|
471 | 473 | show=show) |
|
472 | 474 | |
|
473 | 475 | if xmin == None: xmin = numpy.nanmin(x) |
|
474 | 476 | if xmax == None: xmax = numpy.nanmax(x) |
|
475 | 477 | if ymin == None: ymin = numpy.nanmin(y) |
|
476 | 478 | if ymax == None: ymax = numpy.nanmax(y) |
|
477 | 479 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
478 | 480 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
479 | 481 | |
|
480 | 482 | self.__isConfig = True |
|
481 | 483 | |
|
482 | 484 | self.setWinTitle(title) |
|
483 | 485 | |
|
484 | 486 | for i in range(self.nplots): |
|
485 | 487 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
486 | 488 | axes = self.axesList[i*self.__nsubplots] |
|
487 | 489 | axes.pcolor(x, y, zdB[i,:,:], |
|
488 | 490 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
489 | 491 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
490 | 492 | ticksize=9, cblabel='') |
|
491 | 493 | |
|
492 | 494 | if self.__showprofile: |
|
493 | 495 | axes = self.axesList[i*self.__nsubplots +1] |
|
494 | 496 | axes.pline(avgdB[i], y, |
|
495 | 497 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
496 | 498 | xlabel='dB', ylabel='', title='', |
|
497 | 499 | ytick_visible=False, |
|
498 | 500 | grid='x') |
|
499 | 501 | |
|
500 | 502 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
501 | 503 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
502 | 504 | |
|
503 | 505 | self.draw() |
|
504 | 506 | |
|
505 | 507 | if save: |
|
506 | 508 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
507 | 509 | if figfile == None: |
|
508 | 510 | figfile = self.getFilename(name = date) |
|
509 | 511 | |
|
510 | 512 | self.saveFigure(figpath, figfile) |
|
511 | 513 | |
|
512 | 514 | class Scope(Figure): |
|
513 | 515 | |
|
514 | 516 | __isConfig = None |
|
515 | 517 | |
|
516 | 518 | def __init__(self): |
|
517 | 519 | |
|
518 | 520 | self.__isConfig = False |
|
519 | 521 | self.WIDTH = 600 |
|
520 | 522 | self.HEIGHT = 200 |
|
521 | 523 | |
|
522 | 524 | def getSubplots(self): |
|
523 | 525 | |
|
524 | 526 | nrow = self.nplots |
|
525 | 527 | ncol = 3 |
|
526 | 528 | return nrow, ncol |
|
527 | 529 | |
|
528 | 530 | def setup(self, idfigure, nplots, wintitle, show): |
|
529 | 531 | |
|
530 | 532 | self.nplots = nplots |
|
531 | 533 | |
|
532 | 534 | self.createFigure(idfigure=idfigure, |
|
533 | 535 | wintitle=wintitle, |
|
534 | 536 | show=show) |
|
535 | 537 | |
|
536 | 538 | nrow,ncol = self.getSubplots() |
|
537 | 539 | colspan = 3 |
|
538 | 540 | rowspan = 1 |
|
539 | 541 | |
|
540 | 542 | for i in range(nplots): |
|
541 | 543 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
542 | 544 | |
|
543 | 545 | |
|
544 | 546 | |
|
545 | 547 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
546 | 548 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
547 | 549 | figpath='./', figfile=None, show=True): |
|
548 | 550 | |
|
549 | 551 | """ |
|
550 | 552 | |
|
551 | 553 | Input: |
|
552 | 554 | dataOut : |
|
553 | 555 | idfigure : |
|
554 | 556 | wintitle : |
|
555 | 557 | channelList : |
|
556 | 558 | xmin : None, |
|
557 | 559 | xmax : None, |
|
558 | 560 | ymin : None, |
|
559 | 561 | ymax : None, |
|
560 | 562 | """ |
|
561 | 563 | |
|
562 | 564 | if channelList == None: |
|
563 | 565 | channelIndexList = dataOut.channelIndexList |
|
564 | 566 | else: |
|
565 | 567 | channelIndexList = [] |
|
566 | 568 | for channel in channelList: |
|
567 | 569 | if channel not in dataOut.channelList: |
|
568 | 570 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
569 | 571 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
570 | 572 | |
|
571 | 573 | x = dataOut.heightList |
|
572 | 574 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
573 | 575 | y = y.real |
|
574 | 576 | |
|
575 | thisDatetime = dataOut.datatime | |
|
576 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
577 | #thisDatetime = dataOut.datatime | |
|
578 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
579 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
577 | 580 | xlabel = "Range (Km)" |
|
578 | 581 | ylabel = "Intensity" |
|
579 | 582 | |
|
580 | 583 | if not self.__isConfig: |
|
581 | 584 | nplots = len(channelIndexList) |
|
582 | 585 | |
|
583 | 586 | self.setup(idfigure=idfigure, |
|
584 | 587 | nplots=nplots, |
|
585 | 588 | wintitle=wintitle, |
|
586 | 589 | show=show) |
|
587 | 590 | |
|
588 | 591 | if xmin == None: xmin = numpy.nanmin(x) |
|
589 | 592 | if xmax == None: xmax = numpy.nanmax(x) |
|
590 | 593 | if ymin == None: ymin = numpy.nanmin(y) |
|
591 | 594 | if ymax == None: ymax = numpy.nanmax(y) |
|
592 | 595 | |
|
593 | 596 | self.__isConfig = True |
|
594 | 597 | |
|
595 | 598 | self.setWinTitle(title) |
|
596 | 599 | |
|
597 | 600 | for i in range(len(self.axesList)): |
|
598 | 601 | title = "Channel %d" %(i) |
|
599 | 602 | axes = self.axesList[i] |
|
600 | 603 | ychannel = y[i,:] |
|
601 | 604 | axes.pline(x, ychannel, |
|
602 | 605 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
603 | 606 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
604 | 607 | |
|
605 | 608 | self.draw() |
|
606 | 609 | |
|
607 | 610 | if save: |
|
608 | 611 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
609 | 612 | if figfile == None: |
|
610 | 613 | figfile = self.getFilename(name = date) |
|
611 | 614 | |
|
612 | 615 | self.saveFigure(figpath, figfile) |
|
613 | 616 | |
|
614 | 617 | class PowerProfilePlot(Figure): |
|
615 | 618 | __isConfig = None |
|
616 | 619 | __nsubplots = None |
|
617 | 620 | |
|
618 | 621 | WIDTHPROF = None |
|
619 | 622 | HEIGHTPROF = None |
|
620 | 623 | PREFIX = 'spcprofile' |
|
621 | 624 | |
|
622 | 625 | def __init__(self): |
|
623 | 626 | self.__isConfig = False |
|
624 | 627 | self.__nsubplots = 1 |
|
625 | 628 | |
|
626 | 629 | self.WIDTH = 300 |
|
627 | 630 | self.HEIGHT = 500 |
|
628 | 631 | |
|
629 | 632 | def getSubplots(self): |
|
630 | 633 | ncol = 1 |
|
631 | 634 | nrow = 1 |
|
632 | 635 | |
|
633 | 636 | return nrow, ncol |
|
634 | 637 | |
|
635 | 638 | def setup(self, idfigure, nplots, wintitle, show): |
|
636 | 639 | |
|
637 | 640 | self.nplots = nplots |
|
638 | 641 | |
|
639 | 642 | ncolspan = 1 |
|
640 | 643 | colspan = 1 |
|
641 | 644 | |
|
642 | 645 | self.createFigure(idfigure = idfigure, |
|
643 | 646 | wintitle = wintitle, |
|
644 | 647 | widthplot = self.WIDTH, |
|
645 | 648 | heightplot = self.HEIGHT, |
|
646 | 649 | show=show) |
|
647 | 650 | |
|
648 | 651 | nrow, ncol = self.getSubplots() |
|
649 | 652 | |
|
650 | 653 | counter = 0 |
|
651 | 654 | for y in range(nrow): |
|
652 | 655 | for x in range(ncol): |
|
653 | 656 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
654 | 657 | |
|
655 | 658 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
656 | 659 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
657 | 660 | save=False, figpath='./', figfile=None, show=True): |
|
658 | 661 | |
|
659 | 662 | if channelList == None: |
|
660 | 663 | channelIndexList = dataOut.channelIndexList |
|
661 | 664 | channelList = dataOut.channelList |
|
662 | 665 | else: |
|
663 | 666 | channelIndexList = [] |
|
664 | 667 | for channel in channelList: |
|
665 | 668 | if channel not in dataOut.channelList: |
|
666 | 669 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
667 | 670 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
668 | 671 | |
|
669 | 672 | factor = dataOut.normFactor |
|
670 | 673 | y = dataOut.getHeiRange() |
|
671 | 674 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
672 | 675 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
673 | 676 | avg = numpy.average(x, axis=1) |
|
674 | 677 | |
|
675 | 678 | avgdB = 10*numpy.log10(avg) |
|
676 | 679 | |
|
677 | thisDatetime = dataOut.datatime | |
|
678 | title = "Power Profile" | |
|
680 | #thisDatetime = dataOut.datatime | |
|
681 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
682 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
679 | 683 | xlabel = "dB" |
|
680 | 684 | ylabel = "Range (Km)" |
|
681 | 685 | |
|
682 | 686 | if not self.__isConfig: |
|
683 | 687 | |
|
684 | 688 | nplots = 1 |
|
685 | 689 | |
|
686 | 690 | self.setup(idfigure=idfigure, |
|
687 | 691 | nplots=nplots, |
|
688 | 692 | wintitle=wintitle, |
|
689 | 693 | show=show) |
|
690 | 694 | |
|
691 | 695 | if ymin == None: ymin = numpy.nanmin(y) |
|
692 | 696 | if ymax == None: ymax = numpy.nanmax(y) |
|
693 | 697 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
694 | 698 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
695 | 699 | |
|
696 | 700 | self.__isConfig = True |
|
697 | 701 | |
|
698 | 702 | self.setWinTitle(title) |
|
699 | 703 | |
|
700 | 704 | |
|
701 | 705 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
702 | 706 | axes = self.axesList[0] |
|
703 | 707 | |
|
704 | 708 | legendlabels = ["channel %d"%x for x in channelList] |
|
705 | 709 | axes.pmultiline(avgdB, y, |
|
706 | 710 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
707 | 711 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
708 | 712 | ytick_visible=True, nxticks=5, |
|
709 | 713 | grid='x') |
|
710 | 714 | |
|
711 | 715 | self.draw() |
|
712 | 716 | |
|
713 | 717 | if save: |
|
714 | 718 | date = thisDatetime.strftime("%Y%m%d") |
|
715 | 719 | if figfile == None: |
|
716 | 720 | figfile = self.getFilename(name = date) |
|
717 | 721 | |
|
718 | 722 | self.saveFigure(figpath, figfile) |
|
719 | 723 | |
|
720 | 724 | class CoherenceMap(Figure): |
|
721 | 725 | __isConfig = None |
|
722 | 726 | __nsubplots = None |
|
723 | 727 | |
|
724 | 728 | WIDTHPROF = None |
|
725 | 729 | HEIGHTPROF = None |
|
726 | 730 | PREFIX = 'cmap' |
|
727 | 731 | |
|
728 | 732 | def __init__(self): |
|
729 | 733 | self.timerange = 2*60*60 |
|
730 | 734 | self.__isConfig = False |
|
731 | 735 | self.__nsubplots = 1 |
|
732 | 736 | |
|
733 | 737 | self.WIDTH = 800 |
|
734 | 738 | self.HEIGHT = 150 |
|
735 | 739 | self.WIDTHPROF = 120 |
|
736 | 740 | self.HEIGHTPROF = 0 |
|
737 | 741 | self.counterftp = 0 |
|
738 | 742 | |
|
739 | 743 | def getSubplots(self): |
|
740 | 744 | ncol = 1 |
|
741 | 745 | nrow = self.nplots*2 |
|
742 | 746 | |
|
743 | 747 | return nrow, ncol |
|
744 | 748 | |
|
745 | 749 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
746 | 750 | self.__showprofile = showprofile |
|
747 | 751 | self.nplots = nplots |
|
748 | 752 | |
|
749 | 753 | ncolspan = 1 |
|
750 | 754 | colspan = 1 |
|
751 | 755 | if showprofile: |
|
752 | 756 | ncolspan = 7 |
|
753 | 757 | colspan = 6 |
|
754 | 758 | self.__nsubplots = 2 |
|
755 | 759 | |
|
756 | 760 | self.createFigure(idfigure = idfigure, |
|
757 | 761 | wintitle = wintitle, |
|
758 | 762 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
759 | 763 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
760 | 764 | show=True) |
|
761 | 765 | |
|
762 | 766 | nrow, ncol = self.getSubplots() |
|
763 | 767 | |
|
764 | 768 | for y in range(nrow): |
|
765 | 769 | for x in range(ncol): |
|
766 | 770 | |
|
767 | 771 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
768 | 772 | |
|
769 | 773 | if showprofile: |
|
770 | 774 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
771 | 775 | |
|
772 | 776 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
773 | 777 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
774 | 778 | timerange=None, |
|
775 | 779 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, |
|
776 | 780 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
777 | 781 | |
|
778 | 782 | if pairsList == None: |
|
779 | 783 | pairsIndexList = dataOut.pairsIndexList |
|
780 | 784 | else: |
|
781 | 785 | pairsIndexList = [] |
|
782 | 786 | for pair in pairsList: |
|
783 | 787 | if pair not in dataOut.pairsList: |
|
784 | 788 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
785 | 789 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
786 | 790 | |
|
787 | 791 | if timerange != None: |
|
788 | 792 | self.timerange = timerange |
|
789 | 793 | |
|
790 | 794 | if pairsIndexList == []: |
|
791 | 795 | return |
|
792 | 796 | |
|
793 | 797 | if len(pairsIndexList) > 4: |
|
794 | 798 | pairsIndexList = pairsIndexList[0:4] |
|
795 | 799 | |
|
796 | 800 | tmin = None |
|
797 | 801 | tmax = None |
|
798 | 802 | x = dataOut.getTimeRange() |
|
799 | 803 | y = dataOut.getHeiRange() |
|
800 | 804 | |
|
801 | thisDatetime = dataOut.datatime | |
|
802 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
805 | #thisDatetime = dataOut.datatime | |
|
806 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
807 | title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
803 | 808 | xlabel = "" |
|
804 | 809 | ylabel = "Range (Km)" |
|
805 | 810 | |
|
806 | 811 | if not self.__isConfig: |
|
807 | 812 | nplots = len(pairsIndexList) |
|
808 | 813 | self.setup(idfigure=idfigure, |
|
809 | 814 | nplots=nplots, |
|
810 | 815 | wintitle=wintitle, |
|
811 | 816 | showprofile=showprofile, |
|
812 | 817 | show=show) |
|
813 | 818 | |
|
814 | 819 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
815 | 820 | if ymin == None: ymin = numpy.nanmin(y) |
|
816 | 821 | if ymax == None: ymax = numpy.nanmax(y) |
|
817 | 822 | |
|
818 | 823 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
819 | 824 | |
|
820 | 825 | self.__isConfig = True |
|
821 | 826 | |
|
822 | 827 | self.setWinTitle(title) |
|
823 | 828 | |
|
824 | 829 | for i in range(self.nplots): |
|
825 | 830 | |
|
826 | 831 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
827 | 832 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
828 | 833 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
829 | 834 | coherence = numpy.abs(avgcoherenceComplex) |
|
830 | 835 | # coherence = numpy.abs(coherenceComplex) |
|
831 | 836 | # avg = numpy.average(coherence, axis=0) |
|
832 | 837 | |
|
833 | 838 | z = coherence.reshape((1,-1)) |
|
834 | 839 | |
|
835 | 840 | counter = 0 |
|
836 | 841 | |
|
837 | 842 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
838 | 843 | axes = self.axesList[i*self.__nsubplots*2] |
|
839 | 844 | axes.pcolorbuffer(x, y, z, |
|
840 | 845 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
841 | 846 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
842 | 847 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
843 | 848 | |
|
844 | 849 | if self.__showprofile: |
|
845 | 850 | counter += 1 |
|
846 | 851 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
847 | 852 | axes.pline(coherence, y, |
|
848 | 853 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
849 | 854 | xlabel='', ylabel='', title='', ticksize=7, |
|
850 | 855 | ytick_visible=False, nxticks=5, |
|
851 | 856 | grid='x') |
|
852 | 857 | |
|
853 | 858 | counter += 1 |
|
854 | 859 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
855 | 860 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
856 | 861 | # avg = numpy.average(phase, axis=0) |
|
857 | 862 | z = phase.reshape((1,-1)) |
|
858 | 863 | |
|
859 | 864 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
860 | 865 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
861 | 866 | axes.pcolorbuffer(x, y, z, |
|
862 | 867 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
863 | 868 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
864 | 869 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
865 | 870 | |
|
866 | 871 | if self.__showprofile: |
|
867 | 872 | counter += 1 |
|
868 | 873 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
869 | 874 | axes.pline(phase, y, |
|
870 | 875 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
871 | 876 | xlabel='', ylabel='', title='', ticksize=7, |
|
872 | 877 | ytick_visible=False, nxticks=4, |
|
873 | 878 | grid='x') |
|
874 | 879 | |
|
875 | 880 | self.draw() |
|
876 | 881 | |
|
877 | 882 | if save: |
|
878 | 883 | |
|
879 | 884 | if figfile == None: |
|
880 | 885 | figfile = self.getFilename(name = self.name) |
|
881 | 886 | |
|
882 | 887 | self.saveFigure(figpath, figfile) |
|
883 | 888 | |
|
884 | 889 | self.counterftp += 1 |
|
885 | 890 | if (ftp and (self.counterftp==ftpratio)): |
|
886 | 891 | figfilename = os.path.join(figpath,figfile) |
|
887 | 892 | self.sendByFTP(figfilename) |
|
888 | 893 | self.counterftp = 0 |
|
889 | 894 | |
|
890 | 895 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
891 | 896 | self.__isConfig = False |
|
892 | 897 | |
|
893 | 898 | class RTIfromNoise(Figure): |
|
894 | 899 | |
|
895 | 900 | __isConfig = None |
|
896 | 901 | __nsubplots = None |
|
897 | 902 | |
|
898 | 903 | PREFIX = 'rtinoise' |
|
899 | 904 | |
|
900 | 905 | def __init__(self): |
|
901 | 906 | |
|
902 | 907 | self.timerange = 24*60*60 |
|
903 | 908 | self.__isConfig = False |
|
904 | 909 | self.__nsubplots = 1 |
|
905 | 910 | |
|
906 | 911 | self.WIDTH = 820 |
|
907 | 912 | self.HEIGHT = 200 |
|
908 | 913 | self.WIDTHPROF = 120 |
|
909 | 914 | self.HEIGHTPROF = 0 |
|
910 | 915 | self.xdata = None |
|
911 | 916 | self.ydata = None |
|
912 | 917 | |
|
913 | 918 | def getSubplots(self): |
|
914 | 919 | |
|
915 | 920 | ncol = 1 |
|
916 | 921 | nrow = 1 |
|
917 | 922 | |
|
918 | 923 | return nrow, ncol |
|
919 | 924 | |
|
920 | 925 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
921 | 926 | |
|
922 | 927 | self.__showprofile = showprofile |
|
923 | 928 | self.nplots = nplots |
|
924 | 929 | |
|
925 | 930 | ncolspan = 7 |
|
926 | 931 | colspan = 6 |
|
927 | 932 | self.__nsubplots = 2 |
|
928 | 933 | |
|
929 | 934 | self.createFigure(idfigure = idfigure, |
|
930 | 935 | wintitle = wintitle, |
|
931 | 936 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
932 | 937 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
933 | 938 | show=show) |
|
934 | 939 | |
|
935 | 940 | nrow, ncol = self.getSubplots() |
|
936 | 941 | |
|
937 | 942 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
938 | 943 | |
|
939 | 944 | |
|
940 | 945 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
941 | 946 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
942 | 947 | timerange=None, |
|
943 | 948 | save=False, figpath='./', figfile=None, show=True): |
|
944 | 949 | |
|
945 | 950 | if channelList == None: |
|
946 | 951 | channelIndexList = dataOut.channelIndexList |
|
947 | 952 | channelList = dataOut.channelList |
|
948 | 953 | else: |
|
949 | 954 | channelIndexList = [] |
|
950 | 955 | for channel in channelList: |
|
951 | 956 | if channel not in dataOut.channelList: |
|
952 | 957 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
953 | 958 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
954 | 959 | |
|
955 | 960 | if timerange != None: |
|
956 | 961 | self.timerange = timerange |
|
957 | 962 | |
|
958 | 963 | tmin = None |
|
959 | 964 | tmax = None |
|
960 | 965 | x = dataOut.getTimeRange() |
|
961 | 966 | y = dataOut.getHeiRange() |
|
962 | 967 | factor = dataOut.normFactor |
|
963 | 968 | noise = dataOut.getNoise()/factor |
|
964 | 969 | noisedB = 10*numpy.log10(noise) |
|
965 | 970 | |
|
966 | thisDatetime = dataOut.datatime | |
|
967 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
971 | #thisDatetime = dataOut.datatime | |
|
972 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
973 | title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
968 | 974 | xlabel = "" |
|
969 | 975 | ylabel = "Range (Km)" |
|
970 | 976 | |
|
971 | 977 | if not self.__isConfig: |
|
972 | 978 | |
|
973 | 979 | nplots = 1 |
|
974 | 980 | |
|
975 | 981 | self.setup(idfigure=idfigure, |
|
976 | 982 | nplots=nplots, |
|
977 | 983 | wintitle=wintitle, |
|
978 | 984 | showprofile=showprofile, |
|
979 | 985 | show=show) |
|
980 | 986 | |
|
981 | 987 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
982 | 988 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
983 | 989 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
984 | 990 | |
|
985 | 991 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
986 | 992 | self.__isConfig = True |
|
987 | 993 | |
|
988 | 994 | self.xdata = numpy.array([]) |
|
989 | 995 | self.ydata = numpy.array([]) |
|
990 | 996 | |
|
991 | 997 | self.setWinTitle(title) |
|
992 | 998 | |
|
993 | 999 | |
|
994 | 1000 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
995 | 1001 | |
|
996 | 1002 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
997 | 1003 | axes = self.axesList[0] |
|
998 | 1004 | |
|
999 | 1005 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1000 | 1006 | |
|
1001 | 1007 | if len(self.ydata)==0: |
|
1002 | 1008 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1003 | 1009 | else: |
|
1004 | 1010 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1005 | 1011 | |
|
1006 | 1012 | |
|
1007 | 1013 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1008 | 1014 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1009 | 1015 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1010 | 1016 | XAxisAsTime=True |
|
1011 | 1017 | ) |
|
1012 | 1018 | |
|
1013 | 1019 | self.draw() |
|
1014 | 1020 | |
|
1015 | 1021 | if save: |
|
1016 | 1022 | |
|
1017 | 1023 | if figfile == None: |
|
1018 | 1024 | figfile = self.getFilename(name = self.name) |
|
1019 | 1025 | |
|
1020 | 1026 | self.saveFigure(figpath, figfile) |
|
1021 | 1027 | |
|
1022 | 1028 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1023 | 1029 | self.__isConfig = False |
|
1024 | 1030 | del self.xdata |
|
1025 | 1031 | del self.ydata |
|
1026 | 1032 | |
|
1027 | 1033 | |
|
1028 | 1034 | class SpectraHeisScope(Figure): |
|
1029 | 1035 | |
|
1030 | 1036 | |
|
1031 | 1037 | __isConfig = None |
|
1032 | 1038 | __nsubplots = None |
|
1033 | 1039 | |
|
1034 | 1040 | WIDTHPROF = None |
|
1035 | 1041 | HEIGHTPROF = None |
|
1036 | 1042 | PREFIX = 'spc' |
|
1037 | 1043 | |
|
1038 | 1044 | def __init__(self): |
|
1039 | 1045 | |
|
1040 | 1046 | self.__isConfig = False |
|
1041 | 1047 | self.__nsubplots = 1 |
|
1042 | 1048 | |
|
1043 | 1049 | self.WIDTH = 230 |
|
1044 | 1050 | self.HEIGHT = 250 |
|
1045 | 1051 | self.WIDTHPROF = 120 |
|
1046 | 1052 | self.HEIGHTPROF = 0 |
|
1047 | 1053 | self.counterftp = 0 |
|
1048 | 1054 | |
|
1049 | 1055 | def getSubplots(self): |
|
1050 | 1056 | |
|
1051 | 1057 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1052 | 1058 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1053 | 1059 | |
|
1054 | 1060 | return nrow, ncol |
|
1055 | 1061 | |
|
1056 | 1062 | def setup(self, idfigure, nplots, wintitle, show): |
|
1057 | 1063 | |
|
1058 | 1064 | showprofile = False |
|
1059 | 1065 | self.__showprofile = showprofile |
|
1060 | 1066 | self.nplots = nplots |
|
1061 | 1067 | |
|
1062 | 1068 | ncolspan = 1 |
|
1063 | 1069 | colspan = 1 |
|
1064 | 1070 | if showprofile: |
|
1065 | 1071 | ncolspan = 3 |
|
1066 | 1072 | colspan = 2 |
|
1067 | 1073 | self.__nsubplots = 2 |
|
1068 | 1074 | |
|
1069 | 1075 | self.createFigure(idfigure = idfigure, |
|
1070 | 1076 | wintitle = wintitle, |
|
1071 | 1077 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1072 | 1078 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1073 | 1079 | show = show) |
|
1074 | 1080 | |
|
1075 | 1081 | nrow, ncol = self.getSubplots() |
|
1076 | 1082 | |
|
1077 | 1083 | counter = 0 |
|
1078 | 1084 | for y in range(nrow): |
|
1079 | 1085 | for x in range(ncol): |
|
1080 | 1086 | |
|
1081 | 1087 | if counter >= self.nplots: |
|
1082 | 1088 | break |
|
1083 | 1089 | |
|
1084 | 1090 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1085 | 1091 | |
|
1086 | 1092 | if showprofile: |
|
1087 | 1093 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1088 | 1094 | |
|
1089 | 1095 | counter += 1 |
|
1090 | 1096 | |
|
1091 | 1097 | # __isConfig = None |
|
1092 | 1098 | # def __init__(self): |
|
1093 | 1099 | # |
|
1094 | 1100 | # self.__isConfig = False |
|
1095 | 1101 | # self.WIDTH = 600 |
|
1096 | 1102 | # self.HEIGHT = 200 |
|
1097 | 1103 | # |
|
1098 | 1104 | # def getSubplots(self): |
|
1099 | 1105 | # |
|
1100 | 1106 | # nrow = self.nplots |
|
1101 | 1107 | # ncol = 3 |
|
1102 | 1108 | # return nrow, ncol |
|
1103 | 1109 | # |
|
1104 | 1110 | # def setup(self, idfigure, nplots, wintitle): |
|
1105 | 1111 | # |
|
1106 | 1112 | # self.nplots = nplots |
|
1107 | 1113 | # |
|
1108 | 1114 | # self.createFigure(idfigure, wintitle) |
|
1109 | 1115 | # |
|
1110 | 1116 | # nrow,ncol = self.getSubplots() |
|
1111 | 1117 | # colspan = 3 |
|
1112 | 1118 | # rowspan = 1 |
|
1113 | 1119 | # |
|
1114 | 1120 | # for i in range(nplots): |
|
1115 | 1121 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
1116 | 1122 | |
|
1117 | 1123 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
1118 | 1124 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1119 | 1125 | figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): |
|
1120 | 1126 | |
|
1121 | 1127 | """ |
|
1122 | 1128 | |
|
1123 | 1129 | Input: |
|
1124 | 1130 | dataOut : |
|
1125 | 1131 | idfigure : |
|
1126 | 1132 | wintitle : |
|
1127 | 1133 | channelList : |
|
1128 | 1134 | xmin : None, |
|
1129 | 1135 | xmax : None, |
|
1130 | 1136 | ymin : None, |
|
1131 | 1137 | ymax : None, |
|
1132 | 1138 | """ |
|
1133 | 1139 | |
|
1134 | 1140 | if dataOut.realtime: |
|
1135 | 1141 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1136 | 1142 | print 'Skipping this plot function' |
|
1137 | 1143 | return |
|
1138 | 1144 | |
|
1139 | 1145 | if channelList == None: |
|
1140 | 1146 | channelIndexList = dataOut.channelIndexList |
|
1141 | 1147 | else: |
|
1142 | 1148 | channelIndexList = [] |
|
1143 | 1149 | for channel in channelList: |
|
1144 | 1150 | if channel not in dataOut.channelList: |
|
1145 | 1151 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1146 | 1152 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1147 | 1153 | |
|
1148 | 1154 | # x = dataOut.heightList |
|
1149 | 1155 | c = 3E8 |
|
1150 | 1156 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1151 | 1157 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1152 | 1158 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1153 | 1159 | x= x/(10000.0) |
|
1154 | 1160 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1155 | 1161 | # y = y.real |
|
1156 | 1162 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1157 | 1163 | y = datadB |
|
1158 | 1164 | |
|
1159 | thisDatetime = dataOut.datatime | |
|
1160 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
1165 | #thisDatetime = dataOut.datatime | |
|
1166 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
1167 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
1161 | 1168 | xlabel = "Frequency x 10000" |
|
1162 | 1169 | ylabel = "Intensity (dB)" |
|
1163 | 1170 | |
|
1164 | 1171 | if not self.__isConfig: |
|
1165 | 1172 | nplots = len(channelIndexList) |
|
1166 | 1173 | |
|
1167 | 1174 | self.setup(idfigure=idfigure, |
|
1168 | 1175 | nplots=nplots, |
|
1169 | 1176 | wintitle=wintitle, |
|
1170 | 1177 | show=show) |
|
1171 | 1178 | |
|
1172 | 1179 | if xmin == None: xmin = numpy.nanmin(x) |
|
1173 | 1180 | if xmax == None: xmax = numpy.nanmax(x) |
|
1174 | 1181 | if ymin == None: ymin = numpy.nanmin(y) |
|
1175 | 1182 | if ymax == None: ymax = numpy.nanmax(y) |
|
1176 | 1183 | |
|
1177 | 1184 | self.__isConfig = True |
|
1178 | 1185 | |
|
1179 | 1186 | self.setWinTitle(title) |
|
1180 | 1187 | |
|
1181 | 1188 | for i in range(len(self.axesList)): |
|
1182 | 1189 | ychannel = y[i,:] |
|
1183 | 1190 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1184 | 1191 | axes = self.axesList[i] |
|
1185 | 1192 | axes.pline(x, ychannel, |
|
1186 | 1193 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1187 | 1194 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1188 | 1195 | |
|
1189 | 1196 | |
|
1190 | 1197 | self.draw() |
|
1191 | 1198 | |
|
1192 | 1199 | if save: |
|
1193 | 1200 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1194 | 1201 | if figfile == None: |
|
1195 | 1202 | figfile = self.getFilename(name = date) |
|
1196 | 1203 | |
|
1197 | 1204 | self.saveFigure(figpath, figfile) |
|
1198 | 1205 | |
|
1199 | 1206 | self.counterftp += 1 |
|
1200 | 1207 | if (ftp and (self.counterftp==ftpratio)): |
|
1201 | 1208 | figfilename = os.path.join(figpath,figfile) |
|
1202 | 1209 | self.sendByFTP(figfilename) |
|
1203 | 1210 | self.counterftp = 0 |
|
1204 | 1211 | |
|
1205 | 1212 | |
|
1206 | 1213 | class RTIfromSpectraHeis(Figure): |
|
1207 | 1214 | |
|
1208 | 1215 | __isConfig = None |
|
1209 | 1216 | __nsubplots = None |
|
1210 | 1217 | |
|
1211 | 1218 | PREFIX = 'rtinoise' |
|
1212 | 1219 | |
|
1213 | 1220 | def __init__(self): |
|
1214 | 1221 | |
|
1215 | 1222 | self.timerange = 24*60*60 |
|
1216 | 1223 | self.__isConfig = False |
|
1217 | 1224 | self.__nsubplots = 1 |
|
1218 | 1225 | |
|
1219 | 1226 | self.WIDTH = 820 |
|
1220 | 1227 | self.HEIGHT = 200 |
|
1221 | 1228 | self.WIDTHPROF = 120 |
|
1222 | 1229 | self.HEIGHTPROF = 0 |
|
1223 | 1230 | self.counterftp = 0 |
|
1224 | 1231 | self.xdata = None |
|
1225 | 1232 | self.ydata = None |
|
1226 | 1233 | |
|
1227 | 1234 | def getSubplots(self): |
|
1228 | 1235 | |
|
1229 | 1236 | ncol = 1 |
|
1230 | 1237 | nrow = 1 |
|
1231 | 1238 | |
|
1232 | 1239 | return nrow, ncol |
|
1233 | 1240 | |
|
1234 | 1241 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
1235 | 1242 | |
|
1236 | 1243 | self.__showprofile = showprofile |
|
1237 | 1244 | self.nplots = nplots |
|
1238 | 1245 | |
|
1239 | 1246 | ncolspan = 7 |
|
1240 | 1247 | colspan = 6 |
|
1241 | 1248 | self.__nsubplots = 2 |
|
1242 | 1249 | |
|
1243 | 1250 | self.createFigure(idfigure = idfigure, |
|
1244 | 1251 | wintitle = wintitle, |
|
1245 | 1252 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1246 | 1253 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1247 | 1254 | show = show) |
|
1248 | 1255 | |
|
1249 | 1256 | nrow, ncol = self.getSubplots() |
|
1250 | 1257 | |
|
1251 | 1258 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1252 | 1259 | |
|
1253 | 1260 | |
|
1254 | 1261 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
1255 | 1262 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1256 | 1263 | timerange=None, |
|
1257 | 1264 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): |
|
1258 | 1265 | |
|
1259 | 1266 | if channelList == None: |
|
1260 | 1267 | channelIndexList = dataOut.channelIndexList |
|
1261 | 1268 | channelList = dataOut.channelList |
|
1262 | 1269 | else: |
|
1263 | 1270 | channelIndexList = [] |
|
1264 | 1271 | for channel in channelList: |
|
1265 | 1272 | if channel not in dataOut.channelList: |
|
1266 | 1273 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1267 | 1274 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1268 | 1275 | |
|
1269 | 1276 | if timerange != None: |
|
1270 | 1277 | self.timerange = timerange |
|
1271 | 1278 | |
|
1272 | 1279 | tmin = None |
|
1273 | 1280 | tmax = None |
|
1274 | 1281 | x = dataOut.getTimeRange() |
|
1275 | 1282 | y = dataOut.getHeiRange() |
|
1276 | 1283 | |
|
1277 | 1284 | factor = 1 |
|
1278 | 1285 | data = dataOut.data_spc/factor |
|
1279 | 1286 | data = numpy.average(data,axis=1) |
|
1280 | 1287 | datadB = 10*numpy.log10(data) |
|
1281 | 1288 | |
|
1282 | 1289 | # factor = dataOut.normFactor |
|
1283 | 1290 | # noise = dataOut.getNoise()/factor |
|
1284 | 1291 | # noisedB = 10*numpy.log10(noise) |
|
1285 | 1292 | |
|
1286 | thisDatetime = dataOut.datatime | |
|
1287 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
1293 | #thisDatetime = dataOut.datatime | |
|
1294 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
1295 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
1288 | 1296 | xlabel = "Local Time" |
|
1289 | 1297 | ylabel = "Intensity (dB)" |
|
1290 | 1298 | |
|
1291 | 1299 | if not self.__isConfig: |
|
1292 | 1300 | |
|
1293 | 1301 | nplots = 1 |
|
1294 | 1302 | |
|
1295 | 1303 | self.setup(idfigure=idfigure, |
|
1296 | 1304 | nplots=nplots, |
|
1297 | 1305 | wintitle=wintitle, |
|
1298 | 1306 | showprofile=showprofile, |
|
1299 | 1307 | show=show) |
|
1300 | 1308 | |
|
1301 | 1309 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1302 | 1310 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1303 | 1311 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1304 | 1312 | |
|
1305 | 1313 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1306 | 1314 | self.__isConfig = True |
|
1307 | 1315 | |
|
1308 | 1316 | self.xdata = numpy.array([]) |
|
1309 | 1317 | self.ydata = numpy.array([]) |
|
1310 | 1318 | |
|
1311 | 1319 | self.setWinTitle(title) |
|
1312 | 1320 | |
|
1313 | 1321 | |
|
1314 | 1322 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1315 | 1323 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1316 | 1324 | |
|
1317 | 1325 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1318 | 1326 | axes = self.axesList[0] |
|
1319 | 1327 | |
|
1320 | 1328 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1321 | 1329 | |
|
1322 | 1330 | if len(self.ydata)==0: |
|
1323 | 1331 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1324 | 1332 | else: |
|
1325 | 1333 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1326 | 1334 | |
|
1327 | 1335 | |
|
1328 | 1336 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1329 | 1337 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1330 | 1338 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1331 | 1339 | XAxisAsTime=True |
|
1332 | 1340 | ) |
|
1333 | 1341 | |
|
1334 | 1342 | self.draw() |
|
1335 | 1343 | |
|
1336 | 1344 | if save: |
|
1337 | 1345 | |
|
1338 | 1346 | if figfile == None: |
|
1339 | 1347 | figfile = self.getFilename(name = self.name) |
|
1340 | 1348 | |
|
1341 | 1349 | self.saveFigure(figpath, figfile) |
|
1342 | 1350 | |
|
1343 | 1351 | self.counterftp += 1 |
|
1344 | 1352 | if (ftp and (self.counterftp==ftpratio)): |
|
1345 | 1353 | figfilename = os.path.join(figpath,figfile) |
|
1346 | 1354 | self.sendByFTP(figfilename) |
|
1347 | 1355 | self.counterftp = 0 |
|
1348 | 1356 | |
|
1349 | 1357 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1350 | 1358 | self.__isConfig = False |
|
1351 | 1359 | del self.xdata |
|
1352 | 1360 | del self.ydata |
|
1353 | 1361 | |
|
1354 | 1362 | |
|
1355 | 1363 | No newline at end of file |
@@ -1,1635 +1,1643 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: dsuarez $ |
|
4 | 4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import numpy |
|
8 | 8 | import datetime |
|
9 | 9 | import time |
|
10 | 10 | |
|
11 | 11 | from jrodata import * |
|
12 | 12 | from jrodataIO import * |
|
13 | 13 | from jroplot import * |
|
14 | 14 | |
|
15 | 15 | try: |
|
16 | 16 | import cfunctions |
|
17 | 17 | except: |
|
18 | 18 | pass |
|
19 | 19 | |
|
20 | 20 | class ProcessingUnit: |
|
21 | 21 | |
|
22 | 22 | """ |
|
23 | 23 | Esta es la clase base para el procesamiento de datos. |
|
24 | 24 | |
|
25 | 25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
26 | 26 | - Metodos internos (callMethod) |
|
27 | 27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
28 | 28 | tienen que ser agreagados con el metodo "add". |
|
29 | 29 | |
|
30 | 30 | """ |
|
31 | 31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
32 | 32 | dataIn = None |
|
33 | 33 | |
|
34 | 34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
35 | 35 | dataOut = None |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | objectDict = None |
|
39 | 39 | |
|
40 | 40 | def __init__(self): |
|
41 | 41 | |
|
42 | 42 | self.objectDict = {} |
|
43 | 43 | |
|
44 | 44 | def init(self): |
|
45 | 45 | |
|
46 | 46 | raise ValueError, "Not implemented" |
|
47 | 47 | |
|
48 | 48 | def addOperation(self, object, objId): |
|
49 | 49 | |
|
50 | 50 | """ |
|
51 | 51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
52 | 52 | identificador asociado a este objeto. |
|
53 | 53 | |
|
54 | 54 | Input: |
|
55 | 55 | |
|
56 | 56 | object : objeto de la clase "Operation" |
|
57 | 57 | |
|
58 | 58 | Return: |
|
59 | 59 | |
|
60 | 60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | self.objectDict[objId] = object |
|
64 | 64 | |
|
65 | 65 | return objId |
|
66 | 66 | |
|
67 | 67 | def operation(self, **kwargs): |
|
68 | 68 | |
|
69 | 69 | """ |
|
70 | 70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
71 | 71 | atributos del objeto dataOut |
|
72 | 72 | |
|
73 | 73 | Input: |
|
74 | 74 | |
|
75 | 75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
76 | 76 | """ |
|
77 | 77 | |
|
78 | 78 | raise ValueError, "ImplementedError" |
|
79 | 79 | |
|
80 | 80 | def callMethod(self, name, **kwargs): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
84 | 84 | |
|
85 | 85 | Input: |
|
86 | 86 | name : nombre del metodo a ejecutar |
|
87 | 87 | |
|
88 | 88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | if name != 'run': |
|
92 | 92 | |
|
93 | 93 | if name == 'init' and self.dataIn.isEmpty(): |
|
94 | 94 | self.dataOut.flagNoData = True |
|
95 | 95 | return False |
|
96 | 96 | |
|
97 | 97 | if name != 'init' and self.dataOut.isEmpty(): |
|
98 | 98 | return False |
|
99 | 99 | |
|
100 | 100 | methodToCall = getattr(self, name) |
|
101 | 101 | |
|
102 | 102 | methodToCall(**kwargs) |
|
103 | 103 | |
|
104 | 104 | if name != 'run': |
|
105 | 105 | return True |
|
106 | 106 | |
|
107 | 107 | if self.dataOut.isEmpty(): |
|
108 | 108 | return False |
|
109 | 109 | |
|
110 | 110 | return True |
|
111 | 111 | |
|
112 | 112 | def callObject(self, objId, **kwargs): |
|
113 | 113 | |
|
114 | 114 | """ |
|
115 | 115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
116 | 116 | |
|
117 | 117 | Input: |
|
118 | 118 | |
|
119 | 119 | objId : identificador del objeto a ejecutar |
|
120 | 120 | |
|
121 | 121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
122 | 122 | |
|
123 | 123 | Return: |
|
124 | 124 | |
|
125 | 125 | None |
|
126 | 126 | """ |
|
127 | 127 | |
|
128 | 128 | if self.dataOut.isEmpty(): |
|
129 | 129 | return False |
|
130 | 130 | |
|
131 | 131 | object = self.objectDict[objId] |
|
132 | 132 | |
|
133 | 133 | object.run(self.dataOut, **kwargs) |
|
134 | 134 | |
|
135 | 135 | return True |
|
136 | 136 | |
|
137 | 137 | def call(self, operationConf, **kwargs): |
|
138 | 138 | |
|
139 | 139 | """ |
|
140 | 140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
141 | 141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
142 | 142 | La operacion puede ser de dos tipos: |
|
143 | 143 | |
|
144 | 144 | 1. Un metodo propio de esta clase: |
|
145 | 145 | |
|
146 | 146 | operation.type = "self" |
|
147 | 147 | |
|
148 | 148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
149 | 149 | operation.type = "other". |
|
150 | 150 | |
|
151 | 151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
152 | 152 | "addOperation" e identificado con el operation.id |
|
153 | 153 | |
|
154 | 154 | |
|
155 | 155 | con el id de la operacion. |
|
156 | 156 | |
|
157 | 157 | Input: |
|
158 | 158 | |
|
159 | 159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
160 | 160 | |
|
161 | 161 | """ |
|
162 | 162 | |
|
163 | 163 | if operationConf.type == 'self': |
|
164 | 164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
165 | 165 | |
|
166 | 166 | if operationConf.type == 'other': |
|
167 | 167 | sts = self.callObject(operationConf.id, **kwargs) |
|
168 | 168 | |
|
169 | 169 | return sts |
|
170 | 170 | |
|
171 | 171 | def setInput(self, dataIn): |
|
172 | 172 | |
|
173 | 173 | self.dataIn = dataIn |
|
174 | 174 | |
|
175 | 175 | def getOutput(self): |
|
176 | 176 | |
|
177 | 177 | return self.dataOut |
|
178 | 178 | |
|
179 | 179 | class Operation(): |
|
180 | 180 | |
|
181 | 181 | """ |
|
182 | 182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
183 | 183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
184 | 184 | acumulacion dentro de esta clase |
|
185 | 185 | |
|
186 | 186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
187 | 187 | |
|
188 | 188 | """ |
|
189 | 189 | |
|
190 | 190 | __buffer = None |
|
191 | 191 | __isConfig = False |
|
192 | 192 | |
|
193 | 193 | def __init__(self): |
|
194 | 194 | |
|
195 | 195 | pass |
|
196 | 196 | |
|
197 | 197 | def run(self, dataIn, **kwargs): |
|
198 | 198 | |
|
199 | 199 | """ |
|
200 | 200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
201 | 201 | |
|
202 | 202 | Input: |
|
203 | 203 | |
|
204 | 204 | dataIn : objeto del tipo JROData |
|
205 | 205 | |
|
206 | 206 | Return: |
|
207 | 207 | |
|
208 | 208 | None |
|
209 | 209 | |
|
210 | 210 | Affected: |
|
211 | 211 | __buffer : buffer de recepcion de datos. |
|
212 | 212 | |
|
213 | 213 | """ |
|
214 | 214 | |
|
215 | 215 | raise ValueError, "ImplementedError" |
|
216 | 216 | |
|
217 | 217 | class VoltageProc(ProcessingUnit): |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | def __init__(self): |
|
221 | 221 | |
|
222 | 222 | self.objectDict = {} |
|
223 | 223 | self.dataOut = Voltage() |
|
224 | 224 | self.flip = 1 |
|
225 | 225 | |
|
226 | 226 | def init(self): |
|
227 | 227 | |
|
228 | 228 | self.dataOut.copy(self.dataIn) |
|
229 | 229 | # No necesita copiar en cada init() los atributos de dataIn |
|
230 | 230 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
231 | 231 | |
|
232 | 232 | def selectChannels(self, channelList): |
|
233 | 233 | |
|
234 | 234 | channelIndexList = [] |
|
235 | 235 | |
|
236 | 236 | for channel in channelList: |
|
237 | 237 | index = self.dataOut.channelList.index(channel) |
|
238 | 238 | channelIndexList.append(index) |
|
239 | 239 | |
|
240 | 240 | self.selectChannelsByIndex(channelIndexList) |
|
241 | 241 | |
|
242 | 242 | def selectChannelsByIndex(self, channelIndexList): |
|
243 | 243 | """ |
|
244 | 244 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
245 | 245 | |
|
246 | 246 | Input: |
|
247 | 247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
248 | 248 | |
|
249 | 249 | Affected: |
|
250 | 250 | self.dataOut.data |
|
251 | 251 | self.dataOut.channelIndexList |
|
252 | 252 | self.dataOut.nChannels |
|
253 | 253 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
254 | 254 | self.dataOut.systemHeaderObj.numChannels |
|
255 | 255 | self.dataOut.m_ProcessingHeader.blockSize |
|
256 | 256 | |
|
257 | 257 | Return: |
|
258 | 258 | None |
|
259 | 259 | """ |
|
260 | 260 | |
|
261 | 261 | for channelIndex in channelIndexList: |
|
262 | 262 | if channelIndex not in self.dataOut.channelIndexList: |
|
263 | 263 | print channelIndexList |
|
264 | 264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
265 | 265 | |
|
266 | 266 | nChannels = len(channelIndexList) |
|
267 | 267 | |
|
268 | 268 | data = self.dataOut.data[channelIndexList,:] |
|
269 | 269 | |
|
270 | 270 | self.dataOut.data = data |
|
271 | 271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
272 | 272 | # self.dataOut.nChannels = nChannels |
|
273 | 273 | |
|
274 | 274 | return 1 |
|
275 | 275 | |
|
276 | def selectHeights(self, minHei, maxHei): | |
|
276 | def selectHeights(self, minHei=None, maxHei=None): | |
|
277 | 277 | """ |
|
278 | 278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
279 | 279 | minHei <= height <= maxHei |
|
280 | 280 | |
|
281 | 281 | Input: |
|
282 | 282 | minHei : valor minimo de altura a considerar |
|
283 | 283 | maxHei : valor maximo de altura a considerar |
|
284 | 284 | |
|
285 | 285 | Affected: |
|
286 | 286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
287 | 287 | |
|
288 | 288 | Return: |
|
289 | 289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
290 | 290 | """ |
|
291 | ||
|
292 | if minHei == None: | |
|
293 | minHei = self.dataOut.heightList[0] | |
|
294 | ||
|
295 | if maxHei == None: | |
|
296 | maxHei = self.dataOut.heightList[-1] | |
|
297 | ||
|
291 | 298 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
292 | 299 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
293 | 300 | |
|
301 | ||
|
294 | 302 | if (maxHei > self.dataOut.heightList[-1]): |
|
295 | 303 | maxHei = self.dataOut.heightList[-1] |
|
296 | 304 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
297 | 305 | |
|
298 | 306 | minIndex = 0 |
|
299 | 307 | maxIndex = 0 |
|
300 | 308 | heights = self.dataOut.heightList |
|
301 | 309 | |
|
302 | 310 | inda = numpy.where(heights >= minHei) |
|
303 | 311 | indb = numpy.where(heights <= maxHei) |
|
304 | 312 | |
|
305 | 313 | try: |
|
306 | 314 | minIndex = inda[0][0] |
|
307 | 315 | except: |
|
308 | 316 | minIndex = 0 |
|
309 | 317 | |
|
310 | 318 | try: |
|
311 | 319 | maxIndex = indb[0][-1] |
|
312 | 320 | except: |
|
313 | 321 | maxIndex = len(heights) |
|
314 | 322 | |
|
315 | 323 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
316 | 324 | |
|
317 | 325 | return 1 |
|
318 | 326 | |
|
319 | 327 | |
|
320 | 328 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
321 | 329 | """ |
|
322 | 330 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
323 | 331 | minIndex <= index <= maxIndex |
|
324 | 332 | |
|
325 | 333 | Input: |
|
326 | 334 | minIndex : valor de indice minimo de altura a considerar |
|
327 | 335 | maxIndex : valor de indice maximo de altura a considerar |
|
328 | 336 | |
|
329 | 337 | Affected: |
|
330 | 338 | self.dataOut.data |
|
331 | 339 | self.dataOut.heightList |
|
332 | 340 | |
|
333 | 341 | Return: |
|
334 | 342 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
335 | 343 | """ |
|
336 | 344 | |
|
337 | 345 | if (minIndex < 0) or (minIndex > maxIndex): |
|
338 | 346 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
339 | 347 | |
|
340 | 348 | if (maxIndex >= self.dataOut.nHeights): |
|
341 | 349 | maxIndex = self.dataOut.nHeights-1 |
|
342 | 350 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
343 | 351 | |
|
344 | 352 | nHeights = maxIndex - minIndex + 1 |
|
345 | 353 | |
|
346 | 354 | #voltage |
|
347 | 355 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
348 | 356 | |
|
349 | 357 | firstHeight = self.dataOut.heightList[minIndex] |
|
350 | 358 | |
|
351 | 359 | self.dataOut.data = data |
|
352 | 360 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
353 | 361 | |
|
354 | 362 | return 1 |
|
355 | 363 | |
|
356 | 364 | |
|
357 | 365 | def filterByHeights(self, window): |
|
358 | 366 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
359 | 367 | |
|
360 | 368 | if window == None: |
|
361 | window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight | |
|
369 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
|
362 | 370 | |
|
363 | 371 | newdelta = deltaHeight * window |
|
364 | 372 | r = self.dataOut.data.shape[1] % window |
|
365 | 373 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
366 | 374 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
367 | 375 | buffer = numpy.sum(buffer,2) |
|
368 | 376 | self.dataOut.data = buffer |
|
369 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta) | |
|
377 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
|
370 | 378 | self.dataOut.windowOfFilter = window |
|
371 | 379 | |
|
372 | 380 | def deFlip(self): |
|
373 | 381 | self.dataOut.data *= self.flip |
|
374 | 382 | self.flip *= -1. |
|
375 | 383 | |
|
376 | 384 | |
|
377 | 385 | class CohInt(Operation): |
|
378 | 386 | |
|
379 | 387 | __isConfig = False |
|
380 | 388 | |
|
381 | 389 | __profIndex = 0 |
|
382 | 390 | __withOverapping = False |
|
383 | 391 | |
|
384 | 392 | __byTime = False |
|
385 | 393 | __initime = None |
|
386 | 394 | __lastdatatime = None |
|
387 | 395 | __integrationtime = None |
|
388 | 396 | |
|
389 | 397 | __buffer = None |
|
390 | 398 | |
|
391 | 399 | __dataReady = False |
|
392 | 400 | |
|
393 | 401 | n = None |
|
394 | 402 | |
|
395 | 403 | |
|
396 | 404 | def __init__(self): |
|
397 | 405 | |
|
398 | 406 | self.__isConfig = False |
|
399 | 407 | |
|
400 | 408 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
401 | 409 | """ |
|
402 | 410 | Set the parameters of the integration class. |
|
403 | 411 | |
|
404 | 412 | Inputs: |
|
405 | 413 | |
|
406 | 414 | n : Number of coherent integrations |
|
407 | 415 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
408 | 416 | overlapping : |
|
409 | 417 | |
|
410 | 418 | """ |
|
411 | 419 | |
|
412 | 420 | self.__initime = None |
|
413 | 421 | self.__lastdatatime = 0 |
|
414 | 422 | self.__buffer = None |
|
415 | 423 | self.__dataReady = False |
|
416 | 424 | |
|
417 | 425 | |
|
418 | 426 | if n == None and timeInterval == None: |
|
419 | 427 | raise ValueError, "n or timeInterval should be specified ..." |
|
420 | 428 | |
|
421 | 429 | if n != None: |
|
422 | 430 | self.n = n |
|
423 | 431 | self.__byTime = False |
|
424 | 432 | else: |
|
425 | 433 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
426 | 434 | self.n = 9999 |
|
427 | 435 | self.__byTime = True |
|
428 | 436 | |
|
429 | 437 | if overlapping: |
|
430 | 438 | self.__withOverapping = True |
|
431 | 439 | self.__buffer = None |
|
432 | 440 | else: |
|
433 | 441 | self.__withOverapping = False |
|
434 | 442 | self.__buffer = 0 |
|
435 | 443 | |
|
436 | 444 | self.__profIndex = 0 |
|
437 | 445 | |
|
438 | 446 | def putData(self, data): |
|
439 | 447 | |
|
440 | 448 | """ |
|
441 | 449 | Add a profile to the __buffer and increase in one the __profileIndex |
|
442 | 450 | |
|
443 | 451 | """ |
|
444 | 452 | |
|
445 | 453 | if not self.__withOverapping: |
|
446 | 454 | self.__buffer += data.copy() |
|
447 | 455 | self.__profIndex += 1 |
|
448 | 456 | return |
|
449 | 457 | |
|
450 | 458 | #Overlapping data |
|
451 | 459 | nChannels, nHeis = data.shape |
|
452 | 460 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
453 | 461 | |
|
454 | 462 | #If the buffer is empty then it takes the data value |
|
455 | 463 | if self.__buffer == None: |
|
456 | 464 | self.__buffer = data |
|
457 | 465 | self.__profIndex += 1 |
|
458 | 466 | return |
|
459 | 467 | |
|
460 | 468 | #If the buffer length is lower than n then stakcing the data value |
|
461 | 469 | if self.__profIndex < self.n: |
|
462 | 470 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
463 | 471 | self.__profIndex += 1 |
|
464 | 472 | return |
|
465 | 473 | |
|
466 | 474 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
467 | 475 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
468 | 476 | self.__buffer[self.n-1] = data |
|
469 | 477 | self.__profIndex = self.n |
|
470 | 478 | return |
|
471 | 479 | |
|
472 | 480 | |
|
473 | 481 | def pushData(self): |
|
474 | 482 | """ |
|
475 | 483 | Return the sum of the last profiles and the profiles used in the sum. |
|
476 | 484 | |
|
477 | 485 | Affected: |
|
478 | 486 | |
|
479 | 487 | self.__profileIndex |
|
480 | 488 | |
|
481 | 489 | """ |
|
482 | 490 | |
|
483 | 491 | if not self.__withOverapping: |
|
484 | 492 | data = self.__buffer |
|
485 | 493 | n = self.__profIndex |
|
486 | 494 | |
|
487 | 495 | self.__buffer = 0 |
|
488 | 496 | self.__profIndex = 0 |
|
489 | 497 | |
|
490 | 498 | return data, n |
|
491 | 499 | |
|
492 | 500 | #Integration with Overlapping |
|
493 | 501 | data = numpy.sum(self.__buffer, axis=0) |
|
494 | 502 | n = self.__profIndex |
|
495 | 503 | |
|
496 | 504 | return data, n |
|
497 | 505 | |
|
498 | 506 | def byProfiles(self, data): |
|
499 | 507 | |
|
500 | 508 | self.__dataReady = False |
|
501 | 509 | avgdata = None |
|
502 | 510 | n = None |
|
503 | 511 | |
|
504 | 512 | self.putData(data) |
|
505 | 513 | |
|
506 | 514 | if self.__profIndex == self.n: |
|
507 | 515 | |
|
508 | 516 | avgdata, n = self.pushData() |
|
509 | 517 | self.__dataReady = True |
|
510 | 518 | |
|
511 | 519 | return avgdata |
|
512 | 520 | |
|
513 | 521 | def byTime(self, data, datatime): |
|
514 | 522 | |
|
515 | 523 | self.__dataReady = False |
|
516 | 524 | avgdata = None |
|
517 | 525 | n = None |
|
518 | 526 | |
|
519 | 527 | self.putData(data) |
|
520 | 528 | |
|
521 | 529 | if (datatime - self.__initime) >= self.__integrationtime: |
|
522 | 530 | avgdata, n = self.pushData() |
|
523 | 531 | self.n = n |
|
524 | 532 | self.__dataReady = True |
|
525 | 533 | |
|
526 | 534 | return avgdata |
|
527 | 535 | |
|
528 | 536 | def integrate(self, data, datatime=None): |
|
529 | 537 | |
|
530 | 538 | if self.__initime == None: |
|
531 | 539 | self.__initime = datatime |
|
532 | 540 | |
|
533 | 541 | if self.__byTime: |
|
534 | 542 | avgdata = self.byTime(data, datatime) |
|
535 | 543 | else: |
|
536 | 544 | avgdata = self.byProfiles(data) |
|
537 | 545 | |
|
538 | 546 | |
|
539 | 547 | self.__lastdatatime = datatime |
|
540 | 548 | |
|
541 | 549 | if avgdata == None: |
|
542 | 550 | return None, None |
|
543 | 551 | |
|
544 | 552 | avgdatatime = self.__initime |
|
545 | 553 | |
|
546 | 554 | deltatime = datatime -self.__lastdatatime |
|
547 | 555 | |
|
548 | 556 | if not self.__withOverapping: |
|
549 | 557 | self.__initime = datatime |
|
550 | 558 | else: |
|
551 | 559 | self.__initime += deltatime |
|
552 | 560 | |
|
553 | 561 | return avgdata, avgdatatime |
|
554 | 562 | |
|
555 | 563 | def run(self, dataOut, **kwargs): |
|
556 | 564 | |
|
557 | 565 | if not self.__isConfig: |
|
558 | 566 | self.setup(**kwargs) |
|
559 | 567 | self.__isConfig = True |
|
560 | 568 | |
|
561 | 569 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
562 | 570 | |
|
563 | 571 | # dataOut.timeInterval *= n |
|
564 | 572 | dataOut.flagNoData = True |
|
565 | 573 | |
|
566 | 574 | if self.__dataReady: |
|
567 | 575 | dataOut.data = avgdata |
|
568 | 576 | dataOut.nCohInt *= self.n |
|
569 | 577 | dataOut.utctime = avgdatatime |
|
570 | 578 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
571 | 579 | dataOut.flagNoData = False |
|
572 | 580 | |
|
573 | 581 | |
|
574 | 582 | class Decoder(Operation): |
|
575 | 583 | |
|
576 | 584 | __isConfig = False |
|
577 | 585 | __profIndex = 0 |
|
578 | 586 | |
|
579 | 587 | code = None |
|
580 | 588 | |
|
581 | 589 | nCode = None |
|
582 | 590 | nBaud = None |
|
583 | 591 | |
|
584 | 592 | def __init__(self): |
|
585 | 593 | |
|
586 | 594 | self.__isConfig = False |
|
587 | 595 | |
|
588 | 596 | def setup(self, code, shape): |
|
589 | 597 | |
|
590 | 598 | self.__profIndex = 0 |
|
591 | 599 | |
|
592 | 600 | self.code = code |
|
593 | 601 | |
|
594 | 602 | self.nCode = len(code) |
|
595 | 603 | self.nBaud = len(code[0]) |
|
596 | 604 | |
|
597 | 605 | self.__nChannels, self.__nHeis = shape |
|
598 | 606 | |
|
599 | 607 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
600 | 608 | |
|
601 | 609 | __codeBuffer[:,0:self.nBaud] = self.code |
|
602 | 610 | |
|
603 | 611 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
604 | 612 | |
|
605 | 613 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
606 | 614 | |
|
607 | 615 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
608 | 616 | |
|
609 | 617 | def convolutionInFreq(self, data): |
|
610 | 618 | |
|
611 | 619 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
612 | 620 | |
|
613 | 621 | fft_data = numpy.fft.fft(data, axis=1) |
|
614 | 622 | |
|
615 | 623 | conv = fft_data*fft_code |
|
616 | 624 | |
|
617 | 625 | data = numpy.fft.ifft(conv,axis=1) |
|
618 | 626 | |
|
619 | 627 | datadec = data[:,:-self.nBaud+1] |
|
620 | 628 | |
|
621 | 629 | return datadec |
|
622 | 630 | |
|
623 | 631 | def convolutionInFreqOpt(self, data): |
|
624 | 632 | |
|
625 | 633 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
626 | 634 | |
|
627 | 635 | data = cfunctions.decoder(fft_code, data) |
|
628 | 636 | |
|
629 | 637 | datadec = data[:,:-self.nBaud+1] |
|
630 | 638 | |
|
631 | 639 | return datadec |
|
632 | 640 | |
|
633 | 641 | def convolutionInTime(self, data): |
|
634 | 642 | |
|
635 | 643 | code = self.code[self.__profIndex] |
|
636 | 644 | |
|
637 | 645 | for i in range(self.__nChannels): |
|
638 | 646 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
639 | 647 | |
|
640 | 648 | return self.datadecTime |
|
641 | 649 | |
|
642 | 650 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
643 | 651 | |
|
644 | 652 | if not self.__isConfig: |
|
645 | 653 | |
|
646 | 654 | if code == None: |
|
647 | 655 | code = dataOut.code |
|
648 | 656 | else: |
|
649 | 657 | code = numpy.array(code).reshape(nCode,nBaud) |
|
650 | 658 | dataOut.code = code |
|
651 | 659 | dataOut.nCode = nCode |
|
652 | 660 | dataOut.nBaud = nBaud |
|
653 | 661 | |
|
654 | 662 | if code == None: |
|
655 | 663 | return 1 |
|
656 | 664 | |
|
657 | 665 | self.setup(code, dataOut.data.shape) |
|
658 | 666 | self.__isConfig = True |
|
659 | 667 | |
|
660 | 668 | if mode == 0: |
|
661 | 669 | datadec = self.convolutionInTime(dataOut.data) |
|
662 | 670 | |
|
663 | 671 | if mode == 1: |
|
664 | 672 | datadec = self.convolutionInFreq(dataOut.data) |
|
665 | 673 | |
|
666 | 674 | if mode == 2: |
|
667 | 675 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
668 | 676 | |
|
669 | 677 | dataOut.data = datadec |
|
670 | 678 | |
|
671 | 679 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
672 | 680 | |
|
673 | 681 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
674 | 682 | |
|
675 | 683 | if self.__profIndex == self.nCode-1: |
|
676 | 684 | self.__profIndex = 0 |
|
677 | 685 | return 1 |
|
678 | 686 | |
|
679 | 687 | self.__profIndex += 1 |
|
680 | 688 | |
|
681 | 689 | return 1 |
|
682 | 690 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
683 | 691 | |
|
684 | 692 | |
|
685 | 693 | |
|
686 | 694 | class SpectraProc(ProcessingUnit): |
|
687 | 695 | |
|
688 | 696 | def __init__(self): |
|
689 | 697 | |
|
690 | 698 | self.objectDict = {} |
|
691 | 699 | self.buffer = None |
|
692 | 700 | self.firstdatatime = None |
|
693 | 701 | self.profIndex = 0 |
|
694 | 702 | self.dataOut = Spectra() |
|
695 | 703 | |
|
696 | 704 | def __updateObjFromInput(self): |
|
697 | 705 | |
|
698 | 706 | self.dataOut.timeZone = self.dataIn.timeZone |
|
699 | 707 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
700 | 708 | self.dataOut.errorCount = self.dataIn.errorCount |
|
701 | 709 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
702 | 710 | |
|
703 | 711 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
704 | 712 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
705 | 713 | self.dataOut.channelList = self.dataIn.channelList |
|
706 | 714 | self.dataOut.heightList = self.dataIn.heightList |
|
707 | 715 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
708 | 716 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
709 | 717 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
710 | 718 | self.dataOut.nBaud = self.dataIn.nBaud |
|
711 | 719 | self.dataOut.nCode = self.dataIn.nCode |
|
712 | 720 | self.dataOut.code = self.dataIn.code |
|
713 | 721 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
714 | 722 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
715 | 723 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
716 | 724 | self.dataOut.utctime = self.firstdatatime |
|
717 | 725 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
718 | 726 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
719 | 727 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
720 | 728 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
721 | 729 | self.dataOut.nIncohInt = 1 |
|
722 | 730 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
723 | 731 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
724 | 732 | |
|
725 | 733 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
726 | 734 | |
|
727 | 735 | def __getFft(self): |
|
728 | 736 | """ |
|
729 | 737 | Convierte valores de Voltaje a Spectra |
|
730 | 738 | |
|
731 | 739 | Affected: |
|
732 | 740 | self.dataOut.data_spc |
|
733 | 741 | self.dataOut.data_cspc |
|
734 | 742 | self.dataOut.data_dc |
|
735 | 743 | self.dataOut.heightList |
|
736 | 744 | self.profIndex |
|
737 | 745 | self.buffer |
|
738 | 746 | self.dataOut.flagNoData |
|
739 | 747 | """ |
|
740 | 748 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
741 | 749 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
742 | 750 | dc = fft_volt[:,0,:] |
|
743 | 751 | |
|
744 | 752 | #calculo de self-spectra |
|
745 | 753 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
746 | 754 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
747 | 755 | spc = spc.real |
|
748 | 756 | |
|
749 | 757 | blocksize = 0 |
|
750 | 758 | blocksize += dc.size |
|
751 | 759 | blocksize += spc.size |
|
752 | 760 | |
|
753 | 761 | cspc = None |
|
754 | 762 | pairIndex = 0 |
|
755 | 763 | if self.dataOut.pairsList != None: |
|
756 | 764 | #calculo de cross-spectra |
|
757 | 765 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
758 | 766 | for pair in self.dataOut.pairsList: |
|
759 | 767 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
760 | 768 | pairIndex += 1 |
|
761 | 769 | blocksize += cspc.size |
|
762 | 770 | |
|
763 | 771 | self.dataOut.data_spc = spc |
|
764 | 772 | self.dataOut.data_cspc = cspc |
|
765 | 773 | self.dataOut.data_dc = dc |
|
766 | 774 | self.dataOut.blockSize = blocksize |
|
767 | 775 | self.dataOut.flagShiftFFT = False |
|
768 | 776 | |
|
769 | 777 | def init(self, nFFTPoints=None, pairsList=None): |
|
770 | 778 | |
|
771 | 779 | self.dataOut.flagNoData = True |
|
772 | 780 | |
|
773 | 781 | if self.dataIn.type == "Spectra": |
|
774 | 782 | self.dataOut.copy(self.dataIn) |
|
775 | 783 | return |
|
776 | 784 | |
|
777 | 785 | if self.dataIn.type == "Voltage": |
|
778 | 786 | |
|
779 | 787 | if nFFTPoints == None: |
|
780 | 788 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
781 | 789 | |
|
782 | 790 | if pairsList == None: |
|
783 | 791 | nPairs = 0 |
|
784 | 792 | else: |
|
785 | 793 | nPairs = len(pairsList) |
|
786 | 794 | |
|
787 | 795 | self.dataOut.nFFTPoints = nFFTPoints |
|
788 | 796 | self.dataOut.pairsList = pairsList |
|
789 | 797 | self.dataOut.nPairs = nPairs |
|
790 | 798 | |
|
791 | 799 | if self.buffer == None: |
|
792 | 800 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
793 | 801 | self.dataOut.nFFTPoints, |
|
794 | 802 | self.dataIn.nHeights), |
|
795 | 803 | dtype='complex') |
|
796 | 804 | |
|
797 | 805 | |
|
798 | 806 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
799 | 807 | self.profIndex += 1 |
|
800 | 808 | |
|
801 | 809 | if self.firstdatatime == None: |
|
802 | 810 | self.firstdatatime = self.dataIn.utctime |
|
803 | 811 | |
|
804 | 812 | if self.profIndex == self.dataOut.nFFTPoints: |
|
805 | 813 | self.__updateObjFromInput() |
|
806 | 814 | self.__getFft() |
|
807 | 815 | |
|
808 | 816 | self.dataOut.flagNoData = False |
|
809 | 817 | |
|
810 | 818 | self.buffer = None |
|
811 | 819 | self.firstdatatime = None |
|
812 | 820 | self.profIndex = 0 |
|
813 | 821 | |
|
814 | 822 | return |
|
815 | 823 | |
|
816 | 824 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
817 | 825 | |
|
818 | 826 | def selectChannels(self, channelList): |
|
819 | 827 | |
|
820 | 828 | channelIndexList = [] |
|
821 | 829 | |
|
822 | 830 | for channel in channelList: |
|
823 | 831 | index = self.dataOut.channelList.index(channel) |
|
824 | 832 | channelIndexList.append(index) |
|
825 | 833 | |
|
826 | 834 | self.selectChannelsByIndex(channelIndexList) |
|
827 | 835 | |
|
828 | 836 | def selectChannelsByIndex(self, channelIndexList): |
|
829 | 837 | """ |
|
830 | 838 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
831 | 839 | |
|
832 | 840 | Input: |
|
833 | 841 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
834 | 842 | |
|
835 | 843 | Affected: |
|
836 | 844 | self.dataOut.data_spc |
|
837 | 845 | self.dataOut.channelIndexList |
|
838 | 846 | self.dataOut.nChannels |
|
839 | 847 | |
|
840 | 848 | Return: |
|
841 | 849 | None |
|
842 | 850 | """ |
|
843 | 851 | |
|
844 | 852 | for channelIndex in channelIndexList: |
|
845 | 853 | if channelIndex not in self.dataOut.channelIndexList: |
|
846 | 854 | print channelIndexList |
|
847 | 855 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
848 | 856 | |
|
849 | 857 | nChannels = len(channelIndexList) |
|
850 | 858 | |
|
851 | 859 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
852 | 860 | |
|
853 | 861 | self.dataOut.data_spc = data_spc |
|
854 | 862 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
855 | 863 | # self.dataOut.nChannels = nChannels |
|
856 | 864 | |
|
857 | 865 | return 1 |
|
858 | 866 | |
|
859 | 867 | def selectHeights(self, minHei, maxHei): |
|
860 | 868 | """ |
|
861 | 869 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
862 | 870 | minHei <= height <= maxHei |
|
863 | 871 | |
|
864 | 872 | Input: |
|
865 | 873 | minHei : valor minimo de altura a considerar |
|
866 | 874 | maxHei : valor maximo de altura a considerar |
|
867 | 875 | |
|
868 | 876 | Affected: |
|
869 | 877 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
870 | 878 | |
|
871 | 879 | Return: |
|
872 | 880 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
873 | 881 | """ |
|
874 | 882 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
875 | 883 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
876 | 884 | |
|
877 | 885 | if (maxHei > self.dataOut.heightList[-1]): |
|
878 | 886 | maxHei = self.dataOut.heightList[-1] |
|
879 | 887 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
880 | 888 | |
|
881 | 889 | minIndex = 0 |
|
882 | 890 | maxIndex = 0 |
|
883 | 891 | heights = self.dataOut.heightList |
|
884 | 892 | |
|
885 | 893 | inda = numpy.where(heights >= minHei) |
|
886 | 894 | indb = numpy.where(heights <= maxHei) |
|
887 | 895 | |
|
888 | 896 | try: |
|
889 | 897 | minIndex = inda[0][0] |
|
890 | 898 | except: |
|
891 | 899 | minIndex = 0 |
|
892 | 900 | |
|
893 | 901 | try: |
|
894 | 902 | maxIndex = indb[0][-1] |
|
895 | 903 | except: |
|
896 | 904 | maxIndex = len(heights) |
|
897 | 905 | |
|
898 | 906 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
899 | 907 | |
|
900 | 908 | return 1 |
|
901 | 909 | |
|
902 | 910 | |
|
903 | 911 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
904 | 912 | """ |
|
905 | 913 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
906 | 914 | minIndex <= index <= maxIndex |
|
907 | 915 | |
|
908 | 916 | Input: |
|
909 | 917 | minIndex : valor de indice minimo de altura a considerar |
|
910 | 918 | maxIndex : valor de indice maximo de altura a considerar |
|
911 | 919 | |
|
912 | 920 | Affected: |
|
913 | 921 | self.dataOut.data_spc |
|
914 | 922 | self.dataOut.data_cspc |
|
915 | 923 | self.dataOut.data_dc |
|
916 | 924 | self.dataOut.heightList |
|
917 | 925 | |
|
918 | 926 | Return: |
|
919 | 927 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
920 | 928 | """ |
|
921 | 929 | |
|
922 | 930 | if (minIndex < 0) or (minIndex > maxIndex): |
|
923 | 931 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
924 | 932 | |
|
925 | 933 | if (maxIndex >= self.dataOut.nHeights): |
|
926 | 934 | maxIndex = self.dataOut.nHeights-1 |
|
927 | 935 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
928 | 936 | |
|
929 | 937 | nHeights = maxIndex - minIndex + 1 |
|
930 | 938 | |
|
931 | 939 | #Spectra |
|
932 | 940 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
933 | 941 | |
|
934 | 942 | data_cspc = None |
|
935 | 943 | if self.dataOut.data_cspc != None: |
|
936 | 944 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
937 | 945 | |
|
938 | 946 | data_dc = None |
|
939 | 947 | if self.dataOut.data_dc != None: |
|
940 | 948 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
941 | 949 | |
|
942 | 950 | self.dataOut.data_spc = data_spc |
|
943 | 951 | self.dataOut.data_cspc = data_cspc |
|
944 | 952 | self.dataOut.data_dc = data_dc |
|
945 | 953 | |
|
946 | 954 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
947 | 955 | |
|
948 | 956 | return 1 |
|
949 | 957 | |
|
950 | 958 | def removeDC(self, mode = 1): |
|
951 | 959 | |
|
952 | 960 | dc_index = 0 |
|
953 | 961 | freq_index = numpy.array([-2,-1,1,2]) |
|
954 | 962 | data_spc = self.dataOut.data_spc |
|
955 | 963 | data_cspc = self.dataOut.data_cspc |
|
956 | 964 | data_dc = self.dataOut.data_dc |
|
957 | 965 | |
|
958 | 966 | if self.dataOut.flagShiftFFT: |
|
959 | 967 | dc_index += self.dataOut.nFFTPoints/2 |
|
960 | 968 | freq_index += self.dataOut.nFFTPoints/2 |
|
961 | 969 | |
|
962 | 970 | if mode == 1: |
|
963 | 971 | data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2 |
|
964 | 972 | if data_cspc != None: |
|
965 | 973 | data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2 |
|
966 | 974 | return 1 |
|
967 | 975 | |
|
968 | 976 | if mode == 2: |
|
969 | 977 | pass |
|
970 | 978 | |
|
971 | 979 | if mode == 3: |
|
972 | 980 | pass |
|
973 | 981 | |
|
974 | 982 | raise ValueError, "mode parameter has to be 1, 2 or 3" |
|
975 | 983 | |
|
976 | 984 | def removeInterference(self): |
|
977 | 985 | |
|
978 | 986 | pass |
|
979 | 987 | |
|
980 | 988 | |
|
981 | 989 | class IncohInt(Operation): |
|
982 | 990 | |
|
983 | 991 | |
|
984 | 992 | __profIndex = 0 |
|
985 | 993 | __withOverapping = False |
|
986 | 994 | |
|
987 | 995 | __byTime = False |
|
988 | 996 | __initime = None |
|
989 | 997 | __lastdatatime = None |
|
990 | 998 | __integrationtime = None |
|
991 | 999 | |
|
992 | 1000 | __buffer_spc = None |
|
993 | 1001 | __buffer_cspc = None |
|
994 | 1002 | __buffer_dc = None |
|
995 | 1003 | |
|
996 | 1004 | __dataReady = False |
|
997 | 1005 | |
|
998 | 1006 | __timeInterval = None |
|
999 | 1007 | |
|
1000 | 1008 | n = None |
|
1001 | 1009 | |
|
1002 | 1010 | |
|
1003 | 1011 | |
|
1004 | 1012 | def __init__(self): |
|
1005 | 1013 | |
|
1006 | 1014 | self.__isConfig = False |
|
1007 | 1015 | |
|
1008 | 1016 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1009 | 1017 | """ |
|
1010 | 1018 | Set the parameters of the integration class. |
|
1011 | 1019 | |
|
1012 | 1020 | Inputs: |
|
1013 | 1021 | |
|
1014 | 1022 | n : Number of coherent integrations |
|
1015 | 1023 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1016 | 1024 | overlapping : |
|
1017 | 1025 | |
|
1018 | 1026 | """ |
|
1019 | 1027 | |
|
1020 | 1028 | self.__initime = None |
|
1021 | 1029 | self.__lastdatatime = 0 |
|
1022 | 1030 | self.__buffer_spc = None |
|
1023 | 1031 | self.__buffer_cspc = None |
|
1024 | 1032 | self.__buffer_dc = None |
|
1025 | 1033 | self.__dataReady = False |
|
1026 | 1034 | |
|
1027 | 1035 | |
|
1028 | 1036 | if n == None and timeInterval == None: |
|
1029 | 1037 | raise ValueError, "n or timeInterval should be specified ..." |
|
1030 | 1038 | |
|
1031 | 1039 | if n != None: |
|
1032 | 1040 | self.n = n |
|
1033 | 1041 | self.__byTime = False |
|
1034 | 1042 | else: |
|
1035 | 1043 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
1036 | 1044 | self.n = 9999 |
|
1037 | 1045 | self.__byTime = True |
|
1038 | 1046 | |
|
1039 | 1047 | if overlapping: |
|
1040 | 1048 | self.__withOverapping = True |
|
1041 | 1049 | else: |
|
1042 | 1050 | self.__withOverapping = False |
|
1043 | 1051 | self.__buffer_spc = 0 |
|
1044 | 1052 | self.__buffer_cspc = 0 |
|
1045 | 1053 | self.__buffer_dc = 0 |
|
1046 | 1054 | |
|
1047 | 1055 | self.__profIndex = 0 |
|
1048 | 1056 | |
|
1049 | 1057 | def putData(self, data_spc, data_cspc, data_dc): |
|
1050 | 1058 | |
|
1051 | 1059 | """ |
|
1052 | 1060 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1053 | 1061 | |
|
1054 | 1062 | """ |
|
1055 | 1063 | |
|
1056 | 1064 | if not self.__withOverapping: |
|
1057 | 1065 | self.__buffer_spc += data_spc |
|
1058 | 1066 | |
|
1059 | 1067 | if data_cspc == None: |
|
1060 | 1068 | self.__buffer_cspc = None |
|
1061 | 1069 | else: |
|
1062 | 1070 | self.__buffer_cspc += data_cspc |
|
1063 | 1071 | |
|
1064 | 1072 | if data_dc == None: |
|
1065 | 1073 | self.__buffer_dc = None |
|
1066 | 1074 | else: |
|
1067 | 1075 | self.__buffer_dc += data_dc |
|
1068 | 1076 | |
|
1069 | 1077 | self.__profIndex += 1 |
|
1070 | 1078 | return |
|
1071 | 1079 | |
|
1072 | 1080 | #Overlapping data |
|
1073 | 1081 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1074 | 1082 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1075 | 1083 | if data_cspc != None: |
|
1076 | 1084 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1077 | 1085 | if data_dc != None: |
|
1078 | 1086 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1079 | 1087 | |
|
1080 | 1088 | #If the buffer is empty then it takes the data value |
|
1081 | 1089 | if self.__buffer_spc == None: |
|
1082 | 1090 | self.__buffer_spc = data_spc |
|
1083 | 1091 | |
|
1084 | 1092 | if data_cspc == None: |
|
1085 | 1093 | self.__buffer_cspc = None |
|
1086 | 1094 | else: |
|
1087 | 1095 | self.__buffer_cspc += data_cspc |
|
1088 | 1096 | |
|
1089 | 1097 | if data_dc == None: |
|
1090 | 1098 | self.__buffer_dc = None |
|
1091 | 1099 | else: |
|
1092 | 1100 | self.__buffer_dc += data_dc |
|
1093 | 1101 | |
|
1094 | 1102 | self.__profIndex += 1 |
|
1095 | 1103 | return |
|
1096 | 1104 | |
|
1097 | 1105 | #If the buffer length is lower than n then stakcing the data value |
|
1098 | 1106 | if self.__profIndex < self.n: |
|
1099 | 1107 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1100 | 1108 | |
|
1101 | 1109 | if data_cspc != None: |
|
1102 | 1110 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1103 | 1111 | |
|
1104 | 1112 | if data_dc != None: |
|
1105 | 1113 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1106 | 1114 | |
|
1107 | 1115 | self.__profIndex += 1 |
|
1108 | 1116 | return |
|
1109 | 1117 | |
|
1110 | 1118 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1111 | 1119 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1112 | 1120 | self.__buffer_spc[self.n-1] = data_spc |
|
1113 | 1121 | |
|
1114 | 1122 | if data_cspc != None: |
|
1115 | 1123 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1116 | 1124 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1117 | 1125 | |
|
1118 | 1126 | if data_dc != None: |
|
1119 | 1127 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1120 | 1128 | self.__buffer_dc[self.n-1] = data_dc |
|
1121 | 1129 | |
|
1122 | 1130 | self.__profIndex = self.n |
|
1123 | 1131 | return |
|
1124 | 1132 | |
|
1125 | 1133 | |
|
1126 | 1134 | def pushData(self): |
|
1127 | 1135 | """ |
|
1128 | 1136 | Return the sum of the last profiles and the profiles used in the sum. |
|
1129 | 1137 | |
|
1130 | 1138 | Affected: |
|
1131 | 1139 | |
|
1132 | 1140 | self.__profileIndex |
|
1133 | 1141 | |
|
1134 | 1142 | """ |
|
1135 | 1143 | data_spc = None |
|
1136 | 1144 | data_cspc = None |
|
1137 | 1145 | data_dc = None |
|
1138 | 1146 | |
|
1139 | 1147 | if not self.__withOverapping: |
|
1140 | 1148 | data_spc = self.__buffer_spc |
|
1141 | 1149 | data_cspc = self.__buffer_cspc |
|
1142 | 1150 | data_dc = self.__buffer_dc |
|
1143 | 1151 | |
|
1144 | 1152 | n = self.__profIndex |
|
1145 | 1153 | |
|
1146 | 1154 | self.__buffer_spc = 0 |
|
1147 | 1155 | self.__buffer_cspc = 0 |
|
1148 | 1156 | self.__buffer_dc = 0 |
|
1149 | 1157 | self.__profIndex = 0 |
|
1150 | 1158 | |
|
1151 | 1159 | return data_spc, data_cspc, data_dc, n |
|
1152 | 1160 | |
|
1153 | 1161 | #Integration with Overlapping |
|
1154 | 1162 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1155 | 1163 | |
|
1156 | 1164 | if self.__buffer_cspc != None: |
|
1157 | 1165 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1158 | 1166 | |
|
1159 | 1167 | if self.__buffer_dc != None: |
|
1160 | 1168 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1161 | 1169 | |
|
1162 | 1170 | n = self.__profIndex |
|
1163 | 1171 | |
|
1164 | 1172 | return data_spc, data_cspc, data_dc, n |
|
1165 | 1173 | |
|
1166 | 1174 | def byProfiles(self, *args): |
|
1167 | 1175 | |
|
1168 | 1176 | self.__dataReady = False |
|
1169 | 1177 | avgdata_spc = None |
|
1170 | 1178 | avgdata_cspc = None |
|
1171 | 1179 | avgdata_dc = None |
|
1172 | 1180 | n = None |
|
1173 | 1181 | |
|
1174 | 1182 | self.putData(*args) |
|
1175 | 1183 | |
|
1176 | 1184 | if self.__profIndex == self.n: |
|
1177 | 1185 | |
|
1178 | 1186 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1179 | 1187 | self.__dataReady = True |
|
1180 | 1188 | |
|
1181 | 1189 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1182 | 1190 | |
|
1183 | 1191 | def byTime(self, datatime, *args): |
|
1184 | 1192 | |
|
1185 | 1193 | self.__dataReady = False |
|
1186 | 1194 | avgdata_spc = None |
|
1187 | 1195 | avgdata_cspc = None |
|
1188 | 1196 | avgdata_dc = None |
|
1189 | 1197 | n = None |
|
1190 | 1198 | |
|
1191 | 1199 | self.putData(*args) |
|
1192 | 1200 | |
|
1193 | 1201 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1194 | 1202 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1195 | 1203 | self.n = n |
|
1196 | 1204 | self.__dataReady = True |
|
1197 | 1205 | |
|
1198 | 1206 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1199 | 1207 | |
|
1200 | 1208 | def integrate(self, datatime, *args): |
|
1201 | 1209 | |
|
1202 | 1210 | if self.__initime == None: |
|
1203 | 1211 | self.__initime = datatime |
|
1204 | 1212 | |
|
1205 | 1213 | if self.__byTime: |
|
1206 | 1214 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1207 | 1215 | else: |
|
1208 | 1216 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1209 | 1217 | |
|
1210 | 1218 | self.__lastdatatime = datatime |
|
1211 | 1219 | |
|
1212 | 1220 | if avgdata_spc == None: |
|
1213 | 1221 | return None, None, None, None |
|
1214 | 1222 | |
|
1215 | 1223 | avgdatatime = self.__initime |
|
1216 | 1224 | try: |
|
1217 | 1225 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1218 | 1226 | except: |
|
1219 | 1227 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
1220 | 1228 | |
|
1221 | 1229 | deltatime = datatime -self.__lastdatatime |
|
1222 | 1230 | |
|
1223 | 1231 | if not self.__withOverapping: |
|
1224 | 1232 | self.__initime = datatime |
|
1225 | 1233 | else: |
|
1226 | 1234 | self.__initime += deltatime |
|
1227 | 1235 | |
|
1228 | 1236 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1229 | 1237 | |
|
1230 | 1238 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1231 | 1239 | |
|
1232 | 1240 | if n==1: |
|
1233 | 1241 | dataOut.flagNoData = False |
|
1234 | 1242 | return |
|
1235 | 1243 | |
|
1236 | 1244 | if not self.__isConfig: |
|
1237 | 1245 | self.setup(n, timeInterval, overlapping) |
|
1238 | 1246 | self.__isConfig = True |
|
1239 | 1247 | |
|
1240 | 1248 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1241 | 1249 | dataOut.data_spc, |
|
1242 | 1250 | dataOut.data_cspc, |
|
1243 | 1251 | dataOut.data_dc) |
|
1244 | 1252 | |
|
1245 | 1253 | # dataOut.timeInterval *= n |
|
1246 | 1254 | dataOut.flagNoData = True |
|
1247 | 1255 | |
|
1248 | 1256 | if self.__dataReady: |
|
1249 | 1257 | |
|
1250 | 1258 | dataOut.data_spc = avgdata_spc |
|
1251 | 1259 | dataOut.data_cspc = avgdata_cspc |
|
1252 | 1260 | dataOut.data_dc = avgdata_dc |
|
1253 | 1261 | |
|
1254 | 1262 | dataOut.nIncohInt *= self.n |
|
1255 | 1263 | dataOut.utctime = avgdatatime |
|
1256 | 1264 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1257 | 1265 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1258 | 1266 | dataOut.flagNoData = False |
|
1259 | 1267 | |
|
1260 | 1268 | class ProfileSelector(Operation): |
|
1261 | 1269 | |
|
1262 | 1270 | profileIndex = None |
|
1263 | 1271 | # Tamanho total de los perfiles |
|
1264 | 1272 | nProfiles = None |
|
1265 | 1273 | |
|
1266 | 1274 | def __init__(self): |
|
1267 | 1275 | |
|
1268 | 1276 | self.profileIndex = 0 |
|
1269 | 1277 | |
|
1270 | 1278 | def incIndex(self): |
|
1271 | 1279 | self.profileIndex += 1 |
|
1272 | 1280 | |
|
1273 | 1281 | if self.profileIndex >= self.nProfiles: |
|
1274 | 1282 | self.profileIndex = 0 |
|
1275 | 1283 | |
|
1276 | 1284 | def isProfileInRange(self, minIndex, maxIndex): |
|
1277 | 1285 | |
|
1278 | 1286 | if self.profileIndex < minIndex: |
|
1279 | 1287 | return False |
|
1280 | 1288 | |
|
1281 | 1289 | if self.profileIndex > maxIndex: |
|
1282 | 1290 | return False |
|
1283 | 1291 | |
|
1284 | 1292 | return True |
|
1285 | 1293 | |
|
1286 | 1294 | def isProfileInList(self, profileList): |
|
1287 | 1295 | |
|
1288 | 1296 | if self.profileIndex not in profileList: |
|
1289 | 1297 | return False |
|
1290 | 1298 | |
|
1291 | 1299 | return True |
|
1292 | 1300 | |
|
1293 | 1301 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1294 | 1302 | |
|
1295 | 1303 | dataOut.flagNoData = True |
|
1296 | 1304 | self.nProfiles = dataOut.nProfiles |
|
1297 | 1305 | |
|
1298 | 1306 | if profileList != None: |
|
1299 | 1307 | if self.isProfileInList(profileList): |
|
1300 | 1308 | dataOut.flagNoData = False |
|
1301 | 1309 | |
|
1302 | 1310 | self.incIndex() |
|
1303 | 1311 | return 1 |
|
1304 | 1312 | |
|
1305 | 1313 | |
|
1306 | 1314 | elif profileRangeList != None: |
|
1307 | 1315 | minIndex = profileRangeList[0] |
|
1308 | 1316 | maxIndex = profileRangeList[1] |
|
1309 | 1317 | if self.isProfileInRange(minIndex, maxIndex): |
|
1310 | 1318 | dataOut.flagNoData = False |
|
1311 | 1319 | |
|
1312 | 1320 | self.incIndex() |
|
1313 | 1321 | return 1 |
|
1314 | 1322 | |
|
1315 | 1323 | else: |
|
1316 | 1324 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1317 | 1325 | |
|
1318 | 1326 | return 0 |
|
1319 | 1327 | |
|
1320 | 1328 | class SpectraHeisProc(ProcessingUnit): |
|
1321 | 1329 | def __init__(self): |
|
1322 | 1330 | self.objectDict = {} |
|
1323 | 1331 | # self.buffer = None |
|
1324 | 1332 | # self.firstdatatime = None |
|
1325 | 1333 | # self.profIndex = 0 |
|
1326 | 1334 | self.dataOut = SpectraHeis() |
|
1327 | 1335 | |
|
1328 | 1336 | def __updateObjFromInput(self): |
|
1329 | 1337 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1330 | 1338 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
1331 | 1339 | self.dataOut.errorCount = self.dataIn.errorCount |
|
1332 | 1340 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
1333 | 1341 | |
|
1334 | 1342 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1335 | 1343 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1336 | 1344 | self.dataOut.channelList = self.dataIn.channelList |
|
1337 | 1345 | self.dataOut.heightList = self.dataIn.heightList |
|
1338 | 1346 | # self.dataOut.dtype = self.dataIn.dtype |
|
1339 | 1347 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1340 | 1348 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1341 | 1349 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1342 | 1350 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1343 | 1351 | self.dataOut.nCode = self.dataIn.nCode |
|
1344 | 1352 | self.dataOut.code = self.dataIn.code |
|
1345 | 1353 | # self.dataOut.nProfiles = 1 |
|
1346 | 1354 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1347 | 1355 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1348 | 1356 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1349 | 1357 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1350 | 1358 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1351 | 1359 | self.dataOut.utctime = self.dataIn.utctime |
|
1352 | 1360 | # self.dataOut.utctime = self.firstdatatime |
|
1353 | 1361 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1354 | 1362 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1355 | 1363 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1356 | 1364 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1357 | 1365 | self.dataOut.nIncohInt = 1 |
|
1358 | 1366 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1359 | 1367 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1360 | 1368 | |
|
1361 | 1369 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1362 | 1370 | # self.dataOut.set=self.dataIn.set |
|
1363 | 1371 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1364 | 1372 | |
|
1365 | 1373 | |
|
1366 | 1374 | def __getFft(self): |
|
1367 | 1375 | |
|
1368 | 1376 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1369 | 1377 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1370 | 1378 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1371 | 1379 | self.dataOut.data_spc = spc |
|
1372 | 1380 | |
|
1373 | 1381 | def init(self): |
|
1374 | 1382 | |
|
1375 | 1383 | self.dataOut.flagNoData = True |
|
1376 | 1384 | |
|
1377 | 1385 | if self.dataIn.type == "SpectraHeis": |
|
1378 | 1386 | self.dataOut.copy(self.dataIn) |
|
1379 | 1387 | return |
|
1380 | 1388 | |
|
1381 | 1389 | if self.dataIn.type == "Voltage": |
|
1382 | 1390 | self.__updateObjFromInput() |
|
1383 | 1391 | self.__getFft() |
|
1384 | 1392 | self.dataOut.flagNoData = False |
|
1385 | 1393 | |
|
1386 | 1394 | return |
|
1387 | 1395 | |
|
1388 | 1396 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
1389 | 1397 | |
|
1390 | 1398 | |
|
1391 | 1399 | def selectChannels(self, channelList): |
|
1392 | 1400 | |
|
1393 | 1401 | channelIndexList = [] |
|
1394 | 1402 | |
|
1395 | 1403 | for channel in channelList: |
|
1396 | 1404 | index = self.dataOut.channelList.index(channel) |
|
1397 | 1405 | channelIndexList.append(index) |
|
1398 | 1406 | |
|
1399 | 1407 | self.selectChannelsByIndex(channelIndexList) |
|
1400 | 1408 | |
|
1401 | 1409 | def selectChannelsByIndex(self, channelIndexList): |
|
1402 | 1410 | """ |
|
1403 | 1411 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1404 | 1412 | |
|
1405 | 1413 | Input: |
|
1406 | 1414 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1407 | 1415 | |
|
1408 | 1416 | Affected: |
|
1409 | 1417 | self.dataOut.data |
|
1410 | 1418 | self.dataOut.channelIndexList |
|
1411 | 1419 | self.dataOut.nChannels |
|
1412 | 1420 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1413 | 1421 | self.dataOut.systemHeaderObj.numChannels |
|
1414 | 1422 | self.dataOut.m_ProcessingHeader.blockSize |
|
1415 | 1423 | |
|
1416 | 1424 | Return: |
|
1417 | 1425 | None |
|
1418 | 1426 | """ |
|
1419 | 1427 | |
|
1420 | 1428 | for channelIndex in channelIndexList: |
|
1421 | 1429 | if channelIndex not in self.dataOut.channelIndexList: |
|
1422 | 1430 | print channelIndexList |
|
1423 | 1431 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1424 | 1432 | |
|
1425 | 1433 | nChannels = len(channelIndexList) |
|
1426 | 1434 | |
|
1427 | 1435 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1428 | 1436 | |
|
1429 | 1437 | self.dataOut.data_spc = data_spc |
|
1430 | 1438 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1431 | 1439 | |
|
1432 | 1440 | return 1 |
|
1433 | 1441 | |
|
1434 | 1442 | class IncohInt4SpectraHeis(Operation): |
|
1435 | 1443 | |
|
1436 | 1444 | __isConfig = False |
|
1437 | 1445 | |
|
1438 | 1446 | __profIndex = 0 |
|
1439 | 1447 | __withOverapping = False |
|
1440 | 1448 | |
|
1441 | 1449 | __byTime = False |
|
1442 | 1450 | __initime = None |
|
1443 | 1451 | __lastdatatime = None |
|
1444 | 1452 | __integrationtime = None |
|
1445 | 1453 | |
|
1446 | 1454 | __buffer = None |
|
1447 | 1455 | |
|
1448 | 1456 | __dataReady = False |
|
1449 | 1457 | |
|
1450 | 1458 | n = None |
|
1451 | 1459 | |
|
1452 | 1460 | |
|
1453 | 1461 | def __init__(self): |
|
1454 | 1462 | |
|
1455 | 1463 | self.__isConfig = False |
|
1456 | 1464 | |
|
1457 | 1465 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1458 | 1466 | """ |
|
1459 | 1467 | Set the parameters of the integration class. |
|
1460 | 1468 | |
|
1461 | 1469 | Inputs: |
|
1462 | 1470 | |
|
1463 | 1471 | n : Number of coherent integrations |
|
1464 | 1472 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1465 | 1473 | overlapping : |
|
1466 | 1474 | |
|
1467 | 1475 | """ |
|
1468 | 1476 | |
|
1469 | 1477 | self.__initime = None |
|
1470 | 1478 | self.__lastdatatime = 0 |
|
1471 | 1479 | self.__buffer = None |
|
1472 | 1480 | self.__dataReady = False |
|
1473 | 1481 | |
|
1474 | 1482 | |
|
1475 | 1483 | if n == None and timeInterval == None: |
|
1476 | 1484 | raise ValueError, "n or timeInterval should be specified ..." |
|
1477 | 1485 | |
|
1478 | 1486 | if n != None: |
|
1479 | 1487 | self.n = n |
|
1480 | 1488 | self.__byTime = False |
|
1481 | 1489 | else: |
|
1482 | 1490 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1483 | 1491 | self.n = 9999 |
|
1484 | 1492 | self.__byTime = True |
|
1485 | 1493 | |
|
1486 | 1494 | if overlapping: |
|
1487 | 1495 | self.__withOverapping = True |
|
1488 | 1496 | self.__buffer = None |
|
1489 | 1497 | else: |
|
1490 | 1498 | self.__withOverapping = False |
|
1491 | 1499 | self.__buffer = 0 |
|
1492 | 1500 | |
|
1493 | 1501 | self.__profIndex = 0 |
|
1494 | 1502 | |
|
1495 | 1503 | def putData(self, data): |
|
1496 | 1504 | |
|
1497 | 1505 | """ |
|
1498 | 1506 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1499 | 1507 | |
|
1500 | 1508 | """ |
|
1501 | 1509 | |
|
1502 | 1510 | if not self.__withOverapping: |
|
1503 | 1511 | self.__buffer += data.copy() |
|
1504 | 1512 | self.__profIndex += 1 |
|
1505 | 1513 | return |
|
1506 | 1514 | |
|
1507 | 1515 | #Overlapping data |
|
1508 | 1516 | nChannels, nHeis = data.shape |
|
1509 | 1517 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1510 | 1518 | |
|
1511 | 1519 | #If the buffer is empty then it takes the data value |
|
1512 | 1520 | if self.__buffer == None: |
|
1513 | 1521 | self.__buffer = data |
|
1514 | 1522 | self.__profIndex += 1 |
|
1515 | 1523 | return |
|
1516 | 1524 | |
|
1517 | 1525 | #If the buffer length is lower than n then stakcing the data value |
|
1518 | 1526 | if self.__profIndex < self.n: |
|
1519 | 1527 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1520 | 1528 | self.__profIndex += 1 |
|
1521 | 1529 | return |
|
1522 | 1530 | |
|
1523 | 1531 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1524 | 1532 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1525 | 1533 | self.__buffer[self.n-1] = data |
|
1526 | 1534 | self.__profIndex = self.n |
|
1527 | 1535 | return |
|
1528 | 1536 | |
|
1529 | 1537 | |
|
1530 | 1538 | def pushData(self): |
|
1531 | 1539 | """ |
|
1532 | 1540 | Return the sum of the last profiles and the profiles used in the sum. |
|
1533 | 1541 | |
|
1534 | 1542 | Affected: |
|
1535 | 1543 | |
|
1536 | 1544 | self.__profileIndex |
|
1537 | 1545 | |
|
1538 | 1546 | """ |
|
1539 | 1547 | |
|
1540 | 1548 | if not self.__withOverapping: |
|
1541 | 1549 | data = self.__buffer |
|
1542 | 1550 | n = self.__profIndex |
|
1543 | 1551 | |
|
1544 | 1552 | self.__buffer = 0 |
|
1545 | 1553 | self.__profIndex = 0 |
|
1546 | 1554 | |
|
1547 | 1555 | return data, n |
|
1548 | 1556 | |
|
1549 | 1557 | #Integration with Overlapping |
|
1550 | 1558 | data = numpy.sum(self.__buffer, axis=0) |
|
1551 | 1559 | n = self.__profIndex |
|
1552 | 1560 | |
|
1553 | 1561 | return data, n |
|
1554 | 1562 | |
|
1555 | 1563 | def byProfiles(self, data): |
|
1556 | 1564 | |
|
1557 | 1565 | self.__dataReady = False |
|
1558 | 1566 | avgdata = None |
|
1559 | 1567 | n = None |
|
1560 | 1568 | |
|
1561 | 1569 | self.putData(data) |
|
1562 | 1570 | |
|
1563 | 1571 | if self.__profIndex == self.n: |
|
1564 | 1572 | |
|
1565 | 1573 | avgdata, n = self.pushData() |
|
1566 | 1574 | self.__dataReady = True |
|
1567 | 1575 | |
|
1568 | 1576 | return avgdata |
|
1569 | 1577 | |
|
1570 | 1578 | def byTime(self, data, datatime): |
|
1571 | 1579 | |
|
1572 | 1580 | self.__dataReady = False |
|
1573 | 1581 | avgdata = None |
|
1574 | 1582 | n = None |
|
1575 | 1583 | |
|
1576 | 1584 | self.putData(data) |
|
1577 | 1585 | |
|
1578 | 1586 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1579 | 1587 | avgdata, n = self.pushData() |
|
1580 | 1588 | self.n = n |
|
1581 | 1589 | self.__dataReady = True |
|
1582 | 1590 | |
|
1583 | 1591 | return avgdata |
|
1584 | 1592 | |
|
1585 | 1593 | def integrate(self, data, datatime=None): |
|
1586 | 1594 | |
|
1587 | 1595 | if self.__initime == None: |
|
1588 | 1596 | self.__initime = datatime |
|
1589 | 1597 | |
|
1590 | 1598 | if self.__byTime: |
|
1591 | 1599 | avgdata = self.byTime(data, datatime) |
|
1592 | 1600 | else: |
|
1593 | 1601 | avgdata = self.byProfiles(data) |
|
1594 | 1602 | |
|
1595 | 1603 | |
|
1596 | 1604 | self.__lastdatatime = datatime |
|
1597 | 1605 | |
|
1598 | 1606 | if avgdata == None: |
|
1599 | 1607 | return None, None |
|
1600 | 1608 | |
|
1601 | 1609 | avgdatatime = self.__initime |
|
1602 | 1610 | |
|
1603 | 1611 | deltatime = datatime -self.__lastdatatime |
|
1604 | 1612 | |
|
1605 | 1613 | if not self.__withOverapping: |
|
1606 | 1614 | self.__initime = datatime |
|
1607 | 1615 | else: |
|
1608 | 1616 | self.__initime += deltatime |
|
1609 | 1617 | |
|
1610 | 1618 | return avgdata, avgdatatime |
|
1611 | 1619 | |
|
1612 | 1620 | def run(self, dataOut, **kwargs): |
|
1613 | 1621 | |
|
1614 | 1622 | if not self.__isConfig: |
|
1615 | 1623 | self.setup(**kwargs) |
|
1616 | 1624 | self.__isConfig = True |
|
1617 | 1625 | |
|
1618 | 1626 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
1619 | 1627 | |
|
1620 | 1628 | # dataOut.timeInterval *= n |
|
1621 | 1629 | dataOut.flagNoData = True |
|
1622 | 1630 | |
|
1623 | 1631 | if self.__dataReady: |
|
1624 | 1632 | dataOut.data_spc = avgdata |
|
1625 | 1633 | dataOut.nIncohInt *= self.n |
|
1626 | 1634 | # dataOut.nCohInt *= self.n |
|
1627 | 1635 | dataOut.utctime = avgdatatime |
|
1628 | 1636 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
1629 | 1637 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
1630 | 1638 | dataOut.flagNoData = False |
|
1631 | 1639 | |
|
1632 | 1640 | |
|
1633 | 1641 | |
|
1634 | 1642 | |
|
1635 | 1643 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now