From 34a9e34fc63a49325e5da56269869bd380d6767a 2012-12-03 17:48:51 From: Daniel Valdez Date: 2012-12-03 17:48:51 Subject: [PATCH] Adicion de la clase RTIPlot --- diff --git a/schainpy/controller.py b/schainpy/controller.py index 785e32a..001abe6 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -586,10 +586,10 @@ if __name__ == '__main__': controllerObj.setup(id = '191', name='test01', description=desc) readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', - path='D:\Data\IMAGING', - startDate='2011/01/01', + path='/Users/dsuarez/Remote/IMAGING', + startDate='2011/03/20', endDate='2012/12/31', - startTime='00:00:00', + startTime='06:10:00', endTime='23:59:59', online=0) @@ -605,31 +605,38 @@ if __name__ == '__main__': opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') # opObj11.addParameter(name='zmin', value='70', format='int') # opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='showprofile', value='1', format='int') + opObj11.addParameter(name='showprofile', value='0', format='int') - opObj10 = procUnitConfObj1.addOperation(name='selectChannels') - opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') - - opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') - opObj12.addParameter(name='n', value='2', format='int') - - opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='2', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') - opObj11.addParameter(name='zmin', value='70', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') - - opObj10 = procUnitConfObj1.addOperation(name='selectChannels') - opObj10.addParameter(name='channelList', value='2,6', format='intlist') - - opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') - opObj12.addParameter(name='n', value='2', format='int') - - opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='3', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') - opObj11.addParameter(name='zmin', value='70', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') + opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') + opObj11.addParameter(name='idfigure', value='10', format='int') + opObj11.addParameter(name='wintitle', value='RTI', format='str') +# opObj11.addParameter(name='zmin', value='70', format='int') +# opObj11.addParameter(name='zmax', value='90', format='int') + opObj11.addParameter(name='showprofile', value='0', format='int') + +# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') +# opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') +# +# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') +# opObj12.addParameter(name='n', value='2', format='int') +# +# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') +# opObj11.addParameter(name='idfigure', value='2', format='int') +# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') +# opObj11.addParameter(name='zmin', value='70', format='int') +# opObj11.addParameter(name='zmax', value='90', format='int') +# +# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') +# opObj10.addParameter(name='channelList', value='2,6', format='intlist') +# +# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') +# opObj12.addParameter(name='n', value='2', format='int') +# +# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') +# opObj11.addParameter(name='idfigure', value='3', format='int') +# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') +# opObj11.addParameter(name='zmin', value='70', format='int') +# opObj11.addParameter(name='zmax', value='90', format='int') # opObj12 = procUnitConfObj1.addOperation(name='decoder') @@ -640,16 +647,16 @@ if __name__ == '__main__': - procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) - - opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') - opObj21.addParameter(name='n', value='2', format='int') - - opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='4', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') - opObj11.addParameter(name='zmin', value='70', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') +# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) +# +# opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') +# opObj21.addParameter(name='n', value='2', format='int') +# +# opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') +# opObj11.addParameter(name='idfigure', value='4', format='int') +# opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') +# opObj11.addParameter(name='zmin', value='70', format='int') +# opObj11.addParameter(name='zmax', value='90', format='int') print "Escribiendo el archivo XML" diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index 18eb050..2c005f3 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -126,6 +126,9 @@ class Axes: __showprofile = False + __zmin = None + __zmax = None + def __init__(self, *args): """ @@ -198,7 +201,7 @@ class Axes: ymin=None, ymax=None, zmin=None, zmax=None, xlabel='', ylabel='', - title='', + title='', rti = False, **kwargs): """ @@ -218,6 +221,7 @@ class Axes: **kwargs : Los parametros aceptados son ticksize=9, cblabel='' + rti = True or False """ if self.firsttime: @@ -228,7 +232,8 @@ class Axes: if ymax == None: ymax = numpy.nanmax(y) if zmin == None: zmin = numpy.nanmin(z) if zmax == None: zmax = numpy.nanmax(z) - + + self.plot = self.__driver.createPcolor(self.ax, x, y, z, xmin, xmax, ymin, ymax, @@ -238,8 +243,14 @@ class Axes: title=title, **kwargs) self.firsttime = False + if self.__zmin == None: self.__zmin = zmin + if self.__zmax == None: self.__zmax = zmax return - - mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, - ylabel=ylabel, - title=title) + + if rti: + self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax) + return + + self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title) + + \ No newline at end of file diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index a6443d2..9d71c3f 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -107,7 +107,7 @@ def closeFigure(): matplotlib.pyplot.ioff() matplotlib.pyplot.show() - retur + return def setWinTitle(fig, title): @@ -238,6 +238,10 @@ def pcolor(imesh, z, xlabel='', ylabel='', title=''): imesh.set_array(z.ravel()) +def addpcolor(ax, x, y, z, zmin, zmax): + + imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) + def draw(fig): if type(fig) == 'int': diff --git a/schainpy/model/jrodata.py b/schainpy/model/jrodata.py index 47b993a..8d804bb 100644 --- a/schainpy/model/jrodata.py +++ b/schainpy/model/jrodata.py @@ -123,7 +123,7 @@ class JROData: # nChannels = None - nHeights = None +# nHeights = None nProfiles = None @@ -184,6 +184,10 @@ class JROData: return self.flagNoData + def getNoise(self): + + raise ValueError, "Not implemented" + def getNChannels(self): return len(self.channelList) @@ -192,9 +196,53 @@ class JROData: 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 getDatatime(self): + + datatime = [] + + datatime.append(self.utctime) + datatime.append(self.utctime + 2*self.timeInterval) + + datatime = numpy.array(datatime) + + return datatime + + def getFmax(self): + + PRF = 1./(self.ippSeconds * self.nCohInt) + + fmax = PRF/2. + + return fmax + + def getVmax(self): + + _lambda = self.C/self.frequency + + vmax = self.getFmax() * _lambda / 2. + + return vmax + nChannels = property(getNChannels, "I'm the 'nChannel' property.") channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") + nHeights = property(getNHeights, "I'm the 'nHeights' property.") + + noise = property(getNoise, "I'm the 'nHeights' property.") + class Voltage(JROData): #data es un numpy array de 2 dmensiones (canales, alturas) @@ -217,7 +265,7 @@ class Voltage(JROData): # self.nChannels = 0 - self.nHeights = 0 +# self.nHeights = 0 self.nProfiles = None @@ -300,7 +348,7 @@ class Spectra(JROData): # self.nChannels = 0 - self.nHeights = 0 +# self.nHeights = 0 self.nProfiles = None @@ -325,22 +373,6 @@ class Spectra(JROData): self.nFFTPoints = None self.wavelength = None - - def getFmax(self): - - PRF = 1./(self.ippSeconds * self.nCohInt) - - fmax = PRF/2. - - return fmax - - def getVmax(self): - - _lambda = self.C/self.frequency - - vmax = self.getFmax() * _lambda / 2. - - return vmax def getFreqRange(self, extrapoints=0): @@ -441,7 +473,7 @@ class SpectraHeis(JROData): # self.nChannels = 0 - self.nHeights = 0 +# self.nHeights = 0 self.nProfiles = None diff --git a/schainpy/model/jrodataIO.py b/schainpy/model/jrodataIO.py index ebc1811..daa1a89 100644 --- a/schainpy/model/jrodataIO.py +++ b/schainpy/model/jrodataIO.py @@ -1319,7 +1319,7 @@ class VoltageReader(JRODataReader): # self.dataOut.nChannels = self.systemHeaderObj.nChannels - self.dataOut.nHeights = self.processingHeaderObj.nHeights +# self.dataOut.nHeights = self.processingHeaderObj.nHeights self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock @@ -1967,7 +1967,7 @@ class SpectraReader(JRODataReader): self.dataOut.pairsList = self.rdPairList - self.dataOut.nHeights = self.processingHeaderObj.nHeights +# self.dataOut.nHeights = self.processingHeaderObj.nHeights self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index 3eca06a..3a01aff 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -2,6 +2,143 @@ import numpy import datetime from graphics.figure import * +class RTIPlot(Figure): + + __isConfig = None + __nsubplots = None + + WIDTHPROF = None + HEIGHTPROF = None + + def __init__(self): + + self.__timerange = 30*60 + self.__isConfig = False + self.__nsubplots = 1 + + self.WIDTH = 800 + self.HEIGHT = 400 + self.WIDTHPROF = 120 + self.HEIGHTPROF = 0 + + def getSubplots(self): + + ncol = 1 + nrow = self.nplots + + return nrow, ncol + + def setup(self, idfigure, nplots, wintitle, showprofile=True): + + self.__showprofile = showprofile + self.nplots = nplots + + ncolspan = 1 + colspan = 1 + if showprofile: + ncolspan = 7 + colspan = 6 + self.__nsubplots = 2 + self.WIDTH += self.WIDTHPROF + self.HEIGHT += self.HEIGHTPROF + + self.createFigure(idfigure, wintitle) + + nrow, ncol = self.getSubplots() + + counter = 0 + for y in range(nrow): + for x in range(ncol): + + if counter >= self.nplots: + break + + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) + + if showprofile: + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) + + counter += 1 + + def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', + xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + + """ + + Input: + dataOut : + idfigure : + wintitle : + channelList : + showProfile : + xmin : None, + xmax : None, + ymin : None, + ymax : None, + zmin : None, + zmax : None + """ + + if channelList == None: + channelIndexList = dataOut.channelIndexList + else: + channelIndexList = [] + for channel in channelList: + if channel not in dataOut.channelList: + raise ValueError, "Channel %d is not in dataOut.channelList" + channelIndexList.append(channel) + + x = dataOut.getDatatime() + y = dataOut.getHeiRange() + z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) + avg = numpy.average(z, axis=1) + + noise = dataOut.getNoise() + + if not self.__isConfig: + + nplots = len(channelIndexList) + + self.setup(idfigure=idfigure, + nplots=nplots, + wintitle=wintitle, + showprofile=showprofile) + + if xmin == None: xmin = numpy.min(x) + if xmax == None: xmax = xmin + self.__timerange + if ymin == None: ymin = numpy.nanmin(y) + if ymax == None: ymax = numpy.nanmax(y) + if zmin == None: zmin = numpy.nanmin(avg)*0.9 + if zmax == None: zmax = numpy.nanmax(avg)*0.9 + + self.__isConfig = True + + thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) + title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + xlabel = "Velocity (m/s)" + ylabel = "Range (Km)" + + self.setWinTitle(title) + + for i in range(self.nplots): + title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) + axes = self.axesList[i*self.__nsubplots] + z = avg[i].reshape((1,-1)) + axes.pcolor(x, y, z, + xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, + xlabel=xlabel, ylabel=ylabel, title=title, rti=True, + ticksize=9, cblabel='') + + if self.__showprofile: + axes = self.axesList[i*self.__nsubplots +1] + axes.pline(avg[i], y, + xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, + xlabel='dB', ylabel='', title='', + ytick_visible=False, + grid='x') + + self.draw() + class SpectraPlot(Figure): __isConfig = None @@ -55,7 +192,7 @@ class SpectraPlot(Figure): self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) if showprofile: - self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+2, 1, 1) + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) counter += 1 @@ -88,7 +225,7 @@ class SpectraPlot(Figure): channelIndexList.append(channel) x = dataOut.getVelRange(1) - y = dataOut.heightList + y = dataOut.getHeiRange() z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) avg = numpy.average(z, axis=1) diff --git a/schainpy/model/jroprocessing.py b/schainpy/model/jroprocessing.py index 8586126..2211ca9 100644 --- a/schainpy/model/jroprocessing.py +++ b/schainpy/model/jroprocessing.py @@ -479,7 +479,7 @@ class SpectraProc(ProcessingUnit): self.dataOut.channelList = self.dataIn.channelList self.dataOut.heightList = self.dataIn.heightList self.dataOut.dtype = self.dataIn.dtype - self.dataOut.nHeights = self.dataIn.nHeights +# self.dataOut.nHeights = self.dataIn.nHeights # self.dataOut.nChannels = self.dataIn.nChannels self.dataOut.nBaud = self.dataIn.nBaud self.dataOut.nCode = self.dataIn.nCode