##// END OF EJS Templates
Optimizacion del driver para matplotlib. Activacion y descativacion del modo interactivo al crear figures y axes
Optimizacion del driver para matplotlib. Activacion y descativacion del modo interactivo al crear figures y axes

File last commit:

r240:87d92e5aecc6
r244:b2e7e61d8cbe
Show More
figure.py
395 lines | 12.2 KiB | text/x-python | PythonLexer
Miguel Valdez
Se mejora el metodo para grabar graficos de RTI y Spectra....
r212 import os
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 import numpy
Miguel Valdez
r231 import time, datetime
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 import mpldriver
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 class Figure:
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
__driver = mpldriver
Miguel Valdez
Metodo destructor agregado a la clase Figure para desactivar el modo interactivo y mantener el gráfico.
r206 fig = None
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
idfigure = None
wintitle = None
Daniel Valdez
En graphics:...
r192 width = None
height = None
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 nplots = None
Miguel Valdez
r231 timerange = None
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
axesObjList = []
WIDTH = None
HEIGHT = None
Miguel Valdez
Se mejora el metodo para grabar graficos de RTI y Spectra....
r212 PREFIX = 'fig'
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
def __init__(self):
raise ValueError, "This method is not implemented"
Miguel Valdez
Metodo destructor agregado a la clase Figure para desactivar el modo interactivo y mantener el gráfico.
r206 def __del__(self):
self.__driver.closeFigure()
Miguel Valdez
Se mejora el metodo para grabar graficos de RTI y Spectra....
r212
def getFilename(self, name, ext='.png'):
Miguel Valdez
El nombre del archivo grafico esta compuesto por el titulo de la figura mas la fecha y tiempo de los datos.
r238 filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext)
Miguel Valdez
Se mejora el metodo para grabar graficos de RTI y Spectra....
r212
return filename
Miguel Valdez
Metodo destructor agregado a la clase Figure para desactivar el modo interactivo y mantener el gráfico.
r206
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def getAxesObjList(self):
return self.axesObjList
def getSubplots(self):
raise ValueError, "Abstract method: This method should be defined"
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 def getScreenDim(self, widthplot, heightplot):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
nrow, ncol = self.getSubplots()
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 widthscreen = widthplot*ncol
heightscreen = heightplot*nrow
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 return widthscreen, heightscreen
Miguel Valdez
El metodo getTimeLim se ha generalizado y se coloco en a clase base Figure
r230
def getTimeLim(self, x, xmin, xmax):
thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
####################################################
#If the x is out of xrange
if xmax < (thisdatetime - thisdate).seconds/(60*60.):
xmin = None
xmax = None
if xmin == None:
td = thisdatetime - thisdate
xmin = td.seconds/(60*60.)
if xmax == None:
Miguel Valdez
r231 xmax = xmin + self.timerange/(60*60.)
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Miguel Valdez
El metodo getTimeLim se ha generalizado y se coloco en a clase base Figure
r230 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
tmin = time.mktime(mindt.timetuple())
maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
tmax = time.mktime(maxdt.timetuple())
Miguel Valdez
r231 self.timerange = tmax - tmin
Miguel Valdez
El metodo getTimeLim se ha generalizado y se coloco en a clase base Figure
r230
return tmin, tmax
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def init(self, idfigure, nplots, wintitle):
Miguel Valdez
-Se agrego el perfil de potencia al grafico de espectros
r204
raise ValueError, "This method has been replaced with createFigure"
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
"""
Miguel Valdez
-Se agrego el perfil de potencia al grafico de espectros
r204 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
y self.HEIGHT y el numero de subplots (nrow, ncol)
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 Input:
Miguel Valdez
-Se agrego el perfil de potencia al grafico de espectros
r204 idfigure : Los parametros necesarios son
wintitle :
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 """
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 if widthplot == None:
widthplot = self.WIDTH
if heightplot == None:
heightplot = self.HEIGHT
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 self.idfigure = idfigure
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
self.wintitle = wintitle
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
self.fig = self.__driver.createFigure(self.idfigure,
self.wintitle,
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.widthscreen,
self.heightscreen)
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
self.axesObjList = []
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def setDriver(self, driver=mpldriver):
self.__driver = driver
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 def setTitle(self, title):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
self.__driver.setTitle(self.fig, title)
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def setWinTitle(self, title):
self.__driver.setWinTitle(self.fig, title=title)
Daniel Valdez
En esta version se ha implementado la clase para ploteo de espectros, a este grafico aun le falta agregar el perfil de potencia para cada canal.
r196
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def setTextFromAxes(self, text):
raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
def addAxes(self, *args):
"""
Input:
*args : Los parametros necesarios son
nrow, ncol, xpos, ypos, colspan, rowspan
"""
axesObj = Axes(self.fig, *args)
self.axesObjList.append(axesObj)
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
Miguel Valdez
Se mejora el metodo para grabar graficos de RTI y Spectra....
r212 def saveFigure(self, figpath, figfile, *args):
filename = os.path.join(figpath, figfile)
self.__driver.saveFigure(self.fig, filename, *args)
Daniel Valdez
Adicion del metodo saveFigure() para guardar archivos de imagen de la clase Figure(). Se modifica los xaxis se muestran en formato datetime, falta hacer ajustes en los ticks de acuerdo al intervalo [xmin, xmax]
r209
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 def draw(self):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
self.__driver.draw(self.fig)
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
def run(self):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
raise ValueError, "This method is not implemented"
axesList = property(getAxesObjList)
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
class Axes:
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
__driver = mpldriver
fig = None
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 ax = None
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 plot = None
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 __firsttime = None
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Miguel Valdez
-Se agrego el perfil de potencia al grafico de espectros
r204 __showprofile = False
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 xmin = None
xmax = None
ymin = None
ymax = None
zmin = None
zmax = None
Daniel Valdez
Adicion de la clase RTIPlot
r207
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def __init__(self, *args):
"""
Input:
*args : Los parametros necesarios son
fig, nrow, ncol, xpos, ypos, colspan, rowspan
"""
ax = self.__driver.createAxes(*args)
self.fig = args[0]
Daniel Valdez
Se agrega el folder "graphics" que contiene figure.py y mpldriver.py...
r190 self.ax = ax
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 self.plot = None
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.__firsttime = True
Daniel Valdez
Se agrega el metodo deflip a jroprocessing.py....
r239 self.idlineList = []
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
def setText(self, text):
self.__driver.setAxesText(self.ax, text)
Daniel Valdez
Adicion del metodo saveFigure() para guardar archivos de imagen de la clase Figure(). Se modifica los xaxis se muestran en formato datetime, falta hacer ajustes en los ticks de acuerdo al intervalo [xmin, xmax]
r209 def setXAxisAsTime(self):
pass
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def pline(self, x, y,
xmin=None, xmax=None,
ymin=None, ymax=None,
xlabel='', ylabel='',
title='',
**kwargs):
"""
Input:
x :
y :
xmin :
xmax :
ymin :
ymax :
xlabel :
ylabel :
title :
**kwargs : Los parametros aceptados son
ticksize
Miguel Valdez
-Se agrego el perfil de potencia al grafico de espectros
r204 ytick_visible
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 """
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 if self.__firsttime:
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
if xmin == None: xmin = numpy.nanmin(x)
if xmax == None: xmax = numpy.nanmax(x)
if ymin == None: ymin = numpy.nanmin(y)
if ymax == None: ymax = numpy.nanmax(y)
self.plot = self.__driver.createPline(self.ax, x, y,
xmin, xmax,
ymin, ymax,
xlabel=xlabel,
ylabel=ylabel,
title=title,
**kwargs)
Daniel Valdez
Se agrega el metodo deflip a jroprocessing.py....
r239
self.idlineList.append(0)
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.__firsttime = False
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 return
self.__driver.pline(self.plot, x, y, xlabel=xlabel,
ylabel=ylabel,
title=title)
Daniel Valdez
Se agrega el metodo deflip a jroprocessing.py....
r239
def addpline(self, x, y, idline, **kwargs):
lines = self.ax.lines
if idline in self.idlineList:
self.__driver.set_linedata(self.ax, x, y, idline)
if idline not in(self.idlineList):
self.__driver.addpline(self.ax, x, y, **kwargs)
self.idlineList.append(idline)
return
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Daniel Valdez
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
r229 def pmultiline(self, x, y,
xmin=None, xmax=None,
ymin=None, ymax=None,
xlabel='', ylabel='',
title='',
**kwargs):
if self.__firsttime:
if xmin == None: xmin = numpy.nanmin(x)
if xmax == None: xmax = numpy.nanmax(x)
if ymin == None: ymin = numpy.nanmin(y)
if ymax == None: ymax = numpy.nanmax(y)
self.plot = self.__driver.createPmultiline(self.ax, x, y,
xmin, xmax,
ymin, ymax,
xlabel=xlabel,
ylabel=ylabel,
title=title,
**kwargs)
self.__firsttime = False
return
self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
ylabel=ylabel,
title=title)
Daniel Valdez
Adicion de la carpeta test donde se encuentra la aplicacion de prueba para los experimentos EWDrifts y Faraday...
r240
def pmultilineyaxis(self, x, y,
xmin=None, xmax=None,
ymin=None, ymax=None,
xlabel='', ylabel='',
title='',
**kwargs):
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
Daniel Valdez
Adicion de la carpeta test donde se encuentra la aplicacion de prueba para los experimentos EWDrifts y Faraday...
r240 if self.__firsttime:
if xmin == None: xmin = numpy.nanmin(x)
if xmax == None: xmax = numpy.nanmax(x)
if ymin == None: ymin = numpy.nanmin(y)
if ymax == None: ymax = numpy.nanmax(y)
self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
xmin, xmax,
ymin, ymax,
xlabel=xlabel,
ylabel=ylabel,
title=title,
**kwargs)
self.__firsttime = False
return
self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
ylabel=ylabel,
title=title)
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 def pcolor(self, x, y, z,
xmin=None, xmax=None,
ymin=None, ymax=None,
zmin=None, zmax=None,
xlabel='', ylabel='',
Daniel Valdez
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
r229 title='', rti = False, colormap='jet',
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 **kwargs):
"""
Input:
x :
y :
x :
xmin :
xmax :
ymin :
ymax :
zmin :
zmax :
xlabel :
ylabel :
title :
**kwargs : Los parametros aceptados son
ticksize=9,
cblabel=''
Daniel Valdez
Adicion de la clase RTIPlot
r207 rti = True or False
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 """
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 if self.__firsttime:
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201
if xmin == None: xmin = numpy.nanmin(x)
if xmax == None: xmax = numpy.nanmax(x)
if ymin == None: ymin = numpy.nanmin(y)
if ymax == None: ymax = numpy.nanmax(y)
if zmin == None: zmin = numpy.nanmin(z)
if zmax == None: zmax = numpy.nanmax(z)
Daniel Valdez
Adicion de la clase RTIPlot
r207
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
xmin, xmax,
ymin, ymax,
zmin, zmax,
xlabel=xlabel,
ylabel=ylabel,
title=title,
Daniel Valdez
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
r229 colormap=colormap,
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 **kwargs)
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210
if self.xmin == None: self.xmin = xmin
if self.xmax == None: self.xmax = xmax
if self.ymin == None: self.ymin = ymin
if self.ymax == None: self.ymax = ymax
if self.zmin == None: self.zmin = zmin
if self.zmax == None: self.zmax = zmax
self.__firsttime = False
Miguel Valdez
Testeado con datos de Imagenes (Espectros)...
r201 return
Daniel Valdez
Adicion de la clase RTIPlot
r207
if rti:
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
xlabel=xlabel,
ylabel=ylabel,
Daniel Valdez
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
r229 title=title,
colormap=colormap)
Daniel Valdez
Adicion de la clase RTIPlot
r207 return
Miguel Valdez
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
r210 self.__driver.pcolor(self.plot, z,
xlabel=xlabel,
ylabel=ylabel,
title=title)
Daniel Valdez
Adicion de la clase RTIPlot
r207