SpectraPlot.py
170 lines
| 5.2 KiB
| text/x-python
|
PythonLexer
|
r16 | ''' | |
Created on Feb 7, 2012 | |||
@author $Author$ | |||
@version $Id$ | |||
''' | |||
|
r25 | import os, sys | |
|
r10 | import numpy | |
|
r27 | import datetime | |
|
r10 | import plplot | |
|
r25 | path = os.path.split(os.getcwd())[0] | |
sys.path.append(path) | |||
|
r10 | ||
|
r25 | from Graphics.BaseGraph import * | |
from Model.Spectra import Spectra | |||
|
r11 | ||
|
r25 | class Spectrum(): | |
|
r10 | ||
|
r43 | def __init__(self, Spectra, index=0): | |
|
r10 | ||
""" | |||
|
r25 | Inputs: | |
|
r10 | ||
|
r25 | type: "power" ->> Potencia | |
"iq" ->> Real + Imaginario | |||
""" | |||
|
r10 | ||
|
r25 | self.__isPlotConfig = False | |
|
r10 | ||
|
r25 | self.__isPlotIni = False | |
|
r10 | ||
|
r25 | self.__xrange = None | |
|
r10 | ||
|
r25 | self.__yrange = None | |
|
r10 | ||
|
r25 | self.nGraphs = 0 | |
|
r10 | ||
|
r43 | self.indexPlot = index | |
|
r25 | self.graphObjList = [] | |
self.m_Spectra = Spectra | |||
|
r10 | ||
|
r25 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
graphObj = ColorPlot() | |||
graphObj.setup(subpage, | |||
title, | |||
xlabel, | |||
ylabel, | |||
showColorbar=showColorbar, | |||
showPowerProfile=showPowerProfile, | |||
XAxisAsTime=XAxisAsTime) | |||
self.graphObjList.append(graphObj) | |||
def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |||
|
r10 | ||
|
r25 | nChan = int(self.m_Spectra.m_SystemHeader.numChannels) | |
|
r26 | channels = range(nChan) | |
|
r10 | ||
|
r26 | myXlabel = "Radial Velocity (m/s)" | |
myYlabel = "Range (km)" | |||
|
r10 | ||
|
r26 | for i in channels: | |
|
r25 | if titleList != None: | |
myTitle = titleList[i] | |||
myXlabel = xlabelList[i] | |||
myYlabel = ylabelList[i] | |||
|
r26 | ||
if self.m_Spectra.noise != None: | |||
noise = '%4.2fdB' %(self.m_Spectra.noise[i]) | |||
else: | |||
noise = '--' | |||
myTitle = "Channel: %d - Noise: %s" %(i, noise) | |||
|
r25 | ||
self.__addGraph(i+1, | |||
title=myTitle, | |||
xlabel=myXlabel, | |||
ylabel=myYlabel, | |||
showColorbar=showColorbar, | |||
showPowerProfile=showPowerProfile, | |||
XAxisAsTime=XAxisAsTime) | |||
self.nGraphs = nChan | |||
self.__isPlotConfig = True | |||
|
r10 | ||
|
r25 | def iniPlot(self): | |
|
r10 | ||
|
r25 | nx = int(numpy.sqrt(self.nGraphs)+1) | |
#ny = int(self.nGraphs/nx) | |||
|
r10 | ||
|
r43 | plplot.plsstrm(self.indexPlot) | |
|
r26 | plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) | |
|
r44 | plplot.plsdev("xwin") | |
|
r25 | plplot.plscolbg(255,255,255) | |
plplot.plscol0(1,0,0,0) | |||
plplot.plinit() | |||
plplot.plspause(False) | |||
plplot.pladv(0) | |||
plplot.plssub(nx, nx) | |||
|
r10 | ||
|
r27 | self.__nx = nx | |
self.__ny = nx | |||
self.__isPlotIni = True | |||
|
r10 | ||
|
r25 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
if not(self.__isPlotConfig): | |||
self.setup(titleList, | |||
xlabelList, | |||
ylabelList, | |||
showColorbar, | |||
showPowerProfile, | |||
XAxisAsTime) | |||
if not(self.__isPlotIni): | |||
self.iniPlot() | |||
|
r26 | data = 10.*numpy.log10(self.m_Spectra.data_spc) | |
|
r25 | ||
nX, nY, nChan = numpy.shape(data) | |||
x = numpy.arange(nX) | |||
y = self.m_Spectra.heights | |||
|
r27 | thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc) | |
txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
r25 | if xmin == None: xmin = x[0] | |
if xmax == None: xmax = x[-1] | |||
if ymin == None: ymin = y[0] | |||
if ymax == None: ymax = y[-1] | |||
if zmin == None: zmin = numpy.nanmin(abs(data)) | |||
if zmax == None: zmax = numpy.nanmax(abs(data)) | |||
plplot.plbop() | |||
|
r27 | ||
plplot.plssub(self.__nx, self.__ny) | |||
|
r25 | for i in range(self.nGraphs): | |
self.graphObjList[i].iniSubpage() | |||
|
r26 | self.graphObjList[i].plotData(data[i,:,:], | |
|
r25 | x, | |
y, | |||
xmin=xmin, | |||
xmax=xmax, | |||
ymin=ymin, | |||
ymax=ymax, | |||
zmin=zmin, | |||
zmax=zmax) | |||
|
r27 | plplot.plssub(1,0) | |
plplot.pladv(0) | |||
plplot.plvpor(0., 1., 0., 1.) | |||
plplot.plmtex("t",-1., 0.5, 0.5, txtDate) | |||
|
r25 | plplot.plflush() | |
plplot.pleop() | |||
|
r10 | ||
|
r25 | def end(self): | |
plplot.plend() | |||
|
r10 | ||
if __name__ == '__main__': | |||
|
r25 | pass |