@@ -24,6 +24,7 DTYPES = { | |||
|
24 | 24 | 'Spectra': '.pdata' |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | ||
|
27 | 28 | def MPProject(project, n=cpu_count()): |
|
28 | 29 | ''' |
|
29 | 30 | Project wrapper to run schain in n processes |
@@ -34,8 +35,8 def MPProject(project, n=cpu_count()): | |||
|
34 | 35 | dt1 = op.getParameterValue('startDate') |
|
35 | 36 | dt2 = op.getParameterValue('endDate') |
|
36 | 37 | days = (dt2 - dt1).days |
|
37 | ||
|
38 | for day in range(days+1): | |
|
38 | ||
|
39 | for day in range(days + 1): | |
|
39 | 40 | skip = 0 |
|
40 | 41 | cursor = 0 |
|
41 | 42 | processes = [] |
@@ -43,17 +44,17 def MPProject(project, n=cpu_count()): | |||
|
43 | 44 | dt_str = dt.strftime('%Y/%m/%d') |
|
44 | 45 | reader = JRODataReader() |
|
45 | 46 | paths, files = reader.searchFilesOffLine(path=rconf.path, |
|
46 | startDate=dt, | |
|
47 | endDate=dt, | |
|
48 | ext=DTYPES[rconf.datatype]) | |
|
47 | startDate=dt, | |
|
48 | endDate=dt, | |
|
49 | ext=DTYPES[rconf.datatype]) | |
|
49 | 50 | nFiles = len(files) |
|
50 | 51 | if nFiles == 0: |
|
51 | 52 | continue |
|
52 |
skip = int(math.ceil(nFiles/n)) |
|
|
53 | while nFiles > cursor*skip: | |
|
54 |
rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, |
|
|
55 | skip=skip) | |
|
56 |
p = project.clone() |
|
|
53 | skip = int(math.ceil(nFiles / n)) | |
|
54 | while nFiles > cursor * skip: | |
|
55 | rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, | |
|
56 | skip=skip) | |
|
57 | p = project.clone() | |
|
57 | 58 | p.start() |
|
58 | 59 | processes.append(p) |
|
59 | 60 | cursor += 1 |
@@ -72,6 +73,7 def MPProject(project, n=cpu_count()): | |||
|
72 | 73 | |
|
73 | 74 | time.sleep(3) |
|
74 | 75 | |
|
76 | ||
|
75 | 77 | class ParameterConf(): |
|
76 | 78 | |
|
77 | 79 | id = None |
@@ -108,7 +110,7 class ParameterConf(): | |||
|
108 | 110 | return self.__formated_value |
|
109 | 111 | |
|
110 | 112 | if value == '': |
|
111 | raise ValueError, '%s: This parameter value is empty' %self.name | |
|
113 | raise ValueError, '%s: This parameter value is empty' % self.name | |
|
112 | 114 | |
|
113 | 115 | if format == 'list': |
|
114 | 116 | strList = value.split(',') |
@@ -174,16 +176,16 class ParameterConf(): | |||
|
174 | 176 | new_value = ast.literal_eval(value) |
|
175 | 177 | |
|
176 | 178 | if type(new_value) not in (tuple, list): |
|
177 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
179 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
178 | 180 | |
|
179 | 181 | if type(new_value[0]) not in (tuple, list): |
|
180 | 182 | if len(new_value) != 2: |
|
181 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
183 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
182 | 184 | new_value = [new_value] |
|
183 | 185 | |
|
184 | 186 | for thisPair in new_value: |
|
185 | 187 | if len(thisPair) != 2: |
|
186 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
188 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
187 | 189 | |
|
188 | 190 | self.__formated_value = new_value |
|
189 | 191 | |
@@ -253,13 +255,14 class ParameterConf(): | |||
|
253 | 255 | self.value = parmElement.get('value') |
|
254 | 256 | self.format = str.lower(parmElement.get('format')) |
|
255 | 257 | |
|
256 | #Compatible with old signal chain version | |
|
258 | # Compatible with old signal chain version | |
|
257 | 259 | if self.format == 'int' and self.name == 'idfigure': |
|
258 | 260 | self.name = 'id' |
|
259 | 261 | |
|
260 | 262 | def printattr(self): |
|
261 | 263 | |
|
262 | print 'Parameter[%s]: name = %s, value = %s, format = %s' %(self.id, self.name, self.value, self.format) | |
|
264 | print 'Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format) | |
|
265 | ||
|
263 | 266 | |
|
264 | 267 | class OperationConf(): |
|
265 | 268 | |
@@ -279,10 +282,9 class OperationConf(): | |||
|
279 | 282 | self.priority = None |
|
280 | 283 | self.type = 'self' |
|
281 | 284 | |
|
282 | ||
|
283 | 285 | def __getNewId(self): |
|
284 | 286 | |
|
285 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
|
287 | return int(self.id) * 10 + len(self.parmConfObjList) + 1 | |
|
286 | 288 | |
|
287 | 289 | def updateId(self, new_id): |
|
288 | 290 | |
@@ -291,7 +293,7 class OperationConf(): | |||
|
291 | 293 | n = 1 |
|
292 | 294 | for parmObj in self.parmConfObjList: |
|
293 | 295 | |
|
294 | idParm = str(int(new_id)*10 + n) | |
|
296 | idParm = str(int(new_id) * 10 + n) | |
|
295 | 297 | parmObj.updateId(idParm) |
|
296 | 298 | |
|
297 | 299 | n += 1 |
@@ -329,15 +331,14 class OperationConf(): | |||
|
329 | 331 | def getParameterValue(self, parameterName): |
|
330 | 332 | |
|
331 | 333 | parameterObj = self.getParameterObj(parameterName) |
|
332 | ||
|
334 | ||
|
333 | 335 | # if not parameterObj: |
|
334 | 336 | # return None |
|
335 | ||
|
337 | ||
|
336 | 338 | value = parameterObj.getValue() |
|
337 | 339 | |
|
338 | 340 | return value |
|
339 | 341 | |
|
340 | ||
|
341 | 342 | def getKwargs(self): |
|
342 | 343 | |
|
343 | 344 | kwargs = {} |
@@ -367,7 +368,7 class OperationConf(): | |||
|
367 | 368 | self.parmConfObjList = [] |
|
368 | 369 | |
|
369 | 370 | def addParameter(self, name, value, format='str'): |
|
370 | ||
|
371 | ||
|
371 | 372 | if value is None: |
|
372 | 373 | return None |
|
373 | 374 | id = self.__getNewId() |
@@ -405,8 +406,8 class OperationConf(): | |||
|
405 | 406 | self.type = opElement.get('type') |
|
406 | 407 | self.priority = opElement.get('priority') |
|
407 | 408 | |
|
408 | #Compatible with old signal chain version | |
|
409 | #Use of 'run' method instead 'init' | |
|
409 | # Compatible with old signal chain version | |
|
410 | # Use of 'run' method instead 'init' | |
|
410 | 411 | if self.type == 'self' and self.name == 'init': |
|
411 | 412 | self.name = 'run' |
|
412 | 413 | |
@@ -418,8 +419,8 class OperationConf(): | |||
|
418 | 419 | parmConfObj = ParameterConf() |
|
419 | 420 | parmConfObj.readXml(parmElement) |
|
420 | 421 | |
|
421 | #Compatible with old signal chain version | |
|
422 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
|
422 | # Compatible with old signal chain version | |
|
423 | # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
|
423 | 424 | if self.type != 'self' and self.name == 'Plot': |
|
424 | 425 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
425 | 426 | self.name = parmConfObj.value |
@@ -429,22 +430,21 class OperationConf(): | |||
|
429 | 430 | |
|
430 | 431 | def printattr(self): |
|
431 | 432 | |
|
432 | print '%s[%s]: name = %s, type = %s, priority = %s' %(self.ELEMENTNAME, | |
|
433 | self.id, | |
|
434 | self.name, | |
|
435 | self.type, | |
|
436 | self.priority) | |
|
433 | print '%s[%s]: name = %s, type = %s, priority = %s' % (self.ELEMENTNAME, | |
|
434 | self.id, | |
|
435 | self.name, | |
|
436 | self.type, | |
|
437 | self.priority) | |
|
437 | 438 | |
|
438 | 439 | for parmConfObj in self.parmConfObjList: |
|
439 | 440 | parmConfObj.printattr() |
|
440 | 441 | |
|
441 | 442 | def createObject(self, plotter_queue=None): |
|
442 | 443 | |
|
443 | ||
|
444 | 444 | if self.type == 'self': |
|
445 | 445 | raise ValueError, 'This operation type cannot be created' |
|
446 | 446 | |
|
447 |
if self.type == 'plotter': |
|
|
447 | if self.type == 'plotter': | |
|
448 | 448 | if not plotter_queue: |
|
449 | 449 | raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)' |
|
450 | 450 | |
@@ -489,11 +489,11 class ProcUnitConf(): | |||
|
489 | 489 | |
|
490 | 490 | def __getPriority(self): |
|
491 | 491 | |
|
492 | return len(self.opConfObjList)+1 | |
|
492 | return len(self.opConfObjList) + 1 | |
|
493 | 493 | |
|
494 | 494 | def __getNewId(self): |
|
495 | 495 | |
|
496 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
|
496 | return int(self.id) * 10 + len(self.opConfObjList) + 1 | |
|
497 | 497 | |
|
498 | 498 | def getElementName(self): |
|
499 | 499 | |
@@ -505,18 +505,17 class ProcUnitConf(): | |||
|
505 | 505 | |
|
506 | 506 | def updateId(self, new_id, parentId=parentId): |
|
507 | 507 | |
|
508 | new_id = int(parentId) * 10 + (int(self.id) % 10) | |
|
509 | new_inputId = int(parentId) * 10 + (int(self.inputId) % 10) | |
|
508 | 510 | |
|
509 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
|
510 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
|
511 | ||
|
512 | #If this proc unit has not inputs | |
|
511 | # If this proc unit has not inputs | |
|
513 | 512 | if self.inputId == '0': |
|
514 | 513 | new_inputId = 0 |
|
515 | 514 | |
|
516 | 515 | n = 1 |
|
517 | 516 | for opConfObj in self.opConfObjList: |
|
518 | 517 | |
|
519 | idOp = str(int(new_id)*10 + n) | |
|
518 | idOp = str(int(new_id) * 10 + n) | |
|
520 | 519 | opConfObj.updateId(idOp) |
|
521 | 520 | |
|
522 | 521 | n += 1 |
@@ -525,7 +524,6 class ProcUnitConf(): | |||
|
525 | 524 | self.id = str(new_id) |
|
526 | 525 | self.inputId = str(new_inputId) |
|
527 | 526 | |
|
528 | ||
|
529 | 527 | def getInputId(self): |
|
530 | 528 | |
|
531 | 529 | return self.inputId |
@@ -559,18 +557,18 class ProcUnitConf(): | |||
|
559 | 557 | |
|
560 | 558 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
561 | 559 | |
|
562 | #Compatible with old signal chain version | |
|
563 | if datatype==None and name==None: | |
|
560 | # Compatible with old signal chain version | |
|
561 | if datatype == None and name == None: | |
|
564 | 562 | raise ValueError, 'datatype or name should be defined' |
|
565 | 563 | |
|
566 | if name==None: | |
|
564 | if name == None: | |
|
567 | 565 | if 'Proc' in datatype: |
|
568 | 566 | name = datatype |
|
569 | 567 | else: |
|
570 | name = '%sProc' %(datatype) | |
|
568 | name = '%sProc' % (datatype) | |
|
571 | 569 | |
|
572 | if datatype==None: | |
|
573 | datatype = name.replace('Proc','') | |
|
570 | if datatype == None: | |
|
571 | datatype = name.replace('Proc', '') | |
|
574 | 572 | |
|
575 | 573 | self.id = str(id) |
|
576 | 574 | self.name = name |
@@ -650,16 +648,15 class ProcUnitConf(): | |||
|
650 | 648 | |
|
651 | 649 | def printattr(self): |
|
652 | 650 | |
|
653 | print '%s[%s]: name = %s, datatype = %s, inputId = %s' %(self.ELEMENTNAME, | |
|
654 | self.id, | |
|
655 | self.name, | |
|
656 | self.datatype, | |
|
657 | self.inputId) | |
|
658 | ||
|
651 | print '%s[%s]: name = %s, datatype = %s, inputId = %s' % (self.ELEMENTNAME, | |
|
652 | self.id, | |
|
653 | self.name, | |
|
654 | self.datatype, | |
|
655 | self.inputId) | |
|
656 | ||
|
659 | 657 | for opConfObj in self.opConfObjList: |
|
660 | 658 | opConfObj.printattr() |
|
661 | 659 | |
|
662 | ||
|
663 | 660 | def getKwargs(self): |
|
664 | 661 | |
|
665 | 662 | opObj = self.opConfObjList[0] |
@@ -675,10 +672,11 class ProcUnitConf(): | |||
|
675 | 672 | |
|
676 | 673 | for opConfObj in self.opConfObjList: |
|
677 | 674 | |
|
678 | if opConfObj.type=='self' and self.name=='run': | |
|
675 | if opConfObj.type == 'self' and self.name == 'run': | |
|
679 | 676 | continue |
|
680 | elif opConfObj.type=='self': | |
|
681 |
procUnitObj.addOperationKwargs( |
|
|
677 | elif opConfObj.type == 'self': | |
|
678 | procUnitObj.addOperationKwargs( | |
|
679 | opConfObj.id, **opConfObj.getKwargs()) | |
|
682 | 680 | continue |
|
683 | 681 | |
|
684 | 682 | opObj = opConfObj.createObject(plotter_queue) |
@@ -704,10 +702,10 class ProcUnitConf(): | |||
|
704 | 702 | |
|
705 | 703 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
706 | 704 | |
|
707 |
sts = self.procUnitObj.call(opType |
|
|
708 |
opName |
|
|
709 |
opId |
|
|
710 | ||
|
705 | sts = self.procUnitObj.call(opType=opConfObj.type, | |
|
706 | opName=opConfObj.name, | |
|
707 | opId=opConfObj.id) | |
|
708 | ||
|
711 | 709 | is_ok = is_ok or sts |
|
712 | 710 | |
|
713 | 711 | return is_ok |
@@ -725,6 +723,7 class ProcUnitConf(): | |||
|
725 | 723 | |
|
726 | 724 | return |
|
727 | 725 | |
|
726 | ||
|
728 | 727 | class ReadUnitConf(ProcUnitConf): |
|
729 | 728 | |
|
730 | 729 | path = None |
@@ -754,17 +753,17 class ReadUnitConf(ProcUnitConf): | |||
|
754 | 753 | def setup(self, id, name, datatype, path='', startDate='', endDate='', |
|
755 | 754 | startTime='', endTime='', parentId=None, server=None, **kwargs): |
|
756 | 755 | |
|
757 | #Compatible with old signal chain version | |
|
758 | if datatype==None and name==None: | |
|
756 | # Compatible with old signal chain version | |
|
757 | if datatype == None and name == None: | |
|
759 | 758 | raise ValueError, 'datatype or name should be defined' |
|
760 | ||
|
761 | if name==None: | |
|
759 | ||
|
760 | if name == None: | |
|
762 | 761 | if 'Reader' in datatype: |
|
763 | 762 | name = datatype |
|
764 | 763 | else: |
|
765 | name = '%sReader' %(datatype) | |
|
766 | if datatype==None: | |
|
767 | datatype = name.replace('Reader','') | |
|
764 | name = '%sReader' % (datatype) | |
|
765 | if datatype == None: | |
|
766 | datatype = name.replace('Reader', '') | |
|
768 | 767 | |
|
769 | 768 | self.id = id |
|
770 | 769 | self.name = name |
@@ -787,15 +786,16 class ReadUnitConf(ProcUnitConf): | |||
|
787 | 786 | if 'Reader' in datatype: |
|
788 | 787 | self.name = datatype |
|
789 | 788 | else: |
|
790 | self.name = '%sReader' %(datatype) | |
|
789 | self.name = '%sReader' % (datatype) | |
|
791 | 790 | self.datatype = self.name.replace('Reader', '') |
|
792 | 791 | |
|
793 |
attrs = ('path', 'startDate', 'endDate', |
|
|
794 | ||
|
792 | attrs = ('path', 'startDate', 'endDate', | |
|
793 | 'startTime', 'endTime', 'parentId') | |
|
794 | ||
|
795 | 795 | for attr in attrs: |
|
796 | 796 | if attr in kwargs: |
|
797 | 797 | setattr(self, attr, kwargs.pop(attr)) |
|
798 | ||
|
798 | ||
|
799 | 799 | self.inputId = '0' |
|
800 | 800 | self.updateRunOperation(**kwargs) |
|
801 | 801 | |
@@ -808,21 +808,26 class ReadUnitConf(ProcUnitConf): | |||
|
808 | 808 | |
|
809 | 809 | def addRunOperation(self, **kwargs): |
|
810 | 810 | |
|
811 |
opObj = self.addOperation(name |
|
|
811 | opObj = self.addOperation(name='run', optype='self') | |
|
812 | 812 | |
|
813 | 813 | if self.server is None: |
|
814 | opObj.addParameter(name='datatype', value=self.datatype, format='str') | |
|
814 | opObj.addParameter( | |
|
815 | name='datatype', value=self.datatype, format='str') | |
|
815 | 816 | opObj.addParameter(name='path', value=self.path, format='str') |
|
816 | opObj.addParameter(name='startDate', value=self.startDate, format='date') | |
|
817 |
|
|
|
818 | opObj.addParameter(name='startTime', value=self.startTime, format='time') | |
|
819 |
|
|
|
820 | ||
|
817 | opObj.addParameter( | |
|
818 | name='startDate', value=self.startDate, format='date') | |
|
819 | opObj.addParameter( | |
|
820 | name='endDate', value=self.endDate, format='date') | |
|
821 | opObj.addParameter( | |
|
822 | name='startTime', value=self.startTime, format='time') | |
|
823 | opObj.addParameter( | |
|
824 | name='endTime', value=self.endTime, format='time') | |
|
825 | ||
|
821 | 826 | for key, value in kwargs.items(): |
|
822 |
opObj.addParameter(name=key, value=value, |
|
|
827 | opObj.addParameter(name=key, value=value, | |
|
828 | format=type(value).__name__) | |
|
823 | 829 | else: |
|
824 |
opObj.addParameter(name='server' |
|
|
825 | ||
|
830 | opObj.addParameter(name='server', value=self.server, format='str') | |
|
826 | 831 | |
|
827 | 832 | return opObj |
|
828 | 833 | |
@@ -833,16 +838,19 class ReadUnitConf(ProcUnitConf): | |||
|
833 | 838 | |
|
834 | 839 | opObj.addParameter(name='datatype', value=self.datatype, format='str') |
|
835 | 840 | opObj.addParameter(name='path', value=self.path, format='str') |
|
836 | opObj.addParameter(name='startDate', value=self.startDate, format='date') | |
|
841 | opObj.addParameter( | |
|
842 | name='startDate', value=self.startDate, format='date') | |
|
837 | 843 | opObj.addParameter(name='endDate', value=self.endDate, format='date') |
|
838 | opObj.addParameter(name='startTime', value=self.startTime, format='time') | |
|
844 | opObj.addParameter( | |
|
845 | name='startTime', value=self.startTime, format='time') | |
|
839 | 846 | opObj.addParameter(name='endTime', value=self.endTime, format='time') |
|
840 | ||
|
847 | ||
|
841 | 848 | for key, value in kwargs.items(): |
|
842 |
opObj.addParameter(name=key, value=value, |
|
|
849 | opObj.addParameter(name=key, value=value, | |
|
850 | format=type(value).__name__) | |
|
843 | 851 | |
|
844 | 852 | return opObj |
|
845 | ||
|
853 | ||
|
846 | 854 | def readXml(self, upElement): |
|
847 | 855 | |
|
848 | 856 | self.id = upElement.get('id') |
@@ -872,6 +880,7 class ReadUnitConf(ProcUnitConf): | |||
|
872 | 880 | self.startTime = opConfObj.getParameterValue('startTime') |
|
873 | 881 | self.endTime = opConfObj.getParameterValue('endTime') |
|
874 | 882 | |
|
883 | ||
|
875 | 884 | class Project(Process): |
|
876 | 885 | |
|
877 | 886 | id = None |
@@ -900,7 +909,7 class Project(Process): | |||
|
900 | 909 | |
|
901 | 910 | idList = self.procUnitConfObjDict.keys() |
|
902 | 911 | |
|
903 | id = int(self.id)*10 | |
|
912 | id = int(self.id) * 10 | |
|
904 | 913 | |
|
905 | 914 | while True: |
|
906 | 915 | id += 1 |
@@ -933,8 +942,8 class Project(Process): | |||
|
933 | 942 | for procKey in keyList: |
|
934 | 943 | |
|
935 | 944 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
936 | idProcUnit = str(int(self.id)*10 + n) | |
|
937 |
procUnitConfObj.updateId(idProcUnit, parentId |
|
|
945 | idProcUnit = str(int(self.id) * 10 + n) | |
|
946 | procUnitConfObj.updateId(idProcUnit, parentId=self.id) | |
|
938 | 947 | |
|
939 | 948 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
940 | 949 | n += 1 |
@@ -944,9 +953,9 class Project(Process): | |||
|
944 | 953 | def setup(self, id, name='', description=''): |
|
945 | 954 | |
|
946 | 955 | |
|
947 | print '*'*60 | |
|
956 | print '*' * 60 | |
|
948 | 957 | print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__ |
|
949 | print '*'*60 | |
|
958 | print '*' * 60 | |
|
950 | 959 | |
|
951 | 960 | self.id = str(id) |
|
952 | 961 | self.description = description |
@@ -969,7 +978,8 class Project(Process): | |||
|
969 | 978 | idReadUnit = str(id) |
|
970 | 979 | |
|
971 | 980 | readUnitConfObj = ReadUnitConf() |
|
972 |
readUnitConfObj.setup(idReadUnit, name, datatype, |
|
|
981 | readUnitConfObj.setup(idReadUnit, name, datatype, | |
|
982 | parentId=self.id, **kwargs) | |
|
973 | 983 | |
|
974 | 984 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
975 | 985 | |
@@ -980,7 +990,8 class Project(Process): | |||
|
980 | 990 | idProcUnit = self.__getNewId() |
|
981 | 991 | |
|
982 | 992 | procUnitConfObj = ProcUnitConf() |
|
983 |
procUnitConfObj.setup(idProcUnit, name, datatype, |
|
|
993 | procUnitConfObj.setup(idProcUnit, name, datatype, | |
|
994 | inputId, parentId=self.id) | |
|
984 | 995 | |
|
985 | 996 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
986 | 997 | |
@@ -1054,11 +1065,11 class Project(Process): | |||
|
1054 | 1065 | abs_file = os.path.abspath(filename) |
|
1055 | 1066 | |
|
1056 | 1067 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1057 | print 'No write permission on %s' %os.path.dirname(abs_file) | |
|
1068 | print 'No write permission on %s' % os.path.dirname(abs_file) | |
|
1058 | 1069 | return 0 |
|
1059 | 1070 | |
|
1060 | 1071 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1061 | print 'File %s already exists and it could not be overwriten' %abs_file | |
|
1072 | print 'File %s already exists and it could not be overwriten' % abs_file | |
|
1062 | 1073 | return 0 |
|
1063 | 1074 | |
|
1064 | 1075 | self.makeXml() |
@@ -1069,7 +1080,7 class Project(Process): | |||
|
1069 | 1080 | |
|
1070 | 1081 | return 1 |
|
1071 | 1082 | |
|
1072 |
def readXml(self, filename |
|
|
1083 | def readXml(self, filename=None): | |
|
1073 | 1084 | |
|
1074 | 1085 | if not filename: |
|
1075 | 1086 | print 'filename is not defined' |
@@ -1078,7 +1089,7 class Project(Process): | |||
|
1078 | 1089 | abs_file = os.path.abspath(filename) |
|
1079 | 1090 | |
|
1080 | 1091 | if not os.path.isfile(abs_file): |
|
1081 | print '%s file does not exist' %abs_file | |
|
1092 | print '%s file does not exist' % abs_file | |
|
1082 | 1093 | return 0 |
|
1083 | 1094 | |
|
1084 | 1095 | self.projectElement = None |
@@ -1087,16 +1098,17 class Project(Process): | |||
|
1087 | 1098 | try: |
|
1088 | 1099 | self.projectElement = ElementTree().parse(abs_file) |
|
1089 | 1100 | except: |
|
1090 | print 'Error reading %s, verify file format' %filename | |
|
1101 | print 'Error reading %s, verify file format' % filename | |
|
1091 | 1102 | return 0 |
|
1092 | 1103 | |
|
1093 | 1104 | self.project = self.projectElement.tag |
|
1094 | 1105 | |
|
1095 | 1106 | self.id = self.projectElement.get('id') |
|
1096 | 1107 | self.name = self.projectElement.get('name') |
|
1097 |
self.description = self.projectElement.get('description') |
|
|
1098 | ||
|
1099 |
readUnitElementList = self.projectElement.iter( |
|
|
1108 | self.description = self.projectElement.get('description') | |
|
1109 | ||
|
1110 | readUnitElementList = self.projectElement.iter( | |
|
1111 | ReadUnitConf().getElementName()) | |
|
1100 | 1112 | |
|
1101 | 1113 | for readUnitElement in readUnitElementList: |
|
1102 | 1114 | readUnitConfObj = ReadUnitConf() |
@@ -1107,7 +1119,8 class Project(Process): | |||
|
1107 | 1119 | |
|
1108 | 1120 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1109 | 1121 | |
|
1110 |
procUnitElementList = self.projectElement.iter( |
|
|
1122 | procUnitElementList = self.projectElement.iter( | |
|
1123 | ProcUnitConf().getElementName()) | |
|
1111 | 1124 | |
|
1112 | 1125 | for procUnitElement in procUnitElementList: |
|
1113 | 1126 | procUnitConfObj = ProcUnitConf() |
@@ -1124,10 +1137,10 class Project(Process): | |||
|
1124 | 1137 | |
|
1125 | 1138 | def printattr(self): |
|
1126 | 1139 | |
|
1127 | print 'Project[%s]: name = %s, description = %s' %(self.id, | |
|
1128 | self.name, | |
|
1129 | self.description) | |
|
1130 | ||
|
1140 | print 'Project[%s]: name = %s, description = %s' % (self.id, | |
|
1141 | self.name, | |
|
1142 | self.description) | |
|
1143 | ||
|
1131 | 1144 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1132 | 1145 | procUnitConfObj.printattr() |
|
1133 | 1146 | |
@@ -1149,11 +1162,11 class Project(Process): | |||
|
1149 | 1162 | if int(inputId) == 0: |
|
1150 | 1163 | continue |
|
1151 | 1164 | |
|
1152 | #Get input object | |
|
1165 | # Get input object | |
|
1153 | 1166 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1154 | 1167 | puObjIN = puConfINObj.getProcUnitObj() |
|
1155 | 1168 | |
|
1156 | #Get current object | |
|
1169 | # Get current object | |
|
1157 | 1170 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1158 | 1171 | |
|
1159 | 1172 | self.__connect(puObjIN, thisPUObj) |
@@ -1163,11 +1176,11 class Project(Process): | |||
|
1163 | 1176 | import socket |
|
1164 | 1177 | |
|
1165 | 1178 | err = traceback.format_exception(sys.exc_info()[0], |
|
1166 | sys.exc_info()[1], | |
|
1167 | sys.exc_info()[2]) | |
|
1168 | ||
|
1169 | print '***** Error occurred in %s *****' %(procUnitConfObj.name) | |
|
1170 | print '***** %s' %err[-1] | |
|
1179 | sys.exc_info()[1], | |
|
1180 | sys.exc_info()[2]) | |
|
1181 | ||
|
1182 | print '***** Error occurred in %s *****' % (procUnitConfObj.name) | |
|
1183 | print '***** %s' % err[-1] | |
|
1171 | 1184 | |
|
1172 | 1185 | message = ''.join(err) |
|
1173 | 1186 | |
@@ -1176,30 +1189,33 class Project(Process): | |||
|
1176 | 1189 | if not send_email: |
|
1177 | 1190 | return |
|
1178 | 1191 | |
|
1179 |
subject = |
|
|
1192 | subject = 'SChain v%s: Error running %s\n' % ( | |
|
1193 | schainpy.__version__, procUnitConfObj.name) | |
|
1180 | 1194 | |
|
1181 | subtitle = '%s: %s\n' %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
|
1182 | subtitle += 'Hostname: %s\n' %socket.gethostbyname(socket.gethostname()) | |
|
1183 | subtitle += 'Working directory: %s\n' %os.path.abspath('./') | |
|
1184 | subtitle += 'Configuration file: %s\n' %self.filename | |
|
1185 |
subtitle += ' |
|
|
1195 | subtitle = '%s: %s\n' % ( | |
|
1196 | procUnitConfObj.getElementName(), procUnitConfObj.name) | |
|
1197 | subtitle += 'Hostname: %s\n' % socket.gethostbyname( | |
|
1198 | socket.gethostname()) | |
|
1199 | subtitle += 'Working directory: %s\n' % os.path.abspath('./') | |
|
1200 | subtitle += 'Configuration file: %s\n' % self.filename | |
|
1201 | subtitle += 'Time: %s\n' % str(datetime.datetime.now()) | |
|
1186 | 1202 | |
|
1187 | 1203 | readUnitConfObj = self.getReadUnitObj() |
|
1188 | 1204 | if readUnitConfObj: |
|
1189 | 1205 | subtitle += '\nInput parameters:\n' |
|
1190 | subtitle += '[Data path = %s]\n' %readUnitConfObj.path | |
|
1191 | subtitle += '[Data type = %s]\n' %readUnitConfObj.datatype | |
|
1192 | subtitle += '[Start date = %s]\n' %readUnitConfObj.startDate | |
|
1193 | subtitle += '[End date = %s]\n' %readUnitConfObj.endDate | |
|
1194 | subtitle += '[Start time = %s]\n' %readUnitConfObj.startTime | |
|
1195 | subtitle += '[End time = %s]\n' %readUnitConfObj.endTime | |
|
1206 | subtitle += '[Data path = %s]\n' % readUnitConfObj.path | |
|
1207 | subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype | |
|
1208 | subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate | |
|
1209 | subtitle += '[End date = %s]\n' % readUnitConfObj.endDate | |
|
1210 | subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime | |
|
1211 | subtitle += '[End time = %s]\n' % readUnitConfObj.endTime | |
|
1196 | 1212 | |
|
1197 | 1213 | adminObj = schainpy.admin.SchainNotify() |
|
1198 | 1214 | adminObj.sendAlert(message=message, |
|
1199 | subject=subject, | |
|
1200 | subtitle=subtitle, | |
|
1201 | filename=self.filename) | |
|
1202 | ||
|
1215 | subject=subject, | |
|
1216 | subtitle=subtitle, | |
|
1217 | filename=self.filename) | |
|
1218 | ||
|
1203 | 1219 | def isPaused(self): |
|
1204 | 1220 | return 0 |
|
1205 | 1221 | |
@@ -1250,7 +1266,7 class Project(Process): | |||
|
1250 | 1266 | def run(self): |
|
1251 | 1267 | |
|
1252 | 1268 | log.success('Starting {}'.format(self.name)) |
|
1253 | ||
|
1269 | ||
|
1254 | 1270 | self.createObjects() |
|
1255 | 1271 | self.connectObjects() |
|
1256 | 1272 | |
@@ -1282,14 +1298,14 class Project(Process): | |||
|
1282 | 1298 | is_ok = False |
|
1283 | 1299 | break |
|
1284 | 1300 | |
|
1285 | #If every process unit finished so end process | |
|
1301 | # If every process unit finished so end process | |
|
1286 | 1302 | if not(is_ok): |
|
1287 | 1303 | break |
|
1288 | 1304 | |
|
1289 | 1305 | if not self.runController(): |
|
1290 | 1306 | break |
|
1291 | 1307 | |
|
1292 | #Closing every process | |
|
1308 | # Closing every process | |
|
1293 | 1309 | for procKey in keyList: |
|
1294 | 1310 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1295 | 1311 | procUnitConfObj.close() |
@@ -15,6 +15,7 import tempfile | |||
|
15 | 15 | from StringIO import StringIO |
|
16 | 16 | # from _sha import blocksize |
|
17 | 17 | |
|
18 | ||
|
18 | 19 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
19 | 20 | """ |
|
20 | 21 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
@@ -134,13 +135,13 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
134 | 135 | |
|
135 | 136 | self.path = None |
|
136 | 137 | |
|
137 | self.profileIndex = 2**32-1 | |
|
138 | self.profileIndex = 2**32 - 1 | |
|
138 | 139 | |
|
139 |
self.delay |
|
|
140 | self.delay = 3 # seconds | |
|
140 | 141 | |
|
141 |
self.nTries |
|
|
142 | self.nTries = 3 # quantity tries | |
|
142 | 143 | |
|
143 |
self.nFiles = 3 |
|
|
144 | self.nFiles = 3 # number of files for searching | |
|
144 | 145 | |
|
145 | 146 | self.nReadBlocks = 0 |
|
146 | 147 | |
@@ -172,51 +173,49 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
172 | 173 | |
|
173 | 174 | def __hasNotDataInBuffer(self): |
|
174 | 175 | |
|
175 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: | |
|
176 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs: | |
|
176 | 177 | return 1 |
|
177 | 178 | |
|
178 | 179 | return 0 |
|
179 | 180 | |
|
180 | ||
|
181 | 181 | def getBlockDimension(self): |
|
182 | 182 | """ |
|
183 | 183 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
184 | ||
|
184 | ||
|
185 | 185 | Affected: |
|
186 | 186 | self.blocksize |
|
187 | 187 | |
|
188 | 188 | Return: |
|
189 | 189 | None |
|
190 | 190 | """ |
|
191 |
pts2read = self.processingHeaderObj.profilesPerBlock * |
|
|
191 | pts2read = self.processingHeaderObj.profilesPerBlock * \ | |
|
192 | self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
|
192 | 193 | self.blocksize = pts2read |
|
193 | 194 | |
|
194 | ||
|
195 | ||
|
196 | 195 | def readBlock(self): |
|
197 | 196 | """ |
|
198 | 197 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
199 | 198 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
200 | 199 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
201 | 200 | es seteado a 0 |
|
202 | ||
|
201 | ||
|
203 | 202 | Inputs: |
|
204 | 203 | None |
|
205 | ||
|
204 | ||
|
206 | 205 | Return: |
|
207 | 206 | None |
|
208 | ||
|
207 | ||
|
209 | 208 | Affected: |
|
210 | 209 | self.profileIndex |
|
211 | 210 | self.datablock |
|
212 | 211 | self.flagIsNewFile |
|
213 | 212 | self.flagIsNewBlock |
|
214 | 213 | self.nTotalBlocks |
|
215 | ||
|
214 | ||
|
216 | 215 | Exceptions: |
|
217 | 216 | Si un bloque leido no es un bloque valido |
|
218 | 217 | """ |
|
219 | ||
|
218 | ||
|
220 | 219 | # if self.server is not None: |
|
221 | 220 | # self.zBlock = self.receiver.recv() |
|
222 | 221 | # self.zHeader = self.zBlock[:24] |
@@ -227,22 +226,24 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
227 | 226 | # self.systemHeaderObj.nChannels |
|
228 | 227 | # else: |
|
229 | 228 | current_pointer_location = self.fp.tell() |
|
230 |
junk = numpy.fromfile( |
|
|
229 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
|
231 | 230 | |
|
232 | 231 | try: |
|
233 |
junk = junk.reshape( |
|
|
232 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
233 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
234 | 234 | except: |
|
235 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
235 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
236 | 236 | |
|
237 | 237 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
238 |
junk = numpy.fromfile( |
|
|
239 |
junk = junk.reshape( |
|
|
238 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
|
239 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
240 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
240 | 241 | # return 0 |
|
241 | 242 | |
|
242 | #Dimensions : nChannels, nProfiles, nSamples | |
|
243 | # Dimensions : nChannels, nProfiles, nSamples | |
|
243 | 244 | |
|
244 | junk = numpy.transpose(junk, (2,0,1)) | |
|
245 | self.datablock = junk['real'] + junk['imag']*1j | |
|
245 | junk = numpy.transpose(junk, (2, 0, 1)) | |
|
246 | self.datablock = junk['real'] + junk['imag'] * 1j | |
|
246 | 247 | |
|
247 | 248 | self.profileIndex = 0 |
|
248 | 249 | |
@@ -263,8 +264,8 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
263 | 264 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
264 | 265 | |
|
265 | 266 | if self.nTxs > 1: |
|
266 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
|
267 | #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
|
267 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
|
268 | # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
|
268 | 269 | |
|
269 | 270 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
270 | 271 | # |
@@ -280,15 +281,18 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
280 | 281 | |
|
281 | 282 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
282 | 283 | |
|
283 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
284 | self.dataOut.heightList = numpy.arange( | |
|
285 | self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
284 | 286 | |
|
285 | 287 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
286 | 288 | |
|
287 | 289 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
288 | 290 | |
|
289 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada | |
|
291 | # asumo q la data no esta decodificada | |
|
292 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode | |
|
290 | 293 | |
|
291 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip | |
|
294 | # asumo q la data no esta sin flip | |
|
295 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip | |
|
292 | 296 | |
|
293 | 297 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
294 | 298 | |
@@ -300,51 +304,57 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
300 | 304 | if self.nTxs == 1: |
|
301 | 305 | return |
|
302 | 306 | |
|
303 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: | |
|
304 |
raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %( |
|
|
307 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1. / self.nTxs) != 0: | |
|
308 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" % ( | |
|
309 | 1. / self.nTxs, self.processingHeaderObj.profilesPerBlock) | |
|
305 | 310 | |
|
306 | 311 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
307 |
raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %( |
|
|
312 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" % ( | |
|
313 | self.nTxs, self.processingHeaderObj.nHeights) | |
|
308 | 314 | |
|
309 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) | |
|
315 | self.datablock = self.datablock.reshape( | |
|
316 | (self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock * self.nTxs, self.processingHeaderObj.nHeights / self.nTxs)) | |
|
310 | 317 | |
|
311 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
|
312 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) * |
|
|
313 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
|
318 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock * self.nTxs | |
|
319 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights / self.nTxs) * \ | |
|
320 | self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
321 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
|
314 | 322 | |
|
315 | 323 | return |
|
316 | 324 | |
|
317 | 325 | def readFirstHeaderFromServer(self): |
|
318 | ||
|
326 | ||
|
319 | 327 | self.getFirstHeader() |
|
320 | 328 | |
|
321 | 329 | self.firstHeaderSize = self.basicHeaderObj.size |
|
322 | 330 | |
|
323 |
datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
|
331 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & | |
|
332 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
|
324 | 333 | if datatype == 0: |
|
325 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
|
334 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
|
326 | 335 | elif datatype == 1: |
|
327 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
|
336 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
|
328 | 337 | elif datatype == 2: |
|
329 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
|
338 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
|
330 | 339 | elif datatype == 3: |
|
331 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
340 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
|
332 | 341 | elif datatype == 4: |
|
333 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
342 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
|
334 | 343 | elif datatype == 5: |
|
335 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
|
344 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
|
336 | 345 | else: |
|
337 | 346 | raise ValueError, 'Data type was not defined' |
|
338 | 347 | |
|
339 | 348 | self.dtype = datatype_str |
|
340 | 349 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
341 |
self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + |
|
|
350 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ | |
|
351 | self.firstHeaderSize + self.basicHeaderSize * \ | |
|
352 | (self.processingHeaderObj.dataBlocksPerFile - 1) | |
|
342 | 353 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
343 | 354 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
344 | 355 | self.getBlockDimension() |
|
345 | 356 | |
|
346 | ||
|
347 | def getFromServer(self): | |
|
357 | def getFromServer(self): | |
|
348 | 358 | self.flagDiscontinuousBlock = 0 |
|
349 | 359 | self.profileIndex = 0 |
|
350 | 360 | self.flagIsNewBlock = 1 |
@@ -364,38 +374,46 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
364 | 374 | self.processingHeaderObj.read(block[self.blockPointer:]) |
|
365 | 375 | self.blockPointer += self.processingHeaderObj.length |
|
366 | 376 | self.readFirstHeaderFromServer() |
|
367 | ||
|
377 | ||
|
368 | 378 | timestamp = self.basicHeaderObj.get_datatime() |
|
369 | 379 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) |
|
370 | 380 | current_pointer_location = self.blockPointer |
|
371 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
|
381 | junk = numpy.fromstring( | |
|
382 | block[self.blockPointer:], self.dtype, self.blocksize) | |
|
372 | 383 | |
|
373 | 384 | try: |
|
374 |
junk = junk.reshape( |
|
|
385 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
386 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
375 | 387 | except: |
|
376 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
388 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
377 | 389 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
378 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
|
379 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
|
390 | junk = numpy.fromstring( | |
|
391 | block[self.blockPointer:], self.dtype, self.blocksize) | |
|
392 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
393 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
380 | 394 | # return 0 |
|
381 | 395 | |
|
382 | #Dimensions : nChannels, nProfiles, nSamples | |
|
396 | # Dimensions : nChannels, nProfiles, nSamples | |
|
383 | 397 | |
|
384 | junk = numpy.transpose(junk, (2,0,1)) | |
|
385 |
self.datablock = junk['real'] + junk['imag'] * 1j |
|
|
398 | junk = numpy.transpose(junk, (2, 0, 1)) | |
|
399 | self.datablock = junk['real'] + junk['imag'] * 1j | |
|
386 | 400 | self.profileIndex = 0 |
|
387 |
if self.selBlocksize == None: |
|
|
401 | if self.selBlocksize == None: | |
|
402 | self.selBlocksize = self.dataOut.nProfiles | |
|
388 | 403 | if self.selBlocktime != None: |
|
389 | 404 | if self.dataOut.nCohInt is not None: |
|
390 | 405 | nCohInt = self.dataOut.nCohInt |
|
391 | 406 | else: |
|
392 | 407 | nCohInt = 1 |
|
393 |
self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/( |
|
|
394 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] | |
|
408 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
|
409 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
|
410 | self.dataOut.data = self.datablock[:, | |
|
411 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
|
395 | 412 | datasize = self.dataOut.data.shape[1] |
|
396 | 413 | if datasize < self.selBlocksize: |
|
397 | buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex') | |
|
398 | buffer[:,:datasize,:] = self.dataOut.data | |
|
414 | buffer = numpy.zeros( | |
|
415 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
|
416 | buffer[:, :datasize, :] = self.dataOut.data | |
|
399 | 417 | self.dataOut.data = buffer |
|
400 | 418 | self.profileIndex = blockIndex |
|
401 | 419 | |
@@ -411,30 +429,30 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
411 | 429 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
412 | 430 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
413 | 431 | "readNextBlock" |
|
414 | ||
|
432 | ||
|
415 | 433 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
416 | ||
|
434 | ||
|
417 | 435 | Return: |
|
418 | ||
|
436 | ||
|
419 | 437 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
420 | 438 | es igual al total de perfiles leidos desde el archivo. |
|
421 | ||
|
439 | ||
|
422 | 440 | Si self.getByBlock == False: |
|
423 | ||
|
441 | ||
|
424 | 442 | self.dataOut.data = buffer[:, thisProfile, :] |
|
425 | ||
|
443 | ||
|
426 | 444 | shape = [nChannels, nHeis] |
|
427 | ||
|
445 | ||
|
428 | 446 | Si self.getByBlock == True: |
|
429 | ||
|
447 | ||
|
430 | 448 | self.dataOut.data = buffer[:, :, :] |
|
431 | ||
|
449 | ||
|
432 | 450 | shape = [nChannels, nProfiles, nHeis] |
|
433 | ||
|
451 | ||
|
434 | 452 | Variables afectadas: |
|
435 | 453 | self.dataOut |
|
436 | 454 | self.profileIndex |
|
437 | ||
|
455 | ||
|
438 | 456 | Affected: |
|
439 | 457 | self.dataOut |
|
440 | 458 | self.profileIndex |
@@ -448,7 +466,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
448 | 466 | self.flagDiscontinuousBlock = 0 |
|
449 | 467 | self.flagIsNewBlock = 0 |
|
450 | 468 | if self.__hasNotDataInBuffer(): |
|
451 |
if not( |
|
|
469 | if not(self.readNextBlock()): | |
|
452 | 470 | return 0 |
|
453 | 471 | |
|
454 | 472 | self.getFirstHeader() |
@@ -467,11 +485,11 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
467 | 485 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
468 | 486 | """ |
|
469 | 487 | self.dataOut.flagDataAsBlock = False |
|
470 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
|
488 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |
|
471 | 489 | self.dataOut.profileIndex = self.profileIndex |
|
472 | 490 | |
|
473 | 491 | self.profileIndex += 1 |
|
474 | ||
|
492 | ||
|
475 | 493 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: |
|
476 | 494 | # """ |
|
477 | 495 | # Return all block |
@@ -479,42 +497,47 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
479 | 497 | # self.dataOut.flagDataAsBlock = True |
|
480 | 498 | # self.dataOut.data = self.datablock |
|
481 | 499 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 |
|
482 |
# |
|
|
500 | # | |
|
483 | 501 | # self.profileIndex = self.dataOut.nProfiles |
|
484 | ||
|
502 | ||
|
485 | 503 | else: |
|
486 | 504 | """ |
|
487 | 505 | Return a block |
|
488 | 506 | """ |
|
489 |
if self.selBlocksize == None: |
|
|
507 | if self.selBlocksize == None: | |
|
508 | self.selBlocksize = self.dataOut.nProfiles | |
|
490 | 509 | if self.selBlocktime != None: |
|
491 | 510 | if self.dataOut.nCohInt is not None: |
|
492 | 511 | nCohInt = self.dataOut.nCohInt |
|
493 | 512 | else: |
|
494 | 513 | nCohInt = 1 |
|
495 |
self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/( |
|
|
514 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
|
515 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
|
496 | 516 | |
|
497 |
self.dataOut.data = self.datablock[:, |
|
|
517 | self.dataOut.data = self.datablock[:, | |
|
518 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
|
498 | 519 | self.profileIndex += self.selBlocksize |
|
499 | 520 | datasize = self.dataOut.data.shape[1] |
|
500 | 521 | |
|
501 | 522 | if datasize < self.selBlocksize: |
|
502 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') | |
|
503 | buffer[:,:datasize,:] = self.dataOut.data | |
|
523 | buffer = numpy.zeros( | |
|
524 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
|
525 | buffer[:, :datasize, :] = self.dataOut.data | |
|
504 | 526 | |
|
505 | while datasize < self.selBlocksize: #Not enough profiles to fill the block | |
|
506 |
if not( |
|
|
527 | while datasize < self.selBlocksize: # Not enough profiles to fill the block | |
|
528 | if not(self.readNextBlock()): | |
|
507 | 529 | return 0 |
|
508 | 530 | self.getFirstHeader() |
|
509 | 531 | self.reshapeData() |
|
510 | 532 | if self.datablock is None: |
|
511 | 533 | self.dataOut.flagNoData = True |
|
512 | 534 | return 0 |
|
513 | #stack data | |
|
535 | # stack data | |
|
514 | 536 | blockIndex = self.selBlocksize - datasize |
|
515 | datablock1 = self.datablock[:,:blockIndex,:] | |
|
537 | datablock1 = self.datablock[:, :blockIndex, :] | |
|
516 | 538 | |
|
517 |
buffer[:,datasize:datasize+ |
|
|
539 | buffer[:, datasize:datasize + | |
|
540 | datablock1.shape[1], :] = datablock1 | |
|
518 | 541 | datasize += datablock1.shape[1] |
|
519 | 542 | |
|
520 | 543 | self.dataOut.data = buffer |
@@ -531,6 +554,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
531 | 554 | |
|
532 | 555 | return self.dataOut.data |
|
533 | 556 | |
|
557 | ||
|
534 | 558 | class VoltageWriter(JRODataWriter, Operation): |
|
535 | 559 | """ |
|
536 | 560 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
@@ -543,7 +567,6 class VoltageWriter(JRODataWriter, Operation): | |||
|
543 | 567 | |
|
544 | 568 | shapeBuffer = None |
|
545 | 569 | |
|
546 | ||
|
547 | 570 | def __init__(self, **kwargs): |
|
548 | 571 | """ |
|
549 | 572 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
@@ -590,7 +613,6 class VoltageWriter(JRODataWriter, Operation): | |||
|
590 | 613 | return 1 |
|
591 | 614 | return 0 |
|
592 | 615 | |
|
593 | ||
|
594 | 616 | def setBlockDimension(self): |
|
595 | 617 | """ |
|
596 | 618 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
@@ -607,8 +629,8 class VoltageWriter(JRODataWriter, Operation): | |||
|
607 | 629 | self.systemHeaderObj.nChannels) |
|
608 | 630 | |
|
609 | 631 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
610 | self.processingHeaderObj.profilesPerBlock, | |
|
611 | self.processingHeaderObj.nHeights), | |
|
632 | self.processingHeaderObj.profilesPerBlock, | |
|
633 | self.processingHeaderObj.nHeights), | |
|
612 | 634 | dtype=numpy.dtype('complex64')) |
|
613 | 635 | |
|
614 | 636 | def writeBlock(self): |
@@ -624,16 +646,16 class VoltageWriter(JRODataWriter, Operation): | |||
|
624 | 646 | |
|
625 | 647 | Return: None |
|
626 | 648 | """ |
|
627 |
data = numpy.zeros( |
|
|
649 | data = numpy.zeros(self.shapeBuffer, self.dtype) | |
|
628 | 650 | |
|
629 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
|
651 | junk = numpy.transpose(self.datablock, (1, 2, 0)) | |
|
630 | 652 | |
|
631 | 653 | data['real'] = junk.real |
|
632 | 654 | data['imag'] = junk.imag |
|
633 | 655 | |
|
634 |
data = data.reshape( |
|
|
656 | data = data.reshape((-1)) | |
|
635 | 657 | |
|
636 |
data.tofile( |
|
|
658 | data.tofile(self.fp) | |
|
637 | 659 | |
|
638 | 660 | self.datablock.fill(0) |
|
639 | 661 | |
@@ -671,12 +693,12 class VoltageWriter(JRODataWriter, Operation): | |||
|
671 | 693 | if self.profileIndex == 0: |
|
672 | 694 | self.setBasicHeader() |
|
673 | 695 | |
|
674 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
|
696 | self.datablock[:, self.profileIndex, :] = self.dataOut.data | |
|
675 | 697 | |
|
676 | 698 | self.profileIndex += 1 |
|
677 | 699 | |
|
678 | 700 | if self.hasAllDataInBuffer(): |
|
679 | #if self.flagIsNewFile: | |
|
701 | # if self.flagIsNewFile: | |
|
680 | 702 | self.writeNextBlock() |
|
681 | 703 | # self.setFirstHeader() |
|
682 | 704 | |
@@ -689,12 +711,12 class VoltageWriter(JRODataWriter, Operation): | |||
|
689 | 711 | |
|
690 | 712 | dtype_width = self.getDtypeWidth() |
|
691 | 713 | |
|
692 |
blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * |
|
|
714 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * | |
|
715 | self.profilesPerBlock * dtype_width * 2) | |
|
693 | 716 | |
|
694 | 717 | return blocksize |
|
695 | 718 | |
|
696 | 719 | def setFirstHeader(self): |
|
697 | ||
|
698 | 720 | """ |
|
699 | 721 | Obtiene una copia del First Header |
|
700 | 722 | |
@@ -711,14 +733,17 class VoltageWriter(JRODataWriter, Operation): | |||
|
711 | 733 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
712 | 734 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
713 | 735 | |
|
714 | self.processingHeaderObj.dtype = 0 # Voltage | |
|
736 | self.processingHeaderObj.dtype = 0 # Voltage | |
|
715 | 737 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
716 | 738 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
717 | 739 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
718 |
|
|
|
740 | # podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
|
741 | self.processingHeaderObj.nWindows = 1 | |
|
719 | 742 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
720 |
|
|
|
721 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
|
743 | # Cuando la data de origen es de tipo Voltage | |
|
744 | self.processingHeaderObj.nIncohInt = 1 | |
|
745 | # Cuando la data de origen es de tipo Voltage | |
|
746 | self.processingHeaderObj.totalSpectra = 0 | |
|
722 | 747 | |
|
723 | 748 | if self.dataOut.code is not None: |
|
724 | 749 | self.processingHeaderObj.code = self.dataOut.code |
@@ -727,7 +752,8 class VoltageWriter(JRODataWriter, Operation): | |||
|
727 | 752 | |
|
728 | 753 | if self.processingHeaderObj.nWindows != 0: |
|
729 | 754 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
730 |
self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - |
|
|
755 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - \ | |
|
756 | self.dataOut.heightList[0] | |
|
731 | 757 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
732 | 758 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
733 | 759 |
General Comments 0
You need to be logged in to leave comments.
Login now