From cfcc2c9608cc0c090d8c9b6118ae07cafd30c93f 2012-11-27 18:55:15 From: Daniel Valdez Date: 2012-11-27 18:55:15 Subject: [PATCH] Se agrega el folder "graphics" que contiene figure.py y mpldriver.py figure.py contiene las clases: Figure, Axes mpldriver.py driver para matplotlib En el modelo se creado: jroplot.py, aqui se ha agregado la clase Scope, para hacer graficos tipo osciloscopio. El archivo de prueba: test4NewSignalChain.py contiene un ejemplo. --- diff --git a/schainpy/graphics/__init__.py b/schainpy/graphics/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/graphics/__init__.py diff --git a/schainpy/graphics/figure.py b/schainpy/graphics/figure.py new file mode 100644 index 0000000..2fc8641 --- /dev/null +++ b/schainpy/graphics/figure.py @@ -0,0 +1,61 @@ +import mpldriver + +class Figure: + axesList = None + def __init__(self): + pass + + def init(self, idfigure, wintitle, width, height, nplots): + self.idfigure = idfigure + self.wintitle = wintitle + self.width = width + self.height = height + self.nplots = nplots + mpldriver.init(idfigure, wintitle, width, height) + + self.axesList = [] + + def setTitle(self, title): + mpldriver.setTitle(self.idfigure, title) + + def setTextFromAxes(self, title): + mpldriver.setTextFromAxes(self.idfigure, self.axesList[0].ax, title) + + def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): + ax = mpldriver.makeAxes(self.idfigure, nrow, ncol, xpos, ypos, colspan, rowspan) + axesObj = Axes(ax) + self.axesList.append(axesObj) + + def draw(self): + mpldriver.draw(self.idfigure) + + def run(self): + pass + + +class Axes: + firsttime = None + ax = None + + def __init__(self, ax): + self.firsttime = True + self.ax = ax + + def pline(self, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title): + + mpldriver.pline(ax=self.ax, + x=x, + y=y, + xmin=xmin, + xmax=xmax, + ymin=ymin, + ymax=ymax, + xlabel=xlabel, + ylabel=ylabel, + title=title, + firsttime=self.firsttime) + + self.firsttime = False + + def pcolor(self): + pass diff --git a/schainpy/graphics/mpldriver.py b/schainpy/graphics/mpldriver.py new file mode 100644 index 0000000..cf00852 --- /dev/null +++ b/schainpy/graphics/mpldriver.py @@ -0,0 +1,50 @@ +import matplotlib +matplotlib.use("TKAgg") +import matplotlib.pyplot +import scitools.numpyutils + +def init(idfigure, wintitle, width, height): + matplotlib.pyplot.ioff() + fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor="w") + fig.canvas.manager.set_window_title(wintitle) + fig.canvas.manager.resize(width,height) + matplotlib.pyplot.ion() + +def setTextFromAxes(idfigure, ax, title): + fig = matplotlib.pyplot.figure(idfigure) + ax.annotate(title, xy=(.1, .99), + xycoords='figure fraction', + horizontalalignment='left', verticalalignment='top', + fontsize=10) + +def setTitle(idfigure, title): + fig = matplotlib.pyplot.figure(idfigure) + fig.suptitle(title) + +def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): + fig = matplotlib.pyplot.figure(idfigure) + ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) + return ax + +def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): + if firsttime: + ax.plot(x, y) + ax.set_xlim([xmin,xmax]) + ax.set_ylim([ymin,ymax]) + ax.set_xlabel(xlabel, size=8) + ax.set_ylabel(ylabel, size=8) + ax.set_title(title, size=10) + matplotlib.pyplot.tight_layout() + else: + ax.lines[0].set_data(x,y) + +def draw(idfigure): + fig = matplotlib.pyplot.figure(idfigure) + fig.canvas.draw() + +def pcolor(): + pass + + + + \ No newline at end of file diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index e69de29..97d4990 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -0,0 +1,85 @@ +import numpy +import datetime +from graphics.figure import * + +class Scope(Figure): + __isConfig = None + width = None + height = None + + def __init__(self): + self.__isConfig = False + self.width = 850 + self.height = 800 + + def getSubplots(self): + nrow = self.nplots + ncol = 3 + return nrow, ncol + + def setup(self, idfigure, wintitle, width, height, nplots): + self.init(idfigure, wintitle, width, height, nplots) + + nrow,ncol = self.getSubplots() + colspan = 3 + rowspan = 1 + + for i in range(nplots): + self.makeAxes(nrow, ncol, i, 0, colspan, rowspan) + + + + def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None): + + if dataOut.isEmpty(): + return None + + if channelList == None: + channelList = dataOut.channelList + + nplots = len(channelList) + + y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) + y = y.real + + x = dataOut.heightList + + if not self.__isConfig: + self.setup(idfigure=idfigure, + wintitle="Figura 1", + width=self.width, + height=self.height, + nplots=nplots) + + if xmin == None: self.xmin = numpy.min(x) + if xmax == None: self.xmax = numpy.max(x) + if ymin == None: self.ymin = numpy.min(y) + if ymax == None: self.ymax = numpy.max(y) + + self.__isConfig = True + + + + thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) + dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) + figuretitle = "Scope: " + dateTime + + self.setTitle(title=figuretitle) + +# self.setTextFromAxes(title=figuretitle) + + ylabel = "Intensity" + + xlabel = "Range[Km]" + + for i in range(len(self.axesList)): + title = "Channel %d"%i + axes = self.axesList[i] + y2 = y[i,:] + axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title) + + self.draw() + + + \ No newline at end of file diff --git a/schainpy/test4NewSignalChain.py b/schainpy/test4NewSignalChain.py index 4dce49b..122cae3 100644 --- a/schainpy/test4NewSignalChain.py +++ b/schainpy/test4NewSignalChain.py @@ -15,20 +15,18 @@ class Test(): def createObjects(self): - - self.upConfig = controller.UPConf(id=1, name="voltageproc", type="voltage") opConf = self.upConfig.addOperation(name="init", priority=0) opConf1 = self.upConfig.addOperation(name="CohInt", priority=1, type="other") + opConf1.addParameter(name="nCohInt", value=100) - opConf1.addParameter(name="nCohInt", value=10) - - - opConf = self.upConfig.addOperation(name="selectChannels", priority=2) + opConf2 = self.upConfig.addOperation(name="Scope", priority=2, type="other") + opConf2.addParameter(name="idfigure", value=1) - opConf.addParameter(name="channelList", value=[0,1]) +# opConf = self.upConfig.addOperation(name="selectChannels", priority=3) +# opConf.addParameter(name="channelList", value=[0,1]) ######################################### @@ -36,9 +34,13 @@ class Test(): self.objP = jroprocessing.VoltageProc() self.objInt = jroprocessing.CohInt() - + self.objP.addOperation(self.objInt, opConf1.id) + self.objScope = jroplot.Scope() + + self.objP.addOperation(self.objScope, opConf2.id) + self.connect(self.objR, self.objP) def connect(self, obj1, obj2):