@@ -21,6 +21,39 from IO.DataIO import DataWriter | |||
|
21 | 21 | from Model.Voltage import Voltage |
|
22 | 22 | |
|
23 | 23 | |
|
24 | def isFileOK(filename): | |
|
25 | """ | |
|
26 | Determina si la cabecera de un archivo es valido o no, si lo es entonces seria un archivo que podria contener data, | |
|
27 | si no seria un archivo invalido | |
|
28 | ||
|
29 | Return: | |
|
30 | True : si es un archivo valido | |
|
31 | False : si no es un archivo valido | |
|
32 | ||
|
33 | Exceptions: | |
|
34 | Si al leer la cabecera esta no coincide con el tipo de las variables que la contienen entonces se dispara | |
|
35 | una exception | |
|
36 | """ | |
|
37 | m_BasicHeader = BasicHeader() | |
|
38 | m_ProcessingHeader = ProcessingHeader() | |
|
39 | m_RadarControllerHeader = RadarControllerHeader() | |
|
40 | m_SystemHeader = SystemHeader() | |
|
41 | fp = None | |
|
42 | ||
|
43 | try: | |
|
44 | fp = open( filename,'rb' ) #lectura binaria | |
|
45 | m_BasicHeader.read(fp) | |
|
46 | m_SystemHeader.read(fp) | |
|
47 | m_RadarControllerHeader.read(fp) | |
|
48 | m_ProcessingHeader.read(fp) | |
|
49 | fp.close() | |
|
50 | except: | |
|
51 | if fp != None: fp.close() | |
|
52 | return False | |
|
53 | ||
|
54 | return True | |
|
55 | ||
|
56 | ||
|
24 | 57 |
def getlastFileFromPath( |
|
25 | 58 | """ |
|
26 | 59 | Depura el pathList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
@@ -60,7 +93,7 def getlastFileFromPath( pathList, ext ): | |||
|
60 | 93 | |
|
61 | 94 |
def checkForRealPath( |
|
62 | 95 | """ |
|
63 |
Por ser Linux Case Sensitive |
|
|
96 | Por ser Linux Case Sensitive la funcion checkForRealPath encuentra el nombre correcto de un path, | |
|
64 | 97 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
65 | 98 | el path exacto de un determinado file. |
|
66 | 99 | |
@@ -68,14 +101,14 def checkForRealPath( path, year, doy, set, ext ): | |||
|
68 | 101 | nombre correcto del file es ../RAWDATA/D2009307/P2009307367 |
|
69 | 102 | |
|
70 | 103 | Entonces la funcion prueba con las siguientes combinaciones |
|
71 |
../ |
|
|
72 |
../ |
|
|
73 |
../ |
|
|
74 |
../ |
|
|
104 | ../.../d2009307/d2009307367 | |
|
105 | ../.../d2009307/D2009307367 | |
|
106 | ../.../D2009307/d2009307367 | |
|
107 | ../.../D2009307/D2009307367 | |
|
75 | 108 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
76 | 109 | |
|
77 | 110 | Return: |
|
78 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
|
111 | Si encuentra la combinacion adecuada devuelve el path completo y el nombre del file | |
|
79 | 112 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
80 | 113 | para el filename |
|
81 | 114 | """ |
@@ -159,6 +192,7 def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |||
|
159 | 192 | |
|
160 | 193 | return 1 |
|
161 | 194 | |
|
195 | ||
|
162 | 196 | class VoltageReader(DataReader): |
|
163 | 197 | """ |
|
164 | 198 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
@@ -201,6 +235,7 class VoltageReader(DataReader): | |||
|
201 | 235 | #speed of light |
|
202 | 236 | __c = 3E8 |
|
203 | 237 | |
|
238 | ||
|
204 | 239 |
def __init__(self, |
|
205 | 240 | """ |
|
206 | 241 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
@@ -299,6 +334,9 class VoltageReader(DataReader): | |||
|
299 | 334 | self.__path = None |
|
300 | 335 | self.__pts2read = 0 |
|
301 | 336 | self.__blocksize = 0 |
|
337 | self.__utc = 0 | |
|
338 | self.nBlocks = 0 | |
|
339 | ||
|
302 | 340 | |
|
303 | 341 | def __rdSystemHeader(self,fp=None): |
|
304 | 342 | if fp == None: |
@@ -306,18 +344,21 class VoltageReader(DataReader): | |||
|
306 | 344 | |
|
307 | 345 | self.m_SystemHeader.read(fp) |
|
308 | 346 | |
|
347 | ||
|
309 | 348 | def __rdRadarControllerHeader(self,fp=None): |
|
310 | 349 | if fp == None: |
|
311 | 350 | fp = self.__fp |
|
312 | 351 | |
|
313 | 352 | self.m_RadarControllerHeader.read(fp) |
|
314 | 353 | |
|
354 | ||
|
315 | 355 | def __rdProcessingHeader(self,fp=None): |
|
316 | 356 | if fp == None: |
|
317 | 357 | fp = self.__fp |
|
318 | 358 | |
|
319 | 359 | self.m_ProcessingHeader.read(fp) |
|
320 | 360 | |
|
361 | ||
|
321 | 362 |
def __rdBasicHeader(self, |
|
322 | 363 | |
|
323 | 364 | if fp == None: |
@@ -325,8 +366,26 class VoltageReader(DataReader): | |||
|
325 | 366 | |
|
326 | 367 | self.m_BasicHeader.read(fp) |
|
327 | 368 | |
|
369 | ||
|
328 | 370 | def __readFirstHeader(self): |
|
371 | """ | |
|
372 | Lectura del First Header, es decir el Basic Header y el Long Header | |
|
373 | ||
|
374 | Affected: | |
|
375 | self.m_BasicHeader | |
|
376 | self.m_SystemHeader | |
|
377 | self.m_RadarControllerHeader | |
|
378 | self.m_ProcessingHeader | |
|
379 | self.firstHeaderSize | |
|
380 | self.__heights | |
|
381 | self.__dataType | |
|
382 | self.__fileSizeByHeader | |
|
383 | self.__ippSeconds | |
|
384 | self.__blocksize | |
|
385 | self.__pts2read | |
|
329 | 386 | |
|
387 | Return: None | |
|
388 | """ | |
|
330 | 389 | self.__rdBasicHeader() |
|
331 | 390 | self.__rdSystemHeader() |
|
332 | 391 | self.__rdRadarControllerHeader() |
@@ -392,12 +451,9 class VoltageReader(DataReader): | |||
|
392 | 451 | countFiles = 0 |
|
393 | 452 | countTries = 0 |
|
394 | 453 | |
|
395 | fileStatus = 0 | |
|
396 | 454 | notFirstTime_flag = False |
|
397 | bChangeDir = False | |
|
398 | ||
|
399 | fileSize = 0 | |
|
400 | fp = None | |
|
455 | fileOk_flag = False | |
|
456 | changeDir_flag = False | |
|
401 | 457 | |
|
402 | 458 | self.__flagIsNewFile = 0 |
|
403 | 459 | |
@@ -413,80 +469,73 class VoltageReader(DataReader): | |||
|
413 | 469 | if countFiles > self.__nFiles: #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
414 | 470 | self.__set = 0 |
|
415 | 471 | self.__doy += 1 |
|
416 |
|
|
|
472 | changeDir_flag = True | |
|
417 | 473 | |
|
418 | 474 | file = None |
|
419 | 475 | filename = None |
|
476 | fileOk_flag = False | |
|
420 | 477 | |
|
421 | countTries = 0 | |
|
422 | ||
|
423 | #espero hasta encontrar el 1er file disponible | |
|
424 | while( True ): | |
|
478 | #busca el 1er file disponible | |
|
479 | file, filename = checkForRealPath( self.__path, self.__year, self.__doy, self.__set, self.__ext ) | |
|
425 | 480 | |
|
426 | countTries += 1 | |
|
427 | if( countTries >= self.__nTries ): #checkeo que no haya ido mas alla de la cantidad de intentos | |
|
428 | break | |
|
481 | if file == None: | |
|
482 | if notFirstTime_flag: #si no es la primera vez que busca el file entonces no espera y busca for el siguiente file | |
|
483 | print "\tsearching next \"%s\" file ..." % ( filename ) | |
|
484 | continue | |
|
485 | else: #si es la primera vez que busca el file entonces espera self.__nTries veces hasta encontrarlo o no | |
|
486 | for nTries in range( self.__nTries ): | |
|
487 | print "\twaiting new \"%s\" file, try %03d ..." % ( filename, nTries+1 ) | |
|
488 | time.sleep( self.__delay ) | |
|
429 | 489 | |
|
430 | 490 | file, filename = checkForRealPath( self.__path, self.__year, self.__doy, self.__set, self.__ext ) |
|
431 | 491 | if file != None: |
|
492 | fileOk_flag = True | |
|
432 | 493 | break |
|
433 | 494 | |
|
434 | if notFirstTime_flag: #este flag me sirve solo para esperar por el 1er file, en lo siguientes no espera solo checkea si existe o no | |
|
435 | countTries = self.__nTries | |
|
436 | print "\tsearching next \"%s\" file ..." % filename | |
|
437 | break | |
|
438 | ||
|
439 | print "\twaiting new \"%s\" file ..." % filename | |
|
440 | time.sleep( self.__delay ) | |
|
441 | ||
|
442 | if countTries >= self.__nTries: #se realizaron n intentos y no hubo un file nuevo | |
|
495 | if not( fileOk_flag ): #no encontro ningun file valido a leer despues de haber esperado alguno | |
|
443 | 496 | notFirstTime_flag = True |
|
444 | continue #vuelvo al inico del while principal | |
|
497 | continue | |
|
445 | 498 | |
|
446 | countTries = 0 | |
|
499 | #una vez que se obtuvo el 1er file valido se procede a checkear si si tamanho es suficiente para empezar a leerlo | |
|
500 | currentSize = os.path.getsize( file ) | |
|
501 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize | |
|
447 | 502 | |
|
448 | #una vez que se obtuvo el 1er file valido se procede a checkear su contenido, y se espera una cierta cantidad | |
|
449 | #de tiempo por una cierta cantidad de veces hasta que el contenido del file sea un contenido valido | |
|
450 |
|
|
|
451 | countTries += 1 | |
|
452 | if countTries > self.__nTries: | |
|
503 | #si el tamanho es suficiente entonces deja de buscar | |
|
504 | if currentSize > neededSize:# and (neededSize != 0): | |
|
505 | fileOk_flag = True | |
|
453 | 506 |
|
|
454 | 507 |
|
|
455 | try: | |
|
456 | fp = open(file) | |
|
457 | except: | |
|
458 | print "The file \"%s\" can't be opened" % file | |
|
459 | break | |
|
508 | fileOk_flag = False | |
|
509 | #si el file no tiene el tamanho necesario se espera una cierta cantidad de tiempo | |
|
510 | #por una cierta cantidad de veces hasta que el contenido del file sea valido | |
|
511 | if changeDir_flag: #si al buscar un file cambie de directorio ya no espero y sigo con el siguiente file | |
|
512 | print "\tsearching next \"%s\" file ..." % filename | |
|
513 | changeDir_flag = False | |
|
514 | continue | |
|
460 | 515 | |
|
461 | fileSize = os.path.getsize( file ) | |
|
462 | currentSize = fileSize - fp.tell() | |
|
516 | for nTries in range( self.__nTries ): | |
|
517 | print "\twaiting for the First Header block of \"%s\" file, try %03d ..." % ( filename, nTries+1 ) | |
|
518 | time.sleep( self.__delay ) | |
|
519 | ||
|
520 | currentSize = os.path.getsize( file ) | |
|
463 | 521 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize |
|
464 | 522 | |
|
465 | 523 | if currentSize > neededSize: |
|
466 |
file |
|
|
467 | break | |
|
468 | ||
|
469 | fp.close() | |
|
470 | ||
|
471 | if bChangeDir: #si al buscar un file cambie de directorio ya no espero y salgo del bucle while | |
|
472 | print "\tsearching next \"%s\" file ..." % filename | |
|
524 | fileOk_flag = True | |
|
473 | 525 | break |
|
474 | 526 | |
|
475 | print "\twaiting for block of \"%s\" file ..." % filename | |
|
476 | time.sleep( self.__delay ) | |
|
477 | ||
|
478 | if fileStatus == 1: | |
|
527 | if fileOk_flag: #si encontro un file valido sale del bucle y deja de buscar | |
|
479 | 528 | break |
|
480 | 529 | |
|
481 | 530 | print "Skipping the file \"%s\" due to this files is empty" % filename |
|
482 | 531 | countFiles = 0 |
|
483 | 532 | |
|
484 | ||
|
485 | if fileStatus == 1: | |
|
486 | self.fileSize = fileSize | |
|
533 | if fileOk_flag: | |
|
534 | self.fileSize = os.path.getsize( file ) #fileSize | |
|
487 | 535 | self.filename = file |
|
488 | 536 | self.__flagIsNewFile = 1 |
|
489 | self.__fp = fp | |
|
537 | if self.__fp != None: self.__fp.close() | |
|
538 | self.__fp = open(file) | |
|
490 | 539 | self.noMoreFiles = 0 |
|
491 | 540 | print 'Setting the file: %s' % file |
|
492 | 541 | else: |
@@ -496,7 +545,7 class VoltageReader(DataReader): | |||
|
496 | 545 | self.noMoreFiles = 1 |
|
497 | 546 | print 'No more Files' |
|
498 | 547 | |
|
499 |
return file |
|
|
548 | return fileOk_flag | |
|
500 | 549 | |
|
501 | 550 | |
|
502 | 551 | def __setNextFileOffline(self): |
@@ -508,6 +557,7 class VoltageReader(DataReader): | |||
|
508 | 557 | |
|
509 | 558 | if not(idFile < len(self.filenameList)): |
|
510 | 559 | self.noMoreFiles = 1 |
|
560 | print 'No more Files' | |
|
511 | 561 | return 0 |
|
512 | 562 | |
|
513 | 563 | filename = self.filenameList[idFile] |
@@ -537,6 +587,7 class VoltageReader(DataReader): | |||
|
537 | 587 | |
|
538 | 588 | return 1 |
|
539 | 589 | |
|
590 | ||
|
540 | 591 |
def __setNextFile( |
|
541 | 592 | """ |
|
542 | 593 | Determina el siguiente file a leer y si hay uno disponible lee el First Header |
@@ -560,11 +611,14 class VoltageReader(DataReader): | |||
|
560 | 611 | else: |
|
561 | 612 | newFile = self.__setNextFileOffline() |
|
562 | 613 | |
|
614 | if self.noMoreFiles: | |
|
615 | sys.exit(0) | |
|
616 | ||
|
563 | 617 | if not(newFile): |
|
564 | 618 | return 0 |
|
565 | 619 | |
|
566 | 620 | self.__readFirstHeader() |
|
567 | ||
|
621 | self.nBlocks = 0 | |
|
568 | 622 | return 1 |
|
569 | 623 | |
|
570 | 624 | |
@@ -594,15 +648,22 class VoltageReader(DataReader): | |||
|
594 | 648 | if ( currentSize >= neededSize ): |
|
595 | 649 | self.__rdBasicHeader() |
|
596 | 650 | return 1 |
|
597 | elif self.online: | |
|
598 | nTries = 0 | |
|
599 | while( nTries < self.__nTries ): | |
|
600 | nTries += 1 | |
|
601 | print "Waiting for the next block, try %03d ..." % nTries | |
|
651 | ||
|
652 | #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido | |
|
653 | elif (self.nBlocks != self.m_ProcessingHeader.dataBlocksPerFile) and self.online: | |
|
654 | for nTries in range( self.__nTries ): | |
|
655 | ||
|
656 | fpointer = self.__fp.tell() | |
|
657 | self.__fp.close() | |
|
658 | ||
|
659 | print "\tWaiting for the next block, try %03d ..." % (nTries+1) | |
|
602 | 660 | time.sleep( self.__delay ) |
|
603 | 661 | |
|
604 |
|
|
|
605 | currentSize = fileSize - self.__fp.tell() | |
|
662 | self.__fp = open( self.filename, 'rb' ) | |
|
663 | self.__fp.seek( fpointer ) | |
|
664 | ||
|
665 | self.fileSize = os.path.getsize( self.filename ) | |
|
666 | currentSize = self.fileSize - self.__fp.tell() | |
|
606 | 667 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize |
|
607 | 668 | |
|
608 | 669 | if ( currentSize >= neededSize ): |
@@ -619,10 +680,11 class VoltageReader(DataReader): | |||
|
619 | 680 | |
|
620 | 681 | if deltaTime > self.__maxTimeStep: |
|
621 | 682 | self.flagResetProcessing = 1 |
|
622 | self.nReadBlocks = 0 | |
|
683 | #self.nReadBlocks = 0 | |
|
623 | 684 | |
|
624 | 685 | return 1 |
|
625 | 686 | |
|
687 | ||
|
626 | 688 | def __readBlock(self): |
|
627 | 689 | """ |
|
628 | 690 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
@@ -630,71 +692,66 class VoltageReader(DataReader): | |||
|
630 | 692 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
631 | 693 | es seteado a 0 |
|
632 | 694 | |
|
633 | ||
|
634 | 695 | Inputs: |
|
635 | 696 | None |
|
636 | 697 | |
|
637 | 698 | Return: |
|
638 | 699 | None |
|
639 | 700 | |
|
640 |
|
|
|
641 | ||
|
701 | Affected: | |
|
642 | 702 | self.__datablockIndex |
|
643 | ||
|
644 | 703 | self.datablock |
|
645 | ||
|
646 | 704 | self.__flagIsNewFile |
|
647 | ||
|
648 | 705 | self.idProfile |
|
649 | ||
|
650 | 706 | self.flagIsNewBlock |
|
651 | ||
|
652 | 707 | self.nReadBlocks |
|
653 | 708 | |
|
709 | Exceptions: | |
|
710 | Si un bloque leido no es un bloque valido | |
|
654 | 711 | """ |
|
655 | ||
|
656 | #pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels | |
|
657 | ||
|
712 | blockOk_flag = False | |
|
658 | 713 | fpointer = self.__fp.tell() |
|
659 | 714 | |
|
660 | 715 | junk = numpy.fromfile( self.__fp, self.__dataType, self.__pts2read ) |
|
661 | 716 | |
|
662 | 717 | if self.online: |
|
663 | 718 | if junk.size != self.__blocksize: |
|
664 |
nTries |
|
|
665 | while( nTries < self.__nTries ): | |
|
666 | nTries += 1 | |
|
667 | print "Waiting for the next block, try %03d ..." % nTries | |
|
719 | for nTries in range( self.__nTries ): | |
|
720 | print "\tWaiting for the next block, try %03d ..." % (nTries+1) | |
|
668 | 721 | time.sleep( self.__delay ) |
|
669 | 722 | self.__fp.seek( fpointer ) |
|
670 | 723 | fpointer = self.__fp.tell() |
|
671 | 724 | junk = numpy.fromfile( self.__fp, self.__dataType, self.__pts2read ) |
|
672 | 725 | if junk.size == self.__blocksize: |
|
673 |
|
|
|
726 | blockOk_flag = True | |
|
674 | 727 | break |
|
675 | if nTries > 0: | |
|
676 | return | |
|
677 | 728 | |
|
729 | if not( blockOk_flag ): | |
|
730 | return 0 | |
|
731 | ||
|
732 | try: | |
|
678 | 733 | junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) ) |
|
734 | except: | |
|
735 | print "Data file %s is invalid" % self.filename | |
|
736 | return 0 | |
|
679 | 737 | |
|
680 | data = junk['real'] + junk['imag']*1j | |
|
738 | #data = junk['real'] + junk['imag']*1j | |
|
739 | self.datablock = junk['real'] + junk['imag']*1j | |
|
681 | 740 | |
|
682 | 741 | self.__datablockIndex = 0 |
|
683 | ||
|
684 | self.datablock = data | |
|
685 | ||
|
686 | 742 | self.__flagIsNewFile = 0 |
|
687 | ||
|
688 | 743 | self.idProfile = 0 |
|
689 | ||
|
690 | 744 | self.flagIsNewBlock = 1 |
|
691 | 745 | |
|
692 | 746 | self.nReadBlocks += 1 |
|
747 | self.nBlocks += 1 | |
|
748 | ||
|
749 | return 1 | |
|
750 | ||
|
693 | 751 | |
|
694 | 752 | def __hasNotDataInBuffer(self): |
|
695 | 753 | if self.__datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
696 | 754 | return 1 |
|
697 | ||
|
698 | 755 | return 0 |
|
699 | 756 | |
|
700 | 757 | |
@@ -715,7 +772,6 class VoltageReader(DataReader): | |||
|
715 | 772 | filename : el ultimo file de una determinada carpeta |
|
716 | 773 | directory : eL directorio donde esta el file encontrado |
|
717 | 774 | """ |
|
718 | ||
|
719 | 775 | print "Searching files ..." |
|
720 | 776 | |
|
721 | 777 | dirList = [] |
@@ -728,7 +784,7 class VoltageReader(DataReader): | |||
|
728 | 784 | |
|
729 | 785 | dirList = sorted( dirList, key=str.lower ) #para que quede ordenado al margen de si el nombre esta en mayusculas o minusculas, utilizo la funcion sorted |
|
730 | 786 | if len(dirList) > 0 : |
|
731 | directory = dirList[-1] | |
|
787 | directory = dirList[-1] #me quedo con el ultimo directorio de una carpeta | |
|
732 | 788 | else: |
|
733 | 789 | year = startDateTime.timetuple().tm_year |
|
734 | 790 | doy = startDateTime.timetuple().tm_yday |
@@ -804,7 +860,6 class VoltageReader(DataReader): | |||
|
804 | 860 | Excepciones: |
|
805 | 861 | |
|
806 | 862 | """ |
|
807 | ||
|
808 | 863 | print "Searching files ..." |
|
809 | 864 | |
|
810 | 865 | dirList = [] |
@@ -863,13 +918,7 class VoltageReader(DataReader): | |||
|
863 | 918 | |
|
864 | 919 | file = os.path.join( path, dirfilename, filename ) |
|
865 | 920 | |
|
866 | nTries = 0 | |
|
867 | while(True): | |
|
868 | ||
|
869 | nTries += 1 | |
|
870 | if nTries > self.__nTries: | |
|
871 | break | |
|
872 | ||
|
921 | for nTries in range( self.__nTries+1 ): | |
|
873 | 922 | try: |
|
874 | 923 | fp = open( file,'rb' ) #lectura binaria |
|
875 | 924 | except: |
@@ -881,11 +930,15 class VoltageReader(DataReader): | |||
|
881 | 930 | print "The file %s is empty" % filename |
|
882 | 931 | |
|
883 | 932 | fp.close() |
|
933 | fp = None | |
|
884 | 934 | |
|
885 | 935 | if m_BasicHeader.size > 24: |
|
886 | 936 | break |
|
887 | 937 | |
|
888 | print 'waiting for new block: try %02d' % ( nTries ) | |
|
938 | if nTries >= self.__nTries: #si ya espero la cantidad de veces necesarias entonces ya no vuelve a esperar | |
|
939 | break | |
|
940 | ||
|
941 | print '\twaiting for new block: try %02d' % ( nTries ) | |
|
889 | 942 | time.sleep( self.__delay) |
|
890 | 943 | |
|
891 | 944 | if m_BasicHeader.size <= 24: |
@@ -938,24 +991,30 class VoltageReader(DataReader): | |||
|
938 | 991 | self.online |
|
939 | 992 | """ |
|
940 | 993 | if online: |
|
941 |
|
|
|
942 | while( nTries < self.__nTries ): | |
|
943 | nTries += 1 | |
|
994 | fileOK_flag = False | |
|
944 | 995 |
|
|
945 | year, doy, set, filename, dirfilename = self.__searchFilesOnLine( path, startDateTime, ext ) | |
|
946 | if filename == None: | |
|
947 | 996 |
|
|
948 | print "Searching first file in \"%s\", try %03d ..." % ( file, nTries ) | |
|
949 | time.sleep( self.__delay ) | |
|
950 | else: | |
|
997 | ||
|
998 | for nTries in range( self.__nTries+1 ): #espera por el 1er file | |
|
999 | year, doy, set, filename, dirfilename = self.__searchFilesOnLine( path, startDateTime, ext ) | |
|
1000 | ||
|
1001 | if filename != None: | |
|
1002 | if isFileOK( os.path.join( path,dirfilename,filename ) ): | |
|
1003 | fileOK_flag = True | |
|
951 | 1004 | break |
|
952 | 1005 | |
|
953 | if filename == None: | |
|
954 |
|
|
|
1006 | if nTries >= self.__nTries: #si ya espero la cantidad de veces necesarias entonces ya no vuelve a esperar | |
|
1007 | break | |
|
1008 | ||
|
1009 | print "Searching first file in \"%s\", try %03d ..." % ( file, nTries+1 ) | |
|
1010 | time.sleep( self.__delay ) | |
|
1011 | ||
|
1012 | if not( fileOK_flag ): #filename == None: | |
|
1013 | print "No files on line or invalid first file" | |
|
955 | 1014 | return 0 |
|
956 | 1015 | |
|
957 | 1016 | if self.__initFilesOnline( path, dirfilename, filename ) == 0: |
|
958 | print "The file %s hasn't enough data" | |
|
1017 | print "The file %s hasn't enough data" % filename | |
|
959 | 1018 | return 0 |
|
960 | 1019 | |
|
961 | 1020 | self.__year = year |
@@ -1014,7 +1073,8 class VoltageReader(DataReader): | |||
|
1014 | 1073 | if not(self.__setNewBlock()): |
|
1015 | 1074 | return 0 |
|
1016 | 1075 | |
|
1017 | self.__readBlock() | |
|
1076 | if not( self.__readBlock() ): | |
|
1077 | return 0 | |
|
1018 | 1078 | |
|
1019 | 1079 | self.__lastUTTime = self.m_BasicHeader.utc |
|
1020 | 1080 | |
@@ -1045,12 +1105,16 class VoltageReader(DataReader): | |||
|
1045 | 1105 | self.flagIsNewBlock |
|
1046 | 1106 | self.idProfile |
|
1047 | 1107 | """ |
|
1108 | if self.noMoreFiles: return 0 | |
|
1109 | ||
|
1048 | 1110 | self.flagResetProcessing = 0 |
|
1049 | 1111 | self.flagIsNewBlock = 0 |
|
1050 | 1112 | |
|
1051 | 1113 | if self.__hasNotDataInBuffer(): |
|
1052 | 1114 | |
|
1053 | self.readNextBlock() | |
|
1115 | if not( self.readNextBlock() ): | |
|
1116 | self.__setNextFile() | |
|
1117 | return 0 | |
|
1054 | 1118 | |
|
1055 | 1119 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() |
|
1056 | 1120 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
@@ -1061,12 +1125,17 class VoltageReader(DataReader): | |||
|
1061 | 1125 | |
|
1062 | 1126 | if self.noMoreFiles == 1: |
|
1063 | 1127 | print 'Process finished' |
|
1064 |
return |
|
|
1128 | return 0 | |
|
1065 | 1129 | |
|
1066 | 1130 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1067 | 1131 | |
|
1132 | if self.datablock == None: | |
|
1133 | self.m_Voltage.flagNoData = True | |
|
1134 | return 0 | |
|
1135 | ||
|
1068 | 1136 | time = self.m_BasicHeader.utc + self.__datablockIndex * self.__ippSeconds |
|
1069 |
self. |
|
|
1137 | self.__utc = time | |
|
1138 | #self.m_Voltage.m_BasicHeader.utc = time | |
|
1070 | 1139 | |
|
1071 | 1140 | self.m_Voltage.flagNoData = False |
|
1072 | 1141 | self.m_Voltage.flagResetProcessing = self.flagResetProcessing |
@@ -1079,7 +1148,7 class VoltageReader(DataReader): | |||
|
1079 | 1148 | |
|
1080 | 1149 | #call setData - to Data Object |
|
1081 | 1150 | |
|
1082 | return self.m_Voltage.data | |
|
1151 | return 1 #self.m_Voltage.data | |
|
1083 | 1152 | |
|
1084 | 1153 | |
|
1085 | 1154 |
class VoltageWriter( |
@@ -1214,6 +1283,7 class VoltageWriter( DataWriter ): | |||
|
1214 | 1283 | |
|
1215 | 1284 | self.m_ProcessingHeader.write(fp) |
|
1216 | 1285 | |
|
1286 | ||
|
1217 | 1287 |
def __setNextFile( |
|
1218 | 1288 | """ |
|
1219 | 1289 | Determina el siguiente file que sera escrito |
@@ -1247,7 +1317,12 class VoltageWriter( DataWriter ): | |||
|
1247 | 1317 | os.mkdir(tmp) |
|
1248 | 1318 | """ |
|
1249 | 1319 | ################################## |
|
1250 | if self.m_BasicHeader.size <= 24: return 0 #no existe la suficiente data para ser escrita | |
|
1320 | """ | |
|
1321 | if self.m_BasicHeader.size <= 24: | |
|
1322 | self.__fp.close() | |
|
1323 | self.__fp = None | |
|
1324 | return 0 #no existe la suficiente data para ser escrita | |
|
1325 | """ | |
|
1251 | 1326 | |
|
1252 | 1327 | timeTuple = time.localtime( self.m_Voltage.m_BasicHeader.utc ) # utc from m_Voltage |
|
1253 | 1328 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
@@ -1319,6 +1394,7 class VoltageWriter( DataWriter ): | |||
|
1319 | 1394 | |
|
1320 | 1395 | return 1 |
|
1321 | 1396 | |
|
1397 | ||
|
1322 | 1398 |
def __writeBlock( |
|
1323 | 1399 | """ |
|
1324 | 1400 | Escribe el buffer en el file designado |
@@ -1342,15 +1418,10 class VoltageWriter( DataWriter ): | |||
|
1342 | 1418 | data.tofile( self.__fp ) |
|
1343 | 1419 | |
|
1344 | 1420 | self.datablock.fill(0) |
|
1345 | ||
|
1346 | 1421 | self.__datablockIndex = 0 |
|
1347 | ||
|
1348 | 1422 | self.__flagIsNewFile = 0 |
|
1349 | ||
|
1350 | 1423 | self.flagIsNewBlock = 1 |
|
1351 | ||
|
1352 | 1424 | self.nWriteBlocks += 1 |
|
1353 | ||
|
1354 | 1425 | self.__blocksCounter += 1 |
|
1355 | 1426 | |
|
1356 | 1427 | |
@@ -1366,14 +1437,12 class VoltageWriter( DataWriter ): | |||
|
1366 | 1437 | return 0 |
|
1367 | 1438 | |
|
1368 | 1439 | self.__writeBlock() |
|
1369 | ||
|
1370 | 1440 | return 1 |
|
1371 | 1441 | |
|
1372 | 1442 | |
|
1373 | 1443 |
def __hasAllDataInBuffer( |
|
1374 | 1444 | if self.__datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
1375 | 1445 | return 1 |
|
1376 | ||
|
1377 | 1446 | return 0 |
|
1378 | 1447 | |
|
1379 | 1448 | |
@@ -1397,7 +1466,6 class VoltageWriter( DataWriter ): | |||
|
1397 | 1466 | if self.m_Voltage.flagResetProcessing: |
|
1398 | 1467 | |
|
1399 | 1468 | self.datablock.fill(0) |
|
1400 | ||
|
1401 | 1469 | self.__datablockIndex = 0 |
|
1402 | 1470 | self.__setNextFile() |
|
1403 | 1471 | |
@@ -1406,7 +1474,6 class VoltageWriter( DataWriter ): | |||
|
1406 | 1474 | self.__datablockIndex += 1 |
|
1407 | 1475 | |
|
1408 | 1476 | if self.__hasAllDataInBuffer(): |
|
1409 | ||
|
1410 | 1477 | self.__getHeader() |
|
1411 | 1478 | self.writeNextBlock() |
|
1412 | 1479 | |
@@ -1556,8 +1623,9 class VoltageWriter( DataWriter ): | |||
|
1556 | 1623 | |
|
1557 | 1624 | self.datablock = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex')) |
|
1558 | 1625 | |
|
1559 |
|
|
|
1560 |
|
|
|
1626 | if not( self.__setNextFile() ): | |
|
1627 | return 0 | |
|
1628 | ||
|
1561 | 1629 | return 1 |
|
1562 | 1630 | |
|
1563 | 1631 |
General Comments 0
You need to be logged in to leave comments.
Login now