From b3b2528ac950ec22413adf8a4d2f6cc98f0e3822 2012-09-27 17:05:50 From: Miguel Valdez Date: 2012-09-27 17:05:50 Subject: [PATCH] Inicia nueva version de graficos --- diff --git a/schainpy/Graphics/schainPlot.py b/schainpy/Graphics/schainPlot.py new file mode 100644 index 0000000..f5d2659 --- /dev/null +++ b/schainpy/Graphics/schainPlot.py @@ -0,0 +1,213 @@ + +import numpy +import schainPlplotLib + +class Figure: + + __driverObj = None + __isDriverOpen = False + __isFigureOpen = False + __isConfig = False + __width = None + __height = None + + idfigure = None + nframes = None + wintitle = wintitle + colormap = None + driver = None + overplot = None + + frameObjList = [] + + def __init__(self, idfigure, nframes, wintitle, width=600, height=800, overplot=0, driver='xwin', colormap='br_green', *showGraphs): + + self.idfigure = idfigure + self.nframes = nframes + self.wintitle = wintitle + self.colormap = colormap + self.driver = driver + self.overplot = overplot + + self.showGraphs = showGraphs + + self.__driverObj = Driver(driver) + + def __createFrames(self): + + for frame in range(self.nframes): + frameObj = Frame(idFrame = frame, + showGraph1 = self.showGraph1, + showGraph2 = self.showGraph2 + ) + + self.frameObjList.append(frameObj) + + def __openDriver(self): + + self.__driverObj.openDriver(self.idfigure, self.wintitle, self.width, self.height) + + def __openFigure(self): + + self.__createFrames() + nrows, ncolumns = self.getSubplots() + + self.__driverObj.openFigure() + self.__driverObj.setSubPlots(nrows, ncolumns) + + + def __verifyXRange(self, x): + pass + + def __updateXRange(self, x): + pass + + def plot1DArray(self, data1D, x=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'): + + if not(self.__isDriverOpen): + self.__openDriver() + self.__isDriverOpen = True + + if not(self.__isConfig): + if x == None: x = numpy.arange(data1D.size) + if xmin == None: xmin = numpy.min(x) + if xmax == None: xmax = numpy.max(x) + if minvalue == None: minvalue = numpy.min(data1D) + if maxvalue == None: maxvalue = numpy.max(data1D) + + self.setRange(xmin=xmin, xmax=xmax, minvalue=minvalue, maxvalue=maxvalue) + self.__isConfig = True + + if not(self.__verifyXRange(x)): + self.__updateXRange(x) + if self.__isFigureOpen: + close_figure() + self.__isFigureOpen = False + + if not(self.__isFigureOpen): + self.__openFigure() + self.__isFigureOpen = True + + for frame in channelList: + dataCh = data1D[channel] + frameObj = frameObjList[channel] + frameObj.plotBox() + + for channel in channelList: + dataCh = dataArray[channel] + frameObj = frameObjList[channel] + frameObj.plot(dataCh) + + if not(self.overplot): + close_figure() + 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 + + for channel in channelList: + dataCh = dataArray[channel] + frameObj = frameObjList[channel] + frameObj.plot(dataCh) + + def saveFigure(self, filename): + pass + + + def getSubplots(self): + + raise ValueError, '' + +class Frame: + + plotObjList = [] + + def __init__(self, idFrame, showGraph1=False, showGraph2=False): + + self.idFrame = idFrame + self.showGraph1 = showGraph1 + self.showGraph2 = showGraph2 + + self.nPlots = 2 + self.createPlots() + + def __getScreenPosMain(self): + left = 1.2 + bottom = 2.3 + width = 2.0 + height = 1.4 + + return left, bottom, width, height + + def __getScreenPosGraph1(self): + left = 1.2 + bottom = 2.3 + width = 2.0 + height = 1.4 + + return left, bottom, width, height + + def __getScreenPosGraph2(self): + left = 1.2 + bottom = 2.3 + width = 2.0 + height = 1.4 + + return left, bottom, width, height + + def __getScreenPos(self, nplot): + + if nplot == 0: + left, bottom, width, height = self.__getScreenPosMain() + if nplot == 1: + left, bottom, width, height = self.__getScreenPosMain() + if nplot == 2: + left, bottom, width, height = self.__getScreenPosMain() + + return left, bottom, width, height + + def createPlots(self): + + for nplot in range(self.nPlots): + left, bottom, width, height = self.__getScreenPos(nplot) + plotObj = Plot(left, bottom, width, height) + + self.plotObjList.append(plotObj) + + def setup(self): + pass + + def plot(self, data): + pass + +class Plot: + + def __init__(self, left, bottom, width, height): + + self.left = left + self.bottom = bottom + self.width = width + self.height = height + + def setRange(self, xrange, yrange, zrange): + pass + + def setLabels(self, xlabel, ylabel, zlabel): + pass + + def plotBox(self): + pass + + def plotData(self): + pass + diff --git a/schainpy/Graphics/schainPlotTypes.py b/schainpy/Graphics/schainPlotTypes.py new file mode 100644 index 0000000..f48f78e --- /dev/null +++ b/schainpy/Graphics/schainPlotTypes.py @@ -0,0 +1,68 @@ +import numpy +from schainPlot import * + + +class RTIFigure(Figure): + def __init__(self, idstream, nframe, wintitle, colormap, driver, showColorbar, showPowerProfile): + self.idStream = idStream + self.nFrames = nFrames + self.winTitle = winTitle + self.colormap = colormap + self.driver = driver + self.showGraph1 = showColorbar + self.showGraph2 = showPowerProfile + self.overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0 + + self.width = 700 + self.height = 150 + self.ncol = int(numpy.sqrt(self.nFrames)+0.9) + self.nrow = int(self.nFrames*1./ncol + 0.9) + + + def __createFrames(self): + for frame in range(self.nFrames): + frameObj = RTIFrame(idFrame = frame, + showGraph1 = self.showGraph1, + showGraph2 = self.showGraph2 + ) + + self.frameObjList.append(frameObj) + + + + + + +class RTIFrame(Frame): + def __init__(self,idFrame, showColorbar, showPowerProfile): + self.idFrame = idFrame + self.showGraph1 = showColorbar + self.showGraph2 = showPowerProfile + + def setXYPos + + +class SelfSpcFigure(Figure): + def __init__(self): + pass + +class SelfSpcFrame(Frame): + def __init__(self): + pass + +class CrossSpcFigure(Figure): + def __init__(self): + pass + +class CrossSpcFrame(Frame): + def __init__(self): + pass + +class ScopeFigure(Figure): + def __init__(self): + pass + +class ScopeFrame(Frame): + def __init__(self): + pass + diff --git a/schainpy/Graphics/schainPlplotLib.py b/schainpy/Graphics/schainPlplotLib.py new file mode 100644 index 0000000..f646ae7 --- /dev/null +++ b/schainpy/Graphics/schainPlplotLib.py @@ -0,0 +1,468 @@ +import plplot +import numpy +import sys + +class Driver: + + __isDriverOpen = False + + def __init__(self, driver=plplot): + + self.idStream = idStream + self.nFrames = nFrames + self.winTitle = winTitle + self.colormap = colormap + self.driver = driver + + self.showGraph1 = showGraph1 + self.showGraph2 = showGraph2 + + self.overplot = overplot + + def configDriver(self): + + pass + + def openDriver(self): + + pass + + def closeDriver(self): + + pass + + def openPage(self): + pass + + def closePage(self): + + pass + + def setColorMap(self): + + pass + + 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 + + def figure(self): + + pass + + def setSubPlots(self): + + pass + + +def config_driver(idStream, wintitle, width, height): + plplot.plsstrm(idStream) + 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 + + 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 + + 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": + 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)