diff --git a/schainpy/Graphics/BaseGraph.py b/schainpy/Graphics/BaseGraph.py index 9fefb7c..5c57b3a 100644 --- a/schainpy/Graphics/BaseGraph.py +++ b/schainpy/Graphics/BaseGraph.py @@ -7,8 +7,13 @@ Created on Feb 7, 2012 """ import numpy +import sys +import time +import datetime +import time import plplot + def cmap1_init(colormap="gray"): if colormap == None: @@ -38,7 +43,43 @@ def cmap1_init(colormap="gray"): plplot.plscmap1l(0, i, h, l, s) return None + + if colormap == 'jet': + ncolor = 256 + pos = numpy.zeros((ncolor)) + r = numpy.zeros((ncolor)) + g = numpy.zeros((ncolor)) + b = numpy.zeros((ncolor)) + + for i in range(ncolor): + if(i <= 35.0/100*(ncolor-1)): rf = 0.0 + elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 + elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 + else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 + + if(i <= 12.0/100*(ncolor-1)): gf = 0.0 + elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 + elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 + elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 + else: gf = 0.0 + + if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 + elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 + elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 + else: bf = 0 + + r[i] = rf + g[i] = gf + b[i] = bf + pos[i] = float(i)/float(ncolor-1) + + + plplot.plscmap1n(ncolor) + plplot.plscmap1l(1, pos, r, g, b) + + + if colormap=="br_green": ncolor = 256 # Hue ranges from blue (240 deg) to red (0 or 360 deg) @@ -147,167 +188,146 @@ def cmap1_init(colormap="gray"): return rgb_lvl -def setColormap(colormap="br_green"): - cmap1_init(colormap) - -class BaseGraph: - """ - - """ - hasNotRange = True - - xrange = None - yrange = None - zrange = None +def setColormap(colormap="jet"): + cmap1_init(colormap) + +def initPlplot(indexPlot,ncol,nrow,winTitle,width,height): + plplot.plsstrm(indexPlot) + plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL) + plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow)) + plplot.plsdev("xwin") + plplot.plscolbg(255,255,255) + plplot.plscol0(1,0,0,0) + plplot.plinit() + plplot.plspause(False) + plplot.plssub(ncol,nrow) + +def clearData(objGraph): + objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc") - xlabel = None - ylabel = None - title = None + objGraph.setColor(15) #Setting Line Color to White - legends = None + if objGraph.datatype == "complex": + objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) + objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) + + if objGraph.datatype == "real": + objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) - __name = None + objGraph.setColor(1) #Setting Line Color to Black +# objGraph.setLineStyle(2) +# objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc") +# objGraph.setLineStyle(1) + +def setStrm(indexPlot): + plplot.plsstrm(indexPlot) + +def plFlush(): + plplot.plflush() - __colormap = None - __colbox = None - __colleg = None - - __xpos = None - __ypos = None +def setPlTitle(pltitle,color): + setSubpages(1, 0) + plplot.pladv(0) + plplot.plvpor(0., 1., 0., 1.) - __xopt = None #"bcnst" - __yopt = None #"bcnstv" - - __xlpos = None - __ylpos = None + if color == "black": + plplot.plcol0(1) + if color == "white": + plplot.plcol0(15) - __xrangeIsTime = False + plplot.plmtex("t",-1., 0.5, 0.5, pltitle) - #Advanced +def setSubpages(ncol,nrow): + plplot.plssub(ncol,nrow) + +class BaseGraph: + __name = None + __xpos = None + __ypos = None + __subplot = None __xg = None __yg = None - - def __init__(self): - """ - - """ - self.hasNotRange = True - - self.xrange = None - self.yrange = None - self.zrange = None - - self.xlabel = None - self.ylabel = None - self.title = None - - self.legends = None - - self.__name = None - - self.__colormap = None - self.__colbox = None - self.__colleg = None - - self.__xpos = None - self.__ypos = None - - self.__xopt = None #"bcnst" - self.__yopt = None #"bcnstv" - - self.__xlpos = None - self.__ylpos = None - - self.__xrangeIsTime = False - - #Advanced - self.__xg = None - self.__yg = None + xdata = None + ydata = None + getGrid = True + xaxisIsTime = False + deltax = None + xmin = None + xmax = None + def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): + self.setName(name) + self.setScreenPos(xpos, ypos) + self.setLabels(xlabel,ylabel,title) + self.setSubPlot(subplot) + self.setSizeOfChar(szchar) + self.setXYZrange(xrange,yrange,zrange) + self.getGrid = True + self.xaxisIsTime = False + self.deltax = deltax + + def setXYZrange(self,xrange,yrange,zrange): + self.xrange = xrange + self.yrange = yrange + self.zrange = zrange def setName(self, name): self.__name = name - - def setScreenPos(self, xpos, ypos): + + def setScreenPos(self,xpos,ypos): self.__xpos = xpos self.__ypos = ypos - - def setOpt(self, xopt, yopt): - self.__xopt = xopt - self.__yopt = yopt - - def setXAxisAsTime(self): - self.__xrangeIsTime = True - - - def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): - """ - """ - self.title = title - self.xlabel = xlabel - self.ylabel = ylabel - self.__colormap = colormap - - def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False): - """ - - """ - if self.__xrangeIsTime: - plplot.pltimefmt("%H:%M") + + def setXYData(self,xdata=None,ydata=None,datatype="real"): + if((xdata != None) and (ydata != None)): + self.xdata = xdata + self.ydata = ydata + self.datatype = datatype - plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) - plplot.plwind(float(xmin), - float(xmax), - float(ymin), - float(ymax) - ) - - if xopt == None: xopt = self.__xopt - if yopt == None: yopt = self.__yopt - - plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) + if((self.xdata == None) and (self.ydata == None)): + return None - if not(nolabels): - plplot.pllab(self.xlabel, self.ylabel, self.title) - + return 1 - def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): - data = numpy.arange(256) - data = numpy.reshape(data, (1,-1)) - - plplot.plimage(data, - float(xmin), - float(xmax), - float(ymin), - float(ymax), - 0., - 255., - float(xmin), - float(xmax), - float(ymin), - float(ymax)) + + def setLabels(self,xlabel=None,ylabel=None,title=None): + if xlabel != None: self.xlabel = xlabel + if ylabel != None: self.ylabel = ylabel + if title != None: self.title = title + + def setSubPlot(self,subplot): + self.__subplot = subplot + + def setSizeOfChar(self,szchar): + self.__szchar = szchar - def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): + def setLineStyle(self,style): + plplot.pllsty(style) + + def setColor(self,color): + plplot.plcol0(color) + + def setXAxisAsTime(self,value=False): + self.xaxisIsTime = value + + def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): if xmin == None: xmin = x[0] if xmax == None: xmax = x[-1] if ymin == None: ymin = y[0] if ymax == None: ymax = y[-1] + plplot.plcol0(colline) plplot.plline(x, y) + plplot.plcol0(1) - def basicXYwithErrorPlot(self): - pass - - def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): + def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): if xmin == None: xmin = x[0] if xmax == None: xmax = x[-1] if ymin == None: ymin = y[0] if ymax == None: ymax = y[-1] - plplot.plcol0(colline) plplot.plline(x, y) - plplot.plcol0(1) def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): """ @@ -331,10 +351,10 @@ class BaseGraph: float(ymin), float(ymax) ) - + def __getBoxpltr(self, x, y, deltax=None, deltay=None): - if not(len(x)>1 and len(y)>1): + if not(len(x)>0 and len(y)>0): raise ValueError, "x axis and y axis are empty" if deltax == None: deltax = x[-1] - x[-2] @@ -349,555 +369,570 @@ class BaseGraph: self.__xg = xg self.__yg = yg - def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): - """ - """ - - if self.__xg == None and self.__yg == None: - self.__getBoxpltr(x, y) - - plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) + return xg, yg + + + def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): + if getGrid: + xg, yg = self.__getBoxpltr(x, y, deltax, deltay) + else: + xg = self.__xg + yg = self.__yg + + plplot.plimagefr(data, + float(xmin), + float(xmax), + float(ymin), + float(ymax), + 0., + 0., + float(zmin), + float(zmax), + plplot.pltr2, + xg, + yg) -class LinearPlot: - - linearGraphObj = BaseGraph() - - __szchar = 1.0 - - __xrange = None - - __yrange = None - - __subpage = 0 - m_BaseGraph= BaseGraph() - - - - def __init__(self): - - - key = "linearplot" - self.linearGraphObj = BaseGraph() - self.linearGraphObj.setName(key) - - self.__subpage = 0 - - def __iniSubpage(self): + def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): + data = numpy.arange(256) + data = numpy.reshape(data, (1,-1)) - if plplot.plgdev() == '': - raise ValueError, "Plot device has not been initialize" + plplot.plimage(data, + float(xmin), + float(xmax), + float(ymin), + float(ymax), + 0., + 255., + float(xmin), + float(xmax), + float(ymin), + float(ymax)) + + def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): - plplot.pladv(self.__subpage) - plplot.plschr(0.0, self.__szchar) + plplot.plschr(0.0,self.__szchar-0.05) + plplot.pladv(self.__subplot) + plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) + plplot.plwind(float(xmin), # self.xrange[0] + float(xmax), # self.xrange[1] + float(ymin), # self.yrange[0] + float(ymax) # self.yrange[1] + ) - setColormap() - def setScreenPos(self, width='small'): - if width == 'small': - xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 + if self.xaxisIsTime: + plplot.pltimefmt("%H:%M") + timedelta = (xmax - xmin + 1)/8. + plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) + else: + plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) - if width == 'medium': - xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 - - xf = xi + xw - yf = yi + yw - self.linearGraphObj.setScreenPos([xi, xf], [yi, yf]) + if not(nolabels): + plplot.pllab(self.xlabel, self.ylabel, self.title) - def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): - """ - """ - - self.linearGraphObj.setOpt("bcnts","bcntsv") - self.linearGraphObj.setup(title, - xlabel, - ylabel - ) - - self.setScreenPos(width='medium') - - if XAxisAsTime: - self.linearGraphObj.setXAxisAsTime() - - self.__subpage = subpage -# def setRanges(self, xrange, yrange, zrange): -# -# self.linearGraphObj.setRanges(xrange, yrange, zrange) + + def delLabels(self): + self.setColor(15) #Setting Line Color to White + plplot.pllab(self.xlabel, self.ylabel, self.title) + self.setColor(1) #Setting Line Color to Black + + + + def plotImage(self,x,y,z,xrange,yrange,zrange): + xi = x[0] + xf = x[-1] + yi = y[0] + yf = y[-1] + + plplot.plimage(z, + float(xi), + float(xf), + float(yi), + float(yf), + float(zrange[0]), + float(zrange[1]), + float(xi), + float(xf), + float(yrange[0]), + yrange[1]) + +class LinearPlot: + linearObjDic = {} + __xpos = None + __ypos = None + def __init__(self,indexPlot,nsubplot,winTitle): + self.width = 700 + self.height = 150 + ncol = 1 + nrow = nsubplot + initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) - def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): - """ - Inputs: - - x : Numpy array of dimension 1 - y : Numpy array of dimension 1 - - """ + + def setFigure(self,indexPlot): + setStrm(indexPlot) - try: - nX = numpy.shape(x) - except: - raise ValueError, "x is not a numpy array" + def setPosition(self): - if y == None: y = numpy.arange(nX) + xi = 0.07; xf = 0.9 #0.8,0.7,0.5 + yi = 0.15; yf = 0.8 - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = y[0] - if ymax == None: ymax = y[-1] + xpos = [xi,xf] + ypos = [yi,yf] - self.__iniSubpage() - self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) - self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) - - def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): - """ - Inputs: - - x : Numpy array of dimension 1 - y : Complex numpy array of dimension 1 + self.__xpos = xpos + self.__ypos = ypos - """ + return xpos,ypos + + def refresh(self): + plFlush() - try: - nX = numpy.shape(x) - except: - raise ValueError, "x is not a numpy array" + def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): + szchar = 1.10 + name = "linear" + key = name + "%d"%subplot + xrange = [xmin,xmax] + yrange = [ymin,ymax] - try: - nY = numpy.shape(y) - except: - raise ValueError, "y is not a numpy array" + xpos,ypos = self.setPosition() + linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) + linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv") + self.linearObjDic[key] = linearObj + + def plot(self,subplot,x,y,type="power"): + name = "linear" + key = name + "%d"%subplot - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = y[0] - if ymax == None: ymax = y[-1] + linearObj = self.linearObjDic[key] + linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") - self.__iniSubpage() - self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) + if linearObj.setXYData() != None: + clearData(linearObj) + + else: + if type.lower() == 'power': + linearObj.setXYData(x,abs(y),"real") + if type.lower() == 'iq': + linearObj.setXYData(x,y,"complex") if type.lower() == 'power': - self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) + colline = 9 + linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) + linearObj.setXYData(x,abs(y),"real") if type.lower() == 'iq': + colline = 9 + linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline) + colline = 13 + linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline) - self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) - self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) - -class ColorPlot: - - colorGraphObj = BaseGraph() - - graphObjDict = {} + linearObj.setXYData(x,y,"complex") - __subpage = 0 - - __showColorbar = False - - __showPowerProfile = True - - __szchar = 0.65 - - __xrange = None - - __yrange = None - - __zrange = None - m_BaseGraph= BaseGraph() - - - - def __init__(self): - - self.graphObjDict = {} + linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") - self.__subpage = 0 - self.__showColorbar = False - self.__showPowerProfile = True - self.__szchar = 0.65 - self.__xrange = None - self.__yrange = None - self.__zrange = None +# linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc") +# linearObj.basicXYPlot(data,y) +# linearObj.setXYData(data,y) - key = "colorplot" - self.colorGraphObj = BaseGraph() - self.colorGraphObj.setName(key) + - def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): - """ - """ - - self.colorGraphObj.setOpt("bcnts","bcntsv") - self.colorGraphObj.setup(title, - xlabel, - ylabel - ) - - self.__subpage = subpage - self.__colormap = colormap - self.__showColorbar = showColorbar - self.__showPowerProfile = showPowerProfile - - if showColorbar: - key = "colorbar" - - cmapObj = BaseGraph() - cmapObj.setName(key) - cmapObj.setOpt("bc","bcmtv") - cmapObj.setup(title="dBs", - xlabel="", - ylabel="", - colormap=colormap) - - self.graphObjDict[key] = cmapObj - - - if showPowerProfile: - key = "powerprof" - - powObj = BaseGraph() - powObj.setName(key) - powObj.setOpt("bcntg","bc") - powObj.setup(title="Power Profile", - xlabel="dB", - ylabel="") - - self.graphObjDict[key] = powObj - - self.setScreenPos(width='small') - - if XAxisAsTime: - self.colorGraphObj.setXAxisAsTime() - - def __iniSubpage(self): +class SpectraPlot: + pcolorObjDic = {} + colorbarObjDic = {} + pwprofileObjDic = {} + showColorbar = None + showPowerProfile = None + XAxisAsTime = None + widht = None + height = None + __spcxpos = None + __spcypos = None + __cmapxpos = None + __cmapypos = None + __profxpos = None + __profypos = None + __lastTitle = None + + def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): + self.width = 460 + self.height = 300 + self.showColorbar = showColorbar + self.showPowerProfile = showPowerProfile + self.XAxisAsTime = XAxisAsTime + + nrow = 2 + if (nsubplot%2)==0: + ncol = nsubplot/nrow + else: + ncol = int(nsubplot)/nrow + 1 + + initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) + setColormap(colormap) + self.ncol = ncol + self.nrow = nrow + + def setFigure(self,indexPlot): + setStrm(indexPlot) + + def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile + if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 + else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 + yi = 0.15; yf = 0.80 - if plplot.plgdev() == '': - raise ValueError, "Plot device has not been initialize" + xpos = [xi,xf] + ypos = [yi,yf] - plplot.pladv(self.__subpage) - plplot.plschr(0.0, self.__szchar) + self.__spcxpos = xpos + self.__spcypos = ypos - setColormap(self.__colormap) - - def setScreenPos(self, width='small'): + return xpos,ypos + + def setColorbarScreenPos(self): + + xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 + yi = self.__spcypos[0]; yf = self.__spcypos[1] - if width == 'small': - xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06 + xpos = [xi,xf] + ypos = [yi,yf] - if width == 'medium': - xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06 + self.__cmapxpos = xpos + self.__cmapypos = ypos + + return xpos,ypos + + def setPowerprofileScreenPos(self): - if self.__showColorbar: - xw -= xcmapw + deltaxcmap + xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 + yi = self.__spcypos[0]; yf = self.__spcypos[1] - if self.__showPowerProfile: - xw -= xpoww + deltaxpow - - xf = xi + xw - yf = yi + yw - xcmapf = xf + xpos = [xi,xf] + ypos = [yi,yf] - self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) + self.__profxpos = [xi,xf] + self.__profypos = [yi,yf] - if self.__showColorbar: - xcmapi = xf + deltaxcmap - xcmapf = xcmapi + xcmapw - - key = "colorbar" - cmapObj = self.graphObjDict[key] - cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) - - if self.__showPowerProfile: - - xpowi = xcmapf + deltaxpow - xpowf = xpowi + xpoww + return xpos,ypos + + def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): + # Config Spectra plot + szchar = 0.7 + name = "spc" + key = name + "%d"%subplot + xrange = [xmin,xmax] + yrange = [ymin,ymax] + zrange = [zmin,zmax] + + xpos,ypos = self.setSpectraPos() + pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) + pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv") + self.pcolorObjDic[key] = pcolorObj + + # Config Colorbar + if self.showColorbar: + szchar = 0.65 + name = "colorbar" + key = name + "%d"%subplot + + xpos,ypos = self.setColorbarScreenPos() + xrange = [0.,1.] + yrange = [zmin,zmax] + cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) + cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") + cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) + cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") + self.colorbarObjDic[key] = cmapObj + + # Config Power profile + if self.showPowerProfile: + szchar = 0.55 + name = "pwprofile" + key = name + "%d"%subplot - key = "powerprof" - powObj = self.graphObjDict[key] - powObj.setScreenPos([xpowi, xpowf], [yi, yf]) - - + xpos,ypos = self.setPowerprofileScreenPos() + xrange = [zmin,zmax] + yrange = [ymin,ymax] + powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) + powObj.setLineStyle(2) + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") + powObj.setLineStyle(1) + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") + self.pwprofileObjDic[key] = powObj - def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, title = ''): - """ - Inputs: + def printTitle(self,pltitle): + if self.__lastTitle != None: + setPlTitle(self.__lastTitle,"white") - x : Numpy array of dimension 1 - y : Numpy array of dimension 1 + self.__lastTitle = pltitle - """ + setPlTitle(pltitle,"black") - try: - nX, nY = numpy.shape(data) - except: - raise ValueError, "data is not a numpy array" + setSubpages(self.ncol,self.nrow) - if x == None: x = numpy.arange(nX) - if y == None: y = numpy.arange(nY) - - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = y[0] - if ymax == None: ymax = y[-1] - if zmin == None: zmin = numpy.nanmin(data) - if zmax == None: zmax = numpy.nanmax(data) + def plot(self,subplot,x,y,z,subtitle): + # Spectra plot - plplot.plschr(0.0, self.__szchar) - self.__iniSubpage() - self.colorGraphObj.title = title - self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax) - self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) + name = "spc" + key = name + "%d"%subplot - if self.__showColorbar: - - - key = "colorbar" - cmapObj = self.graphObjDict[key] - - plplot.plschr(0.0, self.__szchar-0.05) - cmapObj.plotBox(0., 1., zmin, zmax) - cmapObj.colorbarPlot(0., 1., zmin, zmax) - - if self.__showPowerProfile: - power = numpy.average(data, axis=0) - - step = (ymax - ymin)/(nY-1) - heis = numpy.arange(ymin, ymax + step, step) - - key = "powerprof" - powObj = self.graphObjDict[key] - - plplot.pllsty(2) - plplot.plschr(0.0, self.__szchar-0.05) - powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True) - - plplot.pllsty(1) - plplot.plschr(0.0, self.__szchar) - powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc') - - plplot.plcol0(9) - powObj.basicXYPlot(power, heis) - plplot.plcol0(1) - +# newx = [x[0],x[-1]] + pcolorObj = self.pcolorObjDic[key] + pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") + pcolorObj.delLabels() + pcolorObj.setLabels(title=subtitle) -class ColorPlotX: + deltax = None; deltay = None + + pcolorObj.advPcolorPlot(z, + x, + y, + xmin=pcolorObj.xrange[0], + xmax=pcolorObj.xrange[1], + ymin=pcolorObj.yrange[0], + ymax=pcolorObj.yrange[1], + zmin=pcolorObj.zrange[0], + zmax=pcolorObj.zrange[1], + deltax=deltax, + deltay=deltay, + getGrid=pcolorObj.getGrid) + + pcolorObj.getGrid = False + + pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") + + # Power Profile + if self.showPowerProfile: + power = numpy.average(z, axis=0) + name = "pwprofile" + key = name + "%d"%subplot + powObj = self.pwprofileObjDic[key] + + if powObj.setXYData() != None: + clearData(powObj) + else: + powObj.setXYData(power,y) + + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") + powObj.basicXYPlot(power,y) + powObj.setXYData(power,y) + + def refresh(self): + plFlush() +class RtiPlot: + + pcolorObjDic = {} + colorbarObjDic = {} + pwprofileObjDic = {} + showColorbar = None + showPowerProfile = None + XAxisAsTime = None + widht = None + height = None + __rtixpos = None + __rtiypos = None + __cmapxpos = None + __cmapypos = None + __profxpos = None + __profypos = None + + def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): + self.width = 700 + self.height = 150 + self.showColorbar = showColorbar + self.showPowerProfile = showPowerProfile + self.XAxisAsTime = XAxisAsTime + + ncol = 1 + nrow = nsubplot + initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) + setColormap(colormap) - graphObjDict = {} - showColorbar = False - showPowerProfile = True - - __szchar = 0.7 - __xrange = None - __yrange = None - __zrange = None - - colorGraphObj = BaseGraph() + def setFigure(self,indexPlot): + setStrm(indexPlot) - def __init__(self): - - key = "colorplot" - self.colorGraphObj.setName(key) - - self.__subpage = 0 - - self.graphObjDict[key] = self.colorGraphObj - - def __iniSubpage(self): + def setRtiScreenPos(self): + + if self.showPowerProfile: xi = 0.07; xf = 0.65 + else: xi = 0.07; xf = 0.9 + yi = 0.15; yf = 0.80 - if plplot.plgdev() == '': - raise ValueError, "Plot device has not been initialize" + xpos = [xi,xf] + ypos = [yi,yf] - plplot.pladv(self.__subpage) - plplot.plschr(0.0, self.__szchar) + self.__rtixpos = xpos + self.__rtiypos = ypos - setColormap(self.__colormap) + return xpos,ypos - def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): - - if self.showColorbar: - xw -= xcmapw + deltaxcmap - - if self.showPowerProfile: - xw -= xpoww + deltaxpow + def setColorbarScreenPos(self): + + xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 - xf = xi + xw - yf = yi + yw - xcmapf = xf + yi = self.__rtiypos[0]; yf = self.__rtiypos[1] - self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) + xpos = [xi,xf] + ypos = [yi,yf] - if self.showColorbar: - xcmapi = xf + deltaxcmap - xcmapf = xcmapi + xcmapw - - key = "colorbar" - cmapObj = self.graphObjDict[key] - cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) - - if self.showPowerProfile: - - xpowi = xcmapf + deltaxpow - xpowf = xpowi + xpoww - - key = "powerprof" - powObj = self.graphObjDict[key] - powObj.setScreenPos([xpowi, xpowf], [yi, yf]) + self.__cmapxpos = xpos + self.__cmapypos = ypos + + return xpos,ypos - def setRanges(self, xrange, yrange, zrange): - - self.colorGraphObj.setRanges(xrange, yrange, zrange) - - keyList = self.graphObjDict.keys() + def setPowerprofileScreenPos(self): - key = "colorbar" - if key in keyList: - cmapObj = self.graphObjDict[key] - cmapObj.setRanges([0., 1.], zrange) - - key = "powerprof" - if key in keyList: - powObj = self.graphObjDict[key] - powObj.setRanges(zrange, yrange) + xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 - def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): - """ - """ + yi = self.__rtiypos[0]; yf = self.__rtiypos[1] - self.colorGraphObj.setSubpage(subpage) - self.colorGraphObj.setSzchar(self.__szchar) - self.colorGraphObj.setOpt("bcnts","bcntsv") - self.colorGraphObj.setup(title, - xlabel, - ylabel, - colormap) + xpos = [xi,xf] + ypos = [yi,yf] - if showColorbar: - key = "colorbar" - - cmapObj = BaseGraph() - cmapObj.setName(key) - cmapObj.setSubpage(subpage) - cmapObj.setSzchar(self.__szchar) - cmapObj.setOpt("bc","bcmt") - cmapObj.setup(title="dBs", - xlabel="", - ylabel="", - colormap=colormap) - - self.graphObjDict[key] = cmapObj - + self.__profxpos = [xi,xf] + self.__profypos = [yi,yf] + + return xpos,ypos + + def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100): + # Config Rti plot + szchar = 1.10 + name = "rti" + key = name + "%d"%subplot + + # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] + thisDateTime = datetime.datetime.fromtimestamp(timedata) + startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) + endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) + deltaTime = 0 + if timezone == "lt": + deltaTime = time.timezone + startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime + endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime + + xrange = [startTimeInSecs,endTimeInSecs] + totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. + deltax = totalTimeInXrange / npoints + + yrange = [ymin,ymax] + zrange = [zmin,zmax] + + xpos,ypos = self.setRtiScreenPos() + pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) + if self.XAxisAsTime: + pcolorObj.setXAxisAsTime(self.XAxisAsTime) + xopt = "bcnstd" + yopt = "bcnstv" + else: + xopt = "bcnst" + yopt = "bcnstv" + + pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) + self.pcolorObjDic[key] = pcolorObj - if showPowerProfile: - key = "powerprof" - - powObj = BaseGraph() - powObj.setName(key) - powObj.setSubpage(subpage) - powObj.setSzchar(self.__szchar) - plplot.pllsty(2) - powObj.setOpt("bcntg","bc") - plplot.pllsty(1) - powObj.setup(title="Power Profile", - xlabel="dBs", - ylabel="") - - self.graphObjDict[key] = powObj + + # Config Colorbar + if self.showColorbar: + szchar = 0.9 + name = "colorbar" + key = name + "%d"%subplot - self.showColorbar = showColorbar - self.showPowerProfile = showPowerProfile - self.setScreenPos() + xpos,ypos = self.setColorbarScreenPos() + xrange = [0.,1.] + yrange = [zmin,zmax] + cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) + cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") + cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) + cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") + self.colorbarObjDic[key] = cmapObj - if XAxisAsTime: - self.colorGraphObj.setXAxisAsTime() - #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) - - - def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): - """ - """ - - try: - nX, nY = numpy.shape(data) - except: - raise ValueError, "data is not a numpy array" - - if x == None: x = numpy.arange(nX) - if y == None: y = numpy.arange(nY) - - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = y[0] - if ymax == None: ymax = y[-1] - if zmin == None: zmin = numpy.nanmin(data) - if zmax == None: zmax = numpy.nanmax(data) - - if self.colorGraphObj.hasNotRange: - self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) - - self.colorGraphObj.initSubpage() - self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1]) - - if self.showColorbar: - key = "colorbar" - cmapObj = self.graphObjDict[key] - cmapObj.colorbarPlot() + # Config Power profile if self.showPowerProfile: - power = numpy.average(data, axis=1) - - step = (ymax - ymin)/(nY-1) - heis = numpy.arange(ymin, ymax + step, step) - - key = "powerprof" - powObj = self.graphObjDict[key] - powObj.basicXYPlot(power, heis) - -if __name__ == '__main__': - - import numpy - plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) - plplot.plsdev("xwin") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plspause(False) - plplot.plinit() - plplot.plssub(2, 2) - - nx = 64 - ny = 100 - - data = numpy.random.uniform(-50,50,(nx,ny)) - - baseObj = ColorPlot() - specObj = ColorPlot() - baseObj1 = ColorPlot() - specObj1 = ColorPlot() - - baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) - specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) + szchar = 0.8 + name = "pwprofile" + key = name + "%d"%subplot + + xpos,ypos = self.setPowerprofileScreenPos() + xrange = [zmin,zmax] + yrange = [ymin,ymax] + powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) + powObj.setLineStyle(2) + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") + powObj.setLineStyle(1) + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") + self.pwprofileObjDic[key] = powObj - baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) - specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) - - data = numpy.random.uniform(-50,50,(nx,ny)) - - plplot.plbop() - baseObj.plotData(data) - - specObj.plotData(data) - - baseObj1.plotData(data) - - specObj1.plotData(data) - plplot.plflush() - - plplot.plspause(1) - plplot.plend() - exit(0) - - + def plot(self,subplot,x,y,z): + # RTI plot + name = "rti" + key = name + "%d"%subplot + + data = numpy.reshape(z, (1,-1)) + data = numpy.abs(data) + data = 10*numpy.log10(data) + newx = [x,x+1] + + pcolorObj = self.pcolorObjDic[key] + + if pcolorObj.xaxisIsTime: + xopt = "bcstd" + yopt = "bcst" + else: + xopt = "bcst" + yopt = "bcst" + + pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) + + deltax = pcolorObj.deltax + deltay = None + + if pcolorObj.xmin == None and pcolorObj.xmax == None: + pcolorObj.xmin = x + pcolorObj.xmax = x + + if x >= pcolorObj.xmax: + xmin = x + xmax = x + deltax + x = [x] + pcolorObj.advPcolorPlot(data, + x, + y, + xmin=xmin, + xmax=xmax, + ymin=pcolorObj.yrange[0], + ymax=pcolorObj.yrange[1], + zmin=pcolorObj.zrange[0], + zmax=pcolorObj.zrange[1], + deltax=deltax, + deltay=deltay, + getGrid=pcolorObj.getGrid) + + pcolorObj.xmin = xmin + pcolorObj.xmax = xmax + + + # Power Profile + if self.showPowerProfile: + data = numpy.reshape(data,(numpy.size(data))) + name = "pwprofile" + key = name + "%d"%subplot + powObj = self.pwprofileObjDic[key] + + if powObj.setXYData() != None: + clearData(powObj) + powObj.setLineStyle(2) + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") + powObj.setLineStyle(1) + else: + powObj.setXYData(data,y) + + powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") + powObj.basicXYPlot(data,y) + powObj.setXYData(data,y) + + def refresh(self): + plFlush() \ No newline at end of file diff --git a/schainpy/Graphics/SpectraPlot.py b/schainpy/Graphics/SpectraPlot.py index 0939108..204164e 100644 --- a/schainpy/Graphics/SpectraPlot.py +++ b/schainpy/Graphics/SpectraPlot.py @@ -5,10 +5,11 @@ Created on Feb 7, 2012 @version $Id$ ''' -import os, sys import numpy -import datetime +import os +import sys import plplot +import datetime path = os.path.split(os.getcwd())[0] sys.path.append(path) @@ -17,188 +18,102 @@ from Graphics.BaseGraph import * from Model.Spectra import Spectra class Spectrum: - - __isPlotConfig = False - - __isPlotIni = False - - __xrange = None - - __yrange = None - - nGraphs = 0 + colorplotObj = None - indexPlot = None - - graphObjList = [] - - spectraObj = Spectra - - colorGraphObj = ColorPlot() - m_Spectra= Spectra() - - - m_ColorPlot= ColorPlot() - - - - - - def __init__(self, Spectra, index=0): - - """ - - Inputs: - - type: "power" ->> Potencia - "iq" ->> Real + Imaginario - """ - + def __init__(self,Spectra, index): self.__isPlotConfig = False - self.__isPlotIni = False - self.__xrange = None - self.__yrange = None - self.nGraphs = 0 - self.indexPlot = index - - self.graphObjList = [] - self.spectraObj = Spectra - - def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): - - graphObj = ColorPlot() - graphObj.setup(subpage, - title, - xlabel, - ylabel, - showColorbar=showColorbar, - showPowerProfile=showPowerProfile, - XAxisAsTime=XAxisAsTime) - - self.graphObjList.append(graphObj) - + def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): + self.colorplotObj = SpectraPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) - def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): - - nChan = int(self.spectraObj.m_SystemHeader.numChannels) - channels = range(nChan) - - myXlabel = "Radial Velocity (m/s)" - myYlabel = "Range (km)" - - for i in channels: - if titleList != None: - myTitle = titleList[i] - myXlabel = xlabelList[i] - myYlabel = ylabelList[i] - -# if self.spectraObj.m_NoiseObj != None: -# noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i]) -# else: - noise = '--' - - myTitle = "Channel: %d - Noise: %s" %(i, noise) - - self.__addGraph(i+1, - title=myTitle, - xlabel=myXlabel, - ylabel=myYlabel, - showColorbar=showColorbar, - showPowerProfile=showPowerProfile, - XAxisAsTime=XAxisAsTime) + def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList): + nsubplot = self.spectraObj.nChannels - self.nGraphs = nChan - self.__isPlotConfig = True + for index in range(nsubplot): + title = titleList[index] + xlabel = xlabelList[index] + ylabel = ylabelList[index] + subplot = index + self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) - def iniPlot(self, winTitle=""): + + def plotData(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + zmin=None, + zmax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + colormap = "br_green", + showColorbar = True, + showPowerProfile = True, + XAxisAsTime = False): + + databuffer = 10.*numpy.log10(self.spectraObj.data_spc) + noise = 10.*numpy.log10(self.spectraObj.noise) - nx = int(numpy.sqrt(self.nGraphs)+1) - #ny = int(self.nGraphs/nx) + nsubplot = self.spectraObj.nChannels + nsubplot, nX, nY = numpy.shape(databuffer) - plplot.plsstrm(self.indexPlot) - plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) - plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) - plplot.plsdev("xwin") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plspause(False) - plplot.pladv(0) - plplot.plssub(nx, nx) + x = numpy.arange(nX) + y = self.spectraObj.heightList - self.__nx = nx - self.__ny = nx - self.__isPlotIni = True - - - def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"): + indexPlot = self.indexPlot if not(self.__isPlotConfig): - self.setup(titleList, - xlabelList, - ylabelList, - showColorbar, - showPowerProfile, - XAxisAsTime) + self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) + self.__isPlotConfig = True if not(self.__isPlotIni): - self.iniPlot(winTitle) - - plplot.plsstrm(self.indexPlot) - - data = 10.*numpy.log10(self.spectraObj.data_spc) - noise = 10.*numpy.log10(self.spectraObj.noise) - #data.shape = Channels x Heights x Profiles -# data = numpy.transpose( data, (0,2,1) ) - #data.shape = Channels x Profiles x Heights - - nChan, nX, nY = numpy.shape(data) + if titleList == None: + titleList = [] + for i in range(nsubplot): + titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i])) + + if xlabelList == None: + xlabelList = [] + for i in range(nsubplot): + xlabelList.append("") + + if ylabelList == None: + ylabelList = [] + for i in range(nsubplot): + ylabelList.append("Range (Km)") + + if xmin == None: xmin = x[0] + if xmax == None: xmax = x[-1] + if ymin == None: ymin = y[0] + if ymax == None: ymax = y[-1] + if zmin == None: zmin = 0 + if zmax == None: zmax = 120 + + self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList) + self.__isPlotIni = True - x = numpy.arange(nX) - y = self.spectraObj.heightList + self.colorplotObj.setFigure(indexPlot) thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) - txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = y[0] - if ymax == None: ymax = y[-1] - if zmin == None: zmin = numpy.nanmin(abs(data)) - if zmax == None: zmax = numpy.nanmax(abs(data)) + self.colorplotObj.printTitle(pltitle) #setPlTitle(pltitle) - plplot.plbop() + for index in range(nsubplot): + data = databuffer[index,:,:] + subtitle = "Channel: %d - Noise: %.2f" %(index, noise[index]) + self.colorplotObj.plot(index+1,x,y,data,subtitle) - plplot.plssub(self.__nx, self.__ny) - for i in range(self.nGraphs): - self.graphObjList[i].plotData(data[i,:,:], - x, - y, - xmin=xmin, - xmax=xmax, - ymin=ymin, - ymax=ymax, - zmin=zmin, - zmax=zmax, - title = "Channel: %d - Noise: %.2f" %(i, noise[i])) - plplot.plssub(1,0) - plplot.pladv(0) - plplot.plvpor(0., 1., 0., 1.) - plplot.plmtex("t",-1., 0.5, 0.5, txtDate) - plplot.plflush() - plplot.pleop() - - def end(self): - plplot.plend() - + + self.colorplotObj.refresh() + -if __name__ == '__main__': - pass \ No newline at end of file diff --git a/schainpy/Graphics/VoltagePlot.py b/schainpy/Graphics/VoltagePlot.py index 20f928e..d2ac9f1 100644 --- a/schainpy/Graphics/VoltagePlot.py +++ b/schainpy/Graphics/VoltagePlot.py @@ -4,9 +4,9 @@ Created on Feb 7, 2012 @author $Author$ @version $Id$ ''' -import os, sys import numpy -import plplot +import os +import sys path = os.path.split(os.getcwd())[0] sys.path.append(path) @@ -15,190 +15,183 @@ from Graphics.BaseGraph import * from Model.Voltage import Voltage class Osciloscope: + linearplotObj = None - voltageObj = Voltage() + def __init__(self, Voltage, index): + self.__isPlotConfig = False + self.__isPlotIni = False + self.__xrange = None + self.__yrange = None + self.indexPlot = index + self.voltageObj = Voltage - linearGraphObj = LinearPlot() + def setup(self,indexPlot,nsubplot,winTitle=''): + self.linearplotObj = LinearPlot(indexPlot,nsubplot,winTitle) - __isPlotConfig = False + def initPlot(self,xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList): + nsubplot = self.voltageObj.nChannels - __isPlotIni = False - - __xrange = None - - __yrange = None - - voltageObj = Voltage() - - nGraphs = 0 + for index in range(nsubplot): + title = titleList[index] + xlabel = xlabelList[index] + ylabel = ylabelList[index] + subplot = index + self.linearplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,title,xlabel,ylabel) - indexPlot = None - - graphObjList = [] - m_LinearPlot= LinearPlot() - - - m_Voltage= Voltage() - - + def plotData(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + type="power"): - def __init__(self, Voltage, index=0): + databuffer = self.voltageObj.data - """ + height = self.voltageObj.heightList + nsubplot = self.voltageObj.nChannels + indexPlot = self.indexPlot - Inputs: - - type: "power" ->> Potencia - "iq" ->> Real + Imaginario - """ - - self.__isPlotConfig = False - self.__isPlotIni = False - - self.__xrange = None + if not(self.__isPlotConfig): + self.setup(indexPlot,nsubplot,winTitle) + self.__isPlotConfig = True - self.__yrange = None + if not(self.__isPlotIni): + if titleList == None: + titleList = [] + thisDatetime = datetime.datetime.fromtimestamp(self.voltageObj.m_BasicHeader.utc) + txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) + for i in range(nsubplot): + titleList.append("Channel: %d %s" %(i, txtdate)) + + if xlabelList == None: + xlabelList = [] + for i in range(nsubplot): + xlabelList.append("") + + if ylabelList == None: + ylabelList = [] + for i in range(nsubplot): + ylabelList.append("") + + if xmin == None: xmin = height[0] + if xmax == None: xmax = height[-1] + if ymin == None: ymin = numpy.nanmin(abs(databuffer)) + if ymax == None: ymax = numpy.nanmax(abs(databuffer)) + + self.initPlot(xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList) + self.__isPlotIni = True - self.voltageObj = None + self.linearplotObj.setFigure(indexPlot) - self.nGraphs = 0 + for index in range(nsubplot): + data = databuffer[index,:] + self.linearplotObj.plot(subplot=index+1,x=height,y=data,type=type) - self.indexPlot = index + self.linearplotObj.refresh() - self.graphObjList = [] - self.voltageObj = Voltage - - def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): + - graphObj = LinearPlot() - graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) - #graphObj.setScreenPos() - - self.graphObjList.append(graphObj) + - del graphObj - -# def setXRange(self, xmin, xmax): -# self.__xrange = (xmin, xmax) -# -# def setYRange(self, ymin, ymax): -# self.__yrange = (ymin, ymax) +class RTI: + colorplotObj = None - def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): - - nChan = int(self.voltageObj.m_SystemHeader.numChannels) - - myTitle = "" - myXlabel = "" - myYlabel = "" - - for chan in range(nChan): - if titleList != None: - myTitle = titleList[chan] - myXlabel = xlabelList[chan] - myYlabel = ylabelList[chan] - - self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) - - self.nGraphs = nChan - self.__isPlotConfig = True - - def iniPlot(self, winTitle=""): - - plplot.plsstrm(self.indexPlot) - plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) - plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) - plplot.plsdev("xwin") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plspause(False) - plplot.plssub(1, self.nGraphs) - - self.__isPlotIni = True - - def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): - + def __init__(self, Voltage, index): + self.__isPlotConfig = False + self.__isPlotIni = False + self.__xrange = None + self.__yrange = None + self.indexPlot = index + self.voltageObj = Voltage + + def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): + self.colorplotObj = RtiPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) + + def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints): + + nsubplot = self.voltageObj.nChannels + timedata = self.voltageObj.m_BasicHeader.utc + + for index in range(nsubplot): + title = titleList[index] + xlabel = xlabelList[index] + ylabel = ylabelList[index] + subplot = index + self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone,npoints) + + def plotData(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + zmin=None, + zmax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + timezone='lt', + npoints=1000.0, + colormap="br_green", + showColorbar=True, + showPowerProfile=True, + XAxisAsTime=True): + + databuffer = self.voltageObj.data + timedata = self.voltageObj.m_BasicHeader.utc + height = self.voltageObj.heightList + nsubplot = self.voltageObj.nChannels + indexPlot = self.indexPlot + if not(self.__isPlotConfig): - self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) - + self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) + self.__isPlotConfig = True + if not(self.__isPlotIni): - self.iniPlot(winTitle) - - plplot.plsstrm(self.indexPlot) - - data = self.voltageObj.data - - x = self.voltageObj.heightList + if titleList == None: + titleList = [] + thisDatetime = datetime.datetime.fromtimestamp(timedata) + txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) + for i in range(nsubplot): + titleList.append("Channel: %d %s" %(i, txtdate)) + + if xlabelList == None: + xlabelList = [] + for i in range(nsubplot): + xlabelList.append("") + + if ylabelList == None: + ylabelList = [] + for i in range(nsubplot): + ylabelList.append("") + + if xmin == None: xmin = 0 + if xmax == None: xmax = 23 + if ymin == None: ymin = min(self.voltageObj.heightList) + if ymax == None: ymax = max(self.voltageObj.heightList) + if zmin == None: zmin = 0 + if zmax == None: zmax = 50 + + + self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints) + self.__isPlotIni = True - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = numpy.nanmin(abs(data)) - if ymax == None: ymax = numpy.nanmax(abs(data)) + + self.colorplotObj.setFigure(indexPlot) - plplot.plbop() - for chan in range(self.nGraphs): - y = data[chan,:] - - self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) + if timezone == 'lt': + timedata = timedata - time.timezone - plplot.plflush() - plplot.pleop() - - def end(self): - plplot.plend() + for index in range(nsubplot): + data = databuffer[index,:] + self.colorplotObj.plot(subplot=index+1,x=timedata,y=height,z=data) -class VoltagePlot(object): - ''' - classdocs - ''' - - __m_Voltage = None - - def __init__(self, voltageObj): - ''' - Constructor - ''' - self.__m_Voltage = voltageObj - - def setup(self): - pass - - def addGraph(self, type, xrange=None, yrange=None, zrange=None): - pass - - def plotData(self): - pass - -if __name__ == '__main__': - - import numpy - - plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) - plplot.plsdev("xcairo") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plssub(1, 2) - - nx = 64 - ny = 100 - - data = numpy.random.uniform(-50,50,(nx,ny)) - - baseObj = RTI() - baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) - baseObj.plotData(data) - - data = numpy.random.uniform(-50,50,(nx,ny)) - - base2Obj = RTI() - base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) - base2Obj.plotData(data) - - plplot.plend() - exit(0) \ No newline at end of file + self.colorplotObj.refresh() diff --git a/schainpy/Processing/SpectraProcessor.py b/schainpy/Processing/SpectraProcessor.py index 38c076a..5f25337 100644 --- a/schainpy/Processing/SpectraProcessor.py +++ b/schainpy/Processing/SpectraProcessor.py @@ -238,6 +238,7 @@ class SpectraProcessor: self.dataOutObj.data_cspc = cspc self.dataOutObj.data_dc = dc self.dataOutObj.m_ProcessingHeader.blockSize = blocksize + self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc def addWriter(self,wrpath): @@ -245,15 +246,12 @@ class SpectraProcessor: objWriter.setup(wrpath) self.writerObjList.append(objWriter) - - def addPlotter(self, index=None): - + def addPlotter(self,index=None): if index==None: index = self.plotterObjIndex plotObj = Spectrum(self.dataOutObj, index) self.plotterObjList.append(plotObj) - def addIntegrator(self,N,timeInterval): @@ -271,14 +269,43 @@ class SpectraProcessor: self.writerObjIndex += 1 - def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): + def plotData(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + zmin=None, + zmax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + colormap="br_green", + showColorbar=False, + showPowerProfile=False, + XAxisAsTime=False, + index=None): + if self.dataOutObj.flagNoData: return 0 if len(self.plotterObjList) <= self.plotterObjIndex: self.addPlotter(index) - self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) + self.plotterObjList[self.plotterObjIndex].plotData(xmin, + xmax, + ymin, + ymax, + zmin, + zmax, + titleList, + xlabelList, + ylabelList, + winTitle, + colormap, + showColorbar, + showPowerProfile, + XAxisAsTime) self.plotterObjIndex += 1 @@ -340,7 +367,7 @@ class SpectraProcessor: noise = self.noiseObj.bySort(parm) self.dataOutObj.noise = noise - print 10*numpy.log10(noise) +# print 10*numpy.log10(noise) def selectChannels(self, channelList, pairList=[]): diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py index c5be060..c15f139 100644 --- a/schainpy/Processing/VoltageProcessor.py +++ b/schainpy/Processing/VoltageProcessor.py @@ -14,6 +14,7 @@ sys.path.append(path) from Model.Voltage import Voltage from IO.VoltageIO import VoltageWriter from Graphics.VoltagePlot import Osciloscope +from Graphics.VoltagePlot import RTI class VoltageProcessor: ''' @@ -85,7 +86,14 @@ class VoltageProcessor: objWriter = VoltageWriter(self.dataOutObj) objWriter.setup(wrpath) self.writerObjList.append(objWriter) - + + def addRti(self,index=None): + if index==None: + index = self.plotterObjIndex + + plotObj = RTI(self.dataOutObj, index) + self.plotterObjList.append(plotObj) + def addPlotter(self, index=None): if index==None: index = self.plotterObjIndex @@ -118,10 +126,89 @@ class VoltageProcessor: self.writerObjList[self.writerObjIndex].putData() -# myWrObj = self.writerObjList[self.writerObjIndex] -# myWrObj.putData() - self.writerObjIndex += 1 + + def addScope(self,index=None): + if index==None: + index = self.plotterObjIndex + + plotObj = Osciloscope(self.dataOutObj, index) + self.plotterObjList.append(plotObj) + + def plotScope(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + type="power", + index=None): + + if self.dataOutObj.flagNoData: + return 0 + + if len(self.plotterObjList) <= self.plotterObjIndex: + self.addScope(index) + + self.plotterObjList[self.plotterObjIndex].plotData(xmin, + xmax, + ymin, + ymax, + titleList, + xlabelList, + ylabelList, + winTitle, + type) + + self.plotterObjIndex += 1 + + def plotRti(self, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + zmin=None, + zmax=None, + titleList=None, + xlabelList=None, + ylabelList=None, + winTitle='', + timezone='lt', + npoints=1000.0, + colormap="br_green", + showColorbar=True, + showPowerProfile=False, + XAxisAsTime=True, + index=None): + + if self.dataOutObj.flagNoData: + return 0 + + if len(self.plotterObjList) <= self.plotterObjIndex: + self.addRti(index) + + self.plotterObjList[self.plotterObjIndex].plotData(xmin, + xmax, + ymin, + ymax, + zmin, + zmax, + titleList, + xlabelList, + ylabelList, + winTitle, + timezone, + npoints, + colormap, + showColorbar, + showPowerProfile, + XAxisAsTime) + + self.plotterObjIndex += 1 + def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None): if self.dataOutObj.flagNoData: diff --git a/schainpy/TestSVoltageChain.py b/schainpy/TestSVoltageChain.py index 5b8ecbe..796261f 100644 --- a/schainpy/TestSVoltageChain.py +++ b/schainpy/TestSVoltageChain.py @@ -1,15 +1,15 @@ ''' -Created on 27/03/2012 +Created on Jul 31, 2012 @author $Author$ @version $Id$ ''' + import os, sys import time, datetime from Model.Voltage import Voltage from IO.VoltageIO import * -#from Graphics.VoltagePlot import Osciloscope from Model.Spectra import Spectra from IO.SpectraIO import * @@ -24,23 +24,16 @@ class TestSChain(): self.setValues() self.createObjects() self.testSChain() - - + def setValues( self ): - self.path = "/home/dsuarez/Projects" #1 + self.path = "/home/dsuarez/Projects" self.path = "/Users/jro/Documents/RadarData/EW_Drifts" self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST" -# self.startDateTime = datetime.datetime(2007,5,1,15,49,0) -# self.endDateTime = datetime.datetime(2007,5,1,23,0,0) self.startDateTime = datetime.datetime(2009,01,1,0,0,0) self.endDateTime = datetime.datetime(2009,01,31,0,20,0) -# self.startDateTime = datetime.datetime(2011,11,1,0,0,0) -# self.endDateTime = datetime.datetime(2011,12,31,0,20,0) - - self.N = 4 self.npts = 8 @@ -50,51 +43,44 @@ class TestSChain(): self.voltProcObj = VoltageProcessor() self.specProcObj = SpectraProcessor() - voltObj1 = self.readerObj.setup( + self.voltObj1 = self.readerObj.setup( path = self.path, startDateTime = self.startDateTime, endDateTime = self.endDateTime, expLabel = '', online = 0) - if not(voltObj1): + if not(self.voltObj1): sys.exit(0) - voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1) + self.voltObj2 = self.voltProcObj.setup(dataInObj = self.voltObj1) - specObj1 = self.specProcObj.setup(dataInObj = voltObj2, + self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj2, nFFTPoints = 16) -# voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1, -# dataOutObj = voltObj2) -# -# specObj1 = self.specProcObj.setup(dataInObj = voltObj2, -# dataOutObj =specObj1, -# nFFTPoints=16) - def testSChain( self ): ini = time.time() + while(True): self.readerObj.getData() self.voltProcObj.init() -# self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1) -# -# self.voltProcObj.integrator(4) -# -# self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2) -# + self.voltProcObj.plotScope(winTitle="Scope 1",type="iq", index=1) + self.voltProcObj.plotRti(winTitle='VOLTAGE INPUT', showPowerProfile=True, index=2) + + self.voltProcObj.integrator(4) + self.specProcObj.init() - self.specProcObj.integrator(N=1) - - self.specProcObj.plotData(winTitle='Spectra 1', index=1) - - + self.specProcObj.integrator(N=4) + +# self.specProcObj.plotSpec(winTitle='Spectra Test', showColorbar=True,showPowerProfile=True,index=3) + self.specProcObj.plotData(winTitle='Spectra Test', showColorbar=True,showPowerProfile=True,index=3) + if self.readerObj.flagNoMoreFiles: break @@ -102,8 +88,6 @@ class TestSChain(): print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) - -# self.plotObj.end() if __name__ == '__main__': TestSChain() \ No newline at end of file