jroplot.py
208 lines
| 6.2 KiB
| text/x-python
|
PythonLexer
|
r190 | import numpy | |
import datetime | |||
from graphics.figure import * | |||
|
r192 | class SpectraPlot(Figure): | |
|
r199 | ||
|
r192 | __isConfig = None | |
def __init__(self): | |||
|
r199 | ||
|
r192 | self.__isConfig = False | |
|
r201 | self.WIDTH = 300 | |
self.HEIGHT = 400 | |||
|
r192 | def getSubplots(self): | |
|
r199 | ||
|
r192 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
nrow = int(self.nplots*1./ncol + 0.9) | |||
return nrow, ncol | |||
|
r201 | ||
|
r192 | def setAxesWithOutProfiles(self, nrow, ncol): | |
|
r199 | ||
|
r192 | colspan = 1 | |
rowspan = 1 | |||
counter = 0 | |||
for y in range(nrow): | |||
for x in range(ncol): | |||
if counter < self.nplots: | |||
|
r201 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
r192 | counter += 1 | |
def setAxesWithProfiles(self, nrow, ncol): | |||
|
r199 | ||
|
r192 | colspan = 1 | |
rowspan = 1 | |||
factor = 2 | |||
ncol = ncol*factor | |||
counter = 0 | |||
for y in range(nrow): | |||
for x in range(ncol): | |||
if counter < self.nplots*factor: | |||
# plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) | |||
|
r201 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
r192 | counter += 1 | |
|
r201 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
r199 | ||
|
r201 | self.init(idfigure, nplots, wintitle) | |
|
r192 | ||
|
r201 | nrow, ncol = self.getSubplots() | |
|
r192 | ||
|
r201 | if showprofile: | |
|
r192 | self.setAxesWithProfiles(nrow, ncol) | |
else: | |||
self.setAxesWithOutProfiles(nrow, ncol) | |||
|
r201 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile=False, | |
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: | |||
channelList = dataOut.channelList | |||
|
r201 | x = dataOut.getVelRange(1) | |
|
r192 | y = dataOut.heightList | |
|
r201 | z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) | |
|
r192 | ||
|
r199 | noise = dataOut.getNoise() | |
|
r192 | if not self.__isConfig: | |
|
r201 | nplots = len(channelList) | |
|
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) | |||
if zmin == None: zmin = numpy.nanmin(z)*0.9 | |||
if zmax == None: zmax = numpy.nanmax(z)*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) | |||
|
r201 | for i in range(self.nplots): | |
|
r200 | title = "Channel %d: %4.2fdB" %(channelList[i], noise[i]) | |
|
r201 | zchannel = z[i,:,:] | |
|
r192 | axes = self.axesList[i] | |
|
r201 | axes.pcolor(x, y, zchannel, | |
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='dB') | |||
|
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): | |
self.init(idfigure, nplots, wintitle) | |||
|
r190 | ||
nrow,ncol = self.getSubplots() | |||
colspan = 3 | |||
rowspan = 1 | |||
for i in range(nplots): | |||
|
r201 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
|
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() | |||