From d9a82835d983ee466fad0e36ad519382a31be127 2012-10-18 15:11:18 From: Daniel Valdez Date: 2012-10-18 15:11:18 Subject: [PATCH] Avance de graficos: Scope --- diff --git a/schainpy2/Graphics/schainPlot.py b/schainpy2/Graphics/schainPlot.py index 699e98d..eddc6c0 100644 --- a/schainpy2/Graphics/schainPlot.py +++ b/schainpy2/Graphics/schainPlot.py @@ -1,78 +1,67 @@ - import numpy from schainPlotLib import Driver class Figure: - - __driverObj = None __isDriverOpen = False __isFigureOpen = False __isConfig = False - __xw = None - __yw = None - - xmin = None - xmax = None - minvalue = None - maxvalue = None - + drvObj = None idfigure = None nframes = None wintitle = None colormap = None driver = None overplot = None - + xmin = None + xmax = None + minvalue = None + maxvalue = None frameObjList = [] + figtitle = "" - def __init__(self, idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, *showGraphs): - - self.driver = driver + def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args): self.idfigure = idfigure self.nframes = nframes self.wintitle = wintitle + self.xw = xw + self.yw = yw self.overplot = overplot + self.colorbar = colorbar self.colormap = colormap - - self.showGraph1 = showGraphs[0] - self.showGraph2 = showGraphs[1] - self.__xw = xw - self.__yw = yw + #esta seccion deberia ser dinamica de acuerdo a len(args) + self.showGraph1 = args[0] + self.showGraph2 = args[1] - self.__driverObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) + self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap) - self.__driverObj.driver.configDriver() + self.drvObj.driver.setFigure() - + def __openDriver(self): - - self.__driverObj.driver.openDriver() + self.drvObj.driver.openDriver() - def __openFigure(self): +# def __openFigure(self): +# nrows, ncolumns = self.getSubplots() +# self.drvObj.driver.openFigure() +# self.drvObj.driver.setTitleFig(title) +# self.drvObj.driver.setSubPlots(nrows, ncolumns) + def __initFigure(self): nrows, ncolumns = self.getSubplots() - - self.__driverObj.driver.openFigure() - self.__driverObj.driver.setSubPlots(nrows, ncolumns) - - - def __isOutOfXRange(self, x): - pass + self.drvObj.driver.openFigure() + self.drvObj.driver.setFigTitle(self.figtitle) + self.drvObj.driver.setSubPlots(nrows, ncolumns) - def __changeXRange(self, x): - pass - - def __createFrames(self): - - for frame in range(self.nframes): - frameObj = Frame(idframe = frame, - showGraph1 = self.showGraph1, - showGraph2 = self.showGraph2 - ) - - self.frameObjList.append(frameObj) - - def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'): + def __isOutOfXRange(self,x): + return 1 + + def __refresh(self): + self.drvObj.driver.refresh() + + def createFrames(self): + raise ValueError, "No implemented" + + def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figtitle=None, save=False, gpath='./'): nx, ny = data1D.shape @@ -81,186 +70,163 @@ class Figure: if x == None: x = numpy.arange(data1D.size) - + + if figtitle == None: + self.figtitle = "" + else: + self.figtitle = figtitle + if not(self.__isDriverOpen): self.__openDriver() self.__isDriverOpen = True if not(self.__isConfig): - if self.xmin == None: xmin = numpy.min(x) - if self.xmax == None: xmax = numpy.max(x) - if self.minvalue == None: minvalue = numpy.min(data1D) - if self.maxvalue == None: maxvalue = numpy.max(data1D) + self.xmin = xmin + self.xmax = xmax + self.minvalue = minvalue + self.maxvalue = maxvalue + + if self.xmin == None: self.xmin = numpy.min(x) + if self.xmax == None: self.xmax = numpy.max(x) + if self.minvalue == None: self.minvalue = numpy.min(data1D) + if self.maxvalue == None: self.maxvalue = numpy.max(data1D) - self.__createFrames() + self.createFrames() self.__isConfig = True if not(self.__isOutOfXRange(x)): self.__changeXRange(x) if self.__isFigureOpen: - self.__driverObj.closePage() + self.driverObj.closePage() self.__isFigureOpen = False - if not(self.__isFigureOpen): - self.__openFigure() - - for channel in channelList: - frameObj = self.frameObjList[channel] - frameObj.init(xmin=xmin, - xmax=xmax, - minvalue=minvalue, - maxvalue=maxvalue) - - self.__isFigureOpen = True + self.__initFigure() for channel in channelList: - dataCh = data1D[channel] +# frametitle = self.plotTitleDict[channel] frameObj = self.frameObjList[channel] - - frameObj.clearData() - frameObj.plot(dataCh) - - frameObj.refresh() - - if not(self.overplot): - self.__driverObj.closeFigure() - self.__isFigureOpen = False - - - def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'): - - if not(self.__isCOpen): - self.__createFrames() - self.__openFigure() - self.__isOpen = True - - if not(self.__isConfig): - self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue) - self.__isConfig = True + frameObj.init(xmin=self.xmin, + xmax=self.xmax, + ymin=self.minvalue, + ymax=self.maxvalue, + minvalue=self.minvalue, + maxvalue=self.maxvalue) for channel in channelList: - dataCh = dataArray[channel] - frameObj = frameObjList[channel] - frameObj.plot(dataCh) - - def saveFigure(self, filename): - pass - + dataCh = data1D[channel,:] + frameObj = self.frameObjList[channel] +# frameObj.clearData() + frameObj.plot(x, dataCh) + +# frameObj.refresh() + self.__refresh() - def getSubplots(self): - raise ValueError, "No implemented" - -class Frame: - - """ - subplots - """ +# +# if save: +# self.colorplotObj.setFigure(indexPlot) +# path = "/home/roj-idl71/tmp/" +# now = datetime.datetime.now().timetuple() +# file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5]) +# filename = os.path.join(path,file) +# self.colorplotObj.savePlot(indexPlot, filename) +# +# self.colorplotObj.closePage() +class Frame: + nplots = None plotObjList = [] title = "" - def __init__(self, idframe, showGraph1=False, showGraph2=False): - + def __init__(self,drvObj, idframe): + self.drvObj = drvObj self.idframe = idframe - self.showGraph1 = showGraph1 - self.showGraph2 = showGraph2 - - self.nplots = 1 + showGraph1 + showGraph2#para el caso de RTI showGrap1 deberia indicar colorbar como propiedad, no como plot - self.__createPlots() + self.createPlots() - def __createPlots(self): - - for nplot in range(self.nplots): - xi, yi, xw, yw = self.__getScreenPos(nplot) - plotObj = Plot(xi, yi, xw, yw) - - self.plotObjList.append(plotObj) - - def __getScreenPosMainPlot(self): - - """ - Calcula las coordenadas asociadas al plot principal. - """ - - xi = 1.2 - yi = 2.3 - xw = 2.0 - yw = 1.4 - - return xi, yi, xw, yw - - def __getScreenPosGraph1(self): - xi = 1.2 - yi = 2.3 - xw = 2.0 - yw = 1.4 - - return xi, yi, xw, yw + def createPlots(self): + raise ValueError, "No implemented" - def __getScreenPosGraph2(self): - xi = 1.2 - yi = 2.3 - xw = 2.0 - yw = 1.4 - - return xi, yi, xw, yw - - def __getScreenPos(self, nplot): + def getScreenPosMainPlot(self): + raise ValueError, "No implemented" + + def getScreenPos(self, nplot): if nplot == 0: - xi, yi, xw, yw = self.__getScreenPosMain() - if nplot == 1: - xi, yi, xw, yw = self.__getScreenPosMain() - if nplot == 2: - xi, yi, xw, yw = self.__getScreenPosMain() - + xi, yi, xw, yw = self.getScreenPosMainPlot() return xi, yi, xw, yw - - - def init(self, xmin, xmax, ymin, yamx, minvalue, maxvalue): - - """ - """ - - for plotObj in self.plotObjList: - plotObj.plotBox(xmin, xmax, ymin, yamx, minvalue, maxvalue) - def clearData(self): - pass - - def plot(self, data): - + + def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): + for plotObj in self.plotObjList: - plotObj.plotData(data) - - def refresh(self): - pass + plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue) +# plotObj.setLabels() # ? evaluar si conviene colocarlo dentro del plotbox - + def refresh(self): + for plotObj in self.plotObjList: + plotObj.refresh() class Plot: - title = "" - - def __init__(self, xi, yi, xw, yw): - + xlabel = "" + ylabel = "" + xaxisastime = None + timefmt = None + xopt = "" + yopt = "" + xpos = None + ypos = None + szchar = None + idframe = None + idplot = None + + def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): + self.drvObj = drvObj + self.idframe = idframe + self.idplot = idplot self.xi = xi self.yi = yi self.xw = xw self.yw = yw - - def __setRange(self, xrange, yrange, zrange): - pass - - def __setLabels(self, xlabel, ylabel, zlabel): - pass - - def plotBox(self,xmin, xmax, ymin, yamx, minvalue, maxvalue): - pass - - def plotData(self): +# def setLabels(self): +# self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) + + def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): + self.xmin = xmin + self.xmax = xmax + self.ymin = ymin + self.ymax = ymax + self.minvalue = minvalue + self.maxvalue = maxvalue + + self.drvObj.driver.plotBox(self.idframe, + self.xpos, + self.ypos, + self.xmin, + self.xmax, + self.ymin, + self.ymax, + self.minvalue, + self.maxvalue, + self.xopt, + self.yopt, + self.szchar, + self.xaxisastime, + self.timefmt) + + self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) + + def plotBasicLine(self,x, y, color): + """ + Inputs: + x: + + y: + + color: + """ + self.drvObj.driver.basicLine(x, y, self.xmin, self.xmax, self.ymin, self.ymax, color, self.idframe, self.xpos, self.ypos) + - raise ValueError, "" - + \ No newline at end of file diff --git a/schainpy2/Graphics/schainPlotLib.py b/schainpy2/Graphics/schainPlotLib.py index 09650bd..a72ec70 100644 --- a/schainpy2/Graphics/schainPlotLib.py +++ b/schainpy2/Graphics/schainPlotLib.py @@ -4,11 +4,11 @@ import sys import plplot #condicional class Driver: - def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs): + def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap): if driver == "plplot": - self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) + self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colorbar, colormap) elif driver == "mpl": - self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) + self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap) else: raise ValueError, "The driver: %s is not defined"%driver @@ -17,7 +17,7 @@ class PlplotDriver: __isDriverOpen = False pldriver = None - def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs): + def __init__(self, idfigure, xw, yw, wintitle, overplot, colorbar, colormap): if idfigure == None: raise ValueError, 'idfigure input must be defined' @@ -27,11 +27,12 @@ class PlplotDriver: self.yw = yw self.wintitle = wintitle self.overplot = overplot + self.colorbar = colorbar self.colormap = colormap - self.showGraph1 = showGraphs[0] - self.showGraph2 = showGraphs[1] + + - def configDriver(self): + def setFigure(self): """ previous configuration to open(init) the plplot driver """ @@ -80,604 +81,73 @@ class PlplotDriver: plplot.pleop() def setSubPlots(self,nrows, ncolumns): - plplot.plssub(nrows, ncolumns) + plplot.plssub(ncolumns,nrows) - def setColorMap(self,colormap): - - if colormap == None: - return - - ncolor = None - rgb_lvl = None - - # Routine for defining a specific color map 1 in HLS space. - # if gray is true, use basic grayscale variation from half-dark to light. - # otherwise use false color variation from blue (240 deg) to red (360 deg). + def setPlotLabels(self, xlabel, ylabel, title): + plplot.pllab(xlabel, ylabel, title) - # Independent variable of control points. + def setFigTitle(self, title,color="black", szchar=0.55): + self.setSubPlots(1, 0) + plplot.pladv(0) + plplot.plvpor(0., 1., 0., 1.) - i = numpy.array((0., 1.)) + if color == "black": + plplot.plcol0(1) + if color == "white": + plplot.plcol0(15) - if colormap=="gray": - ncolor = 256 - # Hue for control points. Doesn't matter since saturation is zero. - h = numpy.array((0., 0.)) - # Lightness ranging from half-dark (for interest) to light. - l = numpy.array((0.5, 1.)) - # Gray scale has zero saturation - s = numpy.array((0., 0.)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - 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)) + plplot.plschr(0.0,szchar) + plplot.plmtex("t",-1., 0.5, 0.5, title) + + def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): + """ + xopt, yopt: entradas que no se aplican en MPL + """ + plplot.pladv(id) + plplot.plschr(0.0,szchar-0.05) + plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) + plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) + if xaxisastime: + plplot.pltimefmt(timefmt) + 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) - 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 + def refresh(self): + plplot.plflush() - 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 + def basicLine(self, x, y, xmin, xmax, ymin, ymax, color, id, xpos, ypos): - 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 + """ + Inputs: + x: datos en el eje x - pos[i] = float(i)/float(ncolor-1) + y: datos en el eje y - - 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) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) + xmin, xmax: intervalo de datos en el eje x - return None - - if colormap=="tricolor": - ncolor = 3 - # Hue ranges from blue (240 deg) to red (0 or 360 deg) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) + ymin, ymax: intervalo de datos en el eje y - return None - - if colormap == 'rgb' or colormap == 'rgb666': + color: color de la linea a dibujarse - color_sz = 6 - ncolor = color_sz*color_sz*color_sz - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(color_sz): - for gi in range(color_sz): - for bi in range(color_sz): - r[ind] = ri/(color_sz-1.0) - g[ind] = gi/(color_sz-1.0) - b[ind] = bi/(color_sz-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,6,6] #Levels for RGB colors + id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada + plot esta definido por xpos, ypos. - if colormap == 'rgb676': - ncolor = 6*7*6 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(7-1.0) - b[ind] = bi/(6-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,7,6] #Levels for RGB colors - - if colormap == 'rgb685': - ncolor = 6*8*5 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(5-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,8,5] #Levels for RGB colors - - if colormap == 'rgb884': - ncolor = 8*8*4 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(8-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(4-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [8,8,4] #Levels for RGB colors - - if ncolor == None: - raise ValueError, "The colormap selected is not valid" - - plplot.plscmap1n(ncolor) - plplot.plscmap1l(1, pos, r, g, b) - - return rgb_lvl - - def setBox(self): - - pass - - def refreshBox(self): - - pass - - def save(self): - - pass - - def show(self): - - pass - - def colorbarPlot(self): - - pass - - def linePlot(self): - - pass - - def pcolorPlot(self): - - pass - - def setLabels(self): - - pass - - - - - -class MplDriver: - def __init__(self): - pass - -def config_driver(idfigure, wintitle, width, height): - plplot.plsstrm(idfigure) - plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL) - plplot.plsetopt("geometry", "%dx%d"%(width,height)) - -def ini_driver(driver): - if sys.platform == "darwin": - plplot.plsdev("xwin") - if sys.platform == "linux": - plplot.plsdev("xcairo") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plspause(False) - -def set_subpages(ncol,nrow): - plplot.plssub(ncol,nrow) - -def cmap1_init(colormap="gray"): - - if colormap == None: - return - - ncolor = None - rgb_lvl = None - - # Routine for defining a specific color map 1 in HLS space. - # if gray is true, use basic grayscale variation from half-dark to light. - # otherwise use false color variation from blue (240 deg) to red (360 deg). - - # Independent variable of control points. - i = numpy.array((0., 1.)) - if colormap=="gray": - ncolor = 256 - # Hue for control points. Doesn't matter since saturation is zero. - h = numpy.array((0., 0.)) - # Lightness ranging from half-dark (for interest) to light. - l = numpy.array((0.5, 1.)) - # Gray scale has zero saturation - s = numpy.array((0., 0.)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - 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 + xpos,ypos: coordenadas que indican la posicion del plot en el frame - 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) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) - - return None - - if colormap=="tricolor": - ncolor = 3 - # Hue ranges from blue (240 deg) to red (0 or 360 deg) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) - - return None - - if colormap == 'rgb' or colormap == 'rgb666': + """ - color_sz = 6 - ncolor = color_sz*color_sz*color_sz - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(color_sz): - for gi in range(color_sz): - for bi in range(color_sz): - r[ind] = ri/(color_sz-1.0) - g[ind] = gi/(color_sz-1.0) - b[ind] = bi/(color_sz-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,6,6] #Levels for RGB colors + plplot.pladv(id) + plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) + plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) - if colormap == 'rgb676': - ncolor = 6*7*6 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(7-1.0) - b[ind] = bi/(6-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,7,6] #Levels for RGB colors - - if colormap == 'rgb685': - ncolor = 6*8*5 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(5-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,8,5] #Levels for RGB colors - - if colormap == 'rgb884': - ncolor = 8*8*4 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(8-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(4-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [8,8,4] #Levels for RGB colors - - if ncolor == None: - raise ValueError, "The colormap selected is not valid" - - plplot.plscmap1n(ncolor) - plplot.plscmap1l(1, pos, r, g, b) - - return rgb_lvl - -def set_colormap(colormap="jet"): - cmap1_init(colormap) - -def save_figure(filename,width,height): - curr_strm = plplot.plgstrm() - save_strm = plplot.plmkstrm() - plplot.plsetopt("geometry", "%dx%d"%(width,height)) - if sys.platform == "darwin": - plplot.plsdev("png") - if sys.platform == "linux": - plplot.plsdev("pngcairo") - plplot.plsfnam(filename) - plplot.plcpstrm(curr_strm,0) - plplot.plreplot() - plplot.plend1() - plplot.plsstrm(curr_strm) - -def set_new_figure(): - plplot.plbop() - plplot.pladv(0) - -def close_figure(): - plplot.pleop() - -def set_strm(indexPlot): - plplot.plsstrm(indexPlot) - -def refresh(): - plplot.plflush() - -def show(): - plplot.plspause(True) - plplot.plend() - -def set_title(pltitle,color, szchar=0.7): - setSubpages(1, 0) - plplot.pladv(0) - plplot.plvpor(0., 1., 0., 1.) - - if color == "black": + if color == "blue": + colline = 9 + if color == "green": + colline = 3 + + plplot.plcol0(colline) + plplot.plline(x, y) plplot.plcol0(1) - if color == "white": - plplot.plcol0(15) - - plplot.plschr(0.0,szchar) - plplot.plmtex("t",-1., 0.5, 0.5, pltitle) - -def set_line_style(style): - plplot.pllsty(style) - -def set_color(color): - plplot.plcol0(color) - -def set_labels(xlabel, ylabel, title): - plplot.pllab(xlabel, ylabel, title) - -def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"): - plplot.pladv(subplot) - plplot.plschr(0.0,szchar-0.05) - plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) - plplot.plwind(float(xmin), - float(xmax), - float(ymin), - float(ymax) - ) - if xaxisastime: - plplot.pltimefmt(timefmt) - 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) - -def colorbar(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 basicline_timeplot(x, y,colline=1): - plplot.plcol0(colline) - plplot.plline(x, y) - plplot.plcol0(1) - -def basic_xy_plot(x, y): - plplot.plline(x, y) - -def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=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] - if zmin == None: zmin = numpy.nanmin(data) - if zmax == None: zmax = numpy.nanmax(data) - - plplot.plimage(data, - float(x[0]), - float(x[-1]), - float(y[0]), - float(y[-1]), - float(zmin), - float(zmax), - float(xmin), - float(xmax), - float(ymin), - float(ymax) - ) - -def image_plot(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]) - -def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.): - plplot.plimagefr(data, - float(xmin), - float(xmax), - float(ymin), - float(ymax), - 0., - 0., - float(zmin), - float(zmax), - plplot.pltr2, - xg, - yg) - -#------------------------------------ - -#def get_grid(x, y, deltax=None, deltay=None): -# -# 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] -# if deltay == None: deltay = y[-1] - y[-2] -# -# x1 = numpy.append(x, x[-1] + deltax) -# y1 = numpy.append(y, y[-1] + deltay) -# -# xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) -# yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) -# -# self.__xg = xg -# self.__yg = yg -# -# return xg, yg -# -#def advPcolorPlot(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) + plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) diff --git a/schainpy2/Graphics/schainPlotTypes.py b/schainpy2/Graphics/schainPlotTypes.py index 5258a7b..b0e8863 100644 --- a/schainpy2/Graphics/schainPlotTypes.py +++ b/schainpy2/Graphics/schainPlotTypes.py @@ -1,116 +1,106 @@ import numpy from schainPlot import * +#from schainPlotLib import Driver class ScopeFigure(Figure): overplot = 0 xw = 700 - yw = 600 + yw = 650 + colorbar = None +# frameObjList = [] def __init__(self,idfigure,nframes,wintitle,driver): - - args = (0, 0) colormap = None - Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colormap,*args) + colorbar = False + addGraph = 0 + args=(addGraph, addGraph) + + self.idfigure = idfigure self.nframes = nframes - self.showColorbar = 0 - self.showPowerProfile = 0 - - def getSubplots(self): - nrows = self.nframes - ncolumns = 1 + self.wintitle = wintitle +# self.xw = +# self.yw = +# self.overplot = + self.driver = driver + self.colorbar = colorbar + self.colormap = colormap - return nrows, ncolumns - - def __createFrames(self): - for frame in range(self.nframes): - frameObj = ScopeFrame(idFrame = frame) - - self.frameObjList.append(frameObj) - + self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colorbar, self.colormap) + self.drvObj.driver.setFigure() - -class ScopeFrame(Frame): - def __init__(self,idFrame): - self.idFrame = idFrame - self.showGraph1 = 0 - self.showGraph2 = 0 - - def setXYPos(self): - pass - -class RTIFigure(Figure): - - overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0 - xw = 700 - yw = 150 - - - def __init__(self, idfigure, nframes, wintitle, driver, colormap, showColorbar, showPowerProfile): - - showGraphs = (showColorbar, showPowerProfile) - - Figure.__init__(self, - idfigure=idfigure, - nframes = nframes, - wintitle=wintitle, - xw=self.xw, - yw=self.yw, - overplot=self.overplot, - driver=driver, - colormap=colormap, - *showGraphs) - - self.nframes = nframes - self.showColorbar = showColorbar - self.showPowerProfile = showPowerProfile +# Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args) def getSubplots(self): nrows = self.nframes ncolumns = 1 - return nrows, ncolumns - - def __createFrames(self): + + def createFrames(self): for frame in range(self.nframes): - frameObj = RTIFrame(idFrame = frame, - showGraph1 = self.showColorbar, - showGraph2 = self.showPowerProfile - ) - + frameObj = ScopeFrame(self.drvObj,frame + 1) self.frameObjList.append(frameObj) - -class RTIFrame(Frame): - def __init__(self,idFrame, showColorbar, showPowerProfile): - self.idFrame = idFrame - self.showGraph1 = showColorbar - self.showGraph2 = showPowerProfile + - def setXYPos(self): - pass +class ScopeFrame(Frame): +# plotObjList = [] + xlabel = "" + ylabel = "" + title = "" + def __init__(self,drvObj,idframe): + self.drvObj = drvObj + self.idframe = idframe + self.nplots = 1 #nplots/frame + self.createPlots() +# Frame.__init__(self, drvObj, idframe) -class SelfSpcFigure(Figure): - def __init__(self): - pass - -class SelfSpcFrame(Frame): - def __init__(self): - pass + def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots + xi = 0.07; xw = 0.9 + yi = 0.20; yw = 0.75 + return xi,yi,xw,yw -class CrossSpcFigure(Figure): - def __init__(self): - pass + def createPlots(self): + plotObjList = [] + for idplot in range(self.nplots): + xi, yi, xw, yw = self.getScreenPos(idplot) + plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) + plotObjList.append(plotObj) + self.plotObjList = plotObjList +# self.plotObjList.append(plotObj) -class CrossSpcFrame(Frame): - def __init__(self): - pass + def plot(self, x, y, z=None): + for plotObj in self.plotObjList: + plotObj.plot(x, y) + +class Plot1D(Plot): + + def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): + self.drvObj = drvObj + self.idframe = idframe + self.idplot = idplot + self.xi = xi + self.yi = yi + self.xw = xw + self.yw = yw + self.xpos = [self.xi,self.xw] + self.ypos = [self.yi,self.yw] + self.xaxisastime = False + self.timefmt = None + self.xopt = "bcnst" + self.yopt = "bcnstv" + self.szchar = 1.0 + self.title = "Channel %d"%self.idframe + self.xlabel = "x-axis" + self.ylabel = "y-axis" -if __name__ == '__main__': - idfigure=0 - nframes=2 - wintitle='' - driver='plplot' - scopeObj = ScopeFigure(idfigure,nframes,wintitle,driver) - + def plot(self,x,y): + if y.dtype == "complex128": + color="blue" + self.plotBasicLine(x, y.real, color) + color="red" + self.plotBasicLine(x, y.imag, color) + else: + color="blue" + self.plotBasicLine(x, y, color)