##// END OF EJS Templates
Lectura/Escritura de Rawdata y Pdata operando correctamente, se hicieron pruebas con datos de Drifts,Faraday e Imagenes.
Daniel Valdez -
r126:ba26fa07a34d
parent child
Show More
@@ -1,70 +1,76
1 '''
2
3 $Author$
4 $Id$
5 '''
6
1 7 import os, sys
2 8 import copy
3 9 import numpy
4 10
5 11 path = os.path.split(os.getcwd())[0]
6 12 sys.path.append(path)
7 13
8 14 from IO.JROHeader import SystemHeader, RadarControllerHeader
9 15
10 16 class JROData:
11 17
12 18 # m_BasicHeader = BasicHeader()
13 19 # m_ProcessingHeader = ProcessingHeader()
14 20
15 21 systemHeaderObj = SystemHeader()
16 22
17 23 radarControllerHeaderObj = RadarControllerHeader()
18 24
19 25 # data = None
20 26
21 27 type = None
22 28
23 29 dtype = None
24 30
25 31 nChannels = None
26 32
27 33 nHeights = None
28 34
29 35 nProfiles = None
30 36
31 37 heightList = None
32 38
33 39 channelList = None
34 40
35 41 channelIndexList = None
36 42
37 43 flagNoData = False
38 44
39 45 flagTimeBlock = False
40 46
41 47 dataUtcTime = None
42 48
43 49 nCode = None
44 50
45 51 nBaud = None
46 52
47 53 code = None
48 54
49 55 flagDecodeData = True #asumo q la data esta decodificada
50 56
51 57 flagDeflipData = True #asumo q la data esta sin flip
52 58
53 59 flagShiftFFT = False
54 60
55 61
56 62 def __init__(self):
57 63
58 64 raise ValueError, "This class has not been implemented"
59 65
60 66 def copy(self, inputObj=None):
61 67
62 68 if inputObj == None:
63 69 return copy.deepcopy(self)
64 70
65 71 for key in inputObj.__dict__.keys():
66 72 self.__dict__[key] = inputObj.__dict__[key]
67 73
68 74 def deepcopy(self):
69 75
70 76 return copy.deepcopy(self) No newline at end of file
@@ -1,60 +1,66
1 '''
2
3 $Author$
4 $Id$
5 '''
6
1 7 import os, sys
2 8 import numpy
3 9
4 10 path = os.path.split(os.getcwd())[0]
5 11 sys.path.append(path)
6 12
7 13 from JROData import JROData
8 14 from IO.JROHeader import SystemHeader, RadarControllerHeader
9 15
10 16 class Spectra(JROData):
11 17 data_spc = None
12 18
13 19 data_cspc = None
14 20
15 21 data_dc = None
16 22
17 23 nFFTPoints = None
18 24
19 25 nPairs = None
20 26
21 27 pairsList = None
22 28
23 29 nIncohInt = None
24 30
25 31 def __init__(self):
26 32 '''
27 33 Constructor
28 34 '''
29 35
30 36 self.m_RadarControllerHeader = RadarControllerHeader()
31 37
32 38 self.m_SystemHeader = SystemHeader()
33 39
34 40 self.type = "Spectra"
35 41
36 42 #data es un numpy array de 2 dmensiones ( canales, alturas)
37 43 # self.data = None
38 44
39 45 self.dtype = None
40 46
41 47 self.nChannels = 0
42 48
43 49 self.nHeights = 0
44 50
45 51 self.nProfiles = None
46 52
47 53 self.heightList = None
48 54
49 55 self.channelList = None
50 56
51 57 self.channelIndexList = None
52 58
53 59 self.flagNoData = True
54 60
55 61 self.flagTimeBlock = False
56 62
57 63 self.dataUtcTime = None
58 64
59 65 self.nIncohInt = None
60 66 No newline at end of file
@@ -1,50 +1,56
1 '''
2
3 $Author$
4 $Id$
5 '''
6
1 7 import os, sys
2 8 import numpy
3 9
4 10 path = os.path.split(os.getcwd())[0]
5 11 sys.path.append(path)
6 12
7 13 from JROData import JROData
8 14 from IO.JROHeader import SystemHeader, RadarControllerHeader
9 15
10 16 class Voltage(JROData):
11 17
12 18 nCohInt = None
13 19
14 20 data = None
15 21
16 22 def __init__(self):
17 23 '''
18 24 Constructor
19 25 '''
20 26
21 27 self.m_RadarControllerHeader = RadarControllerHeader()
22 28
23 29 self.m_SystemHeader = SystemHeader()
24 30
25 31 self.type = "Voltage"
26 32
27 33 #data es un numpy array de 2 dmensiones ( canales, alturas)
28 34 self.data = None
29 35
30 36 self.dtype = None
31 37
32 38 self.nChannels = 0
33 39
34 40 self.nHeights = 0
35 41
36 42 self.nProfiles = None
37 43
38 44 self.heightList = None
39 45
40 46 self.channelList = None
41 47
42 48 self.channelIndexList = None
43 49
44 50 self.flagNoData = True
45 51
46 52 self.flagTimeBlock = False
47 53
48 54 self.dataUtcTime = None
49 55
50 56 self.nCohInt = None
@@ -1,751 +1,757
1 '''
2
3 $Author$
4 $Id$
5 '''
6
1 7 import os, sys
2 8 import glob
3 9 import time
4 10 import numpy
5 11 import fnmatch
6 12 import time, datetime
7 13
8 14 path = os.path.split(os.getcwd())[0]
9 15 sys.path.append(path)
10 16
11 17 from JROHeader import *
12 18 from Data.JROData import JROData
13 19
14 20 def isNumber(str):
15 21 """
16 22 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
17 23
18 24 Excepciones:
19 25 Si un determinado string no puede ser convertido a numero
20 26 Input:
21 27 str, string al cual se le analiza para determinar si convertible a un numero o no
22 28
23 29 Return:
24 30 True : si el string es uno numerico
25 31 False : no es un string numerico
26 32 """
27 33 try:
28 34 float( str )
29 35 return True
30 36 except:
31 37 return False
32 38
33 39 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
34 40 """
35 41 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
36 42
37 43 Inputs:
38 44 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
39 45
40 46 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
41 47 segundos contados desde 01/01/1970.
42 48 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
43 49 segundos contados desde 01/01/1970.
44 50
45 51 Return:
46 52 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
47 53 fecha especificado, de lo contrario retorna False.
48 54
49 55 Excepciones:
50 56 Si el archivo no existe o no puede ser abierto
51 57 Si la cabecera no puede ser leida.
52 58
53 59 """
54 60 basicHeaderObj = BasicHeader()
55 61
56 62 try:
57 63 fp = open(filename,'rb')
58 64 except:
59 65 raise IOError, "The file %s can't be opened" %(filename)
60 66
61 67 sts = basicHeaderObj.read(fp)
62 68 fp.close()
63 69
64 70 if not(sts):
65 71 print "Skipping the file %s because it has not a valid header" %(filename)
66 72 return 0
67 73
68 74 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
69 75 return 0
70 76
71 77 return 1
72 78
73 79
74 80
75 81
76 82 class JRODataIO:
77 83
78 84 c = 3E8
79 85
80 86 basicHeaderObj = BasicHeader()
81 87
82 88 systemHeaderObj = SystemHeader()
83 89
84 90 radarControllerHeaderObj = RadarControllerHeader()
85 91
86 92 processingHeaderObj = ProcessingHeader()
87 93
88 94 online = 0
89 95
90 96 dtype = None
91 97
92 98 pathList = []
93 99
94 100 filenameList = []
95 101
96 102 filename = None
97 103
98 104 ext = None
99 105
100 106 flagNoMoreFiles = 0
101 107
102 108 flagIsNewFile = 1
103 109
104 110 flagTimeBlock = 0
105 111
106 112 flagIsNewBlock = 0
107 113
108 114 fp = None
109 115
110 116 firstHeaderSize = 0
111 117
112 118 basicHeaderSize = 24
113 119
114 120 versionFile = 1103
115 121
116 122 fileSize = None
117 123
118 124 ippSeconds = None
119 125
120 126 fileSizeByHeader = None
121 127
122 128 fileIndex = None
123 129
124 130 profileIndex = None
125 131
126 132 blockIndex = None
127 133
128 134 nTotalBlocks = None
129 135
130 136 maxTimeStep = 30
131 137
132 138 lastUTTime = None
133 139
134 140 datablock = None
135 141
136 142 dataOutObj = None
137 143
138 144 blocksize = None
139 145
140 146 def __init__(self):
141 147 pass
142 148
143 149 class JRODataReader(JRODataIO):
144 150
145 151 nReadBlocks = 0
146 152
147 153 def __init__(self):
148 154
149 155 pass
150 156
151 157 def createObjByDefault(self):
152 158 """
153 159
154 160 """
155 161 raise ValueError, "This method has not been implemented"
156 162
157 163 def getBlockDimension(self):
158 164
159 165 raise ValueError, "No implemented"
160 166
161 167 def __searchFilesOffLine(self,
162 168 path,
163 169 startDate,
164 170 endDate,
165 171 startTime=datetime.time(0,0,0),
166 172 endTime=datetime.time(23,59,59),
167 173 set=None,
168 174 expLabel="",
169 175 ext=".r"):
170 176 dirList = []
171 177 for thisPath in os.listdir(path):
172 178 if os.path.isdir(os.path.join(path,thisPath)):
173 179 dirList.append(thisPath)
174 180
175 181 if not(dirList):
176 182 return None, None
177 183
178 184 pathList = []
179 185 dateList = []
180 186
181 187 thisDate = startDate
182 188
183 189 while(thisDate <= endDate):
184 190 year = thisDate.timetuple().tm_year
185 191 doy = thisDate.timetuple().tm_yday
186 192
187 193 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
188 194 if len(match) == 0:
189 195 thisDate += datetime.timedelta(1)
190 196 continue
191 197
192 198 pathList.append(os.path.join(path,match[0],expLabel))
193 199 dateList.append(thisDate)
194 200 thisDate += datetime.timedelta(1)
195 201
196 202 filenameList = []
197 203 for index in range(len(pathList)):
198 204
199 205 thisPath = pathList[index]
200 206 fileList = glob.glob1(thisPath, "*%s" %ext)
201 207 fileList.sort()
202 208
203 209 #Busqueda de datos en el rango de horas indicados
204 210 thisDate = dateList[index]
205 211 startDT = datetime.datetime.combine(thisDate, startTime)
206 212 endDT = datetime.datetime.combine(thisDate, endTime)
207 213
208 214 startUtSeconds = time.mktime(startDT.timetuple())
209 215 endUtSeconds = time.mktime(endDT.timetuple())
210 216
211 217 for file in fileList:
212 218
213 219 filename = os.path.join(thisPath,file)
214 220
215 221 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
216 222 filenameList.append(filename)
217 223
218 224 if not(filenameList):
219 225 return None, None
220 226
221 227 self.filenameList = filenameList
222 228
223 229 return pathList, filenameList
224 230
225 231 def setup(self,dataOutObj=None,
226 232 path=None,
227 233 startDate=None,
228 234 endDate=None,
229 235 startTime=datetime.time(0,0,0),
230 236 endTime=datetime.time(23,59,59),
231 237 set=0,
232 238 expLabel = "",
233 239 ext = None,
234 240 online = 0):
235 241
236 242 if path == None:
237 243 raise ValueError, "The path is not valid"
238 244
239 245 if ext == None:
240 246 ext = self.ext
241 247
242 248 if dataOutObj == None:
243 249 dataOutObj = self.createObjByDefault()
244 250
245 251 self.dataOutObj = dataOutObj
246 252
247 253 if online:
248 254 pass
249 255
250 256 else:
251 257 print "Searching file in offline mode"
252 258 pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext)
253 259 if not(pathList):
254 260 print "No files in range: %s - %s"%(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
255 261 return None
256 262 self.fileIndex = -1
257 263 self.pathList = pathList
258 264 self.filenameList = filenameList
259 265
260 266 self.online = online
261 267 ext = ext.lower()
262 268 self.ext = ext
263 269
264 270 if not(self.setNextFile()):
265 271 if (startDate!=None) and (endDate!=None):
266 272 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
267 273 elif startDate != None:
268 274 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
269 275 else:
270 276 print "No files"
271 277
272 278 return None
273 279
274 280 # self.updateDataHeader()
275 281
276 282 return self.dataOutObj
277 283
278 284 def __setNextFileOffline(self):
279 285 idFile = self.fileIndex
280 286
281 287 while (True):
282 288 idFile += 1
283 289 if not(idFile < len(self.filenameList)):
284 290 self.flagNoMoreFiles = 1
285 291 print "No more Files"
286 292 return 0
287 293
288 294 filename = self.filenameList[idFile]
289 295
290 296 if not(self.__verifyFile(filename)):
291 297 continue
292 298
293 299 fileSize = os.path.getsize(filename)
294 300 fp = open(filename,'rb')
295 301 break
296 302
297 303 self.flagIsNewFile = 1
298 304 self.fileIndex = idFile
299 305 self.filename = filename
300 306 self.fileSize = fileSize
301 307 self.fp = fp
302 308
303 309 print "Setting the file: %s"%self.filename
304 310
305 311 return 1
306 312
307 313
308 314
309 315 def setNextFile(self):
310 316 if self.fp != None:
311 317 self.fp.close()
312 318
313 319 if self.online:
314 320 newFile = self.__setNextFileOnline()
315 321 else:
316 322 newFile = self.__setNextFileOffline()
317 323
318 324 if not(newFile):
319 325 return 0
320 326
321 327 self.__readFirstHeader()
322 328 self.nReadBlocks = 0
323 329 return 1
324 330
325 331 def __setNewBlock(self):
326 332 if self.fp == None:
327 333 return 0
328 334
329 335 if self.flagIsNewFile:
330 336 return 1
331 337
332 338 self.lastUTTime = self.basicHeaderObj.utc
333 339 currentSize = self.fileSize - self.fp.tell()
334 340 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
335 341
336 342 if (currentSize >= neededSize):
337 343 self.__rdBasicHeader()
338 344 return 1
339 345
340 346 if not(self.setNextFile()):
341 347 return 0
342 348
343 349 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
344 350
345 351 self.flagTimeBlock = 0
346 352
347 353 if deltaTime > self.maxTimeStep:
348 354 self.flagTimeBlock = 1
349 355
350 356 return 1
351 357
352 358
353 359 def readNextBlock(self):
354 360 if not(self.__setNewBlock()):
355 361 return 0
356 362
357 363 if not(self.readBlock()):
358 364 return 0
359 365
360 366 return 1
361 367
362 368 def __rdProcessingHeader(self, fp=None):
363 369 if fp == None:
364 370 fp = self.fp
365 371
366 372 self.processingHeaderObj.read(fp)
367 373
368 374 def __rdRadarControllerHeader(self, fp=None):
369 375 if fp == None:
370 376 fp = self.fp
371 377
372 378 self.radarControllerHeaderObj.read(fp)
373 379
374 380 def __rdSystemHeader(self, fp=None):
375 381 if fp == None:
376 382 fp = self.fp
377 383
378 384 self.systemHeaderObj.read(fp)
379 385
380 386 def __rdBasicHeader(self, fp=None):
381 387 if fp == None:
382 388 fp = self.fp
383 389
384 390 self.basicHeaderObj.read(fp)
385 391
386 392
387 393 def __readFirstHeader(self):
388 394 self.__rdBasicHeader()
389 395 self.__rdSystemHeader()
390 396 self.__rdRadarControllerHeader()
391 397 self.__rdProcessingHeader()
392 398
393 399 self.firstHeaderSize = self.basicHeaderObj.size
394 400
395 401 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
396 402 if datatype == 0:
397 403 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
398 404 elif datatype == 1:
399 405 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
400 406 elif datatype == 2:
401 407 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
402 408 elif datatype == 3:
403 409 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
404 410 elif datatype == 4:
405 411 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
406 412 elif datatype == 5:
407 413 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
408 414 else:
409 415 raise ValueError, 'Data type was not defined'
410 416
411 417 self.dtype = datatype_str
412 418 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
413 419 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
414 420 # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels)
415 421 # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
416 422 self.getBlockDimension()
417 423
418 424
419 425 def __verifyFile(self, filename, msgFlag=True):
420 426 msg = None
421 427 try:
422 428 fp = open(filename, 'rb')
423 429 currentPosition = fp.tell()
424 430 except:
425 431 if msgFlag:
426 432 print "The file %s can't be opened" % (filename)
427 433 return False
428 434
429 435 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
430 436
431 437 if neededSize == 0:
432 438 basicHeaderObj = BasicHeader()
433 439 systemHeaderObj = SystemHeader()
434 440 radarControllerHeaderObj = RadarControllerHeader()
435 441 processingHeaderObj = ProcessingHeader()
436 442
437 443 try:
438 444 if not( basicHeaderObj.read(fp) ): raise ValueError
439 445 if not( systemHeaderObj.read(fp) ): raise ValueError
440 446 if not( radarControllerHeaderObj.read(fp) ): raise ValueError
441 447 if not( processingHeaderObj.read(fp) ): raise ValueError
442 448 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
443 449
444 450 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
445 451
446 452 except:
447 453 if msgFlag:
448 454 print "\tThe file %s is empty or it hasn't enough data" % filename
449 455
450 456 fp.close()
451 457 return False
452 458 else:
453 459 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
454 460
455 461 fp.close()
456 462 fileSize = os.path.getsize(filename)
457 463 currentSize = fileSize - currentPosition
458 464 if currentSize < neededSize:
459 465 if msgFlag and (msg != None):
460 466 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
461 467 return False
462 468
463 469 return True
464 470
465 471 def getData():
466 472 pass
467 473
468 474 def hasNotDataInBuffer():
469 475 pass
470 476
471 477 def readBlock():
472 478 pass
473 479
474 480 class JRODataWriter(JRODataIO):
475 481
476 482 """
477 483 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
478 484 de los datos siempre se realiza por bloques.
479 485 """
480 486
481 487 blockIndex = 0
482 488
483 489 path = None
484 490
485 491 setFile = None
486 492
487 493 profilesPerBlock = None
488 494
489 495 blocksPerFile = None
490 496
491 497 nWriteBlocks = 0
492 498
493 499 def __init__(self, dataOutObj=None):
494 500 raise ValueError, "Not implemented"
495 501
496 502
497 503 def hasAllDataInBuffer(self):
498 504 raise ValueError, "Not implemented"
499 505
500 506
501 507 def setBlockDimension(self):
502 508 raise ValueError, "Not implemented"
503 509
504 510
505 511 def writeBlock(self):
506 512 raise ValueError, "No implemented"
507 513
508 514
509 515 def putData(self):
510 516 raise ValueError, "No implemented"
511 517
512 518
513 519 def __writeFirstHeader(self):
514 520 """
515 521 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
516 522
517 523 Affected:
518 524 __dataType
519 525
520 526 Return:
521 527 None
522 528 """
523 529
524 530 # CALCULAR PARAMETROS
525 531
526 532 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
527 533 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
528 534
529 535 self.__writeBasicHeader()
530 536 self.__wrSystemHeader()
531 537 self.__wrRadarControllerHeader()
532 538 self.__wrProcessingHeader()
533 539 self.dtype = self.dataOutObj.dtype
534 540
535 541
536 542 def __writeBasicHeader(self, fp=None):
537 543 """
538 544 Escribe solo el Basic header en el file creado
539 545
540 546 Return:
541 547 None
542 548 """
543 549 if fp == None:
544 550 fp = self.fp
545 551
546 552 self.basicHeaderObj.write(fp)
547 553
548 554
549 555 def __wrSystemHeader(self, fp=None):
550 556 """
551 557 Escribe solo el System header en el file creado
552 558
553 559 Return:
554 560 None
555 561 """
556 562 if fp == None:
557 563 fp = self.fp
558 564
559 565 self.systemHeaderObj.write(fp)
560 566
561 567
562 568 def __wrRadarControllerHeader(self, fp=None):
563 569 """
564 570 Escribe solo el RadarController header en el file creado
565 571
566 572 Return:
567 573 None
568 574 """
569 575 if fp == None:
570 576 fp = self.fp
571 577
572 578 self.radarControllerHeaderObj.write(fp)
573 579
574 580
575 581 def __wrProcessingHeader(self, fp=None):
576 582 """
577 583 Escribe solo el Processing header en el file creado
578 584
579 585 Return:
580 586 None
581 587 """
582 588 if fp == None:
583 589 fp = self.fp
584 590
585 591 self.processingHeaderObj.write(fp)
586 592
587 593
588 594 def setNextFile(self):
589 595 """
590 596 Determina el siguiente file que sera escrito
591 597
592 598 Affected:
593 599 self.filename
594 600 self.subfolder
595 601 self.fp
596 602 self.setFile
597 603 self.flagIsNewFile
598 604
599 605 Return:
600 606 0 : Si el archivo no puede ser escrito
601 607 1 : Si el archivo esta listo para ser escrito
602 608 """
603 609 ext = self.ext
604 610 path = self.path
605 611
606 612 if self.fp != None:
607 613 self.fp.close()
608 614
609 615 timeTuple = time.localtime( self.dataOutObj.dataUtcTime)
610 616 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
611 617
612 618 doypath = os.path.join( path, subfolder )
613 619 if not( os.path.exists(doypath) ):
614 620 os.mkdir(doypath)
615 621 self.setFile = -1 #inicializo mi contador de seteo
616 622 else:
617 623 filesList = os.listdir( doypath )
618 624 if len( filesList ) > 0:
619 625 filesList = sorted( filesList, key=str.lower )
620 626 filen = filesList[-1]
621 627 # el filename debera tener el siguiente formato
622 628 # 0 1234 567 89A BCDE (hex)
623 629 # x YYYY DDD SSS .ext
624 630 if isNumber( filen[8:11] ):
625 631 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
626 632 else:
627 633 self.setFile = -1
628 634 else:
629 635 self.setFile = -1 #inicializo mi contador de seteo
630 636
631 637 setFile = self.setFile
632 638 setFile += 1
633 639
634 640 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
635 641 timeTuple.tm_year,
636 642 timeTuple.tm_yday,
637 643 setFile,
638 644 ext )
639 645
640 646 filename = os.path.join( path, subfolder, file )
641 647
642 648 fp = open( filename,'wb' )
643 649
644 650 self.blockIndex = 0
645 651
646 652 #guardando atributos
647 653 self.filename = filename
648 654 self.subfolder = subfolder
649 655 self.fp = fp
650 656 self.setFile = setFile
651 657 self.flagIsNewFile = 1
652 658
653 659 self.getDataHeader()
654 660
655 661 print 'Writing the file: %s'%self.filename
656 662
657 663 self.__writeFirstHeader()
658 664
659 665 return 1
660 666
661 667
662 668 def __setNewBlock(self):
663 669 """
664 670 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
665 671
666 672 Return:
667 673 0 : si no pudo escribir nada
668 674 1 : Si escribio el Basic el First Header
669 675 """
670 676 if self.fp == None:
671 677 self.setNextFile()
672 678
673 679 if self.flagIsNewFile:
674 680 return 1
675 681
676 682 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
677 683 self.__writeBasicHeader()
678 684 return 1
679 685
680 686 if not( self.setNextFile() ):
681 687 return 0
682 688
683 689 return 1
684 690
685 691
686 692 def writeNextBlock(self):
687 693 """
688 694 Selecciona el bloque siguiente de datos y los escribe en un file
689 695
690 696 Return:
691 697 0 : Si no hizo pudo escribir el bloque de datos
692 698 1 : Si no pudo escribir el bloque de datos
693 699 """
694 700 if not( self.__setNewBlock() ):
695 701 return 0
696 702
697 703 self.writeBlock()
698 704
699 705 return 1
700 706
701 707
702 708 def getDataHeader(self):
703 709 """Obtiene una copia del First Header Affected: self.basicHeaderObj self.
704 710 systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self.
705 711 dtype Return: None
706 712 """
707 713
708 714 raise ValueError, "No implemented"
709 715
710 def setup(self, path, profilesPerBlock, blocksPerFile, set=0, ext=None):
716 def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
711 717 """
712 718 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
713 719
714 720 Inputs:
715 721 path : el path destino en el cual se escribiran los files a crear
716 722 format : formato en el cual sera salvado un file
717 723 set : el setebo del file
718 724
719 725 Return:
720 726 0 : Si no realizo un buen seteo
721 727 1 : Si realizo un buen seteo
722 728 """
723 729
724 730 if ext == None:
725 731 ext = self.ext
726 732
727 733 ext = ext.lower()
728 734
729 735 self.ext = ext
730 736
731 737 self.path = path
732 738
733 739 self.setFile = set - 1
734 740
735 self.profilesPerBlock = profilesPerBlock
736
737 741 self.blocksPerFile = blocksPerFile
738 742
743 self.profilesPerBlock = profilesPerBlock
744
739 745 if not(self.setNextFile()):
740 746 print "There isn't a next file"
741 747 return 0
742 748
743 749 self.setBlockDimension()
744 750
745 751 return 1
746 752
747 753
748 754
749 755
750 756
751 757
@@ -1,506 +1,505
1 1 '''
2 Created on 23/01/2012
3 2
4 @author $Author: vsarmiento $
5 @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $
3 $Author$
4 $Id$
6 5 '''
7 6
8 7 import numpy
9 8 import copy
10 9
11 10 class Header:
12 11
13 12 def __init__(self):
14 13 raise
15 14
16 15 def copy(self):
17 16 return copy.deepcopy(self)
18 17
19 18 def read():
20 19 pass
21 20
22 21 def write():
23 22 pass
24 23
25 24 class BasicHeader(Header):
26 25
27 26 size = None
28 27 version = None
29 28 dataBlock = None
30 29 utc = None
31 30 miliSecond = None
32 31 timeZone = None
33 32 dstFlag = None
34 33 errorCount = None
35 34 struct = None
36 35
37 36 def __init__(self):
38 37
39 38 self.size = 0
40 39 self.version = 0
41 40 self.dataBlock = 0
42 41 self.utc = 0
43 42 self.miliSecond = 0
44 43 self.timeZone = 0
45 44 self.dstFlag = 0
46 45 self.errorCount = 0
47 46 self.struct = numpy.dtype([
48 47 ('nSize','<u4'),
49 48 ('nVersion','<u2'),
50 49 ('nDataBlockId','<u4'),
51 50 ('nUtime','<u4'),
52 51 ('nMilsec','<u2'),
53 52 ('nTimezone','<i2'),
54 53 ('nDstflag','<i2'),
55 54 ('nErrorCount','<u4')
56 55 ])
57 56
58 57
59 58 def read(self, fp):
60 59 try:
61 60 header = numpy.fromfile(fp, self.struct,1)
62 61 self.size = header['nSize'][0]
63 62 self.version = header['nVersion'][0]
64 63 self.dataBlock = header['nDataBlockId'][0]
65 64 self.utc = header['nUtime'][0]
66 65 self.miliSecond = header['nMilsec'][0]
67 66 self.timeZone = header['nTimezone'][0]
68 67 self.dstFlag = header['nDstflag'][0]
69 68 self.errorCount = header['nErrorCount'][0]
70 69 except:
71 70 return 0
72 71
73 72 return 1
74 73
75 74 def write(self, fp):
76 75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
77 76 header = numpy.array(headerTuple,self.struct)
78 77 header.tofile(fp)
79 78
80 79 return 1
81 80
82 81 class SystemHeader(Header):
83 82
84 83 size = None
85 84 nSamples = None
86 85 nProfiles = None
87 86 nChannels = None
88 87 adcResolution = None
89 88 pciDioBusWidth = None
90 89 struct = None
91 90
92 91 def __init__(self):
93 92 self.size = 0
94 93 self.nSamples = 0
95 94 self.nProfiles = 0
96 95 self.nChannels = 0
97 96 self.adcResolution = 0
98 97 self.pciDioBusWidth = 0
99 98 self.struct = numpy.dtype([
100 99 ('nSize','<u4'),
101 100 ('nNumSamples','<u4'),
102 101 ('nNumProfiles','<u4'),
103 102 ('nNumChannels','<u4'),
104 103 ('nADCResolution','<u4'),
105 104 ('nPCDIOBusWidth','<u4'),
106 105 ])
107 106
108 107
109 108 def read(self, fp):
110 109 try:
111 110 header = numpy.fromfile(fp,self.struct,1)
112 111 self.size = header['nSize'][0]
113 112 self.nSamples = header['nNumSamples'][0]
114 113 self.nProfiles = header['nNumProfiles'][0]
115 114 self.nChannels = header['nNumChannels'][0]
116 115 self.adcResolution = header['nADCResolution'][0]
117 116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
118 117 except:
119 118 return 0
120 119
121 120 return 1
122 121
123 122 def write(self, fp):
124 123 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
125 124 header = numpy.array(headerTuple,self.struct)
126 125 header.tofile(fp)
127 126
128 127 return 1
129 128
130 129 class RadarControllerHeader(Header):
131 130
132 131 size = None
133 132 expType = None
134 133 nTx = None
135 134 ipp = None
136 135 txA = None
137 136 txB = None
138 137 nWindows = None
139 138 numTaus = None
140 139 codeType = None
141 140 line6Function = None
142 141 line5Function = None
143 142 fClock = None
144 143 prePulseBefore = None
145 144 prePulserAfter = None
146 145 rangeIpp = None
147 146 rangeTxA = None
148 147 rangeTxB = None
149 148 struct = None
150 149
151 150 def __init__(self):
152 151 self.size = 0
153 152 self.expType = 0
154 153 self.nTx = 0
155 154 self.ipp = 0
156 155 self.txA = 0
157 156 self.txB = 0
158 157 self.nWindows = 0
159 158 self.numTaus = 0
160 159 self.codeType = 0
161 160 self.line6Function = 0
162 161 self.line5Function = 0
163 162 self.fClock = 0
164 163 self.prePulseBefore = 0
165 164 self.prePulserAfter = 0
166 165 self.rangeIpp = 0
167 166 self.rangeTxA = 0
168 167 self.rangeTxB = 0
169 168 self.struct = numpy.dtype([
170 169 ('nSize','<u4'),
171 170 ('nExpType','<u4'),
172 171 ('nNTx','<u4'),
173 172 ('fIpp','<f4'),
174 173 ('fTxA','<f4'),
175 174 ('fTxB','<f4'),
176 175 ('nNumWindows','<u4'),
177 176 ('nNumTaus','<u4'),
178 177 ('nCodeType','<u4'),
179 178 ('nLine6Function','<u4'),
180 179 ('nLine5Function','<u4'),
181 180 ('fClock','<f4'),
182 181 ('nPrePulseBefore','<u4'),
183 182 ('nPrePulseAfter','<u4'),
184 183 ('sRangeIPP','<a20'),
185 184 ('sRangeTxA','<a20'),
186 185 ('sRangeTxB','<a20'),
187 186 ])
188 187
189 188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
190 189
191 190 self.samplingWindow = None
192 191 self.nHeights = None
193 192 self.firstHeight = None
194 193 self.deltaHeight = None
195 194 self.samplesWin = None
196 195
197 196 self.nCode = None
198 197 self.nBaud = None
199 198 self.code = None
200 199 self.flip1 = None
201 200 self.flip2 = None
202 201
203 202 self.dynamic = numpy.array([],numpy.dtype('byte'))
204 203
205 204
206 205 def read(self, fp):
207 206 try:
208 207 startFp = fp.tell()
209 208 header = numpy.fromfile(fp,self.struct,1)
210 209 self.size = header['nSize'][0]
211 210 self.expType = header['nExpType'][0]
212 211 self.nTx = header['nNTx'][0]
213 212 self.ipp = header['fIpp'][0]
214 213 self.txA = header['fTxA'][0]
215 214 self.txB = header['fTxB'][0]
216 215 self.nWindows = header['nNumWindows'][0]
217 216 self.numTaus = header['nNumTaus'][0]
218 217 self.codeType = header['nCodeType'][0]
219 218 self.line6Function = header['nLine6Function'][0]
220 219 self.line5Function = header['nLine5Function'][0]
221 220 self.fClock = header['fClock'][0]
222 221 self.prePulseBefore = header['nPrePulseBefore'][0]
223 222 self.prePulserAfter = header['nPrePulseAfter'][0]
224 223 self.rangeIpp = header['sRangeIPP'][0]
225 224 self.rangeTxA = header['sRangeTxA'][0]
226 225 self.rangeTxB = header['sRangeTxB'][0]
227 226 # jump Dynamic Radar Controller Header
228 227 jumpFp = self.size - 116
229 228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
230 229 #pointer backward to dynamic header and read
231 230 backFp = fp.tell() - jumpFp
232 231 fp.seek(backFp)
233 232
234 233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
235 234 self.nHeights = numpy.sum(self.samplingWindow['nsa'])
236 235 self.firstHeight = self.samplingWindow['h0']
237 236 self.deltaHeight = self.samplingWindow['dh']
238 237 self.samplesWin = self.samplingWindow['nsa']
239 238
240 239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
241 240
242 241 if self.codeType != 0:
243 242 self.nCode = numpy.fromfile(fp,'<u4',1)
244 243 self.nBaud = numpy.fromfile(fp,'<u4',1)
245 244 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
246 245 tempList = []
247 246 for ic in range(self.nCode):
248 247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.))
249 248 tempList.append(temp)
250 249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
251 250 self.code = 2.0*self.code - 1.0
252 251
253 252 if self.line5Function == RCfunction.FLIP:
254 253 self.flip1 = numpy.fromfile(fp,'<u4',1)
255 254
256 255 if self.line6Function == RCfunction.FLIP:
257 256 self.flip2 = numpy.fromfile(fp,'<u4',1)
258 257
259 258 endFp = self.size + startFp
260 259 jumpFp = endFp - fp.tell()
261 260 if jumpFp > 0:
262 261 fp.seek(jumpFp)
263 262
264 263 except:
265 264 return 0
266 265
267 266 return 1
268 267
269 268 def write(self, fp):
270 269 headerTuple = (self.size,
271 270 self.expType,
272 271 self.nTx,
273 272 self.ipp,
274 273 self.txA,
275 274 self.txB,
276 275 self.nWindows,
277 276 self.numTaus,
278 277 self.codeType,
279 278 self.line6Function,
280 279 self.line5Function,
281 280 self.fClock,
282 281 self.prePulseBefore,
283 282 self.prePulserAfter,
284 283 self.rangeIpp,
285 284 self.rangeTxA,
286 285 self.rangeTxB)
287 286
288 287 header = numpy.array(headerTuple,self.struct)
289 288 header.tofile(fp)
290 289
291 290 dynamic = self.dynamic
292 291 dynamic.tofile(fp)
293 292
294 293 return 1
295 294
296 295
297 296
298 297 class ProcessingHeader(Header):
299 298
300 299 size = None
301 300 dtype = None
302 301 blockSize = None
303 302 profilesPerBlock = None
304 303 dataBlocksPerFile = None
305 304 nWindows = None
306 305 processFlags = None
307 306 nCohInt = None
308 307 nIncohInt = None
309 308 totalSpectra = None
310 309 struct = None
311 310 flag_dc = None
312 311 flag_cspc = None
313 312
314 313 def __init__(self):
315 314 self.size = 0
316 315 self.dataType = 0
317 316 self.blockSize = 0
318 317 self.profilesPerBlock = 0
319 318 self.dataBlocksPerFile = 0
320 319 self.nWindows = 0
321 320 self.processFlags = 0
322 321 self.nCohInt = 0
323 322 self.nIncohInt = 0
324 323 self.totalSpectra = 0
325 324 self.struct = numpy.dtype([
326 325 ('nSize','<u4'),
327 326 ('nDataType','<u4'),
328 327 ('nSizeOfDataBlock','<u4'),
329 328 ('nProfilesperBlock','<u4'),
330 329 ('nDataBlocksperFile','<u4'),
331 330 ('nNumWindows','<u4'),
332 331 ('nProcessFlags','<u4'),
333 332 ('nCoherentIntegrations','<u4'),
334 333 ('nIncoherentIntegrations','<u4'),
335 334 ('nTotalSpectra','<u4')
336 335 ])
337 336 self.samplingWindow = 0
338 337 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
339 338 self.nHeights = 0
340 339 self.firstHeight = 0
341 340 self.deltaHeight = 0
342 341 self.samplesWin = 0
343 342 self.spectraComb = 0
344 343 self.nCode = None
345 344 self.code = None
346 345 self.nBaud = None
347 346 self.shif_fft = False
348 347 self.flag_dc = False
349 348 self.flag_cspc = False
350 349
351 350 def read(self, fp):
352 351 try:
353 352 header = numpy.fromfile(fp,self.struct,1)
354 353 self.size = header['nSize'][0]
355 354 self.dataType = header['nDataType'][0]
356 355 self.blockSize = header['nSizeOfDataBlock'][0]
357 356 self.profilesPerBlock = header['nProfilesperBlock'][0]
358 357 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
359 358 self.nWindows = header['nNumWindows'][0]
360 359 self.processFlags = header['nProcessFlags']
361 360 self.nCohInt = header['nCoherentIntegrations'][0]
362 361 self.nIncohInt = header['nIncoherentIntegrations'][0]
363 362 self.totalSpectra = header['nTotalSpectra'][0]
364 363 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
365 364 self.nHeights = numpy.sum(self.samplingWindow['nsa'])
366 365 self.firstHeight = self.samplingWindow['h0'][0]
367 366 self.deltaHeight = self.samplingWindow['dh'][0]
368 367 self.samplesWin = self.samplingWindow['nsa']
369 368 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
370 369
371 370 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
372 371 self.nCode = numpy.fromfile(fp,'<u4',1)
373 372 self.nBaud = numpy.fromfile(fp,'<u4',1)
374 373 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
375 374
376 375 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
377 376 self.shif_fft = True
378 377 else:
379 378 self.shif_fft = False
380 379
381 380 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
382 381 self.flag_dc = True
383 382
384 383 nChannels = 0
385 384 nPairs = 0
386 385 pairList = []
387 386
388 387 for i in range( 0, self.totalSpectra*2, 2 ):
389 388 if self.spectraComb[i] == self.spectraComb[i+1]:
390 389 nChannels = nChannels + 1 #par de canales iguales
391 390 else:
392 391 nPairs = nPairs + 1 #par de canales diferentes
393 392 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
394 393
395 394 self.flag_cspc = False
396 395 if nPairs > 0:
397 396 self.flag_cspc = True
398 397
399 398 except:
400 399 return 0
401 400
402 401 return 1
403 402
404 403 def write(self, fp):
405 404 headerTuple = (self.size,
406 405 self.dataType,
407 406 self.blockSize,
408 407 self.profilesPerBlock,
409 408 self.dataBlocksPerFile,
410 409 self.nWindows,
411 410 self.processFlags,
412 411 self.nCohInt,
413 412 self.nIncohInt,
414 413 self.totalSpectra)
415 414
416 415 header = numpy.array(headerTuple,self.struct)
417 416 header.tofile(fp)
418 417
419 418 if self.nWindows != 0:
420 419 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
421 420 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
422 421 samplingWindow.tofile(fp)
423 422
424 423
425 424 if self.totalSpectra != 0:
426 425 spectraComb = numpy.array([],numpy.dtype('u1'))
427 426 spectraComb = self.spectraComb
428 427 spectraComb.tofile(fp)
429 428
430 429
431 430 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
432 431 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
433 432 nCode.tofile(fp)
434 433
435 434 nBaud = self.nBaud
436 435 nBaud.tofile(fp)
437 436
438 437 code = self.code.reshape(nCode*nBaud)
439 438 code.tofile(fp)
440 439
441 440 return 1
442 441
443 442 class RCfunction:
444 443 NONE=0
445 444 FLIP=1
446 445 CODE=2
447 446 SAMPLING=3
448 447 LIN6DIV256=4
449 448 SYNCHRO=5
450 449
451 450 class nCodeType:
452 451 NONE=0
453 452 USERDEFINE=1
454 453 BARKER2=2
455 454 BARKER3=3
456 455 BARKER4=4
457 456 BARKER5=5
458 457 BARKER7=6
459 458 BARKER11=7
460 459 BARKER13=8
461 460 AC128=9
462 461 COMPLEMENTARYCODE2=10
463 462 COMPLEMENTARYCODE4=11
464 463 COMPLEMENTARYCODE8=12
465 464 COMPLEMENTARYCODE16=13
466 465 COMPLEMENTARYCODE32=14
467 466 COMPLEMENTARYCODE64=15
468 467 COMPLEMENTARYCODE128=16
469 468 CODE_BINARY28=17
470 469
471 470 class PROCFLAG:
472 471 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
473 472 DECODE_DATA = numpy.uint32(0x00000002)
474 473 SPECTRA_CALC = numpy.uint32(0x00000004)
475 474 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
476 475 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
477 476 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
478 477
479 478 DATATYPE_CHAR = numpy.uint32(0x00000040)
480 479 DATATYPE_SHORT = numpy.uint32(0x00000080)
481 480 DATATYPE_LONG = numpy.uint32(0x00000100)
482 481 DATATYPE_INT64 = numpy.uint32(0x00000200)
483 482 DATATYPE_FLOAT = numpy.uint32(0x00000400)
484 483 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
485 484
486 485 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
487 486 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
488 487 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
489 488
490 489 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
491 490 DEFLIP_DATA = numpy.uint32(0x00010000)
492 491 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
493 492
494 493 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
495 494 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
496 495 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
497 496 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
498 497 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
499 498
500 499 EXP_NAME_ESP = numpy.uint32(0x00200000)
501 500 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
502 501
503 502 OPERATION_MASK = numpy.uint32(0x0000003F)
504 503 DATATYPE_MASK = numpy.uint32(0x00000FC0)
505 504 DATAARRANGE_MASK = numpy.uint32(0x00007000)
506 505 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
@@ -1,775 +1,775
1 1 '''
2 File: SpectraIO.py
3 Created on 20/02/2012
4 2
5 @author $Author: dsuarez $
6 @version $Id: SpectraIO.py 110 2012-07-19 15:18:18Z dsuarez $
3 $Author$
4 $Id$
7 5 '''
8 6
9 7 import os, sys
10 8 import numpy
11 9 import glob
12 10 import fnmatch
13 11 import time, datetime
14 12
15 13 path = os.path.split(os.getcwd())[0]
16 14 sys.path.append(path)
17 15
18 16 from IO.JROHeader import *
19 17 from Data.Spectra import Spectra
20 18
21 19 from JRODataIO import JRODataReader
22 20 from JRODataIO import JRODataWriter
23 21 from JRODataIO import isNumber
24 22
25 23
26 24 class SpectraReader(JRODataReader):
27 25 """
28 26 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
29 27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
30 28 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
31 29
32 30 paresCanalesIguales * alturas * perfiles (Self Spectra)
33 31 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
34 32 canales * alturas (DC Channels)
35 33
36 34 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
37 35 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
38 36 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
39 37 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
40 38
41 39 Example:
42 40 dpath = "/home/myuser/data"
43 41
44 42 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
45 43
46 44 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
47 45
48 46 readerObj = SpectraReader()
49 47
50 48 readerObj.setup(dpath, startTime, endTime)
51 49
52 50 while(True):
53 51
54 52 readerObj.getData()
55 53
56 54 print readerObj.dataOutObj.data
57 55
58 56 if readerObj.flagNoMoreFiles:
59 57 break
60 58
61 59 """
62 60
63 61 pts2read_SelfSpectra = 0
64 62
65 63 pts2read_CrossSpectra = 0
66 64
67 65 pts2read_DCchannels = 0
68 66
69 67 ext = ".pdata"
70 68
71 69 optchar = "P"
72 70
73 71 dataOutObj = None
74 72
75 73 nRdChannels = None
76 74
77 75 nRdPairs = None
78 76
79 77 rdPairList = []
80 78
81 79
82 80 def __init__(self, dataOutObj=None):
83 81 """
84 82 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
85 83
86 84 Inputs:
87 85 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
88 86 almacenar un perfil de datos cada vez que se haga un requerimiento
89 87 (getData). El perfil sera obtenido a partir del buffer de datos,
90 88 si el buffer esta vacio se hara un nuevo proceso de lectura de un
91 89 bloque de datos.
92 90 Si este parametro no es pasado se creara uno internamente.
93 91
94 92 Affected:
95 93 self.dataOutObj
96 94
97 95 Return : None
98 96 """
99 97
100 98 self.pts2read_SelfSpectra = 0
101 99
102 100 self.pts2read_CrossSpectra = 0
103 101
104 102 self.pts2read_DCchannels = 0
105 103
106 104 self.datablock = None
107 105
108 106 self.utc = None
109 107
110 108 self.ext = ".pdata"
111 109
112 110 self.optchar = "P"
113 111
114 112 self.basicHeaderObj = BasicHeader()
115 113
116 114 self.systemHeaderObj = SystemHeader()
117 115
118 116 self.radarControllerHeaderObj = RadarControllerHeader()
119 117
120 118 self.processingHeaderObj = ProcessingHeader()
121 119
122 120 self.online = 0
123 121
124 122 self.fp = None
125 123
126 124 self.idFile = None
127 125
128 126 self.dtype = None
129 127
130 128 self.fileSizeByHeader = None
131 129
132 130 self.filenameList = []
133 131
134 132 self.filename = None
135 133
136 134 self.fileSize = None
137 135
138 136 self.firstHeaderSize = 0
139 137
140 138 self.basicHeaderSize = 24
141 139
142 140 self.pathList = []
143 141
144 142 self.lastUTTime = 0
145 143
146 144 self.maxTimeStep = 30
147 145
148 146 self.flagNoMoreFiles = 0
149 147
150 148 self.set = 0
151 149
152 150 self.path = None
153 151
154 152 self.delay = 3 #seconds
155 153
156 154 self.nTries = 3 #quantity tries
157 155
158 156 self.nFiles = 3 #number of files for searching
159 157
160 158 self.nReadBlocks = 0
161 159
162 160 self.flagIsNewFile = 1
163 161
164 162 self.ippSeconds = 0
165 163
166 164 self.flagTimeBlock = 0
167 165
168 166 self.flagIsNewBlock = 0
169 167
170 168 self.nTotalBlocks = 0
171 169
172 170 self.blocksize = 0
173 171
174 172
175 173 def createObjByDefault(self):
176 174
177 175 dataObj = Spectra()
178 176
179 177 return dataObj
180 178
181 179 def __hasNotDataInBuffer(self):
182 180 return 1
183 181
184 182
185 183 def getBlockDimension(self):
186 184 """
187 185 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 186
189 187 Affected:
190 188 self.nRdChannels
191 189 self.nRdPairs
192 190 self.pts2read_SelfSpectra
193 191 self.pts2read_CrossSpectra
194 192 self.pts2read_DCchannels
195 193 self.blocksize
196 194 self.dataOutObj.nChannels
197 195 self.dataOutObj.nPairs
198 196
199 197 Return:
200 198 None
201 199 """
202 200 self.nRdChannels = 0
203 201 self.nRdPairs = 0
204 202 self.rdPairList = []
205 203
206 204 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 205 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 206 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 207 else:
210 208 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 209 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 210
213 211 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 212
215 213 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 214 self.blocksize = self.pts2read_SelfSpectra
217 215
218 216 if self.processingHeaderObj.flag_cspc:
219 217 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 218 self.blocksize += self.pts2read_CrossSpectra
221 219
222 220 if self.processingHeaderObj.flag_dc:
223 221 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 222 self.blocksize += self.pts2read_DCchannels
225 223
226 224 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 225
228 226
229 227 def readBlock(self):
230 228 """
231 229 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 230 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 231 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 232 es seteado a 0
235 233
236 234 Return: None
237 235
238 236 Variables afectadas:
239 237
240 238 self.flagIsNewFile
241 239 self.flagIsNewBlock
242 240 self.nTotalBlocks
243 241 self.data_spc
244 242 self.data_cspc
245 243 self.data_dc
246 244
247 245 Exceptions:
248 246 Si un bloque leido no es un bloque valido
249 247 """
250 248 blockOk_flag = False
251 249 fpointer = self.fp.tell()
252 250
253 251 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 252 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 253
256 254 if self.processingHeaderObj.flag_cspc:
257 255 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 256 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 257
260 258 if self.processingHeaderObj.flag_dc:
261 259 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 260 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 261
264 262
265 263 if not(self.processingHeaderObj.shif_fft):
266 264 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
267 265
268 266 if self.processingHeaderObj.flag_cspc:
269 267 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
270 268
271 269
272 270 spc = numpy.transpose( spc, (0,2,1) )
273 271 self.data_spc = spc
274 272
275 273 if self.processingHeaderObj.flag_cspc:
276 274 cspc = numpy.transpose( cspc, (0,2,1) )
277 275 self.data_cspc = cspc['real'] + cspc['imag']*1j
278 276 else:
279 277 self.data_cspc = None
280 278
281 279 if self.processingHeaderObj.flag_dc:
282 280 self.data_dc = dc['real'] + dc['imag']*1j
283 281 else:
284 282 self.data_dc = None
285 283
286 284 self.flagIsNewFile = 0
287 285 self.flagIsNewBlock = 1
288 286
289 287 self.nTotalBlocks += 1
290 288 self.nReadBlocks += 1
291 289
292 290 return 1
293 291
294 292
295 293 def getData(self):
296 294 """
297 295 Copia el buffer de lectura a la clase "Spectra",
298 296 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
299 297 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
300 298
301 299 Return:
302 300 0 : Si no hay mas archivos disponibles
303 301 1 : Si hizo una buena copia del buffer
304 302
305 303 Affected:
306 304 self.dataOutObj
307 305
308 306 self.flagTimeBlock
309 307 self.flagIsNewBlock
310 308 """
311 309
312 310 if self.flagNoMoreFiles: return 0
313 311
314 312 self.flagTimeBlock = 0
315 313 self.flagIsNewBlock = 0
316 314
317 315 if self.__hasNotDataInBuffer():
318 316
319 317 if not( self.readNextBlock() ):
320 318 return 0
321 319
322 320 # self.updateDataHeader()
323 321
324 322 if self.flagNoMoreFiles == 1:
325 323 print 'Process finished'
326 324 return 0
327 325
328 326 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
329 327
330 328 if self.data_dc == None:
331 329 self.dataOutObj.flagNoData = True
332 330 return 0
333 331
334 332
335 333 self.dataOutObj.data_spc = self.data_spc
336 334
337 335 self.dataOutObj.data_cspc = self.data_cspc
338 336
339 337 self.dataOutObj.data_dc = self.data_dc
340 338
341 339 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
342 340
343 341 self.dataOutObj.flagNoData = False
344 342
345 343 self.dataOutObj.dtype = self.dtype
346 344
347 345 self.dataOutObj.nChannels = self.nRdChannels
348 346
349 347 self.dataOutObj.nPairs = self.nRdPairs
350 348
351 349 self.dataOutObj.pairsList = self.rdPairList
352 350
353 351 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
354 352
355 353 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
356 354
357 355 self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock
358 356
359 357 self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt
360 358
361 359
362 360 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
363 361
364 362 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
365 363
366 364 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
367 365
368 366 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
369 367
370 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc #+ self.profileIndex * self.ippSeconds
368 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
371 369
372 370 self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft
373 371
374 372 # self.profileIndex += 1
375 373
376 374 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
377 375
378 376 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
379 377
380 378 return 1
381 379
382 380
383 381 class SpectraWriter(JRODataWriter):
384 382
385 383 """
386 384 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
387 385 de los datos siempre se realiza por bloques.
388 386 """
389 387
390 388 ext = ".pdata"
391 389
392 390 optchar = "P"
393 391
394 392 shape_spc_Buffer = None
395 393
396 394 shape_cspc_Buffer = None
397 395
398 396 shape_dc_Buffer = None
399 397
400 398 data_spc = None
401 399
402 400 data_cspc = None
403 401
404 402 data_dc = None
405 403
406 404 wrPairList = []
407 405
408 406 nWrPairs = 0
409 407
410 408 nWrChannels = 0
411 409
412 410 # dataOutObj = None
413 411
414 412 def __init__(self, dataOutObj=None):
415 413 """
416 414 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
417 415
418 416 Affected:
419 417 self.dataOutObj
420 418 self.basicHeaderObj
421 419 self.systemHeaderObj
422 420 self.radarControllerHeaderObj
423 421 self.processingHeaderObj
424 422
425 423 Return: None
426 424 """
427 425 if dataOutObj == None:
428 426 dataOutObj = Spectra()
429 427
430 428 if not( isinstance(dataOutObj, Spectra) ):
431 429 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
432 430
433 431 self.dataOutObj = dataOutObj
434 432
435 433 self.nTotalBlocks = 0
436 434
437 435 self.nWrChannels = self.dataOutObj.nChannels
438 436
439 437 # if len(pairList) > 0:
440 438 # self.wrPairList = pairList
441 439 #
442 440 # self.nWrPairs = len(pairList)
443 441
444 442 self.wrPairList = self.dataOutObj.pairsList
445 443
446 444 self.nWrPairs = self.dataOutObj.nPairs
447 445
448 446
449 447
450 448
451 449
452 450 # self.data_spc = None
453 451 # self.data_cspc = None
454 452 # self.data_dc = None
455 453
456 454 # self.fp = None
457 455
458 456 # self.flagIsNewFile = 1
459 457 #
460 458 # self.nTotalBlocks = 0
461 459 #
462 460 # self.flagIsNewBlock = 0
463 461 #
464 462 # self.flagNoMoreFiles = 0
465 463 #
466 464 # self.setFile = None
467 465 #
468 466 # self.dtype = None
469 467 #
470 468 # self.path = None
471 469 #
472 470 # self.noMoreFiles = 0
473 471 #
474 472 # self.filename = None
475 473 #
476 474 # self.basicHeaderObj = BasicHeader()
477 475 #
478 476 # self.systemHeaderObj = SystemHeader()
479 477 #
480 478 # self.radarControllerHeaderObj = RadarControllerHeader()
481 479 #
482 480 # self.processingHeaderObj = ProcessingHeader()
483 481
484 482
485 483 def hasAllDataInBuffer(self):
486 484 return 1
487 485
488 486
489 487 def setBlockDimension(self):
490 488 """
491 489 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
492 490
493 491 Affected:
494 492 self.shape_spc_Buffer
495 493 self.shape_cspc_Buffer
496 494 self.shape_dc_Buffer
497 495
498 496 Return: None
499 497 """
500 498 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
501 499 self.processingHeaderObj.nHeights,
502 500 self.processingHeaderObj.profilesPerBlock)
503 501
504 502 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
505 503 self.processingHeaderObj.nHeights,
506 504 self.processingHeaderObj.profilesPerBlock)
507 505
508 506 self.shape_dc_Buffer = (self.dataOutObj.nChannels,
509 507 self.processingHeaderObj.nHeights)
510 508
511 509
512 510 def writeBlock(self):
513 511 """
514 512 Escribe el buffer en el file designado
515 513
516 514 Affected:
517 515 self.data_spc
518 516 self.data_cspc
519 517 self.data_dc
520 518 self.flagIsNewFile
521 519 self.flagIsNewBlock
522 520 self.nTotalBlocks
523 521 self.nWriteBlocks
524 522
525 523 Return: None
526 524 """
527 525
528 526 spc = numpy.transpose( self.data_spc, (0,2,1) )
529 527 if not( self.processingHeaderObj.shif_fft ):
530 528 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
531 529 data = spc.reshape((-1))
532 530 data.tofile(self.fp)
533 531
534 532 if self.data_cspc != None:
535 533 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
536 534 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
537 535 if not( self.processingHeaderObj.shif_fft ):
538 536 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
539 537 data['real'] = cspc.real
540 538 data['imag'] = cspc.imag
541 539 data = data.reshape((-1))
542 540 data.tofile(self.fp)
543 541
542 if self.data_dc != None:
544 543 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
545 544 dc = self.data_dc
546 545 data['real'] = dc.real
547 546 data['imag'] = dc.imag
548 547 data = data.reshape((-1))
549 548 data.tofile(self.fp)
550 549
551 550 self.data_spc.fill(0)
552 551 self.data_dc.fill(0)
553 552 if self.data_cspc != None:
554 553 self.data_cspc.fill(0)
555 554
556 555 self.flagIsNewFile = 0
557 556 self.flagIsNewBlock = 1
558 557 self.nTotalBlocks += 1
559 558 self.nWriteBlocks += 1
559 self.blockIndex += 1
560 560
561 561
562 562 def putData(self):
563 563 """
564 564 Setea un bloque de datos y luego los escribe en un file
565 565
566 566 Affected:
567 567 self.data_spc
568 568 self.data_cspc
569 569 self.data_dc
570 570
571 571 Return:
572 572 0 : Si no hay data o no hay mas files que puedan escribirse
573 573 1 : Si se escribio la data de un bloque en un file
574 574 """
575 575 self.flagIsNewBlock = 0
576 576
577 577 if self.dataOutObj.flagNoData:
578 578 return 0
579 579
580 580 if self.dataOutObj.flagTimeBlock:
581 581 self.data_spc.fill(0)
582 582 self.data_cspc.fill(0)
583 583 self.data_dc.fill(0)
584 584 self.setNextFile()
585 585
586 586 if self.flagIsNewFile == 0:
587 587 self.getBasicHeader()
588 588
589 589 self.data_spc = self.dataOutObj.data_spc
590 590 self.data_cspc = self.dataOutObj.data_cspc
591 591 self.data_dc = self.dataOutObj.data_dc
592 592
593 593 # #self.processingHeaderObj.dataBlocksPerFile)
594 594 if self.hasAllDataInBuffer():
595 595 # self.getDataHeader()
596 596 self.writeNextBlock()
597 597
598 598 if self.flagNoMoreFiles:
599 599 #print 'Process finished'
600 600 return 0
601 601
602 602 return 1
603 603
604 604
605 605 def __getProcessFlags(self):
606 606
607 607 processFlags = 0
608 608
609 609 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
610 610 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
611 611 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
612 612 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
613 613 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
614 614 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
615 615
616 616 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
617 617
618 618
619 619
620 620 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
621 621 PROCFLAG.DATATYPE_SHORT,
622 622 PROCFLAG.DATATYPE_LONG,
623 623 PROCFLAG.DATATYPE_INT64,
624 624 PROCFLAG.DATATYPE_FLOAT,
625 625 PROCFLAG.DATATYPE_DOUBLE]
626 626
627 627
628 628 for index in range(len(dtypeList)):
629 629 if self.dataOutObj.dtype == dtypeList[index]:
630 630 dtypeValue = datatypeValueList[index]
631 631 break
632 632
633 633 processFlags += dtypeValue
634 634
635 635 if self.dataOutObj.flagDecodeData:
636 636 processFlags += PROCFLAG.DECODE_DATA
637 637
638 638 if self.dataOutObj.flagDeflipData:
639 639 processFlags += PROCFLAG.DEFLIP_DATA
640 640
641 641 if self.dataOutObj.code != None:
642 642 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
643 643
644 644 if self.dataOutObj.nIncohInt > 1:
645 645 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
646 646
647 647 if self.dataOutObj.data_dc != None:
648 648 processFlags += PROCFLAG.SAVE_CHANNELS_DC
649 649
650 650 return processFlags
651 651
652 652
653 653 def __getBlockSize(self):
654 654 '''
655 655 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
656 656 '''
657 657
658 658 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
659 659 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
660 660 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
661 661 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
662 662 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
663 663 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
664 664
665 665 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
666 666 datatypeValueList = [1,2,4,8,4,8]
667 667 for index in range(len(dtypeList)):
668 668 if self.dataOutObj.dtype == dtypeList[index]:
669 669 datatypeValue = datatypeValueList[index]
670 670 break
671 671
672 672
673 673 pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints
674 674
675 675 pts2write_SelfSpectra = int(self.nWrChannels * pts2write)
676 blocksize = pts2write_SelfSpectra
676 blocksize = (pts2write_SelfSpectra*datatypeValue)
677 677
678 678 if self.dataOutObj.data_cspc != None:
679 679 pts2write_CrossSpectra = int(self.nWrPairs * pts2write)
680 blocksize += pts2write_CrossSpectra
680 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
681 681
682 682 if self.dataOutObj.data_dc != None:
683 683 pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights)
684 blocksize += pts2write_DCchannels
684 blocksize += (pts2write_DCchannels*datatypeValue*2)
685 685
686 blocksize = blocksize * datatypeValue * 2
686 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
687 687
688 688 return blocksize
689 689
690 690
691 691 def getBasicHeader(self):
692 692 self.basicHeaderObj.size = self.basicHeaderSize #bytes
693 693 self.basicHeaderObj.version = self.versionFile
694 694 self.basicHeaderObj.dataBlock = self.nTotalBlocks
695 695
696 696 utc = numpy.floor(self.dataOutObj.dataUtcTime)
697 697 milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0
698 698
699 699 self.basicHeaderObj.utc = utc
700 700 self.basicHeaderObj.miliSecond = milisecond
701 701 self.basicHeaderObj.timeZone = 0
702 702 self.basicHeaderObj.dstFlag = 0
703 703 self.basicHeaderObj.errorCount = 0
704 704
705 705 def getDataHeader(self):
706 706
707 707 """
708 708 Obtiene una copia del First Header
709 709
710 710 Affected:
711 711 self.systemHeaderObj
712 712 self.radarControllerHeaderObj
713 713 self.dtype
714 714
715 715 Return:
716 716 None
717 717 """
718 718
719 719 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
720 720 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
721 721 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
722 722
723 723 self.getBasicHeader()
724 724
725 725 processingHeaderSize = 40 # bytes
726 726 self.processingHeaderObj.dtype = 0 # Voltage
727 727 self.processingHeaderObj.blockSize = self.__getBlockSize()
728 728 self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints
729 729 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
730 730 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
731 731 self.processingHeaderObj.processFlags = self.__getProcessFlags()
732 732 self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra
733 733 self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt
734 734 self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels
735 735
736 736 if self.processingHeaderObj.totalSpectra > 0:
737 737 channelList = []
738 738 for channel in range(self.dataOutObj.nChannels):
739 739 channelList.append(channel)
740 740 channelList.append(channel)
741 741
742 742 pairsList = []
743 743 for pair in self.dataOutObj.pairsList:
744 744 pairsList.append(pair[0])
745 745 pairsList.append(pair[1])
746 746 spectraComb = channelList + pairsList
747 747 spectraComb = numpy.array(spectraComb,dtype="u1")
748 748 self.processingHeaderObj.spectraComb = spectraComb
749 749 sizeOfSpcComb = len(spectraComb)
750 750 processingHeaderSize += sizeOfSpcComb
751 751
752 752 if self.dataOutObj.code != None:
753 753 self.processingHeaderObj.code = self.dataOutObj.code
754 754 self.processingHeaderObj.nCode = self.dataOutObj.nCode
755 755 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
756 756 nCodeSize = 4 # bytes
757 757 nBaudSize = 4 # bytes
758 758 codeSize = 4 # bytes
759 759 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud)
760 760 processingHeaderSize += sizeOfCode
761 761
762 762 if self.processingHeaderObj.nWindows != 0:
763 763 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
764 764 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
765 765 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
766 766 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
767 767 sizeOfFirstHeight = 4
768 768 sizeOfdeltaHeight = 4
769 769 sizeOfnHeights = 4
770 770 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
771 771 processingHeaderSize += sizeOfWindows
772 772
773 773 self.processingHeaderObj.size = processingHeaderSize
774 774
775 775 No newline at end of file
@@ -1,585 +1,584
1 1 '''
2 Created on 23/01/2012
3 2
4 @author $Author: dsuarez $
5 @version $Id: VoltageIO.py 110 2012-07-19 15:18:18Z dsuarez $
3 $Author$
4 $Id$
6 5 '''
7 6
8 7 import os, sys
9 8 import numpy
10 9 import glob
11 10 import fnmatch
12 11 import time, datetime
13 12
14 13 path = os.path.split(os.getcwd())[0]
15 14 sys.path.append(path)
16 15
17 16 from JROHeader import *
18 17 from JRODataIO import JRODataReader
19 18 from JRODataIO import JRODataWriter
20 19
21 20 from Data.Voltage import Voltage
22 21
23 22 class VoltageReader(JRODataReader):
24 23 """
25 24 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
26 25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
27 26 perfiles*alturas*canales) son almacenados en la variable "buffer".
28 27
29 28 perfiles * alturas * canales
30 29
31 30 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
32 31 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
33 32 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
34 33 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
35 34
36 35 Example:
37 36
38 37 dpath = "/home/myuser/data"
39 38
40 39 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
41 40
42 41 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
43 42
44 43 readerObj = VoltageReader()
45 44
46 45 readerObj.setup(dpath, startTime, endTime)
47 46
48 47 while(True):
49 48
50 49 #to get one profile
51 50 profile = readerObj.getData()
52 51
53 52 #print the profile
54 53 print profile
55 54
56 55 #If you want to see all datablock
57 56 print readerObj.datablock
58 57
59 58 if readerObj.flagNoMoreFiles:
60 59 break
61 60
62 61 """
63 62
64 63 ext = ".r"
65 64
66 65 optchar = "D"
67 66 dataOutObj = None
68 67
69 68
70 69 def __init__(self, dataOutObj=None):
71 70 """
72 71 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
73 72
74 73 Input:
75 74 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
76 75 almacenar un perfil de datos cada vez que se haga un requerimiento
77 76 (getData). El perfil sera obtenido a partir del buffer de datos,
78 77 si el buffer esta vacio se hara un nuevo proceso de lectura de un
79 78 bloque de datos.
80 79 Si este parametro no es pasado se creara uno internamente.
81 80
82 81 Variables afectadas:
83 82 self.dataOutObj
84 83
85 84 Return:
86 85 None
87 86 """
88 87
89 88 self.datablock = None
90 89
91 90 self.utc = 0
92 91
93 92 self.ext = ".r"
94 93
95 94 self.optchar = "D"
96 95
97 96 self.basicHeaderObj = BasicHeader()
98 97
99 98 self.systemHeaderObj = SystemHeader()
100 99
101 100 self.radarControllerHeaderObj = RadarControllerHeader()
102 101
103 102 self.processingHeaderObj = ProcessingHeader()
104 103
105 104 self.online = 0
106 105
107 106 self.fp = None
108 107
109 108 self.idFile = None
110 109
111 110 self.dtype = None
112 111
113 112 self.fileSizeByHeader = None
114 113
115 114 self.filenameList = []
116 115
117 116 self.filename = None
118 117
119 118 self.fileSize = None
120 119
121 120 self.firstHeaderSize = 0
122 121
123 122 self.basicHeaderSize = 24
124 123
125 124 self.pathList = []
126 125
127 126 self.filenameList = []
128 127
129 128 self.lastUTTime = 0
130 129
131 130 self.maxTimeStep = 30
132 131
133 132 self.flagNoMoreFiles = 0
134 133
135 134 self.set = 0
136 135
137 136 self.path = None
138 137
139 138 self.profileIndex = 9999
140 139
141 140 self.delay = 3 #seconds
142 141
143 142 self.nTries = 3 #quantity tries
144 143
145 144 self.nFiles = 3 #number of files for searching
146 145
147 146 self.nReadBlocks = 0
148 147
149 148 self.flagIsNewFile = 1
150 149
151 150 self.ippSeconds = 0
152 151
153 152 self.flagTimeBlock = 0
154 153
155 154 self.flagIsNewBlock = 0
156 155
157 156 self.nTotalBlocks = 0
158 157
159 158 self.blocksize = 0
160 159
161 160 def createObjByDefault(self):
162 161
163 162 dataObj = Voltage()
164 163
165 164 return dataObj
166 165
167 166 def __hasNotDataInBuffer(self):
168 167 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
169 168 return 1
170 169 return 0
171 170
172 171
173 172 def getBlockDimension(self):
174 173 """
175 174 Obtiene la cantidad de puntos a leer por cada bloque de datos
176 175
177 176 Affected:
178 177 self.blocksize
179 178
180 179 Return:
181 180 None
182 181 """
183 182 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
184 183 self.blocksize = pts2read
185 184
186 185
187 186 def readBlock(self):
188 187 """
189 188 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
190 189 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
191 190 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
192 191 es seteado a 0
193 192
194 193 Inputs:
195 194 None
196 195
197 196 Return:
198 197 None
199 198
200 199 Affected:
201 200 self.profileIndex
202 201 self.datablock
203 202 self.flagIsNewFile
204 203 self.flagIsNewBlock
205 204 self.nTotalBlocks
206 205
207 206 Exceptions:
208 207 Si un bloque leido no es un bloque valido
209 208 """
210 209
211 210 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
212 211
213 212 try:
214 213 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
215 214 except:
216 215 print "The read block (%3d) has not enough data" %self.nReadBlocks
217 216 return 0
218 217
219 218 junk = numpy.transpose(junk, (2,0,1))
220 219 self.datablock = junk['real'] + junk['imag']*1j
221 220
222 221 self.profileIndex = 0
223 222
224 223 self.flagIsNewFile = 0
225 224 self.flagIsNewBlock = 1
226 225
227 226 self.nTotalBlocks += 1
228 227 self.nReadBlocks += 1
229 228
230 229 return 1
231 230
232 231
233 232 def getData(self):
234 233 """
235 234 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
236 235 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
237 236 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
238 237
239 238 Ademas incrementa el contador del buffer en 1.
240 239
241 240 Return:
242 241 data : retorna un perfil de voltages (alturas * canales) copiados desde el
243 242 buffer. Si no hay mas archivos a leer retorna None.
244 243
245 244 Variables afectadas:
246 245 self.dataOutObj
247 246 self.profileIndex
248 247
249 248 Affected:
250 249 self.dataOutObj
251 250 self.profileIndex
252 251 self.flagTimeBlock
253 252 self.flagIsNewBlock
254 253 """
255 254 if self.flagNoMoreFiles: return 0
256 255
257 256 self.flagTimeBlock = 0
258 257 self.flagIsNewBlock = 0
259 258
260 259 if self.__hasNotDataInBuffer():
261 260
262 261 if not( self.readNextBlock() ):
263 262 return 0
264 263
265 264 # self.updateDataHeader()
266 265
267 266 if self.flagNoMoreFiles == 1:
268 267 print 'Process finished'
269 268 return 0
270 269
271 270 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
272 271
273 272 if self.datablock == None:
274 273 self.dataOutObj.flagNoData = True
275 274 return 0
276 275
277 276 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
278 277
279 278 self.dataOutObj.dtype = self.dtype
280 279
281 280 self.dataOutObj.nChannels = self.systemHeaderObj.nChannels
282 281
283 282 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
284 283
285 284 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
286 285
287 286 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
288 287
289 288 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
290 289
291 290 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
292 291
293 292 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
294 293
295 294 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
296 295
297 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.profileIndex * self.ippSeconds
296 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
298 297
299 298 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
300 299
301 300 self.dataOutObj.flagShiftFFT = False
302 301
303 302 if self.processingHeaderObj.code != None:
304 303 self.dataOutObj.nCode = self.processingHeaderObj.nCode
305 304
306 305 self.dataOutObj.nBaud = self.processingHeaderObj.nBaud
307 306
308 307 self.dataOutObj.code = self.processingHeaderObj.code
309 308
310 309 self.profileIndex += 1
311 310
312 311 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
313 312
314 313 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
315 314
316 315 self.dataOutObj.flagNoData = False
317 316
318 317 return 1
319 318
320 319
321 320 class VoltageWriter(JRODataWriter):
322 321 """
323 322 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
324 323 de los datos siempre se realiza por bloques.
325 324 """
326 325
327 326 ext = ".r"
328 327
329 328 optchar = "D"
330 329
331 330 shapeBuffer = None
332 331
333 332
334 333 def __init__(self, dataOutObj=None):
335 334 """
336 335 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
337 336
338 337 Affected:
339 338 self.dataOutObj
340 339
341 340 Return: None
342 341 """
343 342 if dataOutObj == None:
344 343 dataOutObj = Voltage()
345 344
346 345 if not( isinstance(dataOutObj, Voltage) ):
347 346 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
348 347
349 348 self.dataOutObj = dataOutObj
350 349
351 350 self.nTotalBlocks = 0
352 351
353 352 self.profileIndex = 0
354 353
355 354 def hasAllDataInBuffer(self):
356 355 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
357 356 return 1
358 357 return 0
359 358
360 359
361 360 def setBlockDimension(self):
362 361 """
363 362 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
364 363
365 364 Affected:
366 365 self.shape_spc_Buffer
367 366 self.shape_cspc_Buffer
368 367 self.shape_dc_Buffer
369 368
370 369 Return: None
371 370 """
372 371 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
373 372 self.processingHeaderObj.nHeights,
374 373 self.systemHeaderObj.nChannels)
375 374
376 375 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
377 376 self.processingHeaderObj.profilesPerBlock,
378 377 self.processingHeaderObj.nHeights),
379 378 dtype=numpy.dtype('complex'))
380 379
381 380
382 381 def writeBlock(self):
383 382 """
384 383 Escribe el buffer en el file designado
385 384
386 385 Affected:
387 386 self.profileIndex
388 387 self.flagIsNewFile
389 388 self.flagIsNewBlock
390 389 self.nTotalBlocks
391 390 self.blockIndex
392 391
393 392 Return: None
394 393 """
395 394 data = numpy.zeros( self.shapeBuffer, self.dtype )
396 395
397 396 junk = numpy.transpose(self.datablock, (1,2,0))
398 397
399 398 data['real'] = junk.real
400 399 data['imag'] = junk.imag
401 400
402 401 data = data.reshape( (-1) )
403 402
404 403 data.tofile( self.fp )
405 404
406 405 self.datablock.fill(0)
407 406
408 407 self.profileIndex = 0
409 408 self.flagIsNewFile = 0
410 409 self.flagIsNewBlock = 1
411 410
412 411 self.blockIndex += 1
413 412 self.nTotalBlocks += 1
414 413
415 414 def putData(self):
416 415 """
417 416 Setea un bloque de datos y luego los escribe en un file
418 417
419 418 Affected:
420 419 self.flagIsNewBlock
421 420 self.profileIndex
422 421
423 422 Return:
424 423 0 : Si no hay data o no hay mas files que puedan escribirse
425 424 1 : Si se escribio la data de un bloque en un file
426 425 """
427 426 self.flagIsNewBlock = 0
428 427
429 428 if self.dataOutObj.flagNoData:
430 429 return 0
431 430
432 431 if self.dataOutObj.flagTimeBlock:
433 432
434 433 self.datablock.fill(0)
435 434 self.profileIndex = 0
436 435 self.setNextFile()
437 436
438 437 if self.profileIndex == 0:
439 438 self.getBasicHeader()
440 439
441 440 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
442 441
443 442 self.profileIndex += 1
444 443
445 444 if self.hasAllDataInBuffer():
446 445 #if self.flagIsNewFile:
447 446 self.writeNextBlock()
448 447 # self.getDataHeader()
449 448
450 449 if self.flagNoMoreFiles:
451 450 #print 'Process finished'
452 451 return 0
453 452
454 453 return 1
455 454
456 455 def __getProcessFlags(self):
457 456
458 457 processFlags = 0
459 458
460 459 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
461 460 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
462 461 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
463 462 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
464 463 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
465 464 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
466 465
467 466 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
468 467
469 468
470 469
471 470 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
472 471 PROCFLAG.DATATYPE_SHORT,
473 472 PROCFLAG.DATATYPE_LONG,
474 473 PROCFLAG.DATATYPE_INT64,
475 474 PROCFLAG.DATATYPE_FLOAT,
476 475 PROCFLAG.DATATYPE_DOUBLE]
477 476
478 477
479 478 for index in range(len(dtypeList)):
480 479 if self.dataOutObj.dtype == dtypeList[index]:
481 480 dtypeValue = datatypeValueList[index]
482 481 break
483 482
484 483 processFlags += dtypeValue
485 484
486 485 if self.dataOutObj.flagDecodeData:
487 486 processFlags += PROCFLAG.DECODE_DATA
488 487
489 488 if self.dataOutObj.flagDeflipData:
490 489 processFlags += PROCFLAG.DEFLIP_DATA
491 490
492 491 if self.dataOutObj.code != None:
493 492 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
494 493
495 494 if self.dataOutObj.nCohInt > 1:
496 495 processFlags += PROCFLAG.COHERENT_INTEGRATION
497 496
498 497 return processFlags
499 498
500 499
501 500 def __getBlockSize(self):
502 501 '''
503 502 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
504 503 '''
505 504
506 505 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
507 506 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
508 507 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
509 508 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
510 509 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
511 510 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
512 511
513 512 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
514 513 datatypeValueList = [1,2,4,8,4,8]
515 514 for index in range(len(dtypeList)):
516 515 if self.dataOutObj.dtype == dtypeList[index]:
517 516 datatypeValue = datatypeValueList[index]
518 517 break
519 518
520 519 blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2)
521 520
522 521 return blocksize
523 522
524 523
525 524 def getBasicHeader(self):
526 525 self.basicHeaderObj.size = self.basicHeaderSize #bytes
527 526 self.basicHeaderObj.version = self.versionFile
528 527 self.basicHeaderObj.dataBlock = self.nTotalBlocks
529 528
530 529 utc = numpy.floor(self.dataOutObj.dataUtcTime)
531 530 milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0
532 531
533 532 self.basicHeaderObj.utc = utc
534 533 self.basicHeaderObj.miliSecond = milisecond
535 534 self.basicHeaderObj.timeZone = 0
536 535 self.basicHeaderObj.dstFlag = 0
537 536 self.basicHeaderObj.errorCount = 0
538 537
539 538 def getDataHeader(self):
540 539
541 540 """
542 541 Obtiene una copia del First Header
543 542
544 543 Affected:
545 544 self.systemHeaderObj
546 545 self.radarControllerHeaderObj
547 546 self.dtype
548 547
549 548 Return:
550 549 None
551 550 """
552 551
553 552 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
554 553 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
555 554 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
556 555
557 556 self.getBasicHeader()
558 557
559 558 processingHeaderSize = 40 # bytes
560 559 self.processingHeaderObj.dtype = 0 # Voltage
561 560 self.processingHeaderObj.blockSize = self.__getBlockSize()
562 561 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
563 562 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
564 563 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
565 564 self.processingHeaderObj.processFlags = self.__getProcessFlags()
566 565 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt
567 566 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
568 567 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
569 568
570 569 if self.dataOutObj.code != None:
571 570 self.processingHeaderObj.code = self.dataOutObj.code
572 571 self.processingHeaderObj.nCode = self.dataOutObj.nCode
573 572 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
574 573 codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud)
575 574 processingHeaderSize += codesize
576 575
577 576 if self.processingHeaderObj.nWindows != 0:
578 577 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
579 578 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
580 579 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
581 580 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
582 581 processingHeaderSize += 12
583 582
584 583 self.processingHeaderObj.size = processingHeaderSize
585 584 No newline at end of file
@@ -1,388 +1,388
1 1 '''
2 Created on Feb 7, 2012
3 2
4 @author $Author: murco $
5 @version $Id: SpectraProcessor.py 119 2012-09-05 17:06:09Z murco $
3 $Author$
4 $Id$
6 5 '''
6
7 7 import os, sys
8 8 import numpy
9 9 import time
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Data.Spectra import Spectra
15 15 from IO.SpectraIO import SpectraWriter
16 16 #from Graphics.SpectraPlot import Spectrum
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 40 # integratorObjList = []
41 41 #
42 42 # decoderObjList = []
43 43 #
44 44 # writerObjList = []
45 45 #
46 46 # plotterObjList = []
47 47 #
48 48 # integratorObjIndex = None
49 49 #
50 50 # decoderObjIndex = None
51 51 #
52 52 # writerObjIndex = None
53 53 #
54 54 # plotterObjIndex = None
55 55 #
56 56 # buffer = None
57 57 #
58 58 # profIndex = 0
59 59 #
60 60 # nFFTPoints = None
61 61 #
62 62 # nChannels = None
63 63 #
64 64 # nHeights = None
65 65 #
66 66 # nPairs = None
67 67 #
68 68 # pairList = None
69 69
70 70
71 71 def __init__(self):
72 72 '''
73 73 Constructor
74 74 '''
75 75
76 76 self.integratorObjIndex = None
77 77 self.writerObjIndex = None
78 78 self.integratorObjList = []
79 79 self.writerObjList = []
80 80 self.noiseObj = None
81 81 self.buffer = None
82 82 self.profIndex = 0
83 83
84 84 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
85 85
86 86 if dataInObj == None:
87 87 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
88 88
89 89 if dataInObj.type == "Voltage":
90 90 if nFFTPoints == None:
91 91 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
92 92 else:
93 93 nFFTPoints = dataInObj.nFFTPoints
94 94
95 95 self.dataInObj = dataInObj
96 96
97 97 if dataOutObj == None:
98 98 dataOutObj = Spectra()
99 99
100 100 self.dataOutObj = dataOutObj
101 101
102 102 # self.noiseObj = Noise() #aun no se incluye el objeto Noise()
103 103
104 104 ##########################################
105 105 # self.nFFTPoints = nFFTPoints
106 106 # self.nChannels = self.dataInObj.nChannels
107 107 # self.nHeights = self.dataInObj.nHeights
108 108 # self.pairList = pairList
109 109 # if pairList != None:
110 110 # self.nPairs = len(pairList)
111 111 # else:
112 112 # self.nPairs = 0
113 113 #
114 114 # self.dataOutObj.heightList = self.dataInObj.heightList
115 115 # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
116 116 # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
117 117 # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
118 118 # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
119 119 # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
120 120 #
121 121 # self.dataOutObj.dataType = self.dataInObj.dataType
122 122 # self.dataOutObj.nPairs = self.nPairs
123 123 # self.dataOutObj.nChannels = self.nChannels
124 124 # self.dataOutObj.nProfiles = self.nFFTPoints
125 125 # self.dataOutObj.nHeights = self.nHeights
126 126 # self.dataOutObj.nFFTPoints = self.nFFTPoints
127 127 # #self.dataOutObj.data = None
128 128 #
129 129 # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
130 130 # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
131 131 #
132 132 # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
133 133 # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
134 134 # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
135 135 # self.dataOutObj.m_ProcessingHeader.shif_fft = True
136 136 #
137 137 # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
138 138 # k = 0
139 139 # for i in range( 0,self.nChannels*2,2 ):
140 140 # spectraComb[i] = k
141 141 # spectraComb[i+1] = k
142 142 # k += 1
143 143 #
144 144 # k *= 2
145 145 #
146 146 # if self.pairList != None:
147 147 #
148 148 # for pair in self.pairList:
149 149 # spectraComb[k] = pair[0]
150 150 # spectraComb[k+1] = pair[1]
151 151 # k += 2
152 152 #
153 153 # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
154 154
155 155 return self.dataOutObj
156 156
157 157 def init(self):
158 158 #
159 159 # self.nHeights = self.dataInObj.nHeights
160 160 # self.dataOutObj.nHeights = self.nHeights
161 161 # self.dataOutObj.heightList = self.dataInObj.heightList
162 162 #
163 163
164 164 self.integratorObjIndex = 0
165 165 self.writerObjIndex = 0
166 166
167 167 if self.dataInObj.type == "Voltage":
168 168
169 169 if self.buffer == None:
170 170 self.buffer = numpy.zeros((self.nChannels,
171 171 self.nFFTPoints,
172 172 self.dataInObj.nHeights),
173 173 dtype='complex')
174 174
175 175 self.buffer[:,self.profIndex,:] = self.dataInObj.data
176 176 self.profIndex += 1
177 177
178 178 if self.profIndex == self.nFFTPoints:
179 179 self.__getFft()
180 180 self.dataOutObj.flagNoData = False
181 181
182 182 self.buffer = None
183 183 self.profIndex = 0
184 184 return
185 185
186 186 self.dataOutObj.flagNoData = True
187 187
188 188 return
189 189
190 190 #Other kind of data
191 191 if self.dataInObj.type == "Spectra":
192 192 self.dataOutObj.copy(self.dataInObj)
193 193 self.dataOutObj.flagNoData = False
194 194 return
195 195
196 196 raise ValueError, "The datatype is not valid"
197 197
198 198 def __getFft(self):
199 199 """
200 200 Convierte valores de Voltaje a Spectra
201 201
202 202 Affected:
203 203 self.dataOutObj.data_spc
204 204 self.dataOutObj.data_cspc
205 205 self.dataOutObj.data_dc
206 206 self.dataOutObj.heightList
207 207 self.dataOutObj.m_BasicHeader
208 208 self.dataOutObj.m_ProcessingHeader
209 209 self.dataOutObj.m_RadarControllerHeader
210 210 self.dataOutObj.m_SystemHeader
211 211 self.profIndex
212 212 self.buffer
213 213 self.dataOutObj.flagNoData
214 214 self.dataOutObj.dataType
215 215 self.dataOutObj.nPairs
216 216 self.dataOutObj.nChannels
217 217 self.dataOutObj.nProfiles
218 218 self.dataOutObj.m_SystemHeader.numChannels
219 219 self.dataOutObj.m_ProcessingHeader.totalSpectra
220 220 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
221 221 self.dataOutObj.m_ProcessingHeader.numHeights
222 222 self.dataOutObj.m_ProcessingHeader.spectraComb
223 223 self.dataOutObj.m_ProcessingHeader.shif_fft
224 224 """
225 225
226 226 if self.dataInObj.flagNoData:
227 227 return 0
228 228
229 229 fft_volt = numpy.fft.fft(self.buffer,axis=1)
230 230 dc = fft_volt[:,0,:]
231 231
232 232 #calculo de self-spectra
233 233 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
234 234 spc = fft_volt * numpy.conjugate(fft_volt)
235 235 spc = spc.real
236 236
237 237 blocksize = 0
238 238 blocksize += dc.size
239 239 blocksize += spc.size
240 240
241 241 cspc = None
242 242 pairIndex = 0
243 243 if self.pairList != None:
244 244 #calculo de cross-spectra
245 245 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
246 246 for pair in self.pairList:
247 247 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
248 248 pairIndex += 1
249 249 blocksize += cspc.size
250 250
251 251 self.dataOutObj.data_spc = spc
252 252 self.dataOutObj.data_cspc = cspc
253 253 self.dataOutObj.data_dc = dc
254 254 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
255 255 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
256 256
257 257 # self.getNoise()
258 258
259 def addWriter(self, wrpath, profilesPerBlock, blocksPerFile):
259 def addWriter(self, wrpath, blocksPerFile):
260 260 objWriter = SpectraWriter(self.dataOutObj)
261 objWriter.setup(wrpath, profilesPerBlock, blocksPerFile)
261 objWriter.setup(wrpath, blocksPerFile)
262 262 self.writerObjList.append(objWriter)
263 263
264 264 def addIntegrator(self,N,timeInterval):
265 265
266 266 objIncohInt = IncoherentIntegration(N,timeInterval)
267 267 self.integratorObjList.append(objIncohInt)
268 268
269 def writeData(self, wrpath, profilesPerBlock, blocksPerFile):
269 def writeData(self, wrpath, blocksPerFile):
270 270 if self.dataOutObj.flagNoData:
271 271 return 0
272 272
273 273 if len(self.writerObjList) <= self.writerObjIndex:
274 self.addWriter(wrpath, profilesPerBlock, blocksPerFile)
274 self.addWriter(wrpath, blocksPerFile)
275 275
276 276 self.writerObjList[self.writerObjIndex].putData()
277 277
278 278 self.writerObjIndex += 1
279 279
280 280 def integrator(self, N=None, timeInterval=None):
281 281
282 282 if self.dataOutObj.flagNoData:
283 283 return 0
284 284
285 285 if len(self.integratorObjList) <= self.integratorObjIndex:
286 286 self.addIntegrator(N,timeInterval)
287 287
288 288 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
289 289 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
290 290
291 291 if myIncohIntObj.isReady:
292 292 self.dataOutObj.data_spc = myIncohIntObj.data
293 293 self.dataOutObj.nAvg = myIncohIntObj.navg
294 294 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
295 295 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
296 296 self.dataOutObj.flagNoData = False
297 297
298 298 """Calcular el ruido"""
299 299 self.getNoise()
300 300 else:
301 301 self.dataOutObj.flagNoData = True
302 302
303 303 self.integratorObjIndex += 1
304 304
305 305
306 306
307 307
308 308 class IncoherentIntegration:
309 309
310 310 integ_counter = None
311 311 data = None
312 312 navg = None
313 313 buffer = None
314 314 nIncohInt = None
315 315
316 316 def __init__(self, N = None, timeInterval = None):
317 317 """
318 318 N
319 319 timeInterval - interval time [min], integer value
320 320 """
321 321
322 322 self.data = None
323 323 self.navg = None
324 324 self.buffer = None
325 325 self.timeOut = None
326 326 self.exitCondition = False
327 327 self.isReady = False
328 328 self.nIncohInt = N
329 329 self.integ_counter = 0
330 330 if timeInterval!=None:
331 331 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
332 332
333 333 if ((timeInterval==None) and (N==None)):
334 334 print 'N = None ; timeInterval = None'
335 335 sys.exit(0)
336 336 elif timeInterval == None:
337 337 self.timeFlag = False
338 338 else:
339 339 self.timeFlag = True
340 340
341 341
342 342 def exe(self,data,timeOfData):
343 343 """
344 344 data
345 345
346 346 timeOfData [seconds]
347 347 """
348 348
349 349 if self.timeFlag:
350 350 if self.timeOut == None:
351 351 self.timeOut = timeOfData + self.timeIntervalInSeconds
352 352
353 353 if timeOfData < self.timeOut:
354 354 if self.buffer == None:
355 355 self.buffer = data
356 356 else:
357 357 self.buffer = self.buffer + data
358 358 self.integ_counter += 1
359 359 else:
360 360 self.exitCondition = True
361 361
362 362 else:
363 363 if self.integ_counter < self.nIncohInt:
364 364 if self.buffer == None:
365 365 self.buffer = data
366 366 else:
367 367 self.buffer = self.buffer + data
368 368
369 369 self.integ_counter += 1
370 370
371 371 if self.integ_counter == self.nIncohInt:
372 372 self.exitCondition = True
373 373
374 374 if self.exitCondition:
375 375 self.data = self.buffer
376 376 self.navg = self.integ_counter
377 377 self.isReady = True
378 378 self.buffer = None
379 379 self.timeOut = None
380 380 self.integ_counter = 0
381 381 self.exitCondition = False
382 382
383 383 if self.timeFlag:
384 384 self.buffer = data
385 385 self.timeOut = timeOfData + self.timeIntervalInSeconds
386 386 else:
387 387 self.isReady = False
388 388 No newline at end of file
@@ -1,147 +1,153
1 '''
2
3 $Author$
4 $Id$
5 '''
6
1 7 import os
2 8 import sys
3 9 import numpy
4 10
5 11 path = os.path.split(os.getcwd())[0]
6 12 sys.path.append(path)
7 13
8 14 from Data.Voltage import Voltage
9 15 from IO.VoltageIO import VoltageWriter
10 16
11 17
12 18 class VoltageProcessor:
13 19 dataInObj = None
14 20 dataOutObj = None
15 21 integratorObjIndex = None
16 22 writerObjIndex = None
17 23 integratorObjList = None
18 24 writerObjList = None
19 25
20 26 def __init__(self):
21 27 self.integratorObjIndex = None
22 28 self.writerObjIndex = None
23 29 self.integratorObjList = []
24 30 self.writerObjList = []
25 31
26 32 def setup(self,dataInObj=None,dataOutObj=None):
27 33 self.dataInObj = dataInObj
28 34
29 35 if self.dataOutObj == None:
30 36 dataOutObj = Voltage()
31 37
32 38 self.dataOutObj = dataOutObj
33 39
34 40 return self.dataOutObj
35 41
36 42 def init(self):
37 43 self.integratorObjIndex = 0
38 44 self.writerObjIndex = 0
39 45
40 46 if not(self.dataInObj.flagNoData):
41 47 self.dataOutObj.copy(self.dataInObj)
42 48 # No necesita copiar en cada init() los atributos de dataInObj
43 49 # la copia deberia hacerse por cada nuevo bloque de datos
44 50
45 51 def addIntegrator(self,N,timeInterval):
46 52 objCohInt = CoherentIntegrator(N,timeInterval)
47 53 self.integratorObjList.append(objCohInt)
48 54
49 def addWriter(self, wrpath, profilesPerBlock, blocksPerFile):
55 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
50 56 objWriter = VoltageWriter(self.dataOutObj)
51 objWriter.setup(wrpath,profilesPerBlock,blocksPerFile)
57 objWriter.setup(wrpath,blocksPerFile,profilesPerBlock)
52 58 self.writerObjList.append(objWriter)
53 59
54 def writeData(self, wrpath, profilesPerBlock, blocksPerFile):
60 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
55 61
56 62 if self.dataOutObj.flagNoData:
57 63 return 0
58 64
59 65 if len(self.writerObjList) <= self.writerObjIndex:
60 self.addWriter(wrpath, profilesPerBlock, blocksPerFile)
66 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
61 67
62 68 self.writerObjList[self.writerObjIndex].putData()
63 69
64 70 self.writerObjIndex += 1
65 71
66 72 def integrator(self, N=None, timeInterval=None):
67 73 if self.dataOutObj.flagNoData:
68 74 return 0
69 75 if len(self.integratorObjList) <= self.integratorObjIndex:
70 76 self.addIntegrator(N,timeInterval)
71 77
72 78 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
73 79 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
74 80
75 81
76 82 class CoherentIntegrator:
77 83
78 84 integ_counter = None
79 85 data = None
80 86 navg = None
81 87 buffer = None
82 88 nCohInt = None
83 89
84 90 def __init__(self, N=None,timeInterval=None):
85 91
86 92 self.data = None
87 93 self.navg = None
88 94 self.buffer = None
89 95 self.timeOut = None
90 96 self.exitCondition = False
91 97 self.isReady = False
92 98 self.nCohInt = N
93 99 self.integ_counter = 0
94 100 if timeInterval!=None:
95 101 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
96 102
97 103 if ((timeInterval==None) and (N==None)):
98 104 raise ValueError, "N = None ; timeInterval = None"
99 105
100 106 if timeInterval == None:
101 107 self.timeFlag = False
102 108 else:
103 109 self.timeFlag = True
104 110
105 111 def exe(self, data, timeOfData):
106 112
107 113 if self.timeFlag:
108 114 if self.timeOut == None:
109 115 self.timeOut = timeOfData + self.timeIntervalInSeconds
110 116
111 117 if timeOfData < self.timeOut:
112 118 if self.buffer == None:
113 119 self.buffer = data
114 120 else:
115 121 self.buffer = self.buffer + data
116 122 self.integ_counter += 1
117 123 else:
118 124 self.exitCondition = True
119 125
120 126 else:
121 127 if self.integ_counter < self.nCohInt:
122 128 if self.buffer == None:
123 129 self.buffer = data
124 130 else:
125 131 self.buffer = self.buffer + data
126 132
127 133 self.integ_counter += 1
128 134
129 135 if self.integ_counter == self.nCohInt:
130 136 self.exitCondition = True
131 137
132 138 if self.exitCondition:
133 139 self.data = self.buffer
134 140 self.navg = self.integ_counter
135 141 self.isReady = True
136 142 self.buffer = None
137 143 self.timeOut = None
138 144 self.integ_counter = 0
139 145 self.exitCondition = False
140 146
141 147 if self.timeFlag:
142 148 self.buffer = data
143 149 self.timeOut = timeOfData + self.timeIntervalInSeconds
144 150 else:
145 151 self.isReady = False
146 152
147 153
@@ -1,81 +1,85
1 '''
1 2
3 $Author$
4 $Id$
5 '''
2 6 import os, sys
3 7 import time, datetime
4 8
5 9 path = os.path.split(os.getcwd())[0]
6 10 sys.path.append(path)
7 11
8 12 from Data.Voltage import Voltage
9 13 from IO.VoltageIO import *
10 14
11 15 from Processing.VoltageProcessor import *
12 16
13 17
14 18
15 19 class TestSChain():
16 20
17 21 def __init__(self):
18 22 self.setValues()
19 23 self.createObjects()
20 24 self.testSChain()
21 25
22 26 def setValues(self):
23 27 self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts"
24 28 self.startDate = datetime.date(2011,11,28)
25 29 self.endDate = datetime.date(2011,11,30)
26 30
27 31 # self.path = "/Users/danielangelsuarezmunoz/Data/Imaging_rawdata"
28 32 # self.startDate = datetime.date(2011,10,4)
29 33 # self.endDate = datetime.date(2011,10,4)
30 34
31 35 # Probando los escritos por Signal Chain
32 36 self.path = "/Users/danielangelsuarezmunoz/Data/testWR"
33 37 self.startDate = datetime.date(2011,11,28)
34 38 self.endDate = datetime.date(2011,11,30)
35 39
36 40 self.startTime = datetime.time(0,0,0)
37 41 self.endTime = datetime.time(23,59,59)
38 42
39 43 self.wrpath = "/Users/danielangelsuarezmunoz/Data/testWR"
40 44 self.profilesPerBlock = 40
41 45 self.blocksPerFile = 50
42 46
43 47 def createObjects(self):
44 48
45 49 self.readerObj = VoltageReader()
46 50
47 51 self.voltObj1 = self.readerObj.setup(
48 52 path = self.path,
49 53 startDate = self.startDate,
50 54 endDate = self.endDate,
51 55 startTime = self.startTime,
52 56 endTime = self.endTime,
53 57 expLabel = '',
54 58 online = 0)
55 59
56 60 self.voltObjProc = VoltageProcessor()
57 61
58 62 self.voltObj2 = self.voltObjProc.setup(dataInObj = self.voltObj1)
59 63
60 64 def testSChain(self):
61 65
62 66 ini = time.time()
63 67
64 68 while(True):
65 69 self.readerObj.getData()
66 70
67 71 # self.voltObjProc.init()
68 72 #
69 73 # self.voltObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile)
70 74
71 75 if self.readerObj.flagNoMoreFiles:
72 76 break
73 77
74 78 if self.readerObj.flagIsNewBlock:
75 79 # print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),)
76 80 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
77 81 datetime.datetime.utcfromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),)
78 82
79 83
80 84 if __name__ == '__main__':
81 85 TestSChain() No newline at end of file
@@ -1,80 +1,85
1 '''
2
3 $Author$
4 $Id$
5 '''
1 6
2 7 import os, sys
3 8 import time, datetime
4 9
5 10 path = os.path.split(os.getcwd())[0]
6 11 sys.path.append(path)
7 12
8 13
9 14 from Data.Spectra import Spectra
10 15 from IO.SpectraIO import *
11 16 from Processing.SpectraProcessor import *
12 17
13 18
14 19
15 20 class TestSChain:
16 21
17 22 def __init__(self):
18 23 self.setValues()
19 24 self.createObjects()
20 25 self.testSChain()
21 26
22 27 def setValues(self):
23 self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
24 # self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING"
25 self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts"
26 self.path = "/Users/danielangelsuarezmunoz/Data/IMAGING"
28 # self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
29 ## self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING"
30 # self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts"
31 # self.path = "/Users/danielangelsuarezmunoz/Data/IMAGING"
32 self.path = "/home/daniel/RadarData/IMAGING"
27 33
28 34 self.startDate = datetime.date(2012,3,1)
29 35 self.endDate = datetime.date(2012,3,30)
30 36
31 37 self.startTime = datetime.time(0,0,0)
32 38 self.endTime = datetime.time(14,1,1)
33 39
34 40 # paramatros para Escritura de Pdata
35 self.wrpath = "/Users/danielangelsuarezmunoz/Data/testWR_pdata"
36 self.profilesPerBlock = 8
41 self.wrpath = "/home/daniel/RadarData/test_wr2"
37 42 self.blocksPerFile = 5
38 # self.pairList = [(0,1),(0,2)]
43
39 44
40 45
41 46 def createObjects(self):
42 47
43 48 self.readerObj = SpectraReader()
44 49
45 50 self.specObj1 = self.readerObj.setup(
46 51 path = self.path,
47 52 startDate = self.startDate,
48 53 endDate = self.endDate,
49 54 startTime = self.startTime,
50 55 endTime = self.endTime,
51 56 expLabel = '',
52 57 online = 0)
53 # new lines
58
54 59 self.specObjProc = SpectraProcessor()
55 60
56 61 self.specObj2 = self.specObjProc.setup(dataInObj = self.specObj1)
57 62
58 63
59 64
60 65 def testSChain(self):
61 66
62 67 ini = time.time()
63 68
64 69 while(True):
65 70 self.readerObj.getData()
66 71
67 72 self.specObjProc.init()
68 73
69 self.specObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile)
70
74 self.specObjProc.writeData(self.wrpath,self.blocksPerFile)
75 #
71 76 if self.readerObj.flagNoMoreFiles:
72 77 break
73 78
74 79 if self.readerObj.flagIsNewBlock:
75 80 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
76 81 datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc))
77 82
78 83
79 84 if __name__ == '__main__':
80 85 TestSChain() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now