From 83ce53852b6c73375be2235ad4e5d8fdbda8b12d 2012-11-30 07:16:59 From: Miguel Valdez Date: 2012-11-30 07:16:59 Subject: [PATCH] Primera version del controlador probada y testeada incluyendo graficos --- diff --git a/schainpy/schain.py b/schainpy/controller.py similarity index 77% rename from schainpy/schain.py rename to schainpy/controller.py index 91ba7a1..a4201e0 100644 --- a/schainpy/schain.py +++ b/schainpy/controller.py @@ -10,6 +10,7 @@ import sys import datetime from model.jrodataIO import * from model.jroprocessing import * +from model.jroplot import * def prettify(elem): """Return a pretty-printed XML string for the Element. @@ -23,13 +24,13 @@ class ParameterConf(): id = None name = None value = None - type = None + format = None ELEMENTNAME = 'Parameter' def __init__(self): - self.type = 'str' + self.format = 'str' def getElementName(self): @@ -37,42 +38,42 @@ class ParameterConf(): def getValue(self): - if self.type == 'list': + if self.format == 'list': strList = self.value.split(',') return strList - if self.type == 'intlist': + if self.format == 'intlist': strList = self.value.split(',') intList = [int(x) for x in strList] return intList - if self.type == 'floatlist': + if self.format == 'floatlist': strList = self.value.split(',') floatList = [float(x) for x in strList] return floatList - if self.type == 'date': + if self.format == 'date': strList = self.value.split('/') intList = [int(x) for x in strList] date = datetime.date(intList[0], intList[1], intList[2]) return date - if self.type == 'time': + if self.format == 'time': strList = self.value.split(':') intList = [int(x) for x in strList] time = datetime.time(intList[0], intList[1], intList[2]) return time - func = eval(self.type) + func = eval(self.format) return func(self.value) - def setup(self, id, name, value, type='str'): + def setup(self, id, name, value, format='str'): self.id = id self.name = name self.value = str(value) - self.type = type + self.format = format def makeXml(self, opElement): @@ -80,18 +81,18 @@ class ParameterConf(): parmElement.set('id', str(self.id)) parmElement.set('name', self.name) parmElement.set('value', self.value) - parmElement.set('type', self.type) + 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.type = parmElement.get('type') + self.format = parmElement.get('format') def printattr(self): - print "Parameter[%s]: name = %s, value = %s, type = %s" %(self.id, self.name, self.value, self.type) + print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) class OperationConf(): @@ -133,12 +134,12 @@ class OperationConf(): self.parmConfObjList = [] - def addParameter(self, name, value, type='str'): + def addParameter(self, name, value, format='str'): id = self.__getNewId() parmConfObj = ParameterConf() - parmConfObj.setup(id, name, value, type) + parmConfObj.setup(id, name, value, format) self.parmConfObjList.append(parmConfObj) @@ -197,7 +198,7 @@ class ProcUnitConf(): id = None name = None - type = None + datatype = None inputId = None opConfObjList = [] @@ -210,7 +211,7 @@ class ProcUnitConf(): def __init__(self): self.id = None - self.type = None + self.datatype = None self.name = None self.inputId = None @@ -247,11 +248,11 @@ class ProcUnitConf(): return self.procUnitObj - def setup(self, id, name, type, inputId): + def setup(self, id, name, datatype, inputId): self.id = id self.name = name - self.type = type + self.datatype = datatype self.inputId = inputId self.opConfObjList = [] @@ -275,7 +276,7 @@ class ProcUnitConf(): upElement = SubElement(procUnitElement, self.ELEMENTNAME) upElement.set('id', str(self.id)) upElement.set('name', self.name) - upElement.set('type', self.type) + upElement.set('datatype', self.datatype) upElement.set('inputId', str(self.inputId)) for opConfObj in self.opConfObjList: @@ -285,7 +286,7 @@ class ProcUnitConf(): self.id = upElement.get('id') self.name = upElement.get('name') - self.type = upElement.get('type') + self.datatype = upElement.get('datatype') self.inputId = upElement.get('inputId') self.opConfObjList = [] @@ -299,10 +300,10 @@ class ProcUnitConf(): def printattr(self): - print "%s[%s]: name = %s, type = %s, inputId = %s" %(self.ELEMENTNAME, + print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, self.id, self.name, - self.type, + self.datatype, self.inputId) for opConfObj in self.opConfObjList: @@ -329,18 +330,22 @@ class ProcUnitConf(): def run(self): + finalSts = False + for opConfObj in self.opConfObjList: + kwargs = {} for parmConfObj in opConfObj.getParameterObjList(): kwargs[parmConfObj.name] = parmConfObj.getValue() - - self.procUnitObj.call(opConfObj, **kwargs) - - + #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) + sts = self.procUnitObj.call(opConfObj, **kwargs) + finalSts = finalSts or sts + + return finalSts + class ReadUnitConf(ProcUnitConf): - path = None startDate = None endDate = None @@ -355,7 +360,7 @@ class ReadUnitConf(ProcUnitConf): def __init__(self): self.id = None - self.type = None + self.datatype = None self.name = None self.inputId = 0 @@ -366,11 +371,11 @@ class ReadUnitConf(ProcUnitConf): return self.ELEMENTNAME - def setup(self, id, name, type, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): + def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): self.id = id self.name = name - self.type = type + self.datatype = datatype self.path = path self.startDate = startDate @@ -387,14 +392,14 @@ class ReadUnitConf(ProcUnitConf): opObj = self.addOperation(name = 'run', optype = 'self') - opObj.addParameter(name='path' , value=self.path, type='str') - opObj.addParameter(name='startDate' , value=self.startDate, type='date') - opObj.addParameter(name='endDate' , value=self.endDate, type='date') - opObj.addParameter(name='startTime' , value=self.startTime, type='time') - opObj.addParameter(name='endTime' , value=self.endTime, type='time') - opObj.addParameter(name='expLabel' , value=self.expLabel, type='str') - opObj.addParameter(name='online' , value=self.online, type='bool') - opObj.addParameter(name='delay' , value=self.delay, type='float') + 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') + opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') + opObj.addParameter(name='online' , value=self.online, format='int') + opObj.addParameter(name='delay' , value=self.delay, format='float') return opObj @@ -434,25 +439,25 @@ class Controller(): self.name = name self.description = description - def addReadUnit(self, type, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): + def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): id = self.__getNewId() - name = '%sReader' %(type) + name = '%sReader' %(datatype) readUnitConfObj = ReadUnitConf() - readUnitConfObj.setup(id, name, type, path, startDate, endDate, startTime, endTime, online, expLabel, delay) + readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj return readUnitConfObj - def addProcUnit(self, type, inputId): + def addProcUnit(self, datatype, inputId): id = self.__getNewId() - name = '%sProc' %(type) + name = '%sProc' %(datatype) procUnitConfObj = ProcUnitConf() - procUnitConfObj.setup(id, name, type, inputId) + procUnitConfObj.setup(id, name, datatype, inputId) self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj @@ -556,9 +561,20 @@ class Controller(): # for readUnitConfObj in self.readUnitConfObjList: # readUnitConfObj.run() + while(True): + + finalSts = False + for procUnitConfObj in self.procUnitConfObjDict.values(): - procUnitConfObj.run() + #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) + sts = procUnitConfObj.run() + finalSts = finalSts or sts + + #If every process unit finished so end process + if not(finalSts): + print "Every process unit finished" + break if __name__ == '__main__': @@ -569,29 +585,38 @@ if __name__ == '__main__': controllerObj.setup(id = '191', name='test01', description=desc) - readUnitConfObj = controllerObj.addReadUnit(type='Voltage', - path='/home/roj-idl71/Data/RAWDATA/Meteors', - startDate='2012/01/01', + readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', + path='D:\Data\IMAGING', + startDate='2011/01/01', endDate='2012/12/31', startTime='00:00:00', endTime='23:59:59', online=0) - procUnitConfObj1 = controllerObj.addProcUnit(type='Voltage', inputId=readUnitConfObj.getId()) + opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks') - procUnitConfObj2 = controllerObj.addProcUnit(type='Voltage', inputId=procUnitConfObj1.getId()) + procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) - opObj11 = procUnitConfObj1.addOperation(name='selectChannels') - opObj11.addParameter(name='channelList', value='1,2', type='intlist') + opObj10 = procUnitConfObj1.addOperation(name='selectChannels') + opObj10.addParameter(name='channelList', value='0,1', format='intlist') + opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') + opObj11.addParameter(name='idfigure', value='1', format='int') + opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') + opObj11.addParameter(name='zmin', value='60', format='int') + opObj11.addParameter(name='zmax', value='100', format='int') + # opObj12 = procUnitConfObj1.addOperation(name='decoder') -# opObj12.addParameter(name='ncode', value='2', type='int') -# opObj12.addParameter(name='nbauds', value='8', type='int') -# opObj12.addParameter(name='code0', value='001110011', type='int') -# opObj12.addParameter(name='code1', value='001110011', type='int') +# opObj12.addParameter(name='ncode', value='2', format='int') +# opObj12.addParameter(name='nbauds', value='8', format='int') +# opObj12.addParameter(name='code0', value='001110011', format='int') +# opObj12.addParameter(name='code1', value='001110011', format='int') + +# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) + - opObj21 = procUnitConfObj2.addOperation(name='CohInt', optype='other') - opObj21.addParameter(name='nCohInt', value='10', type='int') +# opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') +# opObj21.addParameter(name='nCohInt', value='10', format='int') print "Escribiendo el archivo XML" diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 5f9c895..94682ea 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -1,5 +1,5 @@ import matplotlib -matplotlib.use("Agg") +matplotlib.use("TKAgg") import matplotlib.pyplot #import scitools.numpyutils from mpl_toolkits.axes_grid1 import make_axes_locatable @@ -69,6 +69,12 @@ def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl matplotlib.pyplot.tight_layout() return imesh else: + ax.set_xlim([xmin,xmax]) + ax.set_ylim([ymin,ymax]) + ax.set_xlabel(xlabel) + ax.set_ylabel(ylabel) + ax.set_title(title) + z = z.T z = z[0:-1,0:-1] mesh.set_array(z.ravel()) diff --git a/schainpy/model/jrodata.py b/schainpy/model/jrodata.py index d2c9596..a3bab2a 100644 --- a/schainpy/model/jrodata.py +++ b/schainpy/model/jrodata.py @@ -10,6 +10,99 @@ import numpy from jroheaderIO import SystemHeader, RadarControllerHeader +def hildebrand_sekhon(data, navg): + """ + This method is for the objective determination of de noise level in Doppler spectra. This + implementation technique is based on the fact that the standard deviation of the spectral + densities is equal to the mean spectral density for white Gaussian noise + + Inputs: + Data : heights + navg : numbers of averages + + Return: + -1 : any error + anoise : noise's level + """ + + dataflat = data.reshape(-1) + dataflat.sort() + npts = dataflat.size #numbers of points of the data + + if npts < 32: + print "error in noise - requires at least 32 points" + return -1.0 + + dataflat2 = numpy.power(dataflat,2) + + cs = numpy.cumsum(dataflat) + cs2 = numpy.cumsum(dataflat2) + + # data sorted in ascending order + nmin = int((npts + 7.)/8) + + for i in range(nmin, npts): + s = cs[i] + s2 = cs2[i] + p = s / float(i); + p2 = p**2; + q = s2 / float(i) - p2; + leftc = p2; + rightc = q * float(navg); + R2 = leftc/rightc + + # Signal detect: R2 < 1 (R2 = leftc/rightc) + if R2 < 1: + npts_noise = i + break + + + anoise = numpy.average(dataflat[0:npts_noise]) + + return anoise; + +def sorting_bruce(Data, navg): + sortdata = numpy.sort(Data) + lenOfData = len(Data) + nums_min = lenOfData/10 + + if (lenOfData/10) > 0: + nums_min = lenOfData/10 + else: + nums_min = 0 + + rtest = 1.0 + 1.0/navg + + sum = 0. + + sumq = 0. + + j = 0 + + cont = 1 + + while((cont==1)and(j nums_min: + if ((sumq*j) <= (rtest*sum**2)): + lnoise = sum / j + else: + j = j - 1 + sum = sum - sordata[j] + sumq = sumq - sordata[j]**2 + cont = 0 + + if j == nums_min: + lnoise = sum /j + + return lnoise + class JROData: # m_BasicHeader = BasicHeader() @@ -60,6 +153,10 @@ class JROData: ippSeconds = None timeInterval = None + + nCohInt = None + + noise = None def __init__(self): @@ -83,8 +180,6 @@ class JROData: class Voltage(JROData): - nCohInt = None - #data es un numpy array de 2 dmensiones (canales, alturas) data = None @@ -124,7 +219,30 @@ class Voltage(JROData): self.nCohInt = None self.blocksize = None + + def getNoisebyHildebrand(self): + """ + Determino el nivel de ruido usando el metodo Hildebrand-Sekhon + + Return: + noiselevel + """ + for channel in range(self.nChannels): + daux = self.data_spc[channel,:,:] + self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) + + return self.noise + + def getNoise(self, type = 1): + + self.noise = numpy.zeros(self.nChannels) + + if type == 1: + noise = self.getNoisebyHildebrand() + + return 10*numpy.log10(noise) + class Spectra(JROData): #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) @@ -181,6 +299,8 @@ class Spectra(JROData): self.utctime = None + self.nCohInt = None + self.nIncohInt = None self.blocksize = None @@ -194,7 +314,63 @@ class Spectra(JROData): xrange = numpy.arange(self.nFFTPoints) xrange = xrange return None + + def getNoisebyHildebrand(self): + """ + Determino el nivel de ruido usando el metodo Hildebrand-Sekhon + + Return: + noiselevel + """ + + for channel in range(self.nChannels): + daux = self.data_spc[channel,:,:] + self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) + + return self.noise + + def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): + """ + Determina el ruido del canal utilizando la ventana indicada con las coordenadas: + (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) + + Inputs: + heiIndexMin: Limite inferior del eje de alturas + heiIndexMax: Limite superior del eje de alturas + freqIndexMin: Limite inferior del eje de frecuencia + freqIndexMax: Limite supoerior del eje de frecuencia + """ + + data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] + + for channel in range(self.nChannels): + daux = data[channel,:,:] + self.noise[channel] = numpy.average(daux) + + return self.noise + + def getNoisebySort(self): + + for channel in range(self.nChannels): + daux = self.data_spc[channel,:,:] + self.noise[channel] = sorting_bruce(daux, self.nIncohInt) + + return self.noise + + def getNoise(self, type = 1): + + self.noise = numpy.zeros(self.nChannels) + + if type == 1: + noise = self.getNoisebyHildebrand() + + if type == 2: + noise = self.getNoisebySort() + + if type == 3: + noise = self.getNoisebyWindow() + return 10*numpy.log10(noise) class SpectraHeis(JROData): diff --git a/schainpy/model/jrodataIO.py b/schainpy/model/jrodataIO.py index e3e46c7..4d99fcb 100644 --- a/schainpy/model/jrodataIO.py +++ b/schainpy/model/jrodataIO.py @@ -185,8 +185,6 @@ class JRODataIO: ext = None - flagNoMoreFiles = 0 - flagIsNewFile = 1 flagTimeBlock = 0 @@ -246,7 +244,8 @@ class JRODataReader(JRODataIO, ProcessingUnit): nTries = 3 #quantity tries nFiles = 3 #number of files for searching - + + flagNoMoreFiles = 0 def __init__(self): @@ -721,7 +720,7 @@ class JRODataReader(JRODataIO, ProcessingUnit): for nTries in range( self.nTries ): print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) time.sleep( self.delay ) - doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp) + doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) if doypath: break @@ -770,14 +769,29 @@ class JRODataReader(JRODataIO, ProcessingUnit): return self.dataOut def getData(): - pass + + raise ValueError, "This method has not been implemented" def hasNotDataInBuffer(): - pass + + raise ValueError, "This method has not been implemented" def readBlock(): - pass + + raise ValueError, "This method has not been implemented" + + def isEndProcess(self): + + return self.flagNoMoreFiles + def printReadBlocks(self): + + print "Number of read blocks per file %04d" %self.nReadBlocks + + def printTotalBlocks(self): + + print "Number of read blocks %04d" %self.nTotalBlocks + def run(self, **kwargs): if not(self.isConfig): @@ -1277,8 +1291,12 @@ class VoltageReader(JRODataReader): self.flagTimeBlock self.flagIsNewBlock """ - if self.flagNoMoreFiles: return 0 - + + if self.flagNoMoreFiles: + self.dataOut.flagNoData = True + print 'Process finished' + return 0 + self.flagTimeBlock = 0 self.flagIsNewBlock = 0 @@ -1288,10 +1306,6 @@ class VoltageReader(JRODataReader): return 0 # self.updateDataHeader() - - if self.flagNoMoreFiles == 1: - print 'Process finished' - return 0 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) @@ -1387,8 +1401,6 @@ class VoltageWriter(JRODataWriter): self.nTotalBlocks = 0 self.flagIsNewBlock = 0 - - self.flagNoMoreFiles = 0 self.setFile = None @@ -1396,8 +1408,6 @@ class VoltageWriter(JRODataWriter): self.path = None - self.noMoreFiles = 0 - self.filename = None self.basicHeaderObj = BasicHeader() @@ -1503,10 +1513,6 @@ class VoltageWriter(JRODataWriter): self.writeNextBlock() # self.getDataHeader() - if self.flagNoMoreFiles: - #print 'Process finished' - return 0 - return 1 def __getProcessFlags(self): @@ -1872,10 +1878,13 @@ class SpectraReader(JRODataReader): 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 + #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: - cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones + #desplaza a la derecha en el eje 2 determinadas posiciones + cspc = numpy.roll( cspc, shift, axis=2 ) spc = numpy.transpose( spc, (0,2,1) ) @@ -1918,7 +1927,10 @@ class SpectraReader(JRODataReader): self.flagIsNewBlock """ - if self.flagNoMoreFiles: return 0 + if self.flagNoMoreFiles: + self.dataOut.flagNoData = True + print 'Process finished' + return 0 self.flagTimeBlock = 0 self.flagIsNewBlock = 0 @@ -1926,21 +1938,17 @@ class SpectraReader(JRODataReader): if self.__hasNotDataInBuffer(): if not( self.readNextBlock() ): + self.dataOut.flagNoData = True return 0 # self.updateDataHeader() - if self.flagNoMoreFiles == 1: - print 'Process finished' - return 0 - #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) if self.data_dc == None: self.dataOut.flagNoData = True return 0 - self.dataOut.data_spc = self.data_spc self.dataOut.data_cspc = self.data_cspc @@ -2049,8 +2057,6 @@ class SpectraWriter(JRODataWriter): self.nTotalBlocks = 0 self.flagIsNewBlock = 0 - - self.flagNoMoreFiles = 0 self.setFile = None @@ -2187,10 +2193,6 @@ class SpectraWriter(JRODataWriter): # self.getDataHeader() self.writeNextBlock() - if self.flagNoMoreFiles: - #print 'Process finished' - return 0 - return 1 diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index ac9f3cb..ae93d4f 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -3,20 +3,23 @@ import datetime from graphics.figure import * class SpectraPlot(Figure): + __isConfig = None def __init__(self): + self.__isConfig = False self.width = 850 self.height = 800 def getSubplots(self): + ncol = int(numpy.sqrt(self.nplots)+0.9) nrow = int(self.nplots*1./ncol + 0.9) return nrow, ncol - def setAxesWithOutProfiles(self, nrow, ncol): + colspan = 1 rowspan = 1 counter = 0 @@ -28,6 +31,7 @@ class SpectraPlot(Figure): counter += 1 def setAxesWithProfiles(self, nrow, ncol): + colspan = 1 rowspan = 1 factor = 2 @@ -42,6 +46,7 @@ class SpectraPlot(Figure): counter += 1 def setup(self, idfigure, wintitle, width, height, nplots, profile): + self.init(idfigure, wintitle, width, height, nplots) nrow,ncol = self.getSubplots() @@ -52,8 +57,6 @@ class SpectraPlot(Figure): self.setAxesWithOutProfiles(nrow, ncol) def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, profile=False): - if dataOut.isEmpty(): - return None if channelList == None: channelList = dataOut.channelList @@ -66,6 +69,8 @@ class SpectraPlot(Figure): x = numpy.arange(dataOut.nFFTPoints) + noise = dataOut.getNoise() + if not self.__isConfig: self.setup(idfigure=idfigure, wintitle=wintitle, @@ -74,13 +79,20 @@ class SpectraPlot(Figure): nplots=nplots, profile=profile) - if xmin == None: self.xmin = numpy.min(x) - if xmax == None: self.xmax = numpy.max(x) - if ymin == None: self.ymin = numpy.min(y) - if ymax == None: self.ymax = numpy.max(y) - if zmin == None: self.zmin = 0 - if zmax == None: self.zmax = 90 - + if xmin == None: xmin = numpy.min(x) + if xmax == None: xmax = numpy.max(x) + if ymin == None: ymin = numpy.min(y) + if ymax == None: ymax = numpy.max(y) + if zmin == None: zmin = numpy.min(z) + if zmax == None: zmax = numpy.max(z) + + self.xmin = xmin + self.xmax = xmax + self.ymin = ymin + self.ymax = ymax + self.zmin = zmin + self.zmax = zmax + self.__isConfig = True thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) @@ -95,17 +107,12 @@ class SpectraPlot(Figure): xlabel = "m/s" for i in range(len(self.axesList)): - title = "Channel %d"%i + title = "Channel %d: %4.2fdB" %(i, noise[i]) axes = self.axesList[i] z2 = z[i,:,:] axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title) - - + self.draw() - - - - class Scope(Figure): __isConfig = None @@ -175,7 +182,7 @@ class Scope(Figure): xlabel = "Range[Km]" for i in range(len(self.axesList)): - title = "Channel %d"%i + title = "Channel %d: %4.2fdB" %(i, noise[i]) axes = self.axesList[i] y2 = y[i,:] axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title) diff --git a/schainpy/model/jroprocessing.py b/schainpy/model/jroprocessing.py index 1760fa0..074664e 100644 --- a/schainpy/model/jroprocessing.py +++ b/schainpy/model/jroprocessing.py @@ -86,15 +86,24 @@ class ProcessingUnit: if name != 'run': if name == 'init' and self.dataIn.isEmpty(): - return + self.dataOut.flagNoData = True + return False if name != 'init' and self.dataOut.isEmpty(): - return + return False methodToCall = getattr(self, name) methodToCall(**kwargs) + if name != 'run': + return True + + if self.dataOut.isEmpty(): + return False + + return True + def callObject(self, objId, **kwargs): """ @@ -112,17 +121,20 @@ class ProcessingUnit: """ if self.dataOut.isEmpty(): - return + return False object = self.objectDict[objId] object.run(self.dataOut, **kwargs) + + return True def call(self, operationConf, **kwargs): """ - Ejecuta la operacion "operationConf.name" con los argumentos "**kwargs". La operacion puede - ser de dos tipos: + Return True si ejecuta la operacion "operationConf.name" con los + argumentos "**kwargs". False si la operacion no se ha ejecutado. + La operacion puede ser de dos tipos: 1. Un metodo propio de esta clase: @@ -144,12 +156,12 @@ class ProcessingUnit: """ if operationConf.type == 'self': - self.callMethod(operationConf.name, **kwargs) - return + sts = self.callMethod(operationConf.name, **kwargs) if operationConf.type == 'other': - self.callObject(operationConf.id, **kwargs) - return + sts = self.callObject(operationConf.id, **kwargs) + + return sts def setInput(self, dataIn): @@ -213,9 +225,6 @@ class VoltageProc(ProcessingUnit): def selectChannels(self, channelList): - if self.dataIn.isEmpty(): - return 0 - self.selectChannelsByIndex(channelList) def selectChannelsByIndex(self, channelIndexList): @@ -451,58 +460,13 @@ class CohInt(Operation): class SpectraProc(ProcessingUnit): def __init__(self): + self.objectDict = {} self.buffer = None self.firstdatatime = None self.profIndex = 0 self.dataOut = Spectra() - def init(self, nFFTPoints=None, pairsList=None): - if self.dataIn.type == "Spectra": - self.dataOut.copy(self.dataIn) - return - - if self.dataIn.type == "Voltage": - - if nFFTPoints == None: - raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable" - - if pairsList == None: - nPairs = 0 - else: - nPairs = len(pairsList) - - self.dataOut.nFFTPoints = nFFTPoints - self.dataOut.pairsList = pairsList - self.dataOut.nPairs = nPairs - - if self.buffer == None: - self.buffer = numpy.zeros((self.dataIn.nChannels, - self.dataOut.nFFTPoints, - self.dataIn.nHeights), - dtype='complex') - - - self.buffer[:,self.profIndex,:] = self.dataIn.data - self.profIndex += 1 - - if self.firstdatatime == None: - self.firstdatatime = self.dataIn.utctime - - if self.profIndex == self.dataOut.nFFTPoints: - self.__updateObjFromInput() - self.__getFft() - - self.dataOut.flagNoData = False - - self.buffer = None - self.firstdatatime = None - self.profIndex = 0 - - return - - raise ValuError, "The type object %s is not valid"%(self.dataIn.type) - def __updateObjFromInput(self): self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() @@ -526,7 +490,7 @@ class SpectraProc(ProcessingUnit): self.dataOut.nIncohInt = 1 self.dataOut.ippSeconds = self.dataIn.ippSeconds self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints - + def __getFft(self): """ Convierte valores de Voltaje a Spectra @@ -580,6 +544,92 @@ class SpectraProc(ProcessingUnit): self.dataOut.data_cspc = cspc self.dataOut.data_dc = dc self.dataOut.blockSize = blocksize + + def init(self, nFFTPoints=None, pairsList=None): + + if self.dataIn.type == "Spectra": + self.dataOut.copy(self.dataIn) + return + + if self.dataIn.type == "Voltage": + + if nFFTPoints == None: + raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable" + + if pairsList == None: + nPairs = 0 + else: + nPairs = len(pairsList) + + self.dataOut.nFFTPoints = nFFTPoints + self.dataOut.pairsList = pairsList + self.dataOut.nPairs = nPairs + + if self.buffer == None: + self.buffer = numpy.zeros((self.dataIn.nChannels, + self.dataOut.nFFTPoints, + self.dataIn.nHeights), + dtype='complex') + + + self.buffer[:,self.profIndex,:] = self.dataIn.data + self.profIndex += 1 + + if self.firstdatatime == None: + self.firstdatatime = self.dataIn.utctime + + if self.profIndex == self.dataOut.nFFTPoints: + self.__updateObjFromInput() + self.__getFft() + + self.dataOut.flagNoData = False + + self.buffer = None + self.firstdatatime = None + self.profIndex = 0 + + return + + raise ValuError, "The type object %s is not valid"%(self.dataIn.type) + + def selectChannels(self, channelList): + + self.selectChannelsByIndex(channelList) + + def selectChannelsByIndex(self, channelIndexList): + """ + Selecciona un bloque de datos en base a canales segun el channelIndexList + + Input: + channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] + + Affected: + self.dataOut.data + self.dataOut.channelIndexList + self.dataOut.nChannels + self.dataOut.m_ProcessingHeader.totalSpectra + self.dataOut.systemHeaderObj.numChannels + self.dataOut.m_ProcessingHeader.blockSize + + Return: + None + """ + + for channel in channelIndexList: + if channel not in self.dataOut.channelIndexList: + print channelIndexList + raise ValueError, "The value %d in channelIndexList is not valid" %channel + + nChannels = len(channelIndexList) + + data = self.dataOut.data_spc[channelIndexList,:] + + self.dataOut.data_spc = data + self.dataOut.channelIndexList = channelIndexList + self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] + self.dataOut.nChannels = nChannels + + return 1 class IncohInt(Operation):