jroplot.py
226 lines
| 6.8 KiB
| text/x-python
|
PythonLexer
|
r190 | import numpy | |
import datetime | |||
from graphics.figure import * | |||
|
r192 | class SpectraPlot(Figure): | |
|
r199 | ||
|
r192 | __isConfig = None | |
|
r204 | __nsubplots = None | |
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
|
r192 | ||
def __init__(self): | |||
|
r199 | ||
|
r192 | self.__isConfig = False | |
|
r204 | self.__nsubplots = 1 | |
|
r201 | self.WIDTH = 300 | |
self.HEIGHT = 400 | |||
|
r204 | self.WIDTHPROF = 120 | |
self.HEIGHTPROF = 0 | |||
|
r201 | ||
|
r192 | def getSubplots(self): | |
|
r199 | ||
|
r192 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
nrow = int(self.nplots*1./ncol + 0.9) | |||
|
r201 | ||
|
r204 | return nrow, ncol | |
def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
self.__showprofile = showprofile | |||
self.nplots = nplots | |||
|
r199 | ||
|
r204 | ncolspan = 1 | |
|
r192 | colspan = 1 | |
|
r204 | if showprofile: | |
ncolspan = 3 | |||
colspan = 2 | |||
self.__nsubplots = 2 | |||
self.WIDTH += self.WIDTHPROF | |||
self.HEIGHT += self.HEIGHTPROF | |||
self.createFigure(idfigure, wintitle) | |||
|
r192 | ||
|
r204 | nrow, ncol = self.getSubplots() | |
|
r199 | ||
|
r192 | counter = 0 | |
for y in range(nrow): | |||
for x in range(ncol): | |||
|
r204 | ||
if counter >= self.nplots: | |||
break | |||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
if showprofile: | |||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+2, 1, 1) | |||
|
r192 | counter += 1 | |
|
r204 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
|
r201 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
""" | |||
Input: | |||
dataOut : | |||
idfigure : | |||
wintitle : | |||
channelList : | |||
showProfile : | |||
xmin : None, | |||
xmax : None, | |||
ymin : None, | |||
ymax : None, | |||
zmin : None, | |||
zmax : None | |||
""" | |||
|
r192 | ||
if channelList == None: | |||
|
r203 | channelIndexList = dataOut.channelIndexList | |
else: | |||
channelIndexList = [] | |||
for channel in channelList: | |||
if channel not in dataOut.channelList: | |||
raise ValueError, "Channel %d is not in dataOut.channelList" | |||
channelIndexList.append(channel) | |||
|
r192 | ||
|
r201 | x = dataOut.getVelRange(1) | |
|
r192 | y = dataOut.heightList | |
|
r203 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
|
r205 | avg = numpy.average(z, axis=1) | |
|
r192 | ||
|
r199 | noise = dataOut.getNoise() | |
|
r192 | if not self.__isConfig: | |
|
r203 | nplots = len(channelIndexList) | |
|
r199 | ||
|
r201 | self.setup(idfigure=idfigure, | |
nplots=nplots, | |||
wintitle=wintitle, | |||
showprofile=showprofile) | |||
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) | |||
|
r205 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |||
|
r199 | ||
|
r192 | self.__isConfig = True | |
|
r201 | ||
|
r196 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
|
r201 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
xlabel = "Velocity (m/s)" | |||
ylabel = "Range (Km)" | |||
|
r196 | ||
self.setWinTitle(title) | |||
|
r204 | ||
|
r201 | for i in range(self.nplots): | |
|
r203 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
|
r204 | axes = self.axesList[i*self.__nsubplots] | |
axes.pcolor(x, y, z[i,:,:], | |||
|
r201 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
xlabel=xlabel, ylabel=ylabel, title=title, | |||
|
r204 | ticksize=9, cblabel='') | |
if self.__showprofile: | |||
axes = self.axesList[i*self.__nsubplots +1] | |||
axes.pline(avg[i], y, | |||
xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |||
xlabel='dB', ylabel='', title='', | |||
ytick_visible=False, | |||
grid='x') | |||
|
r199 | ||
|
r192 | self.draw() | |
|
r190 | class Scope(Figure): | |
|
r201 | ||
|
r190 | __isConfig = None | |
def __init__(self): | |||
|
r201 | ||
|
r190 | self.__isConfig = False | |
|
r201 | self.WIDTH = 600 | |
self.HEIGHT = 200 | |||
|
r190 | ||
def getSubplots(self): | |||
|
r201 | ||
|
r190 | nrow = self.nplots | |
ncol = 3 | |||
return nrow, ncol | |||
|
r201 | def setup(self, idfigure, nplots, wintitle): | |
|
r204 | self.createFigure(idfigure, wintitle) | |
|
r190 | ||
nrow,ncol = self.getSubplots() | |||
colspan = 3 | |||
rowspan = 1 | |||
for i in range(nplots): | |||
|
r201 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
|
r204 | ||
self.nplots = nplots | |||
|
r190 | ||
|
r201 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
xmin=None, xmax=None, ymin=None, ymax=None): | |||
""" | |||
Input: | |||
dataOut : | |||
idfigure : | |||
wintitle : | |||
channelList : | |||
xmin : None, | |||
xmax : None, | |||
ymin : None, | |||
ymax : None, | |||
""" | |||
|
r190 | ||
if channelList == None: | |||
|
r201 | channelList = dataOut.channelList | |
|
r190 | ||
|
r201 | x = dataOut.heightList | |
|
r190 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
y = y.real | |||
|
r201 | noise = dataOut.getNoise() | |
|
r190 | ||
if not self.__isConfig: | |||
|
r201 | nplots = len(channelList) | |
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle) | |||
|
r190 | ||
|
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) | |||
|
r190 | ||
self.__isConfig = True | |||
thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |||
|
r201 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
xlabel = "Range (Km)" | |||
|
r190 | ylabel = "Intensity" | |
|
r201 | self.setWinTitle(title) | |
|
r190 | ||
for i in range(len(self.axesList)): | |||
|
r199 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
|
r190 | axes = self.axesList[i] | |
|
r201 | ychannel = y[i,:] | |
axes.pline(x, ychannel, | |||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |||
xlabel=xlabel, ylabel=ylabel, title=title) | |||
|
r190 | ||
self.draw() | |||