SpectraPlot.py
170 lines
| 5.6 KiB
| text/x-python
|
PythonLexer
|
r16 | ''' | ||
Created on Feb 7, 2012 | ||||
@author $Author$ | ||||
@version $Id$ | ||||
''' | ||||
|
r10 | import numpy | ||
|
r108 | import os | ||
import sys | ||||
|
r10 | import plplot | ||
|
r108 | import datetime | ||
|
r10 | |||
|
r25 | path = os.path.split(os.getcwd())[0] | ||
sys.path.append(path) | ||||
|
r10 | |||
|
r25 | from Graphics.BaseGraph import * | ||
from Model.Spectra import Spectra | ||||
|
r11 | |||
|
r99 | class Spectrum: | ||
|
r108 | colorplotObj = None | ||
|
r99 | |||
|
r116 | def __init__(self, spectraObj, index): | ||
|
r25 | self.__isPlotConfig = False | ||
self.__isPlotIni = False | ||||
self.__xrange = None | ||||
self.__yrange = None | ||||
|
r112 | self.nsubplots = 0 | ||
|
r43 | self.indexPlot = index | ||
|
r116 | self.spectraObj = spectraObj | ||
|
r10 | |||
|
r112 | def setup(self,indexPlot, nsubplots, winTitle='', colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | ||
""" | ||||
Crea un objeto colorPlot con las opciones seleccinoadas | ||||
""" | ||||
self.nsubplots = nsubplots | ||||
self.colorplotObj = PcolorPlot(indexPlot, | ||||
nsubplots, | ||||
winTitle, | ||||
colormap, | ||||
showColorbar, | ||||
showPowerProfile, | ||||
XAxisAsTime) | ||||
def createObjects(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList): | ||||
""" | ||||
Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos | ||||
""" | ||||
|
r25 | |||
|
r112 | for index in range(self.nsubplots): | ||
|
r108 | title = titleList[index] | ||
xlabel = xlabelList[index] | ||||
ylabel = ylabelList[index] | ||||
subplot = index | ||||
|
r112 | self.colorplotObj.createObjects(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) | ||
def initPlot(self): | ||||
""" | ||||
Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos | ||||
""" | ||||
for index in range(self.nsubplots): | ||||
subplot = index | ||||
self.colorplotObj.iniPlot(subplot+1) | ||||
|
r10 | |||
|
r108 | |||
def plotData(self, | ||||
xmin=None, | ||||
xmax=None, | ||||
ymin=None, | ||||
ymax=None, | ||||
zmin=None, | ||||
zmax=None, | ||||
titleList=None, | ||||
xlabelList=None, | ||||
ylabelList=None, | ||||
winTitle='', | ||||
colormap = "br_green", | ||||
showColorbar = True, | ||||
showPowerProfile = True, | ||||
|
r110 | XAxisAsTime = False, | ||
|
r112 | save = False, | ||
channelList=[]): | ||||
if channelList == []: | ||||
channelList = numpy.arange(self.spectraObj.nChannels) | ||||
|
r108 | |||
|
r112 | nsubplots = len(channelList) | ||
nX = self.spectraObj.nFFTPoints | ||||
nY = self.spectraObj.nHeights | ||||
|
r10 | |||
|
r112 | if self.spectraObj.noise == None: | ||
noise = numpy.ones(nsubplots) | ||||
else: | ||||
noise = 10.*numpy.log10(self.spectraObj.noise[channelList]) | ||||
datadB = 10.*numpy.log10(self.spectraObj.data_spc[channelList,:,:]) | ||||
noisedB = 10.*numpy.log10(noise) | ||||
|
r10 | |||
|
r108 | x = numpy.arange(nX) | ||
y = self.spectraObj.heightList | ||||
|
r10 | |||
|
r108 | indexPlot = self.indexPlot | ||
|
r25 | |||
if not(self.__isPlotConfig): | ||||
|
r112 | self.setup(indexPlot, | ||
nsubplots, | ||||
winTitle, | ||||
colormap, | ||||
showColorbar, | ||||
showPowerProfile, | ||||
XAxisAsTime) | ||||
|
r108 | self.__isPlotConfig = True | ||
|
r112 | |||
|
r25 | if not(self.__isPlotIni): | ||
|
r108 | if titleList == None: | ||
titleList = [] | ||||
|
r112 | for i in range(nsubplots): | ||
|
r108 | titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i])) | ||
if xlabelList == None: | ||||
xlabelList = [] | ||||
|
r112 | for i in range(nsubplots): | ||
|
r108 | xlabelList.append("") | ||
if ylabelList == None: | ||||
ylabelList = [] | ||||
|
r112 | for i in range(nsubplots): | ||
|
r108 | ylabelList.append("Range (Km)") | ||
if xmin == None: xmin = x[0] | ||||
if xmax == None: xmax = x[-1] | ||||
if ymin == None: ymin = y[0] | ||||
if ymax == None: ymax = y[-1] | ||||
|
r116 | if zmin == None: zmin = datadB.min() | ||
if zmax == None: zmax = datadB.max() | ||||
|
r108 | |||
|
r112 | self.createObjects(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList) | ||
|
r108 | self.__isPlotIni = True | ||
|
r25 | |||
|
r99 | thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) | ||
|
r108 | pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
|
r27 | |||
|
r112 | self.colorplotObj.setFigure(indexPlot) | ||
self.colorplotObj.setNewPage(pltitle) | ||||
self.initPlot() | ||||
|
r25 | |||
|
r112 | for channel in range(nsubplots): | ||
data = datadB[channel,:,:] | ||||
subtitle = "Channel: %d - Noise: %.2f" %(channel, noise[channel]) | ||||
self.colorplotObj.plot(channel+1, x, y, data, subtitle) | ||||
|
r108 | |||
self.colorplotObj.refresh() | ||||
|
r110 | |||
if save: | ||||
self.colorplotObj.setFigure(indexPlot) | ||||
|
r112 | path = "/home/roj-idl71/tmp/" | ||
now = datetime.datetime.now().timetuple() | ||||
file = "spc_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) | ||||
self.colorplotObj.closePage() | ||||
|
r108 | |||
|
r10 | |||