VoltagePlot.py
199 lines
| 6.9 KiB
| text/x-python
|
PythonLexer
|
r99 | ''' | ||
Created on Feb 7, 2012 | ||||
@author $Author$ | ||||
@version $Id$ | ||||
''' | ||||
import numpy | ||||
|
r108 | import os | ||
import sys | ||||
|
r99 | |||
path = os.path.split(os.getcwd())[0] | ||||
sys.path.append(path) | ||||
from Graphics.BaseGraph import * | ||||
from Model.Voltage import Voltage | ||||
class Osciloscope: | ||||
|
r108 | linearplotObj = None | ||
|
r99 | |||
|
r108 | def __init__(self, Voltage, index): | ||
self.__isPlotConfig = False | ||||
self.__isPlotIni = False | ||||
self.__xrange = None | ||||
self.__yrange = None | ||||
self.indexPlot = index | ||||
self.voltageObj = Voltage | ||||
|
r99 | |||
|
r108 | def setup(self,indexPlot,nsubplot,winTitle=''): | ||
self.linearplotObj = LinearPlot(indexPlot,nsubplot,winTitle) | ||||
|
r99 | |||
|
r108 | def initPlot(self,xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList): | ||
nsubplot = self.voltageObj.nChannels | ||||
|
r99 | |||
|
r108 | for index in range(nsubplot): | ||
title = titleList[index] | ||||
xlabel = xlabelList[index] | ||||
ylabel = ylabelList[index] | ||||
subplot = index | ||||
self.linearplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,title,xlabel,ylabel) | ||||
|
r99 | |||
|
r108 | def plotData(self, | ||
xmin=None, | ||||
xmax=None, | ||||
ymin=None, | ||||
ymax=None, | ||||
titleList=None, | ||||
xlabelList=None, | ||||
ylabelList=None, | ||||
winTitle='', | ||||
type="power"): | ||||
|
r99 | |||
|
r108 | databuffer = self.voltageObj.data | ||
|
r99 | |||
|
r108 | height = self.voltageObj.heightList | ||
nsubplot = self.voltageObj.nChannels | ||||
indexPlot = self.indexPlot | ||||
|
r99 | |||
|
r108 | if not(self.__isPlotConfig): | ||
self.setup(indexPlot,nsubplot,winTitle) | ||||
self.__isPlotConfig = True | ||||
|
r99 | |||
|
r108 | if not(self.__isPlotIni): | ||
if titleList == None: | ||||
titleList = [] | ||||
thisDatetime = datetime.datetime.fromtimestamp(self.voltageObj.m_BasicHeader.utc) | ||||
txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||||
for i in range(nsubplot): | ||||
titleList.append("Channel: %d %s" %(i, txtdate)) | ||||
if xlabelList == None: | ||||
xlabelList = [] | ||||
for i in range(nsubplot): | ||||
xlabelList.append("") | ||||
if ylabelList == None: | ||||
ylabelList = [] | ||||
for i in range(nsubplot): | ||||
ylabelList.append("") | ||||
if xmin == None: xmin = height[0] | ||||
if xmax == None: xmax = height[-1] | ||||
if ymin == None: ymin = numpy.nanmin(abs(databuffer)) | ||||
if ymax == None: ymax = numpy.nanmax(abs(databuffer)) | ||||
self.initPlot(xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList) | ||||
self.__isPlotIni = True | ||||
|
r99 | |||
|
r108 | self.linearplotObj.setFigure(indexPlot) | ||
|
r99 | |||
|
r108 | for index in range(nsubplot): | ||
data = databuffer[index,:] | ||||
self.linearplotObj.plot(subplot=index+1,x=height,y=data,type=type) | ||||
|
r99 | |||
|
r108 | self.linearplotObj.refresh() | ||
|
r99 | |||
|
r108 | class RTI: | ||
colorplotObj = None | ||||
|
r99 | |||
|
r108 | def __init__(self, Voltage, index): | ||
self.__isPlotConfig = False | ||||
self.__isPlotIni = False | ||||
self.__xrange = None | ||||
self.__yrange = None | ||||
self.indexPlot = index | ||||
self.voltageObj = Voltage | ||||
def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): | ||||
self.colorplotObj = RtiPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) | ||||
def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints): | ||||
nsubplot = self.voltageObj.nChannels | ||||
timedata = self.voltageObj.m_BasicHeader.utc | ||||
for index in range(nsubplot): | ||||
title = titleList[index] | ||||
xlabel = xlabelList[index] | ||||
ylabel = ylabelList[index] | ||||
subplot = index | ||||
self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone,npoints) | ||||
def plotData(self, | ||||
xmin=None, | ||||
xmax=None, | ||||
ymin=None, | ||||
ymax=None, | ||||
zmin=None, | ||||
zmax=None, | ||||
titleList=None, | ||||
xlabelList=None, | ||||
ylabelList=None, | ||||
winTitle='', | ||||
timezone='lt', | ||||
npoints=1000.0, | ||||
colormap="br_green", | ||||
showColorbar=True, | ||||
showPowerProfile=True, | ||||
|
r113 | XAxisAsTime=True, | ||
save = False): | ||||
|
r108 | |||
databuffer = self.voltageObj.data | ||||
timedata = self.voltageObj.m_BasicHeader.utc | ||||
height = self.voltageObj.heightList | ||||
nsubplot = self.voltageObj.nChannels | ||||
indexPlot = self.indexPlot | ||||
|
r99 | if not(self.__isPlotConfig): | ||
|
r108 | self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) | ||
self.__isPlotConfig = True | ||||
|
r99 | if not(self.__isPlotIni): | ||
|
r108 | if titleList == None: | ||
titleList = [] | ||||
thisDatetime = datetime.datetime.fromtimestamp(timedata) | ||||
txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||||
for i in range(nsubplot): | ||||
titleList.append("Channel: %d %s" %(i, txtdate)) | ||||
if xlabelList == None: | ||||
xlabelList = [] | ||||
for i in range(nsubplot): | ||||
xlabelList.append("") | ||||
if ylabelList == None: | ||||
ylabelList = [] | ||||
for i in range(nsubplot): | ||||
ylabelList.append("") | ||||
if xmin == None: xmin = 0 | ||||
if xmax == None: xmax = 23 | ||||
if ymin == None: ymin = min(self.voltageObj.heightList) | ||||
if ymax == None: ymax = max(self.voltageObj.heightList) | ||||
if zmin == None: zmin = 0 | ||||
if zmax == None: zmax = 50 | ||||
self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints) | ||||
self.__isPlotIni = True | ||||
|
r99 | |||
|
r108 | |||
self.colorplotObj.setFigure(indexPlot) | ||||
|
r99 | |||
|
r108 | if timezone == 'lt': | ||
timedata = timedata - time.timezone | ||||
|
r99 | |||
|
r108 | for index in range(nsubplot): | ||
data = databuffer[index,:] | ||||
self.colorplotObj.plot(subplot=index+1,x=timedata,y=height,z=data) | ||||
|
r99 | |||
|
r108 | self.colorplotObj.refresh() | ||
|
r113 | |||
if save: | ||||
self.colorplotObj.setFigure(indexPlot) | ||||
path = "/Users/jro/Pictures" | ||||
now = datetime.datetime.now().timetuple() | ||||
file = "rti_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5]) | ||||
filename = os.path.join(path,file) | ||||
self.colorplotObj.savePlot(indexPlot, filename) | ||||