diff --git a/schainpy2/Graphics/schainPlot.py b/schainpy2/Graphics/schainPlot.py index eddc6c0..e19ffdc 100644 --- a/schainpy2/Graphics/schainPlot.py +++ b/schainpy2/Graphics/schainPlot.py @@ -61,7 +61,7 @@ class Figure: 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='./'): + def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): nx, ny = data1D.shape @@ -71,10 +71,10 @@ class Figure: if x == None: x = numpy.arange(data1D.size) - if figtitle == None: - self.figtitle = "" + if figuretitle == None: + self.figuretitle = "" else: - self.figtitle = figtitle + self.figuretitle = figuretitle if not(self.__isDriverOpen): self.__openDriver() @@ -104,7 +104,6 @@ class Figure: self.__initFigure() for channel in channelList: -# frametitle = self.plotTitleDict[channel] frameObj = self.frameObjList[channel] frameObj.init(xmin=self.xmin, xmax=self.xmax, @@ -133,6 +132,69 @@ class Figure: # self.colorplotObj.savePlot(indexPlot, filename) # # self.colorplotObj.closePage() + + + def plotPcolor(self,data, + x=None, + y=None, + channelList=None, + xmin=None, + xmax=None, + ymin=None, + ymax=None, + minvalue=None, + maxvalue=None, + figuretitle=None, + deltax=None, + save=False, + gpath='./'): +# data, +# currenttime, +# range, +# starttime, +# endtime, +# minrange, +# maxrange, +# minvalue, +# maxvalue, +# figuretitle, +# interval, +# save, +# gpath): + + if figuretitle == None: + self.figuretitle = "" + else: + self.figuretitle = figuretitle + + + + if not(self.__isDriverOpen): + self.__openDriver() + self.__isDriverOpen = True + + if not(self.__isConfig): + + self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,deltax) + + + +# if self.xmin == None: self.xmin = numpy.min(x) +# if self.xmax == None: self.xmax = numpy.max(x) + + + self.createFrames() + self.__isConfig = True + + if not(self.__isOutOfXRange(x)): + self.__changeXRange(x) + + if self.__isFigureOpen: + self.driverObj.closePage() + self.__isFigureOpen = False + + self.__initFigure() + class Frame: nplots = None diff --git a/schainpy2/Graphics/schainPlotLib.py b/schainpy2/Graphics/schainPlotLib.py index a72ec70..45cf74c 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, colorbar, colormap): + def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): if driver == "plplot": - self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colorbar, colormap) + self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) elif driver == "mpl": - self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap) + self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) 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, colorbar, colormap): + def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): if idfigure == None: raise ValueError, 'idfigure input must be defined' @@ -27,10 +27,8 @@ class PlplotDriver: self.yw = yw self.wintitle = wintitle self.overplot = overplot - self.colorbar = colorbar self.colormap = colormap - - + self.colorbar = colorbar def setFigure(self): """ @@ -99,6 +97,31 @@ class PlplotDriver: plplot.plschr(0.0,szchar) plplot.plmtex("t",-1., 0.5, 0.5, title) + def colorbar(self, minvalue, maxvalue, xpos, ypos): +# plplot.pladv(id) +# plplot.plschr(0.0,szchar-0.05) + xmin = 0; xmax = 1 + ymin = minvalue; ymax = maxvalue + plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) + plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) + plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0) + + 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 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 @@ -151,3 +174,8 @@ class PlplotDriver: plplot.plline(x, y) plplot.plcol0(1) plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) + + +class MplDriver: + def __init__(self): + pass \ No newline at end of file diff --git a/schainpy2/Graphics/schainPlotTypes.py b/schainpy2/Graphics/schainPlotTypes.py index b0e8863..aea1a8c 100644 --- a/schainpy2/Graphics/schainPlotTypes.py +++ b/schainpy2/Graphics/schainPlotTypes.py @@ -1,32 +1,224 @@ -import numpy +import nump +import datetime +import time from schainPlot import * #from schainPlotLib import Driver + +class RTIFigure: + overplot = 1 + xw = 700 + yw = 650 + showprofile = False + starttime = None + endtime = None + minrange = None + maxrange = None + minvalue = None + maxvalue = None + + + def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): + self.idfigure = idfigure + self.nframes = nframes + self.wintitle = wintitle + self.colormap = colormap + self.colorbar = colorbar + self.showprofile = showprofile + self.driver = driver + self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) + self.drvObj.driver.setFigure() + + def getSubplots(self): + nrows = self.nframes + ncolumns = 1 + return nrows, ncolumns + + def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax): + + if minvalue == None: minvalue = numpy.min(data) + if maxvalue == None: maxvalue = numpy.max(data) + + utcdatetime = datetime.datetime.utcfromtimestamp(x) + startdatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin.hour,xmin.minute, xmin.second) + enddatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax.hour,xmax.minute, xmax.second) + deltatime = 0 + if timezone == "lt": deltatime = time.timezone + startTimeInSecs = time.mktime(startdatetime.timetuple()) - deltatime + endTimeInSecs = time.mktime(enddatetime.timetuple()) - deltatime + self.starttime = xmin + self.endtime = xmax + self.xmin = startTimeInSecs + self.xmax = self.xmin + interval + + + + if ymin == None: ymin = numpy.min(y) + if ymin == None: ymax = numpy.max(y) + + starttime = None + endtime = None + minrange = None + maxrange = None + minvalue = None + maxvalue = None + + + self.xmin = s + self.xmax = self.starttime + timeinterval + self.ymin = minrange + self.ymax = maxrange + self.minvalue = minvalue + self.maxvalue = maxvalue + + + def createFrames(self): + for frame in range(self.nframes): + frameObj = ScopeFrame(self.drvObj,frame + 1) + self.frameObjList.append(frameObj) + +class RTIFrame(Frame): + def __init__(self,drvObj,idframe,colorbar,showProfile): + self.drvObj = drvObj + self.idframe = idframe + self.nplots = 1 + + if showProfile: + self.nplots += 1 + + self.colorbar = colorbar + self.showprofile = showprofile + self.createPlots() + + def createPlots(self): + plotObjList = [] + + idplot = 0 + xi, yi, xw, yw = self.getScreenPos(idplot) + plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) + plotObjList.append(plotObj) + + if self.showprofile: + idplot = 1 + xi, yi, xw, yw = self.getScreenPos(idplot) + plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) + plotObjList.append(plotObj) + + self.plotObjList = plotObjList + + def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots + xi = 0.07 + + if self.showprofile: + xw = 0.65 + + else: + xw = 0.9 + + if self.colorbar: + xw = xw - 0.06 + + yi = 0.20; yw = 0.75 + + return xi, yi, xw, yw + + def getScreenPosGraph1(self): + if self.colorbar: + xi = 0.65 + 0.05 + else: + xi = 0.9 + 0.05 + + xw = xi + 0.2 + + yi = 0.2; yw = 0.75 + + return xi, yi, xw, yw + + +class RTIPlot: + 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 + + if self.colorbar: + cbxi = xw + 0.03 + cbxw = cbxi + 0.03 + cbyi = yi + cbyw = yw + self.cbxpos = [cbxi,cbxw] + self.cbypos = [cbyi,cbyw] + + self.xpos = [self.xi,self.xw] + self.ypos = [self.yi,self.yw] + self.xaxisastime = True + self.timefmt = "%H:%M" + self.xopt = "bcnstd" + self.yopt = "bcnstv" + + self.szchar = 1.0 + self.title = "Channel %d"%self.idframe + self.xlabel = "x-axis" + self.ylabel = "y-axis" + + 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) + + if self.colorbar: + self.drvObj.driver.colorbar(minvalue, maxvalue, self.cbxpos,self.cbypos) + + + def plot(self): + pass + + + + + class ScopeFigure(Figure): overplot = 0 xw = 700 yw = 650 colorbar = None -# frameObjList = [] def __init__(self,idfigure,nframes,wintitle,driver): colormap = None colorbar = False - addGraph = 0 - args=(addGraph, addGraph) - self.idfigure = idfigure self.nframes = nframes self.wintitle = wintitle -# self.xw = -# self.yw = -# self.overplot = - self.driver = driver - self.colorbar = colorbar + self.colormap = colormap - - self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colorbar, self.colormap) + self.colorbar = colorbar + self.driver = driver + self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) self.drvObj.driver.setFigure() # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args)