diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fdad5c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,98 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site diff --git a/schainpy/controller.py b/schainpy/controller.py index 41f99b2..7cf11b6 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -1,8 +1,8 @@ ''' Created on September , 2012 -@author: +@author: ''' - + import sys import ast import datetime @@ -24,95 +24,95 @@ def prettify(elem): return reparsed.toprettyxml(indent=" ") class ParameterConf(): - + id = None name = None value = None format = None - + __formated_value = None - + ELEMENTNAME = 'Parameter' - + def __init__(self): - + self.format = 'str' - + def getElementName(self): - + return self.ELEMENTNAME - + def getValue(self): value = self.value format = self.format - + if self.__formated_value != None: - + return self.__formated_value - + if format == 'str': self.__formated_value = str(value) return self.__formated_value - + if value == '': raise ValueError, "%s: This parameter value is empty" %self.name - + if format == 'list': strList = value.split(',') - + self.__formated_value = strList - + return self.__formated_value - + if format == 'intlist': """ Example: value = (0,1,2) """ - + new_value = ast.literal_eval(value) - + if type(new_value) not in (tuple, list): new_value = [int(new_value)] - + self.__formated_value = new_value - + return self.__formated_value - + if format == 'floatlist': """ Example: value = (0.5, 1.4, 2.7) """ - + new_value = ast.literal_eval(value) - + if type(new_value) not in (tuple, list): new_value = [float(new_value)] - + self.__formated_value = new_value - + return self.__formated_value - + if format == 'date': strList = value.split('/') intList = [int(x) for x in strList] date = datetime.date(intList[0], intList[1], intList[2]) - + self.__formated_value = date - + return self.__formated_value - + if format == 'time': strList = value.split(':') intList = [int(x) for x in strList] time = datetime.time(intList[0], intList[1], intList[2]) - + self.__formated_value = time - + return self.__formated_value - + if format == 'pairslist': """ Example: @@ -120,605 +120,629 @@ class ParameterConf(): """ new_value = ast.literal_eval(value) - + if type(new_value) not in (tuple, list): raise ValueError, "%s has to be a tuple or list of pairs" %value - + if type(new_value[0]) not in (tuple, list): if len(new_value) != 2: raise ValueError, "%s has to be a tuple or list of pairs" %value new_value = [new_value] - + for thisPair in new_value: if len(thisPair) != 2: raise ValueError, "%s has to be a tuple or list of pairs" %value - + self.__formated_value = new_value - + return self.__formated_value - + if format == 'multilist': """ Example: value = (0,1,2),(3,4,5) """ multiList = ast.literal_eval(value) - + if type(multiList[0]) == int: multiList = ast.literal_eval("(" + value + ")") - + self.__formated_value = multiList - + return self.__formated_value - + if format == 'bool': value = int(value) - + if format == 'int': value = float(value) - + format_func = eval(format) - + self.__formated_value = format_func(value) - + return self.__formated_value def updateId(self, new_id): - + self.id = str(new_id) - + def setup(self, id, name, value, format='str'): - + self.id = str(id) self.name = name self.value = str(value) self.format = str.lower(format) - + self.getValue() - + return 1 - + def update(self, name, value, format='str'): - + self.name = name self.value = str(value) self.format = format - + def makeXml(self, opElement): - + parmElement = SubElement(opElement, self.ELEMENTNAME) parmElement.set('id', str(self.id)) parmElement.set('name', self.name) parmElement.set('value', self.value) parmElement.set('format', self.format) - + def readXml(self, parmElement): - + self.id = parmElement.get('id') self.name = parmElement.get('name') self.value = parmElement.get('value') self.format = str.lower(parmElement.get('format')) - + #Compatible with old signal chain version if self.format == 'int' and self.name == 'idfigure': self.name = 'id' - + def printattr(self): - + print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) class OperationConf(): - + id = None name = None priority = None type = None - + parmConfObjList = [] - + ELEMENTNAME = 'Operation' - + def __init__(self): - + self.id = '0' self.name = None self.priority = None self.type = 'self' - - + + def __getNewId(self): - + return int(self.id)*10 + len(self.parmConfObjList) + 1 def updateId(self, new_id): - + self.id = str(new_id) - + n = 1 for parmObj in self.parmConfObjList: - + idParm = str(int(new_id)*10 + n) parmObj.updateId(idParm) - + n += 1 - + def getElementName(self): - + return self.ELEMENTNAME - + def getParameterObjList(self): - + return self.parmConfObjList - + def getParameterObj(self, parameterName): - + for parmConfObj in self.parmConfObjList: - + if parmConfObj.name != parameterName: continue - + return parmConfObj - + return None def getParameterObjfromValue(self, parameterValue): - + for parmConfObj in self.parmConfObjList: - + if parmConfObj.getValue() != parameterValue: continue - + return parmConfObj.getValue() - + return None - + def getParameterValue(self, parameterName): - + parameterObj = self.getParameterObj(parameterName) - + # if not parameterObj: # return None - + value = parameterObj.getValue() - + return value - + + + def getKwargs(self): + + kwargs = {} + + for parmConfObj in self.parmConfObjList: + if self.name == 'run' and parmConfObj.name == 'datatype': + continue + + kwargs[parmConfObj.name] = parmConfObj.getValue() + + return kwargs + def setup(self, id, name, priority, type): - + self.id = str(id) self.name = name self.type = type self.priority = priority - + self.parmConfObjList = [] - + def removeParameters(self): - + for obj in self.parmConfObjList: del obj - + self.parmConfObjList = [] - + def addParameter(self, name, value, format='str'): - + id = self.__getNewId() - + parmConfObj = ParameterConf() if not parmConfObj.setup(id, name, value, format): return None - + self.parmConfObjList.append(parmConfObj) - + return parmConfObj - + def changeParameter(self, name, value, format='str'): - + parmConfObj = self.getParameterObj(name) parmConfObj.update(name, value, format) - + return parmConfObj - + def makeXml(self, procUnitElement): - + opElement = SubElement(procUnitElement, self.ELEMENTNAME) opElement.set('id', str(self.id)) opElement.set('name', self.name) opElement.set('type', self.type) opElement.set('priority', str(self.priority)) - + for parmConfObj in self.parmConfObjList: parmConfObj.makeXml(opElement) - + def readXml(self, opElement): - + self.id = opElement.get('id') self.name = opElement.get('name') self.type = opElement.get('type') self.priority = opElement.get('priority') - + #Compatible with old signal chain version #Use of 'run' method instead 'init' if self.type == 'self' and self.name == 'init': self.name = 'run' - + self.parmConfObjList = [] - + parmElementList = opElement.iter(ParameterConf().getElementName()) - + for parmElement in parmElementList: parmConfObj = ParameterConf() parmConfObj.readXml(parmElement) - + #Compatible with old signal chain version #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER if self.type != 'self' and self.name == 'Plot': if parmConfObj.format == 'str' and parmConfObj.name == 'type': self.name = parmConfObj.value continue - + self.parmConfObjList.append(parmConfObj) - + def printattr(self): - + print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, self.id, self.name, self.type, self.priority) - + for parmConfObj in self.parmConfObjList: parmConfObj.printattr() - + def createObject(self, plotter_queue=None): - + if self.type == 'self': raise ValueError, "This operation type cannot be created" - + if self.type == 'plotter': #Plotter(plotter_name) if not plotter_queue: raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" - + opObj = Plotter(self.name, plotter_queue) - + if self.type == 'external' or self.type == 'other': className = eval(self.name) - opObj = className() - + kwargs = self.getKwargs() + opObj = className(**kwargs) + return opObj - + + class ProcUnitConf(): - + id = None name = None datatype = None inputId = None parentId = None - + opConfObjList = [] - + procUnitObj = None opObjList = [] - + ELEMENTNAME = 'ProcUnit' - + def __init__(self): - + self.id = None self.datatype = None self.name = None self.inputId = None - + self.opConfObjList = [] - + self.procUnitObj = None self.opObjDict = {} - + def __getPriority(self): - + return len(self.opConfObjList)+1 - + def __getNewId(self): - + return int(self.id)*10 + len(self.opConfObjList) + 1 - + def getElementName(self): - + return self.ELEMENTNAME - + def getId(self): - + return self.id def updateId(self, new_id, parentId=parentId): - - + + new_id = int(parentId)*10 + (int(self.id) % 10) new_inputId = int(parentId)*10 + (int(self.inputId) % 10) - + #If this proc unit has not inputs if self.inputId == '0': new_inputId = 0 - + n = 1 for opConfObj in self.opConfObjList: - + idOp = str(int(new_id)*10 + n) opConfObj.updateId(idOp) - + n += 1 - + self.parentId = str(parentId) self.id = str(new_id) self.inputId = str(new_inputId) - - + + def getInputId(self): - + return self.inputId - + def getOperationObjList(self): - + return self.opConfObjList - + def getOperationObj(self, name=None): - + for opConfObj in self.opConfObjList: - + if opConfObj.name != name: continue - + return opConfObj - + return None - + def getOpObjfromParamValue(self, value=None): - + for opConfObj in self.opConfObjList: if opConfObj.getParameterObjfromValue(parameterValue=value) != value: continue return opConfObj return None - + def getProcUnitObj(self): - + return self.procUnitObj - + def setup(self, id, name, datatype, inputId, parentId=None): - + #Compatible with old signal chain version if datatype==None and name==None: raise ValueError, "datatype or name should be defined" - + if name==None: if 'Proc' in datatype: name = datatype else: name = '%sProc' %(datatype) - + if datatype==None: datatype = name.replace('Proc','') - + self.id = str(id) self.name = name self.datatype = datatype self.inputId = inputId self.parentId = parentId - + self.opConfObjList = [] - + self.addOperation(name='run', optype='self') - + def removeOperations(self): - + for obj in self.opConfObjList: del obj - + self.opConfObjList = [] self.addOperation(name='run') - + def addParameter(self, **kwargs): ''' Add parameters to "run" operation ''' opObj = self.opConfObjList[0] - + opObj.addParameter(**kwargs) - + return opObj - + def addOperation(self, name, optype='self'): - + id = self.__getNewId() - priority = self.__getPriority() - + priority = self.__getPriority() + opConfObj = OperationConf() opConfObj.setup(id, name=name, priority=priority, type=optype) - + self.opConfObjList.append(opConfObj) - + return opConfObj - + def makeXml(self, projectElement): - + procUnitElement = SubElement(projectElement, self.ELEMENTNAME) procUnitElement.set('id', str(self.id)) procUnitElement.set('name', self.name) procUnitElement.set('datatype', self.datatype) procUnitElement.set('inputId', str(self.inputId)) - + for opConfObj in self.opConfObjList: opConfObj.makeXml(procUnitElement) - + def readXml(self, upElement): - + self.id = upElement.get('id') self.name = upElement.get('name') self.datatype = upElement.get('datatype') self.inputId = upElement.get('inputId') - + if self.ELEMENTNAME == "ReadUnit": self.datatype = self.datatype.replace("Reader", "") - + if self.ELEMENTNAME == "ProcUnit": self.datatype = self.datatype.replace("Proc", "") - + if self.inputId == 'None': self.inputId = '0' - + self.opConfObjList = [] - + opElementList = upElement.iter(OperationConf().getElementName()) - + for opElement in opElementList: opConfObj = OperationConf() opConfObj.readXml(opElement) self.opConfObjList.append(opConfObj) - + def printattr(self): - + print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, self.id, self.name, self.datatype, self.inputId) - + for opConfObj in self.opConfObjList: opConfObj.printattr() - + + + def getKwargs(self): + + opObj = self.opConfObjList[0] + kwargs = opObj.getKwargs() + + return kwargs + def createObjects(self, plotter_queue=None): - + className = eval(self.name) - procUnitObj = className() - + kwargs = self.getKwargs() + procUnitObj = className(**kwargs) + for opConfObj in self.opConfObjList: - + if opConfObj.type == 'self': continue - + opObj = opConfObj.createObject(plotter_queue) - + self.opObjDict[opConfObj.id] = opObj procUnitObj.addOperation(opObj, opConfObj.id) - + self.procUnitObj = procUnitObj - + return procUnitObj - + def run(self): - + is_ok = False - + for opConfObj in self.opConfObjList: - + kwargs = {} for parmConfObj in opConfObj.getParameterObjList(): if opConfObj.name == 'run' and parmConfObj.name == 'datatype': continue - + kwargs[parmConfObj.name] = parmConfObj.getValue() - + #ini = time.time() - + #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) sts = self.procUnitObj.call(opType = opConfObj.type, opName = opConfObj.name, opId = opConfObj.id, - **kwargs) - + ) + # total_time = time.time() - ini -# +# # if total_time > 0.002: # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) - + is_ok = is_ok or sts - + return is_ok def close(self): - + for opConfObj in self.opConfObjList: if opConfObj.type == 'self': continue - + opObj = self.procUnitObj.getOperationObj(opConfObj.id) opObj.close() - + self.procUnitObj.close() - + return - + class ReadUnitConf(ProcUnitConf): - + path = None startDate = None endDate = None startTime = None endTime = None - + ELEMENTNAME = 'ReadUnit' - + def __init__(self): - + self.id = None self.datatype = None self.name = None self.inputId = None - + self.parentId = None - + self.opConfObjList = [] self.opObjList = [] - + def getElementName(self): - + return self.ELEMENTNAME - + def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): #Compatible with old signal chain version if datatype==None and name==None: raise ValueError, "datatype or name should be defined" - + if name==None: if 'Reader' in datatype: name = datatype else: name = '%sReader' %(datatype) - + if datatype==None: datatype = name.replace('Reader','') - + self.id = id self.name = name self.datatype = datatype - + self.path = os.path.abspath(path) self.startDate = startDate self.endDate = endDate self.startTime = startTime self.endTime = endTime - + self.inputId = '0' self.parentId = parentId - + self.addRunOperation(**kwargs) - + def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): #Compatible with old signal chain version if datatype==None and name==None: raise ValueError, "datatype or name should be defined" - + if name==None: if 'Reader' in datatype: name = datatype else: name = '%sReader' %(datatype) - + if datatype==None: datatype = name.replace('Reader','') - + self.datatype = datatype self.name = name self.path = path @@ -726,394 +750,394 @@ class ReadUnitConf(ProcUnitConf): self.endDate = endDate self.startTime = startTime self.endTime = endTime - + self.inputId = '0' self.parentId = parentId - + self.updateRunOperation(**kwargs) - + def removeOperations(self): - + for obj in self.opConfObjList: del obj - + self.opConfObjList = [] - + def addRunOperation(self, **kwargs): - + opObj = self.addOperation(name = 'run', optype = 'self') - + opObj.addParameter(name='datatype' , value=self.datatype, format='str') opObj.addParameter(name='path' , value=self.path, format='str') opObj.addParameter(name='startDate' , value=self.startDate, format='date') opObj.addParameter(name='endDate' , value=self.endDate, format='date') opObj.addParameter(name='startTime' , value=self.startTime, format='time') opObj.addParameter(name='endTime' , value=self.endTime, format='time') - + for key, value in kwargs.items(): opObj.addParameter(name=key, value=value, format=type(value).__name__) - + return opObj - + def updateRunOperation(self, **kwargs): - + opObj = self.getOperationObj(name = 'run') opObj.removeParameters() - + opObj.addParameter(name='datatype' , value=self.datatype, format='str') opObj.addParameter(name='path' , value=self.path, format='str') opObj.addParameter(name='startDate' , value=self.startDate, format='date') opObj.addParameter(name='endDate' , value=self.endDate, format='date') opObj.addParameter(name='startTime' , value=self.startTime, format='time') opObj.addParameter(name='endTime' , value=self.endTime, format='time') - + for key, value in kwargs.items(): opObj.addParameter(name=key, value=value, format=type(value).__name__) - + return opObj - + # def makeXml(self, projectElement): -# +# # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) # procUnitElement.set('id', str(self.id)) # procUnitElement.set('name', self.name) # procUnitElement.set('datatype', self.datatype) # procUnitElement.set('inputId', str(self.inputId)) -# +# # for opConfObj in self.opConfObjList: # opConfObj.makeXml(procUnitElement) - + def readXml(self, upElement): - + self.id = upElement.get('id') self.name = upElement.get('name') self.datatype = upElement.get('datatype') self.inputId = upElement.get('inputId') - + if self.ELEMENTNAME == "ReadUnit": self.datatype = self.datatype.replace("Reader", "") - + if self.inputId == 'None': self.inputId = '0' - + self.opConfObjList = [] - + opElementList = upElement.iter(OperationConf().getElementName()) - + for opElement in opElementList: opConfObj = OperationConf() opConfObj.readXml(opElement) self.opConfObjList.append(opConfObj) - + if opConfObj.name == 'run': self.path = opConfObj.getParameterValue('path') self.startDate = opConfObj.getParameterValue('startDate') self.endDate = opConfObj.getParameterValue('endDate') self.startTime = opConfObj.getParameterValue('startTime') self.endTime = opConfObj.getParameterValue('endTime') - + class Project(): - + id = None name = None description = None filename = None - + procUnitConfObjDict = None - + ELEMENTNAME = 'Project' - + plotterQueue = None - + def __init__(self, plotter_queue=None): - + self.id = None self.name = None self.description = None - + self.plotterQueue = plotter_queue - + self.procUnitConfObjDict = {} - + def __getNewId(self): - + idList = self.procUnitConfObjDict.keys() - + id = int(self.id)*10 - + while True: id += 1 - + if str(id) in idList: continue - + break - + return str(id) - + def getElementName(self): - + return self.ELEMENTNAME def getId(self): - + return self.id - + def updateId(self, new_id): - + self.id = str(new_id) - + keyList = self.procUnitConfObjDict.keys() keyList.sort() - + n = 1 newProcUnitConfObjDict = {} - + for procKey in keyList: - + procUnitConfObj = self.procUnitConfObjDict[procKey] idProcUnit = str(int(self.id)*10 + n) procUnitConfObj.updateId(idProcUnit, parentId = self.id) - + newProcUnitConfObjDict[idProcUnit] = procUnitConfObj n += 1 - + self.procUnitConfObjDict = newProcUnitConfObjDict - + def setup(self, id, name, description): - + self.id = str(id) self.name = name self.description = description def update(self, name, description): - + self.name = name self.description = description - + def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): - + if id is None: idReadUnit = self.__getNewId() else: idReadUnit = str(id) - + readUnitConfObj = ReadUnitConf() readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) - + self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj - + return readUnitConfObj - + def addProcUnit(self, inputId='0', datatype=None, name=None): - + idProcUnit = self.__getNewId() - + procUnitConfObj = ProcUnitConf() procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) - + self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj - + return procUnitConfObj - + def removeProcUnit(self, id): - + if id in self.procUnitConfObjDict.keys(): self.procUnitConfObjDict.pop(id) - + def getReadUnitId(self): - + readUnitConfObj = self.getReadUnitObj() - + return readUnitConfObj.id - + def getReadUnitObj(self): - + for obj in self.procUnitConfObjDict.values(): if obj.getElementName() == "ReadUnit": return obj - + return None - + def getProcUnitObj(self, id=None, name=None): - + if id != None: return self.procUnitConfObjDict[id] - + if name != None: return self.getProcUnitObjByName(name) - + return None - + def getProcUnitObjByName(self, name): - + for obj in self.procUnitConfObjDict.values(): if obj.name == name: return obj - + return None - + def procUnitItems(self): - + return self.procUnitConfObjDict.items() - - def makeXml(self): - + + def makeXml(self): + projectElement = Element('Project') projectElement.set('id', str(self.id)) projectElement.set('name', self.name) projectElement.set('description', self.description) - + for procUnitConfObj in self.procUnitConfObjDict.values(): procUnitConfObj.makeXml(projectElement) - + self.projectElement = projectElement - + def writeXml(self, filename=None): - + if filename == None: if self.filename: filename = self.filename else: filename = "schain.xml" - + if not filename: print "filename has not been defined. Use setFilename(filename) for do it." return 0 - + abs_file = os.path.abspath(filename) - + if not os.access(os.path.dirname(abs_file), os.W_OK): print "No write permission on %s" %os.path.dirname(abs_file) return 0 - + if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): print "File %s already exists and it could not be overwriten" %abs_file return 0 - + self.makeXml() - + ElementTree(self.projectElement).write(abs_file, method='xml') - + self.filename = abs_file - + return 1 def readXml(self, filename = None): - + if not filename: print "filename is not defined" return 0 - + abs_file = os.path.abspath(filename) - + if not os.path.isfile(abs_file): print "%s file does not exist" %abs_file return 0 - + self.projectElement = None self.procUnitConfObjDict = {} - + try: self.projectElement = ElementTree().parse(abs_file) except: print "Error reading %s, verify file format" %filename return 0 - + self.project = self.projectElement.tag - + self.id = self.projectElement.get('id') self.name = self.projectElement.get('name') - self.description = self.projectElement.get('description') - + self.description = self.projectElement.get('description') + readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) - + for readUnitElement in readUnitElementList: readUnitConfObj = ReadUnitConf() readUnitConfObj.readXml(readUnitElement) - + if readUnitConfObj.parentId == None: readUnitConfObj.parentId = self.id - + self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj - + procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) - + for procUnitElement in procUnitElementList: procUnitConfObj = ProcUnitConf() procUnitConfObj.readXml(procUnitElement) - + if procUnitConfObj.parentId == None: procUnitConfObj.parentId = self.id - + self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj - + self.filename = abs_file - + return 1 - + def printattr(self): - + print "Project[%s]: name = %s, description = %s" %(self.id, self.name, self.description) - + for procUnitConfObj in self.procUnitConfObjDict.values(): procUnitConfObj.printattr() - + def createObjects(self): - + for procUnitConfObj in self.procUnitConfObjDict.values(): procUnitConfObj.createObjects(self.plotterQueue) - + def __connect(self, objIN, thisObj): - + thisObj.setInput(objIN.getOutputObj()) - + def connectObjects(self): - + for thisPUConfObj in self.procUnitConfObjDict.values(): - + inputId = thisPUConfObj.getInputId() - + if int(inputId) == 0: continue - + #Get input object puConfINObj = self.procUnitConfObjDict[inputId] puObjIN = puConfINObj.getProcUnitObj() - + #Get current object thisPUObj = thisPUConfObj.getProcUnitObj() - + self.__connect(puObjIN, thisPUObj) - + def __handleError(self, procUnitConfObj, send_email=True): - + import socket - + err = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) - + print "***** Error occurred in %s *****" %(procUnitConfObj.name) print "***** %s" %err[-1] message = "".join(err) - + sys.stderr.write(message) - + if not send_email: return - + subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) - + subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) subtitle += "Working directory: %s\n" %os.path.abspath("./") subtitle += "Configuration file: %s\n" %self.filename subtitle += "Time: %s\n" %str(datetime.datetime.now()) - + readUnitConfObj = self.getReadUnitObj() if readUnitConfObj: subtitle += "\nInput parameters:\n" @@ -1123,80 +1147,80 @@ class Project(): subtitle += "[End date = %s]\n" %readUnitConfObj.endDate subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime subtitle += "[End time = %s]\n" %readUnitConfObj.endTime - + adminObj = schainpy.admin.SchainNotify() adminObj.sendAlert(message=message, subject=subject, subtitle=subtitle, filename=self.filename) - + def isPaused(self): return 0 - + def isStopped(self): return 0 - + def runController(self): """ returns 0 when this process has been stopped, 1 otherwise """ - + if self.isPaused(): print "Process suspended" - + while True: sleep(0.1) - + if not self.isPaused(): break - + if self.isStopped(): break - + print "Process reinitialized" - + if self.isStopped(): print "Process stopped" return 0 - + return 1 def setFilename(self, filename): - + self.filename = filename - + def setPlotterQueue(self, plotter_queue): - + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" def getPlotterQueue(self): - + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" def useExternalPlotter(self): - + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" - + def run(self): - + print print "*"*60 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ print "*"*60 print - + keyList = self.procUnitConfObjDict.keys() keyList.sort() - + while(True): - + is_ok = False - + for procKey in keyList: # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) - + procUnitConfObj = self.procUnitConfObjDict[procKey] - + try: sts = procUnitConfObj.run() is_ok = is_ok or sts @@ -1213,7 +1237,7 @@ class Project(): self.__handleError(procUnitConfObj) is_ok = False break - + #If every process unit finished so end process if not(is_ok): # print "Every process unit have finished" @@ -1221,74 +1245,17 @@ class Project(): if not self.runController(): break - + #Closing every process for procKey in keyList: procUnitConfObj = self.procUnitConfObjDict[procKey] procUnitConfObj.close() - + print "Process finished" - + def start(self): - + self.writeXml() - self.createObjects() self.connectObjects() self.run() - -if __name__ == '__main__': - - desc = "Segundo Test" - filename = "schain.xml" - - controllerObj = Project() - - controllerObj.setup(id = '191', name='test01', description=desc) - - readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path='data/rawdata/', - startDate='2011/01/01', - endDate='2012/12/31', - startTime='00:00:00', - endTime='23:59:59', - online=1, - walk=1) - - procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - - opObj10 = procUnitConfObj0.addOperation(name='selectChannels') - opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') - - opObj10 = procUnitConfObj0.addOperation(name='selectHeights') - opObj10.addParameter(name='minHei', value='90', format='float') - opObj10.addParameter(name='maxHei', value='180', format='float') - - opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') - opObj12.addParameter(name='n', value='10', format='int') - - procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) - procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') -# procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') - - - opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') - opObj11.addParameter(name='idfigure', value='1', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') - opObj11.addParameter(name='zmin', value='40', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='showprofile', value='1', format='int') - - print "Escribiendo el archivo XML" - - controllerObj.writeXml(filename) - - print "Leyendo el archivo XML" - controllerObj.readXml(filename) - #controllerObj.printattr() - - controllerObj.createObjects() - controllerObj.connectObjects() - controllerObj.run() - - \ No newline at end of file diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 6cd9c1d..5af51dc 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -13,7 +13,7 @@ from schainpy import cSchain def getNumpyDtype(dataTypeCode): - + if dataTypeCode == 0: numpyDtype = numpy.dtype([('real',' nums_min: # rtest = float(j)/(j-1) + 1.0/navg # if ((sumq*j) > (rtest*sump**2)): @@ -93,288 +93,288 @@ def hildebrand_sekhon(data, navg): # sump = sump - sortdata[j] # sumq = sumq - sortdata[j]**2 # cont = 0 -# +# # j += 1 -# +# # lnoise = sump /j -# +# # return lnoise return cSchain.hildebrand_sekhon(sortdata, navg) class Beam: - + def __init__(self): self.codeList = [] self.azimuthList = [] - self.zenithList = [] + self.zenithList = [] class GenericData(object): - + flagNoData = True - + def __init__(self): - + raise NotImplementedError - + def copy(self, inputObj=None): - + if inputObj == None: return copy.deepcopy(self) for key in inputObj.__dict__.keys(): - + attribute = inputObj.__dict__[key] - + #If this attribute is a tuple or list if type(inputObj.__dict__[key]) in (tuple, list): self.__dict__[key] = attribute[:] continue - + #If this attribute is another object or instance if hasattr(attribute, '__dict__'): self.__dict__[key] = attribute.copy() continue - + self.__dict__[key] = inputObj.__dict__[key] def deepcopy(self): - + return copy.deepcopy(self) - + def isEmpty(self): - + return self.flagNoData - + class JROData(GenericData): - + # m_BasicHeader = BasicHeader() # m_ProcessingHeader = ProcessingHeader() systemHeaderObj = SystemHeader() - + radarControllerHeaderObj = RadarControllerHeader() # data = None - + type = None - + datatype = None #dtype but in string - + # dtype = None - + # nChannels = None - + # nHeights = None - + nProfiles = None - + heightList = None - + channelList = None - + flagDiscontinuousBlock = False - + useLocalTime = False - + utctime = None - + timeZone = None - + dstFlag = None - + errorCount = None - + blocksize = None - + # nCode = None -# +# # nBaud = None -# +# # code = None - + flagDecodeData = False #asumo q la data no esta decodificada - + flagDeflipData = False #asumo q la data no esta sin flip - + flagShiftFFT = False - + # ippSeconds = None - + # timeInterval = None - + nCohInt = None - + # noise = None - + windowOfFilter = 1 - + #Speed of ligth C = 3e8 - + frequency = 49.92e6 - + realtime = False - + beacon_heiIndexList = None - + last_block = None - + blocknow = None azimuth = None - + zenith = None - + beam = Beam() - + profileIndex = None - + def __init__(self): - + raise NotImplementedError - + def getNoise(self): - + raise NotImplementedError - + def getNChannels(self): - + return len(self.channelList) - + def getChannelIndexList(self): - + return range(self.nChannels) - + def getNHeights(self): - + return len(self.heightList) - + def getHeiRange(self, extrapoints=0): - + heis = self.heightList # deltah = self.heightList[1] - self.heightList[0] -# +# # heis.append(self.heightList[-1]) - + return heis - + def getDeltaH(self): - + delta = self.heightList[1] - self.heightList[0] - + return delta - + def getltctime(self): - + if self.useLocalTime: return self.utctime - self.timeZone*60 - + return self.utctime - + def getDatatime(self): - + datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) return datatimeValue - + def getTimeRange(self): - + datatime = [] - + datatime.append(self.ltctime) datatime.append(self.ltctime + self.timeInterval+1) - + datatime = numpy.array(datatime) - + return datatime - + def getFmaxTimeResponse(self): - + period = (10**-6)*self.getDeltaH()/(0.15) - + PRF = 1./(period * self.nCohInt) - + fmax = PRF - + return fmax - + def getFmax(self): - + PRF = 1./(self.ippSeconds * self.nCohInt) - + fmax = PRF - + return fmax - + def getVmax(self): - + _lambda = self.C/self.frequency - + vmax = self.getFmax() * _lambda/2 - + return vmax - + def get_ippSeconds(self): ''' ''' return self.radarControllerHeaderObj.ippSeconds - + def set_ippSeconds(self, ippSeconds): ''' ''' - + self.radarControllerHeaderObj.ippSeconds = ippSeconds - + return - + def get_dtype(self): ''' ''' return getNumpyDtype(self.datatype) - + def set_dtype(self, numpyDtype): ''' ''' - + self.datatype = getDataTypeCode(numpyDtype) def get_code(self): ''' ''' return self.radarControllerHeaderObj.code - + def set_code(self, code): ''' ''' self.radarControllerHeaderObj.code = code - + return def get_ncode(self): ''' ''' return self.radarControllerHeaderObj.nCode - + def set_ncode(self, nCode): ''' ''' self.radarControllerHeaderObj.nCode = nCode - + return def get_nbaud(self): ''' ''' return self.radarControllerHeaderObj.nBaud - + def set_nbaud(self, nBaud): ''' ''' self.radarControllerHeaderObj.nBaud = nBaud - + return - + nChannels = property(getNChannels, "I'm the 'nChannel' property.") channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") nHeights = property(getNHeights, "I'm the 'nHeights' property.") @@ -387,71 +387,71 @@ class JROData(GenericData): code = property(get_code, set_code) nCode = property(get_ncode, set_ncode) nBaud = property(get_nbaud, set_nbaud) - + class Voltage(JROData): - + #data es un numpy array de 2 dmensiones (canales, alturas) data = None - + def __init__(self): ''' Constructor ''' - + self.useLocalTime = True - + self.radarControllerHeaderObj = RadarControllerHeader() - + self.systemHeaderObj = SystemHeader() - + self.type = "Voltage" - + self.data = None - + # self.dtype = None - + # self.nChannels = 0 - + # self.nHeights = 0 - + self.nProfiles = None - + self.heightList = None - + self.channelList = None - + # self.channelIndexList = None - + self.flagNoData = True - + self.flagDiscontinuousBlock = False - + self.utctime = None - + self.timeZone = None - + self.dstFlag = None - + self.errorCount = None - + self.nCohInt = None - + self.blocksize = None - + self.flagDecodeData = False #asumo q la data no esta decodificada - + self.flagDeflipData = False #asumo q la data no esta sin flip - + self.flagShiftFFT = False - + self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil - + self.profileIndex = 0 - + def getNoisebyHildebrand(self, channel = None): """ Determino el nivel de ruido usando el metodo Hildebrand-Sekhon - + Return: noiselevel """ @@ -462,248 +462,275 @@ class Voltage(JROData): else: data = self.data nChannels = self.nChannels - + noise = numpy.zeros(nChannels) power = data * numpy.conjugate(data) - + for thisChannel in range(nChannels): if nChannels == 1: daux = power[:].real else: daux = power[thisChannel,:].real noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) - + return noise - + def getNoise(self, type = 1, channel = None): - + if type == 1: noise = self.getNoisebyHildebrand(channel) - + return noise - + def getPower(self, channel = None): - + if channel != None: data = self.data[channel] else: data = self.data - + power = data * numpy.conjugate(data) powerdB = 10*numpy.log10(power.real) powerdB = numpy.squeeze(powerdB) - + return powerdB - + def getTimeInterval(self): - + timeInterval = self.ippSeconds * self.nCohInt - + return timeInterval - + noise = property(getNoise, "I'm the 'nHeights' property.") timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") - + class Spectra(JROData): - + #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) data_spc = None - + #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) data_cspc = None - + #data dc es un numpy array de 2 dmensiones (canales, alturas) data_dc = None - + #data power data_pwr = None - + nFFTPoints = None - + # nPairs = None - + pairsList = None - + nIncohInt = None - + wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia - + nCohInt = None #se requiere para determinar el valor de timeInterval - + ippFactor = None - + profileIndex = 0 - + plotting = "spectra" - + def __init__(self): ''' Constructor ''' - + self.useLocalTime = True - + self.radarControllerHeaderObj = RadarControllerHeader() - + self.systemHeaderObj = SystemHeader() - + self.type = "Spectra" - + # self.data = None - + # self.dtype = None - + # self.nChannels = 0 - + # self.nHeights = 0 - + self.nProfiles = None - + self.heightList = None - + self.channelList = None - + # self.channelIndexList = None self.pairsList = None - + self.flagNoData = True - + self.flagDiscontinuousBlock = False - + self.utctime = None - + self.nCohInt = None - + self.nIncohInt = None - + self.blocksize = None - + self.nFFTPoints = None - + self.wavelength = None - + self.flagDecodeData = False #asumo q la data no esta decodificada - + self.flagDeflipData = False #asumo q la data no esta sin flip - + self.flagShiftFFT = False - + self.ippFactor = 1 - + #self.noise = None - + self.beacon_heiIndexList = [] - + self.noise_estimation = None - - + + def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): """ Determino el nivel de ruido usando el metodo Hildebrand-Sekhon - + Return: noiselevel """ - + noise = numpy.zeros(self.nChannels) - + for channel in range(self.nChannels): daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) - - return noise - + + return noise + def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): - + if self.noise_estimation is not None: return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py else: noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) return noise - + def getFreqRangeTimeResponse(self, extrapoints=0): - + deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 - + return freqrange - + def getAcfRange(self, extrapoints=0): - + deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 - + return freqrange - + def getFreqRange(self, extrapoints=0): - + deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 - + return freqrange def getVelRange(self, extrapoints=0): - + deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) - velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 - + velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 + return velrange - + def getNPairs(self): - + return len(self.pairsList) - + def getPairsIndexList(self): - + return range(self.nPairs) - + def getNormFactor(self): - + pwcode = 1 - + if self.flagDecodeData: pwcode = numpy.sum(self.code[0]**2) #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter - + return normFactor - + def getFlagCspc(self): - + if self.data_cspc is None: return True - + return False - + def getFlagDc(self): - + if self.data_dc is None: return True - + return False - + def getTimeInterval(self): - + timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles - + return timeInterval - + def getPower(self): - + factor = self.normFactor z = self.data_spc/factor - z = numpy.where(numpy.isfinite(z), z, numpy.NAN) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) avg = numpy.average(z, axis=1) - + return 10*numpy.log10(avg) - + + def getCoherence(self, pairsList=None, phase=False): + + z = [] + if pairsList is None: + pairsIndexList = self.pairsIndexList + else: + pairsIndexList = [] + for pair in pairsList: + if pair not in self.pairsList: + raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) + pairsIndexList.append(self.pairsList.index(pair)) + for i in range(len(pairsIndexList)): + pair = self.pairsList[pairsIndexList[i]] + ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) + powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) + powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) + avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) + if phase: + data = numpy.arctan2(avgcoherenceComplex.imag, + avgcoherenceComplex.real)*180/numpy.pi + else: + data = numpy.abs(avgcoherenceComplex) + + z.append(data) + + return numpy.array(z) + def setValue(self, value): - + print "This property should not be initialized" - + return - + nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") @@ -711,141 +738,141 @@ class Spectra(JROData): flag_dc = property(getFlagDc, setValue) noise = property(getNoise, setValue, "I'm the 'nHeights' property.") timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") - + class SpectraHeis(Spectra): - + data_spc = None - + data_cspc = None - + data_dc = None - + nFFTPoints = None - + # nPairs = None - + pairsList = None - + nCohInt = None - + nIncohInt = None - + def __init__(self): - + self.radarControllerHeaderObj = RadarControllerHeader() - + self.systemHeaderObj = SystemHeader() - + self.type = "SpectraHeis" - + # self.dtype = None - + # self.nChannels = 0 - + # self.nHeights = 0 - + self.nProfiles = None - + self.heightList = None - + self.channelList = None - + # self.channelIndexList = None - + self.flagNoData = True - + self.flagDiscontinuousBlock = False - + # self.nPairs = 0 - + self.utctime = None - + self.blocksize = None - + self.profileIndex = 0 - + self.nCohInt = 1 - + self.nIncohInt = 1 - + def getNormFactor(self): pwcode = 1 if self.flagDecodeData: pwcode = numpy.sum(self.code[0]**2) - + normFactor = self.nIncohInt*self.nCohInt*pwcode - + return normFactor - + def getTimeInterval(self): - + timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt - + return timeInterval - + normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") class Fits(JROData): - + heightList = None - + channelList = None - + flagNoData = True - + flagDiscontinuousBlock = False - + useLocalTime = False - + utctime = None - + timeZone = None - + # ippSeconds = None - + # timeInterval = None - + nCohInt = None - + nIncohInt = None - + noise = None - + windowOfFilter = 1 - + #Speed of ligth C = 3e8 - + frequency = 49.92e6 - + realtime = False - + def __init__(self): - + self.type = "Fits" - + self.nProfiles = None - + self.heightList = None - + self.channelList = None - + # self.channelIndexList = None - + self.flagNoData = True - + self.utctime = None - + self.nCohInt = 1 - + self.nIncohInt = 1 - + self.useLocalTime = True - + self.profileIndex = 0 - + # self.utctime = None # self.timeZone = None # self.ltctime = None @@ -860,230 +887,230 @@ class Fits(JROData): # self.nSamples = None # self.dataBlocksPerFile = None # self.comments = '' -# +# + - def getltctime(self): - + if self.useLocalTime: return self.utctime - self.timeZone*60 - + return self.utctime - + def getDatatime(self): - + datatime = datetime.datetime.utcfromtimestamp(self.ltctime) return datatime - + def getTimeRange(self): - + datatime = [] - + datatime.append(self.ltctime) datatime.append(self.ltctime + self.timeInterval) - + datatime = numpy.array(datatime) - + return datatime - + def getHeiRange(self): - + heis = self.heightList - + return heis - + def getNHeights(self): - + return len(self.heightList) - + def getNChannels(self): - + return len(self.channelList) - + def getChannelIndexList(self): - + return range(self.nChannels) - + def getNoise(self, type = 1): - + #noise = numpy.zeros(self.nChannels) - + if type == 1: noise = self.getNoisebyHildebrand() - + if type == 2: noise = self.getNoisebySort() - + if type == 3: noise = self.getNoisebyWindow() - + return noise - + def getTimeInterval(self): - + timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt - + return timeInterval - + datatime = property(getDatatime, "I'm the 'datatime' property") nHeights = property(getNHeights, "I'm the 'nHeights' property.") nChannels = property(getNChannels, "I'm the 'nChannel' property.") channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") noise = property(getNoise, "I'm the 'nHeights' property.") - + ltctime = property(getltctime, "I'm the 'ltctime' property") timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") - - + + class Correlation(JROData): - + noise = None - + SNR = None - + #-------------------------------------------------- - + mode = None - + split = False data_cf = None - + lags = None - + lagRange = None - + pairsList = None - + normFactor = None - + #-------------------------------------------------- - + # calculateVelocity = None - + nLags = None - + nPairs = None - + nAvg = None - + def __init__(self): ''' Constructor ''' self.radarControllerHeaderObj = RadarControllerHeader() - + self.systemHeaderObj = SystemHeader() - + self.type = "Correlation" - + self.data = None - + self.dtype = None - + self.nProfiles = None - + self.heightList = None - + self.channelList = None - + self.flagNoData = True - + self.flagDiscontinuousBlock = False - + self.utctime = None - + self.timeZone = None - + self.dstFlag = None - + self.errorCount = None - + self.blocksize = None - + self.flagDecodeData = False #asumo q la data no esta decodificada - + self.flagDeflipData = False #asumo q la data no esta sin flip - + self.pairsList = None - + self.nPoints = None def getPairsList(self): - + return self.pairsList - + def getNoise(self, mode = 2): - + indR = numpy.where(self.lagR == 0)[0][0] indT = numpy.where(self.lagT == 0)[0][0] - + jspectra0 = self.data_corr[:,:,indR,:] jspectra = copy.copy(jspectra0) - + num_chan = jspectra.shape[0] num_hei = jspectra.shape[2] - + freq_dc = jspectra.shape[1]/2 - ind_vel = numpy.array([-2,-1,1,2]) + freq_dc - + ind_vel = numpy.array([-2,-1,1,2]) + freq_dc + if ind_vel[0]<0: ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof - - if mode == 1: + + if mode == 1: jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION - + if mode == 2: - + vel = numpy.array([-2,-1,1,2]) xx = numpy.zeros([4,4]) - + for fil in range(4): xx[fil,:] = vel[fil]**numpy.asarray(range(4)) - + xx_inv = numpy.linalg.inv(xx) xx_aux = xx_inv[0,:] - + for ich in range(num_chan): yy = jspectra[ich,ind_vel,:] jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) junkid = jspectra[ich,freq_dc,:]<=0 cjunkid = sum(junkid) - + if cjunkid.any(): jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 - + noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] - + return noise def getTimeInterval(self): - + timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles - + return timeInterval - + def splitFunctions(self): - + pairsList = self.pairsList ccf_pairs = [] acf_pairs = [] ccf_ind = [] acf_ind = [] - for l in range(len(pairsList)): + for l in range(len(pairsList)): chan0 = pairsList[l][0] chan1 = pairsList[l][1] - - #Obteniendo pares de Autocorrelacion + + #Obteniendo pares de Autocorrelacion if chan0 == chan1: acf_pairs.append(chan0) acf_ind.append(l) else: ccf_pairs.append(pairsList[l]) ccf_ind.append(l) - + data_acf = self.data_cf[acf_ind] data_ccf = self.data_cf[ccf_ind] @@ -1093,97 +1120,97 @@ class Correlation(JROData): acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() acf_pairs = numpy.array(acf_pairs) normFactor = numpy.zeros((self.nPairs,self.nHeights)) - + for p in range(self.nPairs): pair = self.pairsList[p] - + ch0 = pair[0] ch1 = pair[1] - + ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) - + return normFactor - + timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") normFactor = property(getNormFactor, "I'm the 'normFactor property'") - + class Parameters(JROData): experimentInfo = None #Information about the experiment - + #Information from previous data - + inputUnit = None #Type of data to be processed - + operation = None #Type of operation to parametrize - + normFactor = None #Normalization Factor - + groupList = None #List of Pairs, Groups, etc - + #Parameters - + data_param = None #Parameters obtained - + data_pre = None #Data Pre Parametrization - + data_SNR = None #Signal to Noise Ratio - + # heightRange = None #Heights - + abscissaList = None #Abscissa, can be velocities, lags or time - + noise = None #Noise Potency - + utctimeInit = None #Initial UTC time - + paramInterval = None #Time interval to calculate Parameters in seconds - + useLocalTime = True - + #Fitting - + data_error = None #Error of the estimation - - constants = None - + + constants = None + library = None - + #Output signal - + outputInterval = None #Time interval to calculate output signal in seconds - + data_output = None #Out signal - + nAvg = None - - + + def __init__(self): ''' Constructor ''' self.radarControllerHeaderObj = RadarControllerHeader() - + self.systemHeaderObj = SystemHeader() - + self.type = "Parameters" - + def getTimeRange1(self, interval): - + datatime = [] - + if self.useLocalTime: time1 = self.utctimeInit - self.timeZone*60 else: time1 = self.utctimeInit - + # datatime.append(self.utctimeInit) # datatime.append(self.utctimeInit + self.outputInterval) datatime.append(time1) datatime.append(time1 + interval) - + datatime = numpy.array(datatime) - + return datatime diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index 3191d1d..2ef13ed 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -1,5 +1,6 @@ import os +import zmq import time import numpy import datetime @@ -7,80 +8,48 @@ import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable from matplotlib.ticker import FuncFormatter, LinearLocator +from multiprocessing import Process from schainpy.model.proc.jroproc_base import Operation +#plt.ion() + func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M')) d1970 = datetime.datetime(1970,1,1) +class PlotData(Operation, Process): -class PlotData(Operation): - - __code = 'Figure' + CODE = 'Figure' + colormap = 'jet' __MAXNUMX = 80 __MAXNUMY = 80 __missing = 1E30 - def __init__(self): + def __init__(self, **kwargs): Operation.__init__(self) - self.xmin = None - self.xmax = None - self.newdataOut = None + Process.__init__(self) + self.mp = False self.dataOut = None self.isConfig = False self.figure = None - self.width = 6 - self.height = 4 - - def setup(self, dataOut, **kwargs): - - self.first = True + self.axes = [] self.localtime = kwargs.pop('localtime', True) - self.show = kwargs.pop('show', True) - self.save = kwargs.pop('save', False) - self.pause = kwargs.pop('pause', False) - self.time = [] - self.nblock = 0 - self.z = [] - self.data = [{} for __ in dataOut.channelList] - self.axes = [] - self.colormap = kwargs.get('colormap', 'jet') + self.show = kwargs.get('show', True) + self.save = kwargs.get('save', False) + self.colormap = kwargs.get('colormap', self.colormap) + self.showprofile = kwargs.get('showprofile', False) self.title = kwargs.get('wintitle', '') - self.xaxis = kwargs.get('xaxis', None) + self.xaxis = kwargs.get('xaxis', 'time') self.zmin = kwargs.get('zmin', None) self.zmax = kwargs.get('zmax', None) - - xmin = kwargs.get('xmin', 0) - xmax = kwargs.get('xmax', xmin+4) - - dt = dataOut.datatime.date() - dtmin = datetime.datetime.combine(dt, datetime.time(xmin, 0, 0)) - dtmax = datetime.datetime.combine(dt, datetime.time(xmax, 59, 59)) - - self.xmin = (dtmin-d1970).total_seconds() - self.xmax = (dtmax-d1970).total_seconds() - + self.xmin = kwargs.get('xmin', None) + self.xmax = kwargs.get('xmax', None) + self.xrange = kwargs.get('xrange', 24) self.ymin = kwargs.get('ymin', None) self.ymax = kwargs.get('ymax', None) - if self.figure is None: - self.figure = plt.figure() - else: - self.figure.clf() - - self.setup_fig() - - for n in range(dataOut.nChannels): - ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) - ax.firsttime = True - self.axes.append(ax) - - self.setup_fig() - - self.figure.set_size_inches (self.width, self.height) - def fill_gaps(self, x_buffer, y_buffer, z_buffer): if x_buffer.shape[0] < 2: @@ -100,160 +69,308 @@ class PlotData(Operation): return x_buffer, y_buffer, z_buffer def decimate(self): - + dx = int(len(self.x)/self.__MAXNUMX) + 1 dy = int(len(self.y)/self.__MAXNUMY) + 1 - + x = self.x[::dx] - y = self.y[::dy] + y = self.y[::dy] z = self.z[::, ::dx, ::dy] - + return x, y, z - def _plot(self): + def __plot(self): + + print 'plotting...{}'.format(self.CODE) self.plot() - - self.figure.suptitle(self.title+self.__code) - + self.figure.suptitle('{} {}'.format(self.title, self.CODE.upper())) + if self.save: - figname = os.path.join(self.save, '{}_{}.png'.format(self.__code, - self.plot_dt.strftime('%y%m%d_%H%M%S'))) + figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, + datetime.datetime.utcfromtimestamp(self.times[-1]).strftime('%y%m%d_%H%M%S'))) print 'Saving figure: {}'.format(figname) self.figure.savefig(figname) self.figure.canvas.draw() - if self.show: - self.figure.show() - if self.pause: - raw_input('Press to continue') - - def update(self): + def plot(self): + + print 'plotting...{}'.format(self.CODE.upper()) + return - pass + def run(self): - def run(self, dataOut, **kwargs): + print '[Starting] {}'.format(self.name) + context = zmq.Context() + receiver = context.socket(zmq.SUB) + receiver.setsockopt(zmq.SUBSCRIBE, '') + receiver.setsockopt(zmq.CONFLATE, True) + receiver.connect("ipc:///tmp/zmq.plots") - self.dataOut = dataOut + while True: + try: + #if True: + self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) + self.dataOut = self.data['dataOut'] + self.times = self.data['times'] + self.times.sort() + self.min_time = self.times[0] + self.max_time = self.times[-1] - if not self.isConfig: - self.setup(dataOut, **kwargs) - self.isConfig = True + if self.isConfig is False: + self.setup() + self.isConfig = True - self.nblock += 1 - self.update() - - if dataOut.ltctime>=self.xmax: - self._plot() - self.isConfig = False + self.__plot() + + if 'ENDED' in self.data: + #self.setup() + #self.__plot() + pass + + except zmq.Again as e: + print 'Waiting for data...' + plt.pause(5) + #time.sleep(3) def close(self): if self.dataOut: self._plot() - + class PlotSpectraData(PlotData): - - __code = 'Spectra' - def setup_fig(self): - pass + CODE = 'spc' + colormap = 'jro' + + def setup(self): + + ncolspan = 1 + colspan = 1 + self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) + self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) + self.width = 3.6*self.ncols + self.height = 3.2*self.nrows + if self.showprofile: + ncolspan = 3 + colspan = 2 + self.width += 1.2*self.ncols + + self.ylabel = 'Range [Km]' + self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] + + if self.figure is None: + self.figure = plt.figure(figsize=(self.width, self.height), + edgecolor='k', + facecolor='w') + else: + self.figure.clf() + + n = 0 + for y in range(self.nrows): + for x in range(self.ncols): + if n>=self.dataOut.nChannels: + break + ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) + if self.showprofile: + ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) + + ax.firsttime = True + self.axes.append(ax) + n += 1 + + self.figure.subplots_adjust(wspace=0.9, hspace=0.5) + self.figure.show() - def update(self): - - for ch in self.dataOut.channelList: - self.data[ch] = self.dataOut.data_spc[ch] - def plot(self): - pass + + if self.xaxis == "frequency": + x = self.dataOut.getFreqRange(1)/1000. + xlabel = "Frequency (kHz)" + elif self.xaxis == "time": + x = self.dataOut.getAcfRange(1) + xlabel = "Time (ms)" + else: + x = self.dataOut.getVelRange(1) + xlabel = "Velocity (m/s)" + + y = self.dataOut.getHeiRange() + z = self.data[self.CODE] + + for n, ax in enumerate(self.axes): + + if ax.firsttime: + self.xmax = self.xmax if self.xmax else np.nanmax(x) + self.xmin = self.xmin if self.xmin else -self.xmax + self.ymin = self.ymin if self.ymin else np.nanmin(y) + self.ymax = self.ymax if self.ymax else np.nanmax(y) + self.zmin = self.zmin if self.zmin else np.nanmin(z) + self.zmax = self.zmax if self.zmax else np.nanmax(z) + ax.plot = ax.pcolormesh(x, y, z[n].T, + vmin=self.zmin, + vmax=self.zmax, + cmap=plt.get_cmap(self.colormap) + ) + divider = make_axes_locatable(ax) + cax = divider.new_horizontal(size='3%', pad=0.05) + self.figure.add_axes(cax) + plt.colorbar(ax.plot, cax) + + ax.set_xlim(self.xmin, self.xmax) + ax.set_ylim(self.ymin, self.ymax) + + ax.xaxis.set_major_locator(LinearLocator(5)) + #ax.yaxis.set_major_locator(LinearLocator(4)) + + ax.set_ylabel(self.ylabel) + ax.set_xlabel(xlabel) + + ax.firsttime = False + + if self.showprofile: + ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] + ax.ax_profile.set_xlim(self.zmin, self.zmax) + ax.ax_profile.set_ylim(self.ymin, self.ymax) + ax.ax_profile.set_xlabel('dB') + ax.ax_profile.grid(b=True, axis='x') + [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] + noise = 10*numpy.log10(self.data['rti'][self.max_time][n]/self.dataOut.normFactor) + ax.ax_profile.vlines(noise, self.ymin, self.ymax, colors="k", linestyle="dashed", lw=2) + else: + ax.plot.set_array(z[n].T.ravel()) + ax.set_title('{} {}'.format(self.titles[n], + datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), + size=8) + if self.showprofile: + ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) class PlotRTIData(PlotData): - - __code = 'RTI' - - def setup_fig(self): - + + CODE = 'rti' + colormap = 'jro' + + def setup(self): + self.ncols = 1 self.nrows = self.dataOut.nChannels - self.width = 8 + self.width = 10 self.height = 2.2*self.nrows self.ylabel = 'Range [Km]' - - def update(self): - - self.time.append(self.dataOut.ltctime) - - for ch in self.dataOut.channelList: - self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] - + self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] + + if self.figure is None: + self.figure = plt.figure(figsize=(self.width, self.height), + edgecolor='k', + facecolor='w') + else: + self.figure.clf() + + for n in range(self.nrows): + ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) + ax.firsttime = True + self.axes.append(ax) + + self.figure.subplots_adjust(hspace=0.5) + self.figure.show() + def plot(self): - - self.plot_dt = datetime.datetime.utcfromtimestamp(self.time[-2]) - self.time.sort() - self.x = self.time + self.x = np.array(self.times) self.y = self.dataOut.getHeiRange() self.z = [] - - for ch in self.dataOut.channelList: - self.z.append([self.data[ch][t] for t in self.time]) - - self.x = np.array(self.x) - self.z = np.array(self.z) - - for n, ax in enumerate(self.axes): - - if self.xaxis=='time': - ax.xaxis.set_major_formatter(FuncFormatter(func)) - ax.xaxis.set_major_locator(LinearLocator(6)) - - ax.yaxis.set_major_locator(LinearLocator(4)) - - ax.set_ylabel(self.ylabel) - - ax.set_xlim(self.xmin, self.xmax) - - ax.set_title('Channel {} {}'.format(self.dataOut.channelList[n], - self.plot_dt.strftime('%y/%m/%d %H:%M:%S')), - size=8) - - self.decimate() + + for ch in range(self.nrows): + self.z.append([self.data[self.CODE][t][ch] for t in self.times]) + + self.z = np.array(self.z) for n, ax in enumerate(self.axes): - + x, y, z = self.fill_gaps(*self.decimate()) - + if ax.firsttime: - ymin = self.ymin if self.ymin else np.nanmin(self.y) - ymax = self.ymax if self.ymax else np.nanmax(self.y) - zmin = self.zmin if self.zmin else np.nanmin(self.z) + self.ymin = self.ymin if self.ymin else np.nanmin(self.y) + self.ymax = self.ymax if self.ymax else np.nanmax(self.y) + self.zmin = self.zmin if self.zmin else np.nanmin(self.z) zmax = self.zmax if self.zmax else np.nanmax(self.z) plot = ax.pcolormesh(x, y, z[n].T, - vmin=zmin, - vmax=zmax, + vmin=self.zmin, + vmax=self.zmax, cmap=plt.get_cmap(self.colormap) ) divider = make_axes_locatable(ax) - cax = divider.new_horizontal(size='3%', pad=0.05) + cax = divider.new_horizontal(size='2%', pad=0.05) self.figure.add_axes(cax) plt.colorbar(plot, cax) ax.set_ylim(self.ymin, self.ymax) + if self.xaxis=='time': + ax.xaxis.set_major_formatter(FuncFormatter(func)) + ax.xaxis.set_major_locator(LinearLocator(6)) + + ax.yaxis.set_major_locator(LinearLocator(4)) + + ax.set_ylabel(self.ylabel) + + if self.xmin is None: + print 'is none' + xmin = self.min_time + else: + + xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), + datetime.time(self.xmin, 0, 0))-d1970).total_seconds() + + xmax = xmin+self.xrange*60*60 + + ax.set_xlim(xmin, xmax) ax.firsttime = False - else: - plot = ax.pcolormesh(x, y, z[n].T) + else: + ax.collections.remove(ax.collections[0]) + plot = ax.pcolormesh(x, y, z[n].T, + vmin=self.zmin, + vmax=self.zmax, + cmap=plt.get_cmap(self.colormap) + ) + ax.set_title('{} {}'.format(self.titles[n], + datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), + size=8) + + +class PlotCOHData(PlotRTIData): + + CODE = 'coh' + + def setup(self): + + self.ncols = 1 + self.nrows = self.dataOut.nPairs + self.width = 10 + self.height = 2.2*self.nrows + self.ylabel = 'Range [Km]' + self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList] - self.figure.subplots_adjust(wspace=None, hspace=0.5) - + if self.figure is None: + self.figure = plt.figure(figsize=(self.width, self.height), + edgecolor='k', + facecolor='w') + else: + self.figure.clf() + + for n in range(self.nrows): + ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) + ax.firsttime = True + self.axes.append(ax) + + self.figure.subplots_adjust(hspace=0.5) + self.figure.show() class PlotSNRData(PlotRTIData): - - __code = 'SNR' - - def update(self): - - self.time.append(self.dataOut.ltctime) - - for ch in self.dataOut.channelList: - self.data[ch][self.dataOut.ltctime] = 10*np.log10(self.dataOut.data_SNR[ch]) \ No newline at end of file + + CODE = 'coh' + + +class PlotPHASEData(PlotCOHData): + + CODE = 'phase' + colormap = 'seismic' diff --git a/schainpy/model/io/jroIO_spectra.py b/schainpy/model/io/jroIO_spectra.py index aba11f2..3cd384c 100644 --- a/schainpy/model/io/jroIO_spectra.py +++ b/schainpy/model/io/jroIO_spectra.py @@ -11,174 +11,174 @@ from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, from schainpy.model.data.jrodata import Spectra class SpectraReader(JRODataReader, ProcessingUnit): - """ + """ Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura - de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) + de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. paresCanalesIguales * alturas * perfiles (Self Spectra) paresCanalesDiferentes * alturas * perfiles (Cross Spectra) canales * alturas (DC Channels) - Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, + Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de datos desde el "buffer" cada vez que se ejecute el metodo "getData". - - Example: + + Example: dpath = "/home/myuser/data" - + startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) - + endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) - + readerObj = SpectraReader() - + readerObj.setup(dpath, startTime, endTime) - + while(True): - + readerObj.getData() - + print readerObj.data_spc - + print readerObj.data_cspc - + print readerObj.data_dc - + if readerObj.flagNoMoreFiles: break - + """ pts2read_SelfSpectra = 0 - + pts2read_CrossSpectra = 0 - + pts2read_DCchannels = 0 - + ext = ".pdata" - + optchar = "P" - + dataOut = None - + nRdChannels = None - + nRdPairs = None - + rdPairList = [] - - def __init__(self): - """ + + def __init__(self, **kwargs): + """ Inicializador de la clase SpectraReader para la lectura de datos de espectros. - Inputs: + Inputs: dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para almacenar un perfil de datos cada vez que se haga un requerimiento (getData). El perfil sera obtenido a partir del buffer de datos, si el buffer esta vacio se hara un nuevo proceso de lectura de un bloque de datos. Si este parametro no es pasado se creara uno internamente. - - Affected: + + Affected: self.dataOut Return : None """ - + #Eliminar de la base la herencia - ProcessingUnit.__init__(self) - + ProcessingUnit.__init__(self, **kwargs) + # self.isConfig = False - + self.pts2read_SelfSpectra = 0 - + self.pts2read_CrossSpectra = 0 - + self.pts2read_DCchannels = 0 - + self.datablock = None - + self.utc = None - + self.ext = ".pdata" - + self.optchar = "P" - + self.basicHeaderObj = BasicHeader(LOCALTIME) - + self.systemHeaderObj = SystemHeader() - + self.radarControllerHeaderObj = RadarControllerHeader() - + self.processingHeaderObj = ProcessingHeader() - + self.online = 0 - + self.fp = None - + self.idFile = None - + self.dtype = None - + self.fileSizeByHeader = None - + self.filenameList = [] - + self.filename = None - + self.fileSize = None - + self.firstHeaderSize = 0 - + self.basicHeaderSize = 24 - + self.pathList = [] self.lastUTTime = 0 - + self.maxTimeStep = 30 - + self.flagNoMoreFiles = 0 - + self.set = 0 - + self.path = None self.delay = 60 #seconds - + self.nTries = 3 #quantity tries - + self.nFiles = 3 #number of files for searching - + self.nReadBlocks = 0 - + self.flagIsNewFile = 1 - + self.__isFirstTimeOnline = 1 - + # self.ippSeconds = 0 - - self.flagDiscontinuousBlock = 0 - + + self.flagDiscontinuousBlock = 0 + self.flagIsNewBlock = 0 - + self.nTotalBlocks = 0 - + self.blocksize = 0 - + self.dataOut = self.createObjByDefault() - + self.profileIndex = 1 #Always def createObjByDefault(self): - + dataObj = Spectra() - + return dataObj - + def __hasNotDataInBuffer(self): return 1 @@ -186,7 +186,7 @@ class SpectraReader(JRODataReader, ProcessingUnit): def getBlockDimension(self): """ Obtiene la cantidad de puntos a leer por cada bloque de datos - + Affected: self.nRdChannels self.nRdPairs @@ -203,10 +203,10 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.nRdChannels = 0 self.nRdPairs = 0 self.rdPairList = [] - + for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: - self.nRdChannels = self.nRdChannels + 1 #par de canales iguales + self.nRdChannels = self.nRdChannels + 1 #par de canales iguales else: self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) @@ -215,29 +215,29 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) self.blocksize = self.pts2read_SelfSpectra - + if self.processingHeaderObj.flag_cspc: self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) self.blocksize += self.pts2read_CrossSpectra - + if self.processingHeaderObj.flag_dc: self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) self.blocksize += self.pts2read_DCchannels - + # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels - + def readBlock(self): """ Lee el bloque de datos desde la posicion actual del puntero del archivo (self.fp) y actualiza todos los parametros relacionados al bloque de datos (metadata + data). La data leida es almacenada en el buffer y el contador del buffer es seteado a 0 - + Return: None - + Variables afectadas: - + self.flagIsNewFile self.flagIsNewBlock self.nTotalBlocks @@ -245,7 +245,7 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.data_cspc self.data_dc - Exceptions: + Exceptions: Si un bloque leido no es un bloque valido """ blockOk_flag = False @@ -253,35 +253,35 @@ class SpectraReader(JRODataReader, ProcessingUnit): spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D - + if self.processingHeaderObj.flag_cspc: cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D - + if self.processingHeaderObj.flag_dc: dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D - - + + if not(self.processingHeaderObj.shif_fft): #desplaza a la derecha en el eje 2 determinadas posiciones shift = int(self.processingHeaderObj.profilesPerBlock/2) spc = numpy.roll( spc, shift , axis=2 ) - + if self.processingHeaderObj.flag_cspc: #desplaza a la derecha en el eje 2 determinadas posiciones cspc = numpy.roll( cspc, shift, axis=2 ) - + #Dimensions : nChannels, nProfiles, nSamples spc = numpy.transpose( spc, (0,2,1) ) self.data_spc = spc - - if self.processingHeaderObj.flag_cspc: + + if self.processingHeaderObj.flag_cspc: cspc = numpy.transpose( cspc, (0,2,1) ) self.data_cspc = cspc['real'] + cspc['imag']*1j else: self.data_cspc = None - + if self.processingHeaderObj.flag_dc: self.data_dc = dc['real'] + dc['imag']*1j else: @@ -294,60 +294,60 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.nReadBlocks += 1 return 1 - + def getFirstHeader(self): - + self.getBasicHeader() - + self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() - + self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() - + # self.dataOut.ippSeconds = self.ippSeconds - + # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock self.dataOut.dtype = self.dtype - + # self.dataOut.nPairs = self.nPairs - + self.dataOut.pairsList = self.rdPairList - + self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock - + self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock - + self.dataOut.nCohInt = self.processingHeaderObj.nCohInt - + self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt - + xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight - self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) - + self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) + self.dataOut.channelList = range(self.systemHeaderObj.nChannels) - + self.dataOut.flagShiftFFT = True #Data is always shifted - + self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada - - self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip - + + self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip + def getData(self): """ First method to execute before "RUN" is called. - + Copia el buffer de lectura a la clase "Spectra", con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" - + Return: 0 : Si no hay mas archivos disponibles 1 : Si hizo una buena copia del buffer - + Affected: self.dataOut - + self.flagDiscontinuousBlock self.flagIsNewBlock """ @@ -356,68 +356,68 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.dataOut.flagNoData = True print 'Process finished' return 0 - + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 - - if self.__hasNotDataInBuffer(): + + if self.__hasNotDataInBuffer(): if not( self.readNextBlock() ): self.dataOut.flagNoData = True return 0 - + #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) if self.data_spc is None: self.dataOut.flagNoData = True return 0 - + self.getBasicHeader() - + self.getFirstHeader() self.dataOut.data_spc = self.data_spc - + self.dataOut.data_cspc = self.data_cspc - + self.dataOut.data_dc = self.data_dc - + self.dataOut.flagNoData = False - + self.dataOut.realtime = self.online - + return self.dataOut.data_spc class SpectraWriter(JRODataWriter, Operation): - - """ + + """ Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura - de los datos siempre se realiza por bloques. + de los datos siempre se realiza por bloques. """ - + ext = ".pdata" - + optchar = "P" - + shape_spc_Buffer = None - + shape_cspc_Buffer = None - + shape_dc_Buffer = None - + data_spc = None - + data_cspc = None - + data_dc = None - + # dataOut = None - + def __init__(self): - """ + """ Inicializador de la clase SpectraWriter para la escritura de datos de espectros. - - Affected: + + Affected: self.dataOut self.basicHeaderObj self.systemHeaderObj @@ -426,50 +426,50 @@ class SpectraWriter(JRODataWriter, Operation): Return: None """ - + Operation.__init__(self) - + self.isConfig = False - + self.nTotalBlocks = 0 - + self.data_spc = None - + self.data_cspc = None - + self.data_dc = None self.fp = None self.flagIsNewFile = 1 - - self.nTotalBlocks = 0 - + + self.nTotalBlocks = 0 + self.flagIsNewBlock = 0 self.setFile = None - + self.dtype = None - + self.path = None - + self.noMoreFiles = 0 - + self.filename = None - + self.basicHeaderObj = BasicHeader(LOCALTIME) - + self.systemHeaderObj = SystemHeader() - + self.radarControllerHeaderObj = RadarControllerHeader() - + self.processingHeaderObj = ProcessingHeader() - + def hasAllDataInBuffer(self): return 1 - + def setBlockDimension(self): """ Obtiene las formas dimensionales del los subbloques de datos que componen un bloque @@ -488,15 +488,15 @@ class SpectraWriter(JRODataWriter, Operation): self.shape_cspc_Buffer = (self.dataOut.nPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) - + self.shape_dc_Buffer = (self.dataOut.nChannels, self.processingHeaderObj.nHeights) - + def writeBlock(self): """ Escribe el buffer en el file designado - + Affected: self.data_spc self.data_cspc @@ -504,11 +504,11 @@ class SpectraWriter(JRODataWriter, Operation): self.flagIsNewFile self.flagIsNewBlock self.nTotalBlocks - self.nWriteBlocks - + self.nWriteBlocks + Return: None """ - + spc = numpy.transpose( self.data_spc, (0,2,1) ) if not( self.processingHeaderObj.shif_fft ): spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones @@ -525,7 +525,7 @@ class SpectraWriter(JRODataWriter, Operation): data['imag'] = cspc.imag data = data.reshape((-1)) data.tofile(self.fp) - + if self.data_dc is not None: data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) dc = self.data_dc @@ -535,40 +535,40 @@ class SpectraWriter(JRODataWriter, Operation): data.tofile(self.fp) # self.data_spc.fill(0) -# +# # if self.data_dc is not None: # self.data_dc.fill(0) -# +# # if self.data_cspc is not None: # self.data_cspc.fill(0) - + self.flagIsNewFile = 0 self.flagIsNewBlock = 1 self.nTotalBlocks += 1 self.nWriteBlocks += 1 self.blockIndex += 1 - + # print "[Writing] Block = %d04" %self.blockIndex - + def putData(self): """ - Setea un bloque de datos y luego los escribe en un file - + Setea un bloque de datos y luego los escribe en un file + Affected: self.data_spc self.data_cspc self.data_dc - Return: - 0 : Si no hay data o no hay mas files que puedan escribirse + Return: + 0 : Si no hay data o no hay mas files que puedan escribirse 1 : Si se escribio la data de un bloque en un file """ - + if self.dataOut.flagNoData: return 0 - + self.flagIsNewBlock = 0 - + if self.dataOut.flagDiscontinuousBlock: self.data_spc.fill(0) if self.dataOut.data_cspc is not None: @@ -576,104 +576,104 @@ class SpectraWriter(JRODataWriter, Operation): if self.dataOut.data_dc is not None: self.data_dc.fill(0) self.setNextFile() - + if self.flagIsNewFile == 0: self.setBasicHeader() - + self.data_spc = self.dataOut.data_spc.copy() - + if self.dataOut.data_cspc is not None: self.data_cspc = self.dataOut.data_cspc.copy() - + if self.dataOut.data_dc is not None: self.data_dc = self.dataOut.data_dc.copy() - + # #self.processingHeaderObj.dataBlocksPerFile) if self.hasAllDataInBuffer(): # self.setFirstHeader() self.writeNextBlock() - + return 1 - + def __getBlockSize(self): ''' Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra ''' - + dtype_width = self.getDtypeWidth() - + pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints - + pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) blocksize = (pts2write_SelfSpectra*dtype_width) - + if self.dataOut.data_cspc is not None: pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) blocksize += (pts2write_CrossSpectra*dtype_width*2) - + if self.dataOut.data_dc is not None: pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) blocksize += (pts2write_DCchannels*dtype_width*2) - + # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO return blocksize - + def setFirstHeader(self): - + """ Obtiene una copia del First Header - + Affected: self.systemHeaderObj self.radarControllerHeaderObj self.dtype - Return: + Return: None """ - + self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() self.systemHeaderObj.nChannels = self.dataOut.nChannels self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() - + self.processingHeaderObj.dtype = 1 # Spectra self.processingHeaderObj.blockSize = self.__getBlockSize() self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval - self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt + self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT - + if self.processingHeaderObj.totalSpectra > 0: channelList = [] for channel in range(self.dataOut.nChannels): channelList.append(channel) channelList.append(channel) - + pairsList = [] if self.dataOut.nPairs > 0: for pair in self.dataOut.pairsList: pairsList.append(pair[0]) pairsList.append(pair[1]) - + spectraComb = channelList + pairsList spectraComb = numpy.array(spectraComb, dtype="u1") self.processingHeaderObj.spectraComb = spectraComb - + if self.dataOut.code is not None: self.processingHeaderObj.code = self.dataOut.code self.processingHeaderObj.nCode = self.dataOut.nCode self.processingHeaderObj.nBaud = self.dataOut.nBaud - + if self.processingHeaderObj.nWindows != 0: self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] self.processingHeaderObj.nHeights = self.dataOut.nHeights self.processingHeaderObj.samplesWin = self.dataOut.nHeights - + self.processingHeaderObj.processFlags = self.getProcessFlags() - + self.setBasicHeader() diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index a9b3cb0..2362475 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -27,7 +27,7 @@ class ProcessingUnit(object): isConfig = False - def __init__(self): + def __init__(self, *args, **kwargs): self.dataIn = None self.dataInList = [] @@ -38,6 +38,9 @@ class ProcessingUnit(object): self.isConfig = False + self.args = args + self.kwargs = kwargs + def addOperation(self, opObj, objId): """ @@ -104,17 +107,13 @@ class ProcessingUnit(object): methodToCall = getattr(self, name) #Executing the self method - methodToCall(**kwargs) - - #Checkin the outputs -# if name == 'run': -# pass -# else: -# pass -# -# if name != 'run': -# return True + if hasattr(self, 'mp'): + if self.mp is False: + self.mp = True + self.start() + else: + methodToCall(**kwargs) if self.dataOut is None: return False @@ -124,7 +123,7 @@ class ProcessingUnit(object): return True - def callObject(self, objId, **kwargs): + def callObject(self, objId): """ Ejecuta la operacion asociada al identificador del objeto "objId" @@ -140,16 +139,21 @@ class ProcessingUnit(object): None """ - if self.dataOut.isEmpty(): + if self.dataOut is not None and self.dataOut.isEmpty(): return False externalProcObj = self.operations2RunDict[objId] - externalProcObj.run(self.dataOut, **kwargs) + if hasattr(externalProcObj, 'mp'): + if externalProcObj.mp is False: + externalProcObj.mp = True + externalProcObj.start() + else: + externalProcObj.run(self.dataOut, **externalProcObj.kwargs) return True - def call(self, opType, opName=None, opId=None, **kwargs): + def call(self, opType, opName=None, opId=None): """ Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa @@ -194,7 +198,7 @@ class ProcessingUnit(object): if not opName: raise ValueError, "opName parameter should be defined" - sts = self.callMethod(opName, **kwargs) + sts = self.callMethod(opName, **self.kwargs) elif opType == 'other' or opType == 'external' or opType == 'plotter': @@ -204,7 +208,7 @@ class ProcessingUnit(object): if opId not in self.operations2RunDict.keys(): raise ValueError, "Any operation with id=%s has been added" %str(opId) - sts = self.callObject(opId, **kwargs) + sts = self.callObject(opId) else: raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType @@ -221,7 +225,7 @@ class ProcessingUnit(object): return self.dataOut def checkInputs(self): - + for thisDataIn in self.dataInList: if thisDataIn.isEmpty(): @@ -255,10 +259,11 @@ class Operation(object): __buffer = None isConfig = False - def __init__(self): + def __init__(self, **kwargs): self.__buffer = None self.isConfig = False + self.kwargs = kwargs def setup(self): diff --git a/schainpy/model/utils/jroutils_publish.py b/schainpy/model/utils/jroutils_publish.py index a9088a4..7cf665a 100644 --- a/schainpy/model/utils/jroutils_publish.py +++ b/schainpy/model/utils/jroutils_publish.py @@ -16,6 +16,8 @@ from multiprocessing import Process from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit +MAXNUMX = 100 +MAXNUMY = 100 throttle_value = 5 class PrettyFloat(float): @@ -28,14 +30,6 @@ def roundFloats(obj): elif isinstance(obj, float): return round(obj, 2) -def pretty_floats(obj): - if isinstance(obj, float): - return PrettyFloat(obj) - elif isinstance(obj, dict): - return dict((k, pretty_floats(v)) for k, v in obj.items()) - elif isinstance(obj, (list, tuple)): - return map(pretty_floats, obj) - return obj class throttle(object): """Decorator that prevents a function from being called more than once every @@ -76,9 +70,6 @@ class throttle(object): class PublishData(Operation): """Clase publish.""" - __MAXNUMX = 100 - __MAXNUMY = 100 - def __init__(self, **kwargs): """Inicio.""" Operation.__init__(self, **kwargs) @@ -146,12 +137,12 @@ class PublishData(Operation): context = zmq.Context() self.zmq_socket = context.socket(zmq.PUSH) server = kwargs.get('server', 'zmq.pipe') - + if 'tcp://' in server: address = server else: address = 'ipc:///tmp/%s' % server - + self.zmq_socket.connect(address) time.sleep(1) print 'zeromq configured' @@ -166,8 +157,8 @@ class PublishData(Operation): z = data/self.dataOut.normFactor zdB = 10*numpy.log10(z) xlen, ylen = zdB[0].shape - dx = numpy.floor(xlen/self.__MAXNUMX) + 1 - dy = numpy.floor(ylen/self.__MAXNUMY) + 1 + dx = int(xlen/MAXNUMX) + 1 + dy = int(ylen/MAXNUMY) + 1 Z = [0 for i in self.dataOut.channelList] for i in self.dataOut.channelList: Z[i] = zdB[i][::dx, ::dy].tolist() @@ -237,7 +228,7 @@ class PublishData(Operation): self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) if self.zeromq is 1: - print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) + print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) self.zmq_socket.send_pyobj(self.dataOut) def run(self, dataOut, **kwargs): @@ -257,3 +248,131 @@ class PublishData(Operation): if self.client: self.client.loop_stop() self.client.disconnect() + + +class ReceiverData(ProcessingUnit, Process): + + def __init__(self, **kwargs): + + ProcessingUnit.__init__(self, **kwargs) + Process.__init__(self) + self.mp = False + self.isConfig = False + self.plottypes =[] + self.connections = 0 + server = kwargs.get('server', 'zmq.pipe') + if 'tcp://' in server: + address = server + else: + address = 'ipc:///tmp/%s' % server + + self.address = address + self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] + self.realtime = kwargs.get('realtime', False) + global throttle_value + throttle_value = kwargs.get('throttle', 10) + self.setup() + + def setup(self): + + self.data = {} + self.data['times'] = [] + for plottype in self.plottypes: + self.data[plottype] = {} + + self.isConfig = True + + def event_monitor(self, monitor): + + events = {} + + for name in dir(zmq): + if name.startswith('EVENT_'): + value = getattr(zmq, name) + events[value] = name + + while monitor.poll(): + evt = recv_monitor_message(monitor) + if evt['event'] == 32: + self.connections += 1 + if evt['event'] == 512: + pass + if self.connections == 0 and self.started is True: + self.ended = True + # send('ENDED') + evt.update({'description': events[evt['event']]}) + + if evt['event'] == zmq.EVENT_MONITOR_STOPPED: + break + monitor.close() + print("event monitor thread done!") + + @throttle(seconds=throttle_value) + def sendData(self, data): + self.send(data) + + def send(self, data): + print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) + self.sender.send_pyobj(data) + + def update(self): + + t = self.dataOut.ltctime + self.data['times'].append(t) + self.data['dataOut'] = self.dataOut + + for plottype in self.plottypes: + + if plottype == 'spc': + z = self.dataOut.data_spc/self.dataOut.normFactor + zdB = 10*numpy.log10(z) + self.data[plottype] = zdB + if plottype == 'rti': + self.data[plottype][t] = self.dataOut.getPower() + if plottype == 'snr': + self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) + if plottype == 'dop': + self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) + if plottype == 'coh': + self.data[plottype][t] = self.dataOut.getCoherence() + if plottype == 'phase': + self.data[plottype][t] = self.dataOut.getCoherence(phase=True) + + def run(self): + + print '[Starting] {} from {}'.format(self.name, self.address) + + self.context = zmq.Context() + self.receiver = self.context.socket(zmq.PULL) + self.receiver.bind(self.address) + monitor = self.receiver.get_monitor_socket() + self.sender = self.context.socket(zmq.PUB) + + self.sender.bind("ipc:///tmp/zmq.plots") + + t = Thread(target=self.event_monitor, args=(monitor,)) + t.start() + + while True: + self.dataOut = self.receiver.recv_pyobj() + print '[Receiving] {} - {}'.format(self.dataOut.type, + self.dataOut.datatime.ctime()) + + self.update() + + if self.dataOut.finished is True: + self.send(self.data) + self.connections -= 1 + if self.connections==0 and self.started: + self.ended = True + self.data['ENDED'] = True + self.send(self.data) + self.setup() + else: + if self.realtime: + self.send(self.data) + else: + self.sendData(self.data) + self.started = True + + return diff --git a/schainpy/scripts/receiver.py b/schainpy/scripts/receiver.py new file mode 100644 index 0000000..54674b8 --- /dev/null +++ b/schainpy/scripts/receiver.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +''' +Created on Jul 7, 2014 + +@author: roj-idl71 +''' +import os, sys + +from schainpy.controller import Project + +if __name__ == '__main__': + desc = "Segundo Test" + + controllerObj = Project() + controllerObj.setup(id = '191', name='test01', description=desc) + + proc1 = controllerObj.addProcUnit(name='ReceiverData') + # proc1.addParameter(name='server', value='tcp://10.10.10.87:3000', format='str') + proc1.addParameter(name='realtime', value='1', format='bool') + proc1.addParameter(name='plottypes', value='rti,spc', format='str') + + op1 = proc1.addOperation(name='PlotRTIData', optype='other') + op1.addParameter(name='wintitle', value='Julia 150Km', format='str') + + op2 = proc1.addOperation(name='PlotSpectraData', optype='other') + op2.addParameter(name='wintitle', value='Julia 150Km', format='str') + op2.addParameter(name='xaxis', value='velocity', format='str') + op2.addParameter(name='showprofile', value='1', format='bool') + #op2.addParameter(name='xmin', value='-0.1', format='float') + #op2.addParameter(name='xmax', value='0.1', format='float') + + # op1 = proc1.addOperation(name='PlotPHASEData', optype='other') + # op1.addParameter(name='wintitle', value='Julia 150Km', format='str') + + +# proc1 = controllerObj.addProcUnit(name='ReceiverData') +# proc1.addParameter(name='server', value='pipe2', format='str') +# proc1.addParameter(name='mode', value='buffer', format='str') +# proc1.addParameter(name='plottypes', value='snr', format='str') + + + controllerObj.start()