##// END OF EJS Templates
Daniel Valdez -
r162:71384e4bf352
parent child
Show More
@@ -1,230 +1,232
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import copy
9 9 import numpy
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from IO.JROHeaderIO import SystemHeader, RadarControllerHeader
15 15
16 16 class JROData:
17 17
18 18 # m_BasicHeader = BasicHeader()
19 19 # m_ProcessingHeader = ProcessingHeader()
20 20
21 21 systemHeaderObj = SystemHeader()
22 22
23 23 radarControllerHeaderObj = RadarControllerHeader()
24 24
25 25 # data = None
26 26
27 27 type = None
28 28
29 29 dtype = None
30 30
31 31 nChannels = None
32 32
33 33 nHeights = None
34 34
35 35 nProfiles = None
36 36
37 37 heightList = None
38 38
39 39 channelList = None
40 40
41 41 channelIndexList = None
42 42
43 43 flagNoData = True
44 44
45 45 flagTimeBlock = False
46 46
47 47 utctime = None
48 48
49 49 blocksize = None
50 50
51 51 nCode = None
52 52
53 53 nBaud = None
54 54
55 55 code = None
56 56
57 57 flagDecodeData = True #asumo q la data esta decodificada
58 58
59 59 flagDeflipData = True #asumo q la data esta sin flip
60 60
61 61 flagShiftFFT = False
62 62
63 63 ippSeconds = None
64 64
65 65 timeInterval = None
66 66
67 67 def __init__(self):
68 68
69 69 raise ValueError, "This class has not been implemented"
70 70
71 71 def copy(self, inputObj=None):
72 72
73 73 if inputObj == None:
74 74 return copy.deepcopy(self)
75 75
76 76 for key in inputObj.__dict__.keys():
77 77 self.__dict__[key] = inputObj.__dict__[key]
78 78
79 79 def deepcopy(self):
80 80
81 81 return copy.deepcopy(self)
82 82
83 83 class Voltage(JROData):
84 84
85 85 nCohInt = None
86 86
87 87 #data es un numpy array de 2 dmensiones (canales, alturas)
88 88 data = None
89 89
90 90 def __init__(self):
91 91 '''
92 92 Constructor
93 93 '''
94 94
95 95 self.radarControllerHeaderObj = RadarControllerHeader()
96 96
97 97 self.systemHeaderObj = SystemHeader()
98 98
99 99 self.type = "Voltage"
100 100
101 101 self.data = None
102 102
103 103 self.dtype = None
104 104
105 105 self.nChannels = 0
106 106
107 107 self.nHeights = 0
108 108
109 109 self.nProfiles = None
110 110
111 111 self.heightList = None
112 112
113 113 self.channelList = None
114 114
115 115 self.channelIndexList = None
116 116
117 117 self.flagNoData = True
118 118
119 119 self.flagTimeBlock = False
120 120
121 121 self.utctime = None
122 122
123 123 self.nCohInt = None
124 124
125 125 self.blocksize = None
126 126
127 127 class Spectra(JROData):
128 128
129 129 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
130 130 data_spc = None
131 131
132 132 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
133 133 data_cspc = None
134 134
135 135 #data es un numpy array de 2 dmensiones (canales, alturas)
136 136 data_dc = None
137 137
138 138 nFFTPoints = None
139 139
140 140 nPairs = None
141 141
142 142 pairsList = None
143 143
144 144 nIncohInt = None
145 145
146 nCohInt = None #se requiere para determinar el valor de timeInterval
147
146 148 def __init__(self):
147 149 '''
148 150 Constructor
149 151 '''
150 152
151 153 self.radarControllerHeaderObj = RadarControllerHeader()
152 154
153 155 self.systemHeaderObj = SystemHeader()
154 156
155 157 self.type = "Spectra"
156 158
157 159 # self.data = None
158 160
159 161 self.dtype = None
160 162
161 163 self.nChannels = 0
162 164
163 165 self.nHeights = 0
164 166
165 167 self.nProfiles = None
166 168
167 169 self.heightList = None
168 170
169 171 self.channelList = None
170 172
171 173 self.channelIndexList = None
172 174
173 175 self.flagNoData = True
174 176
175 177 self.flagTimeBlock = False
176 178
177 179 self.utctime = None
178 180
179 181 self.nIncohInt = None
180 182
181 183 self.blocksize = None
182 184
183 185
184 186 class SpectraHeis(JROData):
185 187
186 188 data_spc = None
187 189
188 190 data_cspc = None
189 191
190 192 data_dc = None
191 193
192 194 nFFTPoints = None
193 195
194 196 nPairs = None
195 197
196 198 pairsList = None
197 199
198 200 nIncohInt = None
199 201
200 202 def __init__(self):
201 203
202 204 self.radarControllerHeaderObj = RadarControllerHeader()
203 205
204 206 self.systemHeaderObj = SystemHeader()
205 207
206 208 self.type = "SpectraHeis"
207 209
208 210 self.dtype = None
209 211
210 212 self.nChannels = 0
211 213
212 214 self.nHeights = 0
213 215
214 216 self.nProfiles = None
215 217
216 218 self.heightList = None
217 219
218 220 self.channelList = None
219 221
220 222 self.channelIndexList = None
221 223
222 224 self.flagNoData = True
223 225
224 226 self.flagTimeBlock = False
225 227
226 228 self.nPairs = 0
227 229
228 230 self.utctime = None
229 231
230 232 self.blocksize = None
@@ -1,781 +1,781
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import glob
10 10 import fnmatch
11 11 import time, datetime
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from JROHeaderIO import *
17 17 from JRODataIO import JRODataReader
18 18 from JRODataIO import JRODataWriter
19 19
20 20 from Data.JROData import Spectra
21 21
22 22 class SpectraReader(JRODataReader):
23 23 """
24 24 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
25 25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
26 26 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
27 27
28 28 paresCanalesIguales * alturas * perfiles (Self Spectra)
29 29 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
30 30 canales * alturas (DC Channels)
31 31
32 32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 33 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
34 34 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
35 35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36 36
37 37 Example:
38 38 dpath = "/home/myuser/data"
39 39
40 40 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
41 41
42 42 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
43 43
44 44 readerObj = SpectraReader()
45 45
46 46 readerObj.setup(dpath, startTime, endTime)
47 47
48 48 while(True):
49 49
50 50 readerObj.getData()
51 51
52 52 print readerObj.data_spc
53 53
54 54 print readerObj.data_cspc
55 55
56 56 print readerObj.data_dc
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62
63 63 pts2read_SelfSpectra = 0
64 64
65 65 pts2read_CrossSpectra = 0
66 66
67 67 pts2read_DCchannels = 0
68 68
69 69 ext = ".pdata"
70 70
71 71 optchar = "P"
72 72
73 73 dataOutObj = None
74 74
75 75 nRdChannels = None
76 76
77 77 nRdPairs = None
78 78
79 79 rdPairList = []
80 80
81 81
82 82 def __init__(self, dataOutObj=None):
83 83 """
84 84 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
85 85
86 86 Inputs:
87 87 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
88 88 almacenar un perfil de datos cada vez que se haga un requerimiento
89 89 (getData). El perfil sera obtenido a partir del buffer de datos,
90 90 si el buffer esta vacio se hara un nuevo proceso de lectura de un
91 91 bloque de datos.
92 92 Si este parametro no es pasado se creara uno internamente.
93 93
94 94 Affected:
95 95 self.dataOutObj
96 96
97 97 Return : None
98 98 """
99 99
100 100 self.pts2read_SelfSpectra = 0
101 101
102 102 self.pts2read_CrossSpectra = 0
103 103
104 104 self.pts2read_DCchannels = 0
105 105
106 106 self.datablock = None
107 107
108 108 self.utc = None
109 109
110 110 self.ext = ".pdata"
111 111
112 112 self.optchar = "P"
113 113
114 114 self.basicHeaderObj = BasicHeader()
115 115
116 116 self.systemHeaderObj = SystemHeader()
117 117
118 118 self.radarControllerHeaderObj = RadarControllerHeader()
119 119
120 120 self.processingHeaderObj = ProcessingHeader()
121 121
122 122 self.online = 0
123 123
124 124 self.fp = None
125 125
126 126 self.idFile = None
127 127
128 128 self.dtype = None
129 129
130 130 self.fileSizeByHeader = None
131 131
132 132 self.filenameList = []
133 133
134 134 self.filename = None
135 135
136 136 self.fileSize = None
137 137
138 138 self.firstHeaderSize = 0
139 139
140 140 self.basicHeaderSize = 24
141 141
142 142 self.pathList = []
143 143
144 144 self.lastUTTime = 0
145 145
146 146 self.maxTimeStep = 30
147 147
148 148 self.flagNoMoreFiles = 0
149 149
150 150 self.set = 0
151 151
152 152 self.path = None
153 153
154 154 self.delay = 3 #seconds
155 155
156 156 self.nTries = 3 #quantity tries
157 157
158 158 self.nFiles = 3 #number of files for searching
159 159
160 160 self.nReadBlocks = 0
161 161
162 162 self.flagIsNewFile = 1
163 163
164 164 self.ippSeconds = 0
165 165
166 166 self.flagTimeBlock = 0
167 167
168 168 self.flagIsNewBlock = 0
169 169
170 170 self.nTotalBlocks = 0
171 171
172 172 self.blocksize = 0
173 173
174 174
175 175 def createObjByDefault(self):
176 176
177 177 dataObj = Spectra()
178 178
179 179 return dataObj
180 180
181 181 def __hasNotDataInBuffer(self):
182 182 return 1
183 183
184 184
185 185 def getBlockDimension(self):
186 186 """
187 187 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 188
189 189 Affected:
190 190 self.nRdChannels
191 191 self.nRdPairs
192 192 self.pts2read_SelfSpectra
193 193 self.pts2read_CrossSpectra
194 194 self.pts2read_DCchannels
195 195 self.blocksize
196 196 self.dataOutObj.nChannels
197 197 self.dataOutObj.nPairs
198 198
199 199 Return:
200 200 None
201 201 """
202 202 self.nRdChannels = 0
203 203 self.nRdPairs = 0
204 204 self.rdPairList = []
205 205
206 206 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 207 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 208 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 209 else:
210 210 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 211 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 212
213 213 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 214
215 215 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 216 self.blocksize = self.pts2read_SelfSpectra
217 217
218 218 if self.processingHeaderObj.flag_cspc:
219 219 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 220 self.blocksize += self.pts2read_CrossSpectra
221 221
222 222 if self.processingHeaderObj.flag_dc:
223 223 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 224 self.blocksize += self.pts2read_DCchannels
225 225
226 226 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 227
228 228
229 229 def readBlock(self):
230 230 """
231 231 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 232 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 233 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 234 es seteado a 0
235 235
236 236 Return: None
237 237
238 238 Variables afectadas:
239 239
240 240 self.flagIsNewFile
241 241 self.flagIsNewBlock
242 242 self.nTotalBlocks
243 243 self.data_spc
244 244 self.data_cspc
245 245 self.data_dc
246 246
247 247 Exceptions:
248 248 Si un bloque leido no es un bloque valido
249 249 """
250 250 blockOk_flag = False
251 251 fpointer = self.fp.tell()
252 252
253 253 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 254 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 255
256 256 if self.processingHeaderObj.flag_cspc:
257 257 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 258 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 259
260 260 if self.processingHeaderObj.flag_dc:
261 261 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 262 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 263
264 264
265 265 if not(self.processingHeaderObj.shif_fft):
266 266 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
267 267
268 268 if self.processingHeaderObj.flag_cspc:
269 269 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
270 270
271 271
272 272 spc = numpy.transpose( spc, (0,2,1) )
273 273 self.data_spc = spc
274 274
275 275 if self.processingHeaderObj.flag_cspc:
276 276 cspc = numpy.transpose( cspc, (0,2,1) )
277 277 self.data_cspc = cspc['real'] + cspc['imag']*1j
278 278 else:
279 279 self.data_cspc = None
280 280
281 281 if self.processingHeaderObj.flag_dc:
282 282 self.data_dc = dc['real'] + dc['imag']*1j
283 283 else:
284 284 self.data_dc = None
285 285
286 286 self.flagIsNewFile = 0
287 287 self.flagIsNewBlock = 1
288 288
289 289 self.nTotalBlocks += 1
290 290 self.nReadBlocks += 1
291 291
292 292 return 1
293 293
294 294
295 295 def getData(self):
296 296 """
297 297 Copia el buffer de lectura a la clase "Spectra",
298 298 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
299 299 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
300 300
301 301 Return:
302 302 0 : Si no hay mas archivos disponibles
303 303 1 : Si hizo una buena copia del buffer
304 304
305 305 Affected:
306 306 self.dataOutObj
307 307
308 308 self.flagTimeBlock
309 309 self.flagIsNewBlock
310 310 """
311 311
312 312 if self.flagNoMoreFiles: return 0
313 313
314 314 self.flagTimeBlock = 0
315 315 self.flagIsNewBlock = 0
316 316
317 317 if self.__hasNotDataInBuffer():
318 318
319 319 if not( self.readNextBlock() ):
320 320 return 0
321 321
322 322 # self.updateDataHeader()
323 323
324 324 if self.flagNoMoreFiles == 1:
325 325 print 'Process finished'
326 326 return 0
327 327
328 328 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
329 329
330 330 if self.data_dc == None:
331 331 self.dataOutObj.flagNoData = True
332 332 return 0
333 333
334 334
335 335 self.dataOutObj.data_spc = self.data_spc
336 336
337 337 self.dataOutObj.data_cspc = self.data_cspc
338 338
339 339 self.dataOutObj.data_dc = self.data_dc
340 340
341 341 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
342 342
343 343 self.dataOutObj.flagNoData = False
344 344
345 345 self.dataOutObj.dtype = self.dtype
346 346
347 347 self.dataOutObj.nChannels = self.nRdChannels
348 348
349 349 self.dataOutObj.nPairs = self.nRdPairs
350 350
351 351 self.dataOutObj.pairsList = self.rdPairList
352 352
353 353 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
354 354
355 355 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
356 356
357 357 self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock
358 358
359 359 self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt
360 360
361 361
362 362 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
363 363
364 364 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
365 365
366 366 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
367 367
368 368 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
369 369
370 370 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
371 371
372 372 self.dataOutObj.ippSeconds = self.ippSeconds
373 373
374 374 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints
375 375
376 376 self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft
377 377
378 378 # self.profileIndex += 1
379 379
380 380 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
381 381
382 382 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
383 383
384 384 return self.dataOutObj.data_spc
385 385
386 386
387 387 class SpectraWriter(JRODataWriter):
388 388
389 389 """
390 390 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
391 391 de los datos siempre se realiza por bloques.
392 392 """
393 393
394 394 ext = ".pdata"
395 395
396 396 optchar = "P"
397 397
398 398 shape_spc_Buffer = None
399 399
400 400 shape_cspc_Buffer = None
401 401
402 402 shape_dc_Buffer = None
403 403
404 404 data_spc = None
405 405
406 406 data_cspc = None
407 407
408 408 data_dc = None
409 409
410 410 wrPairList = []
411 411
412 412 nWrPairs = 0
413 413
414 414 nWrChannels = 0
415 415
416 416 # dataOutObj = None
417 417
418 418 def __init__(self, dataOutObj=None):
419 419 """
420 420 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
421 421
422 422 Affected:
423 423 self.dataOutObj
424 424 self.basicHeaderObj
425 425 self.systemHeaderObj
426 426 self.radarControllerHeaderObj
427 427 self.processingHeaderObj
428 428
429 429 Return: None
430 430 """
431 431 if dataOutObj == None:
432 432 dataOutObj = Spectra()
433 433
434 434 if not( isinstance(dataOutObj, Spectra) ):
435 435 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
436 436
437 437 self.dataOutObj = dataOutObj
438 438
439 439 self.nTotalBlocks = 0
440 440
441 441 self.nWrChannels = self.dataOutObj.nChannels
442 442
443 443 # if len(pairList) > 0:
444 444 # self.wrPairList = pairList
445 445 #
446 446 # self.nWrPairs = len(pairList)
447 447
448 448 self.wrPairList = self.dataOutObj.pairsList
449 449
450 450 self.nWrPairs = self.dataOutObj.nPairs
451 451
452 452
453 453
454 454
455 455
456 456 # self.data_spc = None
457 457 # self.data_cspc = None
458 458 # self.data_dc = None
459 459
460 460 # self.fp = None
461 461
462 462 # self.flagIsNewFile = 1
463 463 #
464 464 # self.nTotalBlocks = 0
465 465 #
466 466 # self.flagIsNewBlock = 0
467 467 #
468 468 # self.flagNoMoreFiles = 0
469 469 #
470 470 # self.setFile = None
471 471 #
472 472 # self.dtype = None
473 473 #
474 474 # self.path = None
475 475 #
476 476 # self.noMoreFiles = 0
477 477 #
478 478 # self.filename = None
479 479 #
480 480 # self.basicHeaderObj = BasicHeader()
481 481 #
482 482 # self.systemHeaderObj = SystemHeader()
483 483 #
484 484 # self.radarControllerHeaderObj = RadarControllerHeader()
485 485 #
486 486 # self.processingHeaderObj = ProcessingHeader()
487 487
488 488
489 489 def hasAllDataInBuffer(self):
490 490 return 1
491 491
492 492
493 493 def setBlockDimension(self):
494 494 """
495 495 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
496 496
497 497 Affected:
498 498 self.shape_spc_Buffer
499 499 self.shape_cspc_Buffer
500 500 self.shape_dc_Buffer
501 501
502 502 Return: None
503 503 """
504 504 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
505 505 self.processingHeaderObj.nHeights,
506 506 self.processingHeaderObj.profilesPerBlock)
507 507
508 508 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
509 509 self.processingHeaderObj.nHeights,
510 510 self.processingHeaderObj.profilesPerBlock)
511 511
512 512 self.shape_dc_Buffer = (self.dataOutObj.nChannels,
513 513 self.processingHeaderObj.nHeights)
514 514
515 515
516 516 def writeBlock(self):
517 517 """
518 518 Escribe el buffer en el file designado
519 519
520 520 Affected:
521 521 self.data_spc
522 522 self.data_cspc
523 523 self.data_dc
524 524 self.flagIsNewFile
525 525 self.flagIsNewBlock
526 526 self.nTotalBlocks
527 527 self.nWriteBlocks
528 528
529 529 Return: None
530 530 """
531 531
532 532 spc = numpy.transpose( self.data_spc, (0,2,1) )
533 533 if not( self.processingHeaderObj.shif_fft ):
534 534 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
535 535 data = spc.reshape((-1))
536 536 data.tofile(self.fp)
537 537
538 538 if self.data_cspc != None:
539 539 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
540 540 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
541 541 if not( self.processingHeaderObj.shif_fft ):
542 542 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
543 543 data['real'] = cspc.real
544 544 data['imag'] = cspc.imag
545 545 data = data.reshape((-1))
546 546 data.tofile(self.fp)
547 547
548 548 if self.data_dc != None:
549 549 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
550 550 dc = self.data_dc
551 551 data['real'] = dc.real
552 552 data['imag'] = dc.imag
553 553 data = data.reshape((-1))
554 554 data.tofile(self.fp)
555 555
556 556 self.data_spc.fill(0)
557 557 self.data_dc.fill(0)
558 558 if self.data_cspc != None:
559 559 self.data_cspc.fill(0)
560 560
561 561 self.flagIsNewFile = 0
562 562 self.flagIsNewBlock = 1
563 563 self.nTotalBlocks += 1
564 564 self.nWriteBlocks += 1
565 565 self.blockIndex += 1
566 566
567 567
568 568 def putData(self):
569 569 """
570 570 Setea un bloque de datos y luego los escribe en un file
571 571
572 572 Affected:
573 573 self.data_spc
574 574 self.data_cspc
575 575 self.data_dc
576 576
577 577 Return:
578 578 0 : Si no hay data o no hay mas files que puedan escribirse
579 579 1 : Si se escribio la data de un bloque en un file
580 580 """
581 581 self.flagIsNewBlock = 0
582 582
583 583 if self.dataOutObj.flagNoData:
584 584 return 0
585 585
586 586 if self.dataOutObj.flagTimeBlock:
587 587 self.data_spc.fill(0)
588 588 self.data_cspc.fill(0)
589 589 self.data_dc.fill(0)
590 590 self.setNextFile()
591 591
592 592 if self.flagIsNewFile == 0:
593 593 self.getBasicHeader()
594 594
595 595 self.data_spc = self.dataOutObj.data_spc
596 596 self.data_cspc = self.dataOutObj.data_cspc
597 597 self.data_dc = self.dataOutObj.data_dc
598 598
599 599 # #self.processingHeaderObj.dataBlocksPerFile)
600 600 if self.hasAllDataInBuffer():
601 601 # self.getDataHeader()
602 602 self.writeNextBlock()
603 603
604 604 if self.flagNoMoreFiles:
605 605 #print 'Process finished'
606 606 return 0
607 607
608 608 return 1
609 609
610 610
611 611 def __getProcessFlags(self):
612 612
613 613 processFlags = 0
614 614
615 615 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
616 616 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
617 617 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
618 618 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
619 619 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
620 620 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
621 621
622 622 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
623 623
624 624
625 625
626 626 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
627 627 PROCFLAG.DATATYPE_SHORT,
628 628 PROCFLAG.DATATYPE_LONG,
629 629 PROCFLAG.DATATYPE_INT64,
630 630 PROCFLAG.DATATYPE_FLOAT,
631 631 PROCFLAG.DATATYPE_DOUBLE]
632 632
633 633
634 634 for index in range(len(dtypeList)):
635 635 if self.dataOutObj.dtype == dtypeList[index]:
636 636 dtypeValue = datatypeValueList[index]
637 637 break
638 638
639 639 processFlags += dtypeValue
640 640
641 641 if self.dataOutObj.flagDecodeData:
642 642 processFlags += PROCFLAG.DECODE_DATA
643 643
644 644 if self.dataOutObj.flagDeflipData:
645 645 processFlags += PROCFLAG.DEFLIP_DATA
646 646
647 647 if self.dataOutObj.code != None:
648 648 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
649 649
650 650 if self.dataOutObj.nIncohInt > 1:
651 651 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
652 652
653 653 if self.dataOutObj.data_dc != None:
654 654 processFlags += PROCFLAG.SAVE_CHANNELS_DC
655 655
656 656 return processFlags
657 657
658 658
659 659 def __getBlockSize(self):
660 660 '''
661 661 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
662 662 '''
663 663
664 664 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
665 665 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
666 666 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
667 667 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
668 668 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
669 669 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
670 670
671 671 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
672 672 datatypeValueList = [1,2,4,8,4,8]
673 673 for index in range(len(dtypeList)):
674 674 if self.dataOutObj.dtype == dtypeList[index]:
675 675 datatypeValue = datatypeValueList[index]
676 676 break
677 677
678 678
679 679 pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints
680 680
681 681 pts2write_SelfSpectra = int(self.nWrChannels * pts2write)
682 682 blocksize = (pts2write_SelfSpectra*datatypeValue)
683 683
684 684 if self.dataOutObj.data_cspc != None:
685 685 pts2write_CrossSpectra = int(self.nWrPairs * pts2write)
686 686 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
687 687
688 688 if self.dataOutObj.data_dc != None:
689 689 pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights)
690 690 blocksize += (pts2write_DCchannels*datatypeValue*2)
691 691
692 692 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
693 693
694 694 return blocksize
695 695
696 696
697 697 def getBasicHeader(self):
698 698 self.basicHeaderObj.size = self.basicHeaderSize #bytes
699 699 self.basicHeaderObj.version = self.versionFile
700 700 self.basicHeaderObj.dataBlock = self.nTotalBlocks
701 701
702 702 utc = numpy.floor(self.dataOutObj.utctime)
703 703 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
704 704
705 705 self.basicHeaderObj.utc = utc
706 706 self.basicHeaderObj.miliSecond = milisecond
707 707 self.basicHeaderObj.timeZone = 0
708 708 self.basicHeaderObj.dstFlag = 0
709 709 self.basicHeaderObj.errorCount = 0
710 710
711 711 def getDataHeader(self):
712 712
713 713 """
714 714 Obtiene una copia del First Header
715 715
716 716 Affected:
717 717 self.systemHeaderObj
718 718 self.radarControllerHeaderObj
719 719 self.dtype
720 720
721 721 Return:
722 722 None
723 723 """
724 724
725 725 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
726 726 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
727 727 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
728 728
729 729 self.getBasicHeader()
730 730
731 731 processingHeaderSize = 40 # bytes
732 732 self.processingHeaderObj.dtype = 0 # Voltage
733 733 self.processingHeaderObj.blockSize = self.__getBlockSize()
734 734 self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints
735 735 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
736 736 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
737 737 self.processingHeaderObj.processFlags = self.__getProcessFlags()
738 self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra
738 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt# Se requiere para determinar el valor de timeInterval
739 739 self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt
740 740 self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels
741 741
742 742 if self.processingHeaderObj.totalSpectra > 0:
743 743 channelList = []
744 744 for channel in range(self.dataOutObj.nChannels):
745 745 channelList.append(channel)
746 746 channelList.append(channel)
747 747
748 748 pairsList = []
749 749 for pair in self.dataOutObj.pairsList:
750 750 pairsList.append(pair[0])
751 751 pairsList.append(pair[1])
752 752 spectraComb = channelList + pairsList
753 753 spectraComb = numpy.array(spectraComb,dtype="u1")
754 754 self.processingHeaderObj.spectraComb = spectraComb
755 755 sizeOfSpcComb = len(spectraComb)
756 756 processingHeaderSize += sizeOfSpcComb
757 757
758 758 if self.dataOutObj.code != None:
759 759 self.processingHeaderObj.code = self.dataOutObj.code
760 760 self.processingHeaderObj.nCode = self.dataOutObj.nCode
761 761 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
762 762 nCodeSize = 4 # bytes
763 763 nBaudSize = 4 # bytes
764 764 codeSize = 4 # bytes
765 765 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud)
766 766 processingHeaderSize += sizeOfCode
767 767
768 768 if self.processingHeaderObj.nWindows != 0:
769 769 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
770 770 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
771 771 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
772 772 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
773 773 sizeOfFirstHeight = 4
774 774 sizeOfdeltaHeight = 4
775 775 sizeOfnHeights = 4
776 776 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
777 777 processingHeaderSize += sizeOfWindows
778 778
779 779 self.processingHeaderObj.size = processingHeaderSize
780 780
781 781 No newline at end of file
@@ -1,698 +1,737
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import time
10 10 import datetime
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Data.JROData import Spectra, SpectraHeis
15 15 from IO.SpectraIO import SpectraWriter
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure
17 17 #from JRONoise import Noise
18 18
19 19 class SpectraProcessor:
20 20 '''
21 21 classdocs
22 22 '''
23 23
24 24 dataInObj = None
25 25
26 26 dataOutObj = None
27 27
28 28 noiseObj = None
29 29
30 30 integratorObjList = []
31 31
32 32 writerObjList = []
33 33
34 34 integratorObjIndex = None
35 35
36 36 writerObjIndex = None
37 37
38 38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39 39
40 firstdatatime = None
40 41
41 42 def __init__(self):
42 43 '''
43 44 Constructor
44 45 '''
45 46
46 47 self.integratorObjIndex = None
47 48 self.writerObjIndex = None
48 49 self.plotObjIndex = None
49 50 self.integratorOst = []
50 51 self.plotObjList = []
51 52 self.noiseObj = []
52 53 self.writerObjList = []
53 54 self.buffer = None
55 self.firstdatatime = None
54 56 self.profIndex = 0
55 57
56 58 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None):
57 59
58 60 if dataInObj == None:
59 61 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60 62
61 63 if dataInObj.type == "Voltage":
62 64 if nFFTPoints == None:
63 65 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 66
65 67
66 68
67 69 if dataInObj.type == "Spectra":
68 70 if nFFTPoints != None:
69 71 raise ValueError, "The nFFTPoints cannot be selected to this object type"
70 72
71 73 nFFTPoints = dataInObj.nFFTPoints
72 74
73 75 if pairsList == None:
74 76 pairsList = dataInObj.pairsList
75 77
76 78 if pairsList == None:
77 79 nPairs = 0
78 80 else:
79 81 nPairs = len(pairsList)
80 82
81 83 self.dataInObj = dataInObj
82 84
83 85 if dataOutObj == None:
84 86 dataOutObj = Spectra()
85 87
86 88 self.dataOutObj = dataOutObj
87 89 self.dataOutObj.nFFTPoints = nFFTPoints
88 90 self.dataOutObj.pairsList = pairsList
89 91 self.dataOutObj.nPairs = nPairs
90 92
91 93 return self.dataOutObj
92 94
93 95 def init(self):
94 96
95 97 self.dataOutObj.flagNoData = True
96 98
97 99 if self.dataInObj.flagNoData:
98 100 return 0
99 101
100 102 self.integratorObjIndex = 0
101 103 self.writerObjIndex = 0
102 104 self.plotObjIndex = 0
103 105
104 106
105 107 if self.dataInObj.type == "Spectra":
106 108
107 109 self.dataOutObj.copy(self.dataInObj)
108 110 self.dataOutObj.flagNoData = False
109 111 return
110 112
111 113 if self.dataInObj.type == "Voltage":
112 114
113 115 if self.buffer == None:
114 116 self.buffer = numpy.zeros((self.dataInObj.nChannels,
115 117 self.dataOutObj.nFFTPoints,
116 118 self.dataInObj.nHeights),
117 119 dtype='complex')
118 120
119 121 self.buffer[:,self.profIndex,:] = self.dataInObj.data
120 122 self.profIndex += 1
121 123
124 if self.firstdatatime == None:
125 self.firstdatatime = self.dataInObj.utctime
126
122 127 if self.profIndex == self.dataOutObj.nFFTPoints:
123 128
124 129 self.__updateObjFromInput()
125 130 self.__getFft()
126 131
127 132 self.dataOutObj.flagNoData = False
128 133
129 134 self.buffer = None
135 self.firstdatatime = None
130 136 self.profIndex = 0
131 137
132 138 return
133 139
134 140 #Other kind of data
135 141 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
136 142
137 143 def __getFft(self):
138 144 """
139 145 Convierte valores de Voltaje a Spectra
140 146
141 147 Affected:
142 148 self.dataOutObj.data_spc
143 149 self.dataOutObj.data_cspc
144 150 self.dataOutObj.data_dc
145 151 self.dataOutObj.heightList
146 152 self.dataOutObj.m_BasicHeader
147 153 self.dataOutObj.m_ProcessingHeader
148 154 self.dataOutObj.radarControllerHeaderObj
149 155 self.dataOutObj.systemHeaderObj
150 156 self.profIndex
151 157 self.buffer
152 158 self.dataOutObj.flagNoData
153 159 self.dataOutObj.dtype
154 160 self.dataOutObj.nPairs
155 161 self.dataOutObj.nChannels
156 162 self.dataOutObj.nProfiles
157 163 self.dataOutObj.systemHeaderObj.numChannels
158 164 self.dataOutObj.m_ProcessingHeader.totalSpectra
159 165 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
160 166 self.dataOutObj.m_ProcessingHeader.numHeights
161 167 self.dataOutObj.m_ProcessingHeader.spectraComb
162 168 self.dataOutObj.m_ProcessingHeader.shif_fft
163 169 """
164 170
165 171 fft_volt = numpy.fft.fft(self.buffer,axis=1)
166 172 dc = fft_volt[:,0,:]
167 173
168 174 #calculo de self-spectra
169 175 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
170 176 spc = fft_volt * numpy.conjugate(fft_volt)
171 177 spc = spc.real
172 178
173 179 blocksize = 0
174 180 blocksize += dc.size
175 181 blocksize += spc.size
176 182
177 183 cspc = None
178 184 pairIndex = 0
179 185 if self.dataOutObj.pairsList != None:
180 186 #calculo de cross-spectra
181 187 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
182 188 for pair in self.dataOutObj.pairsList:
183 189 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
184 190 pairIndex += 1
185 191 blocksize += cspc.size
186 192
187 193 self.dataOutObj.data_spc = spc
188 194 self.dataOutObj.data_cspc = cspc
189 195 self.dataOutObj.data_dc = dc
190 196 self.dataOutObj.blockSize = blocksize
191 197
192 198 # self.getNoise()
193 199
194 200 def __updateObjFromInput(self):
195 201
196 202 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
197 203 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
198 204 self.dataOutObj.channelList = self.dataInObj.channelList
199 205 self.dataOutObj.heightList = self.dataInObj.heightList
200 206 self.dataOutObj.dtype = self.dataInObj.dtype
201 207 self.dataOutObj.nHeights = self.dataInObj.nHeights
202 208 self.dataOutObj.nChannels = self.dataInObj.nChannels
203 209 self.dataOutObj.nBaud = self.dataInObj.nBaud
204 210 self.dataOutObj.nCode = self.dataInObj.nCode
205 211 self.dataOutObj.code = self.dataInObj.code
206 212 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
207 213 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
208 214 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
209 self.dataOutObj.utctime = self.dataInObj.utctime
215 self.dataOutObj.utctime = self.firstdatatime
210 216 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
211 217 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
212 218 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
219 self.dataOutObj.nCohInt = self.dataInObj.nCohInt
213 220 self.dataOutObj.nIncohInt = 1
214 221 self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds
215 self.dataOutObj.timeInterval = self.dataInObj.timeInterval
222 self.dataOutObj.timeInterval = self.dataInObj.timeInterval*self.dataOutObj.nFFTPoints
216 223
217 224 def addWriter(self, wrpath, blocksPerFile):
218 225
219 226 objWriter = SpectraWriter(self.dataOutObj)
220 227 objWriter.setup(wrpath, blocksPerFile)
221 228 self.writerObjList.append(objWriter)
222 229
223 230 def addIntegrator(self,N,timeInterval):
224 231
225 232 objIncohInt = IncoherentIntegration(N,timeInterval)
226 233 self.integratorObjList.append(objIncohInt)
227 234
228 235 def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
229 236 crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
230 237 self.plotObjList.append(crossSpcObj)
231 238
232 239 def plotCrossSpc(self, idfigure=None,
233 240 xmin=None,
234 241 xmax=None,
235 242 ymin=None,
236 243 ymax=None,
237 244 minvalue=None,
238 245 maxvalue=None,
239 246 wintitle='',
240 247 driver='plplot',
241 248 colormap='br_green',
242 249 colorbar=True,
243 250 showprofile=False,
244 251 save=False,
245 252 gpath=None,
246 253 pairsList = None):
247 254
248 255 if self.dataOutObj.flagNoData:
249 256 return 0
250 257
251 258 if pairsList == None:
252 259 pairsList = self.dataOutObj.pairsList
253 260
254 261 nframes = len(pairsList)
255 262
256 263 x = numpy.arange(self.dataOutObj.nFFTPoints)
257 264
258 265 y = self.dataOutObj.heightList
259 266
267 data_spc = self.dataOutObj.data_spc
268 data_cspc = self.dataOutObj.data_cspc
260 269
270 data = []
261 271
262 272
263 273 if len(self.plotObjList) <= self.plotObjIndex:
264 274 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
265 275
276
277
278
279
266 280 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
267 281 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
268 282 self.plotObjList.append(rtiObj)
269 283
270 284 def plotRti(self, idfigure=None,
271 285 starttime=None,
272 286 endtime=None,
273 287 rangemin=None,
274 288 rangemax=None,
275 289 minvalue=None,
276 290 maxvalue=None,
277 291 wintitle='',
278 292 driver='plplot',
279 293 colormap='br_greeen',
280 294 colorbar=True,
281 295 showprofile=False,
282 296 xrangestep=None,
283 297 save=False,
284 298 gpath=None,
285 299 ratio=1,
286 300 channelList=None):
287 301
288 302 if self.dataOutObj.flagNoData:
289 303 return 0
290 304
291 305 if channelList == None:
292 306 channelList = self.dataOutObj.channelList
293 307
294 308 nframes = len(channelList)
295 309
296 310 if len(self.plotObjList) <= self.plotObjIndex:
297 311 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
298 312
299 313 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
300 314
315 data = numpy.average(data, axis=1)
316
301 317 currenttime = self.dataOutObj.utctime - time.timezone
302 318
303 319 range = self.dataOutObj.heightList
304 320
305 321
306 322 figuretitle = "RTI Plot for Spectra Data" #+ date
307 323
308 324 cleardata = False
309 325
310 326 deltax = self.dataOutObj.timeInterval
311 327
312 328 plotObj = self.plotObjList[self.plotObjIndex]
313 329
314
330 plotObj.plotPcolor(data=data,
331 x=currenttime,
332 y=range,
333 channelList=channelList,
334 xmin=starttime,
335 xmax=endtime,
336 ymin=rangemin,
337 ymax=rangemax,
338 minvalue=minvalue,
339 maxvalue=maxvalue,
340 figuretitle=figuretitle,
341 xrangestep=xrangestep,
342 deltax=deltax,
343 save=save,
344 gpath=gpath,
345 ratio=ratio,
346 cleardata=cleardata
347 )
315 348
316 349
317 350
318 351 self.plotObjIndex += 1
319 352
320 353
321 354
322 355
323 356
324 357
325 358
326 359 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
327 360
328 361 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
329 362 self.plotObjList.append(spcObj)
330 363
331 364 def plotSpc(self, idfigure=None,
332 365 xmin=None,
333 366 xmax=None,
334 367 ymin=None,
335 368 ymax=None,
336 369 minvalue=None,
337 370 maxvalue=None,
338 371 wintitle='',
339 372 driver='plplot',
340 373 colormap='br_green',
341 374 colorbar=True,
342 375 showprofile=False,
343 376 save=False,
344 377 gpath=None,
345 378 ratio=1,
346 379 channelList=None):
347 380
348 381 if self.dataOutObj.flagNoData:
349 382 return 0
350 383
351 384 if channelList == None:
352 385 channelList = self.dataOutObj.channelList
353 386
354 387 nframes = len(channelList)
355 388
356 389 if len(self.plotObjList) <= self.plotObjIndex:
357 390 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
358 391
359 392 x = numpy.arange(self.dataOutObj.nFFTPoints)
360 393
361 394 y = self.dataOutObj.heightList
362 395
363 396 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
364 397 # noisedB = 10.*numpy.log10(noise)
365 398 noisedB = numpy.arange(len(channelList)+1)
366 399 noisedB = noisedB *1.2
367 400 titleList = []
368 401 for i in range(len(noisedB)):
369 402 title = "%.2f"%noisedB[i]
370 403 titleList.append(title)
371 404
372 405 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
373 406 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
374 407 figuretitle = "Spc Radar Data: %s"%dateTime
375 408
376 409 cleardata = True
377 410
378 411 plotObj = self.plotObjList[self.plotObjIndex]
379 412
380 413 plotObj.plotPcolor(data=data,
381 414 x=x,
382 415 y=y,
383 416 channelList=channelList,
384 417 xmin=xmin,
385 418 xmax=xmax,
386 419 ymin=ymin,
387 420 ymax=ymax,
388 421 minvalue=minvalue,
389 422 maxvalue=maxvalue,
390 423 figuretitle=figuretitle,
391 424 xrangestep=None,
392 425 deltax=None,
393 426 save=save,
394 427 gpath=gpath,
395 428 cleardata=cleardata
396 429 )
397 430
398 431 self.plotObjIndex += 1
399 432
400 433
401 434 def writeData(self, wrpath, blocksPerFile):
402 435
403 436 if self.dataOutObj.flagNoData:
404 437 return 0
405 438
406 439 if len(self.writerObjList) <= self.writerObjIndex:
407 440 self.addWriter(wrpath, blocksPerFile)
408 441
409 442 self.writerObjList[self.writerObjIndex].putData()
410 443
411 444 self.writerObjIndex += 1
412 445
413 446 def integrator(self, N=None, timeInterval=None):
414 447
415 448 if self.dataOutObj.flagNoData:
416 449 return 0
417 450
418 451 if len(self.integratorObjList) <= self.integratorObjIndex:
419 452 self.addIntegrator(N,timeInterval)
420 453
421 454 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
422 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
455 myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime)
423 456
424 457 if myIncohIntObj.isReady:
425 458 self.dataOutObj.data_spc = myIncohIntObj.data
426 self.dataOutObj.nAvg = myIncohIntObj.navg
427 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
459 self.dataOutObj.timeInterval *= myCohIntObj.nIncohInt
460 self.dataOutObj.nIncohInt = myIncohIntObj.navg * self.dataInObj.nIncohInt
461 self.dataOutObj.utctime = myIncohIntObj.firstdatatime
428 462 self.dataOutObj.flagNoData = False
429 463
430 464 """Calcular el ruido"""
431 465 self.getNoise()
432 466 else:
433 467 self.dataOutObj.flagNoData = True
434 468
435 469 self.integratorObjIndex += 1
436 470
437 471
438 472 class SpectraHeisProcessor:
439 473
440 474 def __init__(self):
441 475
442 476 self.integratorObjIndex = None
443 477 self.writerObjIndex = None
444 478 self.plotObjIndex = None
445 479 self.integratorObjList = []
446 480 self.writerObjList = []
447 481 self.plotObjList = []
448 482 #self.noiseObj = Noise()
449 483
450 484 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
451 485
452 486 if nFFTPoints == None:
453 487 nFFTPoints = self.dataInObj.nHeights
454 488
455 489 self.dataInObj = dataInObj
456 490
457 491 if dataOutObj == None:
458 492 dataOutObj = SpectraHeis()
459 493
460 494 self.dataOutObj = dataOutObj
461 495
462 496 return self.dataOutObj
463 497
464 498 def init(self):
465 499
466 500 self.dataOutObj.flagNoData = True
467 501
468 502 if self.dataInObj.flagNoData:
469 503 return 0
470 504
471 505 self.integratorObjIndex = 0
472 506 self.writerObjIndex = 0
473 507 self.plotObjIndex = 0
474 508
475 509 if self.dataInObj.type == "Voltage":
476 510 self.__updateObjFromInput()
477 511 self.__getFft()
478 512 self.dataOutObj.flagNoData = False
479 513 return
480 514
481 515 #Other kind of data
482 516 if self.dataInObj.type == "SpectraHeis":
483 517 self.dataOutObj.copy(self.dataInObj)
484 518 self.dataOutObj.flagNoData = False
485 519 return
486 520
487 521 raise ValueError, "The type is not valid"
488 522
489 523 def __updateObjFromInput(self):
490 524
491 525 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
492 526 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
493 527 self.dataOutObj.channelList = self.dataInObj.channelList
494 528 self.dataOutObj.heightList = self.dataInObj.heightList
495 529 self.dataOutObj.dtype = self.dataInObj.dtype
496 530 self.dataOutObj.nHeights = self.dataInObj.nHeights
497 531 self.dataOutObj.nChannels = self.dataInObj.nChannels
498 532 self.dataOutObj.nBaud = self.dataInObj.nBaud
499 533 self.dataOutObj.nCode = self.dataInObj.nCode
500 534 self.dataOutObj.code = self.dataInObj.code
501 535 self.dataOutObj.nProfiles = 1
502 536 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
503 537 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
504 538 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
505 539 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
506 540 self.dataOutObj.utctime = self.dataInObj.utctime
507 541 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
508 542 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
509 543 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
510 544 self.dataOutObj.nIncohInt = 1
511 545
512 546 def __getFft(self):
513 547
514 548 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
515 549 #print fft_volt
516 550 #calculo de self-spectra
517 551 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
518 552
519 553 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
520 554 self.dataOutObj.data_spc = spc
521 555
522 556 def getSpectra(self):
523 557
524 558 return self.dataOutObj.data_spc
525 559
526 560 def getFrecuencies(self):
527 561
528 562 print self.nFFTPoints
529 563 return numpy.arange(int(self.nFFTPoints))
530 564
531 565 def addIntegrator(self,N,timeInterval):
532 566
533 567 objIncohInt = IncoherentIntegration(N,timeInterval)
534 568 self.integratorObjList.append(objIncohInt)
535 569
536 570 def integrator(self, N=None, timeInterval=None):
537 571
538 572 if self.dataOutObj.flagNoData:
539 573 return 0
540 574
541 575 if len(self.integratorObjList) <= self.integratorObjIndex:
542 576 self.addIntegrator(N,timeInterval)
543 577
544 578 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
545 579 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
546 580
547 581 if myIncohIntObj.isReady:
548 582 self.dataOutObj.data_spc = myIncohIntObj.data
549 583 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
550 584 self.dataOutObj.flagNoData = False
551 585
552 586 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
553 587 # self.getNoise(type="sort", parm=16)
554 588
555 589 else:
556 590 self.dataOutObj.flagNoData = True
557 591
558 592 self.integratorObjIndex += 1
559 593
560 594
561 595 def addScope(self, idfigure, nframes, wintitle, driver):
562 596
563 597 if idfigure==None:
564 598 idfigure = self.plotObjIndex
565 599
566 600 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
567 601 self.plotObjList.append(scopeObj)
568 602
569 603 def plotScope(self,
570 604 idfigure=None,
571 605 minvalue=None,
572 606 maxvalue=None,
573 607 xmin=None,
574 608 xmax=None,
575 609 wintitle='',
576 610 driver='plplot',
577 611 save=False,
578 612 gpath=None,
579 613 titleList=None,
580 614 xlabelList=None,
581 615 ylabelList=None):
582 616
583 617 if self.dataOutObj.flagNoData:
584 618 return 0
585 619
586 620 nframes = len(self.dataOutObj.channelList)
587 621
588 622 if len(self.plotObjList) <= self.plotObjIndex:
589 623 self.addScope(idfigure, nframes, wintitle, driver)
590 624
591 625
592 626 data1D = self.dataOutObj.data_spc
593 627
594 628 x = numpy.arange(self.dataOutObj.nHeights)
595 629
596 630 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
597 631
598 632 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
599 633 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
600 634
601 635 figureTitle = "Scope Plot Radar Data: " + date
602 636
603 637 plotObj = self.plotObjList[self.plotObjIndex]
604 638
605 639 plotObj.plot1DArray(data1D,
606 640 x,
607 641 self.dataOutObj.channelList,
608 642 xmin,
609 643 xmax,
610 644 minvalue,
611 645 maxvalue,
612 646 figureTitle,
613 647 save,
614 648 gpath)
615 649
616 650 self.plotObjIndex += 1
617 651
618 652 class IncoherentIntegration:
619 653
620 654 integ_counter = None
621 655 data = None
622 656 navg = None
623 657 buffer = None
624 658 nIncohInt = None
659 firstdatatime = None
625 660
626 661 def __init__(self, N = None, timeInterval = None):
627 662 """
628 663 N
629 664 timeInterval - interval time [min], integer value
630 665 """
631 666
632 667 self.data = None
633 668 self.navg = None
634 669 self.buffer = None
635 670 self.timeOut = None
636 671 self.exitCondition = False
637 672 self.isReady = False
638 673 self.nIncohInt = N
639 674 self.integ_counter = 0
675 self.firstdatatime = None
676
640 677 if timeInterval!=None:
641 678 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
642 679
643 680 if ((timeInterval==None) and (N==None)):
644 681 print 'N = None ; timeInterval = None'
645 682 sys.exit(0)
646 683 elif timeInterval == None:
647 684 self.timeFlag = False
648 685 else:
649 686 self.timeFlag = True
650 687
651 688
652 def exe(self,data,timeOfData):
689 def exe(self,data,datatime):
653 690 """
654 691 data
655 692
656 timeOfData [seconds]
693 datatime [seconds]
657 694 """
695 if self.firstdatatime == None or self.isReady:
696 self.firstdatatime = datatime
658 697
659 698 if self.timeFlag:
660 699 if self.timeOut == None:
661 self.timeOut = timeOfData + self.timeIntervalInSeconds
700 self.timeOut = datatime + self.timeIntervalInSeconds
662 701
663 if timeOfData < self.timeOut:
702 if datatime < self.timeOut:
664 703 if self.buffer == None:
665 704 self.buffer = data
666 705 else:
667 706 self.buffer = self.buffer + data
668 707 self.integ_counter += 1
669 708 else:
670 709 self.exitCondition = True
671 710
672 711 else:
673 712 if self.integ_counter < self.nIncohInt:
674 713 if self.buffer == None:
675 714 self.buffer = data
676 715 else:
677 716 self.buffer = self.buffer + data
678 717
679 718 self.integ_counter += 1
680 719
681 720 if self.integ_counter == self.nIncohInt:
682 721 self.exitCondition = True
683 722
684 723 if self.exitCondition:
685 724 self.data = self.buffer
686 725 self.navg = self.integ_counter
687 726 self.isReady = True
688 727 self.buffer = None
689 728 self.timeOut = None
690 729 self.integ_counter = 0
691 730 self.exitCondition = False
692 731
693 732 if self.timeFlag:
694 733 self.buffer = data
695 self.timeOut = timeOfData + self.timeIntervalInSeconds
734 self.timeOut = datatime + self.timeIntervalInSeconds
696 735 else:
697 736 self.isReady = False
698 737 No newline at end of file
@@ -1,419 +1,429
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os
8 8 import sys
9 9 import numpy
10 10 import datetime
11 11 import time
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from Data.JROData import Voltage
17 17 from IO.VoltageIO import VoltageWriter
18 18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19 19
20 20 class VoltageProcessor:
21 21
22 22 dataInObj = None
23 23 dataOutObj = None
24 24 integratorObjIndex = None
25 25 writerObjIndex = None
26 26 integratorObjList = None
27 27 writerObjList = None
28 28
29 29 def __init__(self):
30 30 self.integratorObjIndex = None
31 31 self.writerObjIndex = None
32 32 self.plotObjIndex = None
33 33 self.integratorObjList = []
34 34 self.writerObjList = []
35 35 self.plotObjList = []
36 36
37 37 def setup(self,dataInObj=None,dataOutObj=None):
38 38 self.dataInObj = dataInObj
39 39
40 40 if self.dataOutObj == None:
41 41 dataOutObj = Voltage()
42 42
43 43 self.dataOutObj = dataOutObj
44 44
45 45 return self.dataOutObj
46 46
47 47 def init(self):
48 48 self.integratorObjIndex = 0
49 49 self.writerObjIndex = 0
50 50 self.plotObjIndex = 0
51 51
52 52 if not(self.dataInObj.flagNoData):
53 53 self.dataOutObj.copy(self.dataInObj)
54 54 # No necesita copiar en cada init() los atributos de dataInObj
55 55 # la copia deberia hacerse por cada nuevo bloque de datos
56 56
57 57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 59 self.plotObjList.append(rtiObj)
60 60
61 61 def plotRti(self, idfigure=None,
62 62 starttime=None,
63 63 endtime=None,
64 64 rangemin=None,
65 65 rangemax=None,
66 66 minvalue=None,
67 67 maxvalue=None,
68 68 wintitle='',
69 69 driver='plplot',
70 70 colormap='br_greeen',
71 71 colorbar=True,
72 72 showprofile=False,
73 73 xrangestep=None,
74 74 save=False,
75 75 gpath=None,
76 76 ratio=1,
77 77 channelList=None):
78 78
79 79 if self.dataOutObj.flagNoData:
80 80 return 0
81 81
82 82 if channelList == None:
83 83 channelList = self.dataOutObj.channelList
84 84
85 85 nframes = len(channelList)
86 86
87 87 if len(self.plotObjList) <= self.plotObjIndex:
88 88 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
89 89
90 90 data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:])
91 91 data = 10*numpy.log10(data.real)
92 92
93 93 currenttime = self.dataOutObj.utctime - time.timezone
94 94
95 95 range = self.dataOutObj.heightList
96 96
97 97 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
98 98 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
99 99 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
100 100
101 101 figuretitle = "RTI Plot Radar Data" #+ date
102 102
103 103 plotObj = self.plotObjList[self.plotObjIndex]
104 104
105 105 cleardata = False
106 106
107 107 deltax = self.dataOutObj.timeInterval
108 108
109 109 plotObj.plotPcolor(data=data,
110 110 x=currenttime,
111 111 y=range,
112 112 channelList=channelList,
113 113 xmin=starttime,
114 114 xmax=endtime,
115 115 ymin=rangemin,
116 116 ymax=rangemax,
117 117 minvalue=minvalue,
118 118 maxvalue=maxvalue,
119 119 figuretitle=figuretitle,
120 120 xrangestep=xrangestep,
121 121 deltax=deltax,
122 122 save=save,
123 123 gpath=gpath,
124 124 ratio=ratio,
125 125 cleardata=cleardata
126 126 )
127 127
128 128
129 129 self.plotObjIndex += 1
130 130
131 131 def addScope(self, idfigure, nframes, wintitle, driver):
132 132 if idfigure==None:
133 133 idfigure = self.plotObjIndex
134 134
135 135 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
136 136 self.plotObjList.append(scopeObj)
137 137
138 138 def plotScope(self,
139 139 idfigure=None,
140 140 minvalue=None,
141 141 maxvalue=None,
142 142 xmin=None,
143 143 xmax=None,
144 144 wintitle='',
145 145 driver='plplot',
146 146 save=False,
147 147 gpath=None,
148 148 ratio=1,
149 149 type="power"):
150 150
151 151 if self.dataOutObj.flagNoData:
152 152 return 0
153 153
154 154 nframes = len(self.dataOutObj.channelList)
155 155
156 156 if len(self.plotObjList) <= self.plotObjIndex:
157 157 self.addScope(idfigure, nframes, wintitle, driver)
158 158
159 159
160 160 if type=="power":
161 161 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
162 162 data1D = data1D.real
163 163
164 164 if type =="iq":
165 165 data1D = self.dataOutObj.data
166 166
167 167 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
168 168
169 169 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
170 170 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
171 171
172 172 figuretitle = "Scope Plot Radar Data: " + date
173 173
174 174 plotObj = self.plotObjList[self.plotObjIndex]
175 175
176 176 plotObj.plot1DArray(data1D=data1D,
177 177 x=self.dataOutObj.heightList,
178 178 channelList=self.dataOutObj.channelList,
179 179 xmin=xmin,
180 180 xmax=xmax,
181 181 minvalue=minvalue,
182 182 maxvalue=maxvalue,
183 183 figuretitle=figuretitle,
184 184 save=save,
185 185 gpath=gpath,
186 186 ratio=ratio)
187 187
188 188
189 189 self.plotObjIndex += 1
190 190
191 191
192 192 def addIntegrator(self, *args):
193 193 objCohInt = CoherentIntegrator(*args)
194 194 self.integratorObjList.append(objCohInt)
195 195
196 196 def addWriter(self, *args):
197 197 writerObj = VoltageWriter(self.dataOutObj)
198 198 writerObj.setup(*args)
199 199 self.writerObjList.append(writerObj)
200 200
201 201 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
202 202
203 203 if self.dataOutObj.flagNoData:
204 204 return 0
205 205
206 206 if len(self.writerObjList) <= self.writerObjIndex:
207 207 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
208 208
209 209 self.writerObjList[self.writerObjIndex].putData()
210 210
211 211 self.writerObjIndex += 1
212 212
213 213 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
214 214
215 215 if self.dataOutObj.flagNoData:
216 216 return 0
217 217
218 218 if len(self.integratorObjList) <= self.integratorObjIndex:
219 219 self.addIntegrator(nCohInt, timeInterval, overlapping)
220 220
221 221 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
222 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
222 myCohIntObj.exe(data = self.dataOutObj.data, datatime=self.dataOutObj.utctime)
223 223
224 224 # self.dataOutObj.timeInterval *= nCohInt
225 225 self.dataOutObj.flagNoData = True
226 226
227 227 if myCohIntObj.isReady:
228 self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval
228 self.dataOutObj.data = myCohIntObj.data
229 self.dataOutObj.timeInterval *= myCohIntObj.nCohInt
230 self.dataOutObj.nCohInt = myCohIntObj.nCohInt * self.dataInObj.nCohInt
231 self.dataOutObj.utctime = myCohIntObj.firstdatatime
229 232 self.dataOutObj.flagNoData = False
230 233
231 234 def selectChannels(self, channelList):
232 235
233 236 self.selectChannelsByIndex(channelList)
234 237
235 238 def selectChannelsByIndex(self, channelIndexList):
236 239 """
237 240 Selecciona un bloque de datos en base a canales segun el channelIndexList
238 241
239 242 Input:
240 243 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
241 244
242 245 Affected:
243 246 self.dataOutObj.data
244 247 self.dataOutObj.channelIndexList
245 248 self.dataOutObj.nChannels
246 249 self.dataOutObj.m_ProcessingHeader.totalSpectra
247 250 self.dataOutObj.systemHeaderObj.numChannels
248 251 self.dataOutObj.m_ProcessingHeader.blockSize
249 252
250 253 Return:
251 254 None
252 255 """
253 256 if self.dataOutObj.flagNoData:
254 257 return 0
255 258
256 259 for channel in channelIndexList:
257 260 if channel not in self.dataOutObj.channelIndexList:
258 261 raise ValueError, "The value %d in channelIndexList is not valid" %channel
259 262
260 263 nChannels = len(channelIndexList)
261 264
262 265 data = self.dataOutObj.data[channelIndexList,:]
263 266
264 267 self.dataOutObj.data = data
265 268 self.dataOutObj.channelIndexList = channelIndexList
266 269 self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList]
267 270 self.dataOutObj.nChannels = nChannels
268 271
269 272 return 1
270 273
271 274 class CoherentIntegrator:
272 275
273 276
274 277 __profIndex = 0
275 278 __withOverapping = False
276 279
277 280 __isByTime = False
278 281 __initime = None
279 282 __integrationtime = None
280 283
281 284 __buffer = None
282 285
283 286 isReady = False
284 287 nCohInt = None
285
288 firstdatatime = None
286 289
287 290 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
288 291
289 292 """
290 293 Set the parameters of the integration class.
291 294
292 295 Inputs:
293 296
294 297 nCohInt : Number of coherent integrations
295 298 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
296 299 overlapping :
297 300
298 301 """
299 302
300 303 self.__buffer = None
301 304 self.isReady = False
302 305
303 306 if nCohInt == None and timeInterval == None:
304 307 raise ValueError, "nCohInt or timeInterval should be specified ..."
305 308
306 309 if nCohInt != None:
307 310 self.nCohInt = nCohInt
308 311 self.__isByTime = False
309 312 else:
310 313 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
311 314 self.__isByTime = True
312 315
313 316 if overlapping:
314 317 self.__withOverapping = True
315 318 self.__buffer = None
316 319 else:
317 320 self.__withOverapping = False
318 321 self.__buffer = 0
319 322
320 323 self.__profIndex = 0
324 firstdatatime = None
321 325
322 326 def putData(self, data):
323 327
324 328 """
325 329 Add a profile to the __buffer and increase in one the __profileIndex
326 330
327 331 """
328 332 if not self.__withOverapping:
329 333 self.__buffer += data
330 334 self.__profIndex += 1
331 335 return
332 336
333 337 #Overlapping data
334 338 nChannels, nHeis = data.shape
335 339 data = numpy.reshape(data, (1, nChannels, nHeis))
336 340
337 341 if self.__buffer == None:
338 342 self.__buffer = data
339 343 self.__profIndex += 1
340 344 return
341 345
342 346 if self.__profIndex < self.nCohInt:
343 347 self.__buffer = numpy.vstack((self.__buffer, data))
344 348 self.__profIndex += 1
345 349 return
346 350
347 351 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
348 352 self.__buffer[self.nCohInt-1] = data
349 353 #self.__profIndex = self.nCohInt
350 354 return
351 355
352 356
353 357 def pushData(self):
354 358 """
355 359 Return the sum of the last profiles and the profiles used in the sum.
356 360
357 361 Affected:
358 362
359 363 self.__profileIndex
360 364
361 365 """
362 366
363 367 if not self.__withOverapping:
364 368 data = self.__buffer
365 369 nCohInt = self.__profIndex
366 370
367 371 self.__buffer = 0
368 372 self.__profIndex = 0
369 373
370 374 return data, nCohInt
371 375
372 376 #Overlapping data
373 377 data = numpy.sum(self.__buffer, axis=0)
374 378 nCohInt = self.__profIndex
375 379
376 380 return data, nCohInt
377 381
378 382 def byProfiles(self, data):
379 383
380 384 self.isReady = False
381 385 avg_data = None
382 386
383 387 self.putData(data)
384 388
385 389 if self.__profIndex == self.nCohInt:
386 390 avg_data, nCohInt = self.pushData()
387 391 self.isReady = True
388 392
389 393 return avg_data
390 394
391 395 def byTime(self, data, datatime):
392 396
393 397 self.isReady = False
394 398 avg_data = None
395 399
396 400 if self.__initime == None:
397 401 self.__initime = datatime
398 402
399 403 self.putData(data)
400 404
401 405 if (datatime - self.__initime) >= self.__integrationtime:
402 406 avg_data, nCohInt = self.pushData()
403 407 self.nCohInt = nCohInt
404 408 self.isReady = True
405 409
406 410 return avg_data
407 411
408 412 def exe(self, data, datatime=None):
409 413
414
415 if self.firstdatatime == None or self.isReady:
416 self.firstdatatime = datatime
417
410 418 if not self.__isByTime:
411 419 avg_data = self.byProfiles(data)
412 420 else:
413 421 avg_data = self.byTime(data, datatime)
414 422
415 423 self.data = avg_data
416 424
425
426
417 427 return avg_data
418 428
419 429
General Comments 0
You need to be logged in to leave comments. Login now