diff --git a/schainpy2/Graphics/schainPlot.py b/schainpy2/Graphics/schainPlot.py index e19ffdc..febfb8e 100644 --- a/schainpy2/Graphics/schainPlot.py +++ b/schainpy2/Graphics/schainPlot.py @@ -1,4 +1,5 @@ import numpy +import datetime from schainPlotLib import Driver class Figure: @@ -14,10 +15,15 @@ class Figure: overplot = None xmin = None xmax = None + ymin = None + ymax = None minvalue = None maxvalue = None + deltax = None + deltay = None frameObjList = [] - figtitle = "" + figuretitle = "" + xrangestep = None def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args): self.idfigure = idfigure @@ -35,6 +41,7 @@ class Figure: self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap) self.drvObj.driver.setFigure() + self.drvObj.driver.setColormap(colormap) def __openDriver(self): @@ -49,12 +56,20 @@ class Figure: def __initFigure(self): nrows, ncolumns = self.getSubplots() self.drvObj.driver.openFigure() - self.drvObj.driver.setFigTitle(self.figtitle) + self.drvObj.driver.setFigTitle(self.figuretitle) self.drvObj.driver.setSubPlots(nrows, ncolumns) def __isOutOfXRange(self,x): + + if ((x>=self.xmin) and (x0 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)) + + return xg, yg + + + def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): + + plplot.pladv(id) + plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) + plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) + if xaxisastime: + timedelta = (xmax - xmin + 1)/8. + + if getGrid: + self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) + + xmin = x[0] + xmax = xmin + deltax + + plplot.plimagefr(data, + float(xmin), + float(xmax), + float(ymin), + float(ymax), + 0., + 0., + float(zmin), + float(zmax), + plplot.pltr2, + self.__xg, + self.__yg) + + if xaxisastime: + plplot.pltimefmt(timefmt) + xopt = "bcstd" + yopt = "bcst" + plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) + else: + xopt = "bcst" + yopt = "bcst" + plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) + def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): """ @@ -140,7 +197,7 @@ class PlplotDriver: def refresh(self): plplot.plflush() - def basicLine(self, x, y, xmin, xmax, ymin, ymax, color, id, xpos, ypos): + def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): """ Inputs: @@ -174,6 +231,180 @@ class PlplotDriver: plplot.plline(x, y) plplot.plcol0(1) plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) + + def setColormap(self, 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 class MplDriver: diff --git a/schainpy2/Graphics/schainPlotTypes.py b/schainpy2/Graphics/schainPlotTypes.py index aea1a8c..1536d4d 100644 --- a/schainpy2/Graphics/schainPlotTypes.py +++ b/schainpy2/Graphics/schainPlotTypes.py @@ -1,11 +1,11 @@ -import nump +import numpy import datetime import time from schainPlot import * #from schainPlotLib import Driver -class RTIFigure: +class RTIFigure(Figure): overplot = 1 xw = 700 yw = 650 @@ -16,6 +16,7 @@ class RTIFigure: maxrange = None minvalue = None maxvalue = None + xrangestepinsecs = None def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): @@ -28,62 +29,102 @@ class RTIFigure: 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() + self.drvObj.driver.setColormap(colormap) 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 + def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep): + self.starttime = xmin self.endtime = xmax - self.xmin = startTimeInSecs - self.xmax = self.xmin + interval - + cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime + + mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) + if ((xrangestep == 0) or (xrangestep == None)): + maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second) + self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple()) + npoints = 1000. + if xrangestep == 1: + maxdatetime = mindatetime + datetime.timedelta(hours=1) + self.xrangestepinsecs = 60*60. + npoints = 500. + if xrangestep == 2: + maxdatetime = mindatetime + datetime.timedelta(minutes=1) + self.xrangestepinsecs = 60. + npoints = 250. + if xrangestep == 3: + maxdatetime = mindatetime + datetime.timedelta(seconds=1) + self.xrangestepinsecs = 1. + npoints = 125. + + xmin = time.mktime(mindatetime.timetuple()) + xmax = time.mktime(maxdatetime.timetuple()) + + deltax = (xmax-xmin) / npoints - 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 + if ymin == None: ymin = numpy.min(y) + if ymax == None: ymax = numpy.max(y) + if minvalue == None: minvalue = 0. + if maxvalue == None: maxvalue = 50. - self.xmin = s - self.xmax = self.starttime + timeinterval - self.ymin = minrange - self.ymax = maxrange + self.xmin = xmin + self.xmax = xmax + self.minrange = ymin + self.maxrange = ymax + self.ymin = ymin + self.ymax = ymax self.minvalue = minvalue self.maxvalue = maxvalue + self.xrangestep = xrangestep + self.deltax = deltax + + + def changeXRange(self,x): + + cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime + + if ((cdatetime.time()>=self.starttime) and (cdatetime.time()= self.xmaxpos: + + self.xminpos = currenttime + self.xmaxpos = currenttime + self.deltax + x = [currenttime] + y = range + z = numpy.reshape(data, (1,-1)) + getGrid = True + + self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid) + class ScopeFigure(Figure): overplot = 0