diff --git a/schainpy/Controller/Controller.py b/schainpy/Controller/Controller.py new file mode 100644 index 0000000..b9bd77f --- /dev/null +++ b/schainpy/Controller/Controller.py @@ -0,0 +1,276 @@ +''' +Created on June 5, 2012 + +$Author$ +$Id$ +''' + +import os +import sys +import datetime +import ConfigParser + +path = os.path.split(os.getcwd())[0] +sys.path.append(path) + +from Model.Voltage import Voltage +from IO.VoltageIO import * + +from Model.Spectra import Spectra +from IO.SpectraIO import * + +from Processing.VoltageProcessor import * +from Processing.SpectraProcessor import * + +class Operation: + def __init__(self,name,parameters): + self.name = name + self.parameters = [] + parametersList = parameters.split(',') + nparms = len(parametersList)/2 + for id in range(nparms): + parmtype = parametersList[id*2] + value = parametersList[id*2+1] + if value == 'None': + value = None + else: + if parmtype == 'int': + value = int(value) + elif parmtype == 'float': + value = float(value) + elif parmtype == 'str': + value = str(value) + elif parmtype == 'datetime': + value = value.split('-'); value = numpy.asarray(value,dtype=numpy.int32) + value = datetime.datetime(value[0],value[1],value[2],value[3],value[4],value[5]) + else: + value = None + + self.parameters.append(value) + + +class ExecUnit: + def __init__(self,): + self.id = None + self.type = None + self.execObjIn = None + self.execObjOut = None + self.execProcObj = None + self.input = None + self.operationList = [] + self.flagSetIO = False + + def setIO(self): + self.execProcObj.setIO(self.execObjIn,self.execObjOut) + self.flagSetIO = True + + + def Pfunction(self,name): + + def setup(*args): + inputs = args[0] + if self.type == 'VoltageReader': + path = inputs[0] + startDateTime = inputs[1] + endDateTime = inputs[2] + set = inputs[3] + expLabel = inputs[4] + ext = inputs[5] + online = inputs[6] + + return self.execProcObj.setup(path,startDateTime,endDateTime,set,expLabel,ext,online) + + if self.type == 'Voltage': + return self.execProcObj.setup() + + if self.type == 'Spectra': + nFFTPoints = inputs[0] + pairList = inputs[1] + return self.execProcObj.setup(nFFTPoints,pairList) + + def getData(*args): + + return self.execProcObj.getData() + + def init(*args): + inputs = args[0] + + parm1 = inputs[0] + + if self.type == 'Voltage': + return self.execProcObj.init() + + if self.type == 'Spectra': + return self.execProcObj.init() + + + def plotData(*args): + inputs = args[0] + + if self.type == 'Voltage': + xmin = inputs[0] + xmax = inputs[1] + ymin = inputs[2] + ymax = inputs[3] + type = inputs[4] + winTitle = inputs[5] + index = inputs[6] + + return self.execProcObj.plotData(xmin,xmax,ymin,ymax,type,winTitle,index) + + if self.type == 'Spectra': + xmin = inputs[0] + xmax = inputs[1] + ymin = inputs[2] + ymax = inputs[3] + winTitle = inputs[4] + index = inputs[5] + + return self.execProcObj.plotData(xmin,xmax,ymin,ymax,winTitle,index) + + def integrator(*args): + inputs = args[0] + N = inputs[0] + self.execProcObj.integrator(N) + + pfuncDict = { "setup": setup, + "getdata": getData, + "init": init, + "plotdata": plotData, + "integrator": integrator} + + return pfuncDict[name] + + + def run(self): + nopers = len(self.operationList) + for idOper in range(nopers): + operObj = self.operationList[idOper] + self.Pfunction(operObj.name)(operObj.parameters) + + +class Controller: + + def __init__(self): + self.sectionList = None + self.execUnitList = None + self.execObjList = None + self.readConfigFile() + self.createObjects() + self.setupOjects() + self.start() + + def readConfigFile(self, filename='experiment.cfg'): + + parser = ConfigParser.SafeConfigParser() + parser.read(filename) + self.sectionList = parser.sections() + self.execUnitList = [] + + for section_name in self.sectionList: + itemList = parser.items(section_name) + self.execUnitList.append(itemList) + + print + + def createObjects(self): + self.execObjList = [] + + for itemList in self.execUnitList: + execObj = ExecUnit() + for item in itemList: + name, value = item[0], item[1] + + if name == 'id': + execObj.id = int(value) + continue + + if name == 'type': + execObj.type = value + + if value == 'VoltageReader': + execObj.execObjOut = Voltage() + execObj.execProcObj = VoltageReader(execObj.execObjOut) + + + if value == 'SpectraReader': + execObj.execObjOut = Spectra() + execObj.execProcObj = SpectraReader(execObj.execObjOut) + + + if value == 'CorrelationReader': + execObj.execObjOut = Correlation() + execObj.execProcObj = CorrelationReader(execObj.execObjOut) + + + if value == 'Voltage': + execObj.execProcObj = VoltageProcessor() + execObj.execObjOut = Voltage() + + if value == 'Spectra': + execObj.execProcObj = SpectraProcessor() + execObj.execObjOut = Spectra() + + if value == 'Correlation': + execObj.execProcObj = CorrelationProcessor() + execObj.execObjOut = Correlation() + + elif name == 'input': + execObj.input = int(value) + + else: + operObj = Operation(name,value) + + if name != 'setup': + execObj.operationList.append(operObj) + else: + execObj.Pfunction(name)(operObj.parameters) + + del(operObj) + + self.execObjList.append(execObj) + del(execObj) + + + + def setupOjects(self): + for objIndex in range(len(self.execObjList)): + currExecObj = self.execObjList[objIndex] + + if not(currExecObj.type in ['VoltageReader','SpectraReader','CorrelationReader']): + + idSearch = currExecObj.input + + for objIndex2 in range(len(self.execObjList)): + + lastExecObj = self.execObjList[objIndex2] # este objeto si puede ser un readerl + + if lastExecObj.id == idSearch and currExecObj.flagSetIO == False: + currExecObj.execObjIn = lastExecObj.execObjOut + currExecObj.setIO() + + + + + + + def start(self): + + while(True): + for indexObj in range(len(self.execObjList)): + ExecObj = self.execObjList[indexObj] + ExecObj.run() + + readExecObj = self.execObjList[0] # se asume que el primer elemento es un Reader + if readExecObj.execProcObj.flagNoMoreFiles: + break + if readExecObj.execProcObj.flagIsNewBlock: + print 'Block No %04d, Time: %s' %(readExecObj.execProcObj.nTotalBlocks, + datetime.datetime.fromtimestamp(readExecObj.execProcObj.m_BasicHeader.utc),) + + + + +if __name__ == '__main__': + Controller() + \ No newline at end of file diff --git a/schainpy/Controller/experiment.cfg b/schainpy/Controller/experiment.cfg new file mode 100644 index 0000000..71e2ae7 --- /dev/null +++ b/schainpy/Controller/experiment.cfg @@ -0,0 +1,23 @@ +[Read0] +id = 0 +type = VoltageReader +setup = str,/Users/jro/Documents/RadarData/EW_Drifts,datetime,2011-11-20-0-0-1,datetime,2011-12-31-0-0-1,int,0,str,,str,None,int,0 +getData = None,None + +[Processing0] +id = 1 +type = Voltage +input = 0 +setup = None,None +init = None,None +integrator = int,10 + + +[Processing1] +id = 2 +type = Spectra +input = 1 +setup = int,1024,None,None +init = None,None +integrator = int,2 +plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,1 diff --git a/schainpy/Processing/SpectraProcessor.py b/schainpy/Processing/SpectraProcessor.py index cd084fb..f325e50 100644 --- a/schainpy/Processing/SpectraProcessor.py +++ b/schainpy/Processing/SpectraProcessor.py @@ -49,7 +49,7 @@ class SpectraProcessor: pairList = None - def __init__(self, dataInObj, dataOutObj=None): + def __init__(self, dataInObj=None, dataOutObj=None): ''' Constructor ''' @@ -73,19 +73,40 @@ class SpectraProcessor: self.buffer = None self.ptsId = 0 - def init(self, nFFTPoints, pairList=None): + def setIO(self,inputObject, outputObject): - self.integratorObjIndex = 0 - self.decoderObjIndex = 0 - self.writerObjIndex = 0 - self.plotterObjIndex = 0 +# if not( isinstance(inputObject, Voltage) ): +# print 'InputObject must be an instance from Voltage()' +# sys.exit(0) + if not( isinstance(outputObject, Spectra) ): + print 'OutputObject must be an instance from Spectra()' + sys.exit(0) + + self.dataInObj = inputObject + self.dataOutObj = outputObject + + def setup(self,nFFTPoints=None, pairList=None): if nFFTPoints == None: nFFTPoints = self.dataOutObj.nFFTPoints self.nFFTPoints = nFFTPoints self.pairList = pairList - + +# def init(self, nFFTPoints, pairList=None): + def init(self): + + self.integratorObjIndex = 0 + self.decoderObjIndex = 0 + self.writerObjIndex = 0 + self.plotterObjIndex = 0 + +# if nFFTPoints == None: +# nFFTPoints = self.dataOutObj.nFFTPoints +# +# self.nFFTPoints = nFFTPoints +# self.pairList = pairList +# if not( isinstance(self.dataInObj, Spectra) ): self.__getFft() else: diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py index 5c94849..06d6c94 100644 --- a/schainpy/Processing/VoltageProcessor.py +++ b/schainpy/Processing/VoltageProcessor.py @@ -37,7 +37,7 @@ class VoltageProcessor: plotterObjList = [] m_Voltage= Voltage() - def __init__(self, dataInObj, dataOutObj=None): + def __init__(self, dataInObj=None, dataOutObj=None): ''' Constructor ''' @@ -61,6 +61,22 @@ class VoltageProcessor: self.writerObjList = [] self.plotterObjList = [] + def setIO(self,inputObject, outputObject): + + if not( isinstance(inputObject, Voltage) ): + print 'InputObject must be an instance from Voltage()' + sys.exit(0) + + if not( isinstance(outputObject, Voltage) ): + print 'OutputObject must be an instance from Voltage()' + sys.exit(0) + + self.dataInObj = inputObject + self.dataOutObj = outputObject + + def setup(self): + pass + def init(self): self.integratorObjIndex = 0 @@ -79,11 +95,13 @@ class VoltageProcessor: objWriter.setup(wrpath) self.writerObjList.append(objWriter) - def addPlotter(self): + def addPlotter(self, index=None): + if index==None: + index = self.plotterObjIndex - plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex) + plotObj = Osciloscope(self.dataOutObj, index) self.plotterObjList.append(plotObj) - + def addIntegrator(self, nCohInt): objCohInt = CoherentIntegrator(nCohInt) @@ -114,14 +132,14 @@ class VoltageProcessor: self.writerObjIndex += 1 - def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): + def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None): if self.dataOutObj.flagNoData: return 0 - + if len(self.plotterObjList) <= self.plotterObjIndex: - self.addPlotter() + self.addPlotter(index) - self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) + self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle) self.plotterObjIndex += 1 diff --git a/schainpy/TestSVoltageChain.py b/schainpy/TestSVoltageChain.py index 1f0964c..d2acb5b 100644 --- a/schainpy/TestSVoltageChain.py +++ b/schainpy/TestSVoltageChain.py @@ -28,12 +28,12 @@ class TestSChain(): def setValues( self ): self.path = "/home/dsuarez/Projects" #1 - self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING" + self.path = "/Users/jro/Documents/RadarData/EW_Drifts" # self.startDateTime = datetime.datetime(2007,5,1,15,49,0) # self.endDateTime = datetime.datetime(2007,5,1,23,0,0) - self.startDateTime = datetime.datetime(2011,10,4,0,0,0) - self.endDateTime = datetime.datetime(2011,10,4,0,20,0) + self.startDateTime = datetime.datetime(2011,11,20,0,0,0) + self.endDateTime = datetime.datetime(2011,12,31,0,20,0) self.N = 10 self.npts = 1024 @@ -66,7 +66,7 @@ class TestSChain(): # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-25000, ymax=25000, winTitle='sin decodificar') - self.voltProcObj.decoder(type=0) +# self.voltProcObj.decoder(type=0) # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-70000, ymax=70000,winTitle='Decodificado') #