jroplot.py
585 lines
| 19.1 KiB
| text/x-python
|
PythonLexer
|
r190 | import numpy | |
|
r210 | import time, datetime | |
|
r190 | from graphics.figure import * | |
|
r215 | class CrossSpectraPlot(Figure): | |
__isConfig = None | |||
__nsubplots = None | |||
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
PREFIX = 'spc' | |||
def __init__(self): | |||
self.__isConfig = False | |||
self.__nsubplots = 4 | |||
self.WIDTH = 300 | |||
self.HEIGHT = 400 | |||
self.WIDTHPROF = 0 | |||
self.HEIGHTPROF = 0 | |||
def getSubplots(self): | |||
ncol = 4 | |||
nrow = self.nplots | |||
return nrow, ncol | |||
def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
self.__showprofile = showprofile | |||
self.nplots = nplots | |||
ncolspan = 1 | |||
colspan = 1 | |||
self.createFigure(idfigure = idfigure, | |||
wintitle = wintitle, | |||
widthplot = self.WIDTH + self.WIDTHPROF, | |||
heightplot = self.HEIGHT + self.HEIGHTPROF) | |||
nrow, ncol = self.getSubplots() | |||
counter = 0 | |||
for y in range(nrow): | |||
for x in range(ncol): | |||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
counter += 1 | |||
def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |||
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |||
save=False, figpath='./', figfile=None): | |||
""" | |||
Input: | |||
dataOut : | |||
idfigure : | |||
wintitle : | |||
channelList : | |||
showProfile : | |||
xmin : None, | |||
xmax : None, | |||
ymin : None, | |||
ymax : None, | |||
zmin : None, | |||
zmax : None | |||
""" | |||
if pairsList == None: | |||
pairsIndexList = dataOut.pairsIndexList | |||
else: | |||
pairsIndexList = [] | |||
for pair in pairsList: | |||
if pair not in dataOut.pairsList: | |||
raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |||
pairsIndexList.append(dataOut.pairsList.index(pair)) | |||
x = dataOut.getVelRange(1) | |||
y = dataOut.getHeiRange() | |||
z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) | |||
avg = numpy.average(numpy.abs(z), axis=1) | |||
noise = dataOut.getNoise() | |||
if not self.__isConfig: | |||
nplots = len(pairsIndexList) | |||
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(avg)*0.9 | |||
if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |||
self.__isConfig = True | |||
thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |||
title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
xlabel = "Velocity (m/s)" | |||
ylabel = "Range (Km)" | |||
self.setWinTitle(title) | |||
for i in range(self.nplots): | |||
pair = dataOut.pairsList[pairsIndexList[i]] | |||
title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) | |||
z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |||
axes0 = self.axesList[i*self.__nsubplots] | |||
axes0.pcolor(x, y, z, | |||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='') | |||
title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) | |||
z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |||
axes0 = self.axesList[i*self.__nsubplots+1] | |||
axes0.pcolor(x, y, z, | |||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='') | |||
coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |||
coherence = numpy.abs(coherenceComplex) | |||
phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |||
title = "Coherence %d%d" %(pair[0], pair[1]) | |||
axes0 = self.axesList[i*self.__nsubplots+2] | |||
axes0.pcolor(x, y, coherence, | |||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-1, zmax=1, | |||
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='') | |||
title = "Phase %d%d" %(pair[0], pair[1]) | |||
axes0 = self.axesList[i*self.__nsubplots+3] | |||
axes0.pcolor(x, y, phase, | |||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |||
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='') | |||
self.draw() | |||
if save: | |||
date = thisDatetime.strftime("%Y%m%d") | |||
if figfile == None: | |||
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r207 | class RTIPlot(Figure): | |
__isConfig = None | |||
__nsubplots = None | |||
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
|
r212 | PREFIX = 'rti' | |
|
r207 | ||
def __init__(self): | |||
|
r210 | self.__timerange = 24*60*60 | |
|
r207 | self.__isConfig = False | |
self.__nsubplots = 1 | |||
self.WIDTH = 800 | |||
|
r212 | self.HEIGHT = 200 | |
|
r207 | self.WIDTHPROF = 120 | |
self.HEIGHTPROF = 0 | |||
def getSubplots(self): | |||
ncol = 1 | |||
nrow = self.nplots | |||
return nrow, ncol | |||
def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
self.__showprofile = showprofile | |||
self.nplots = nplots | |||
ncolspan = 1 | |||
colspan = 1 | |||
if showprofile: | |||
ncolspan = 7 | |||
colspan = 6 | |||
self.__nsubplots = 2 | |||
|
r210 | self.createFigure(idfigure = idfigure, | |
wintitle = wintitle, | |||
widthplot = self.WIDTH + self.WIDTHPROF, | |||
heightplot = self.HEIGHT + self.HEIGHTPROF) | |||
|
r207 | ||
nrow, ncol = self.getSubplots() | |||
counter = 0 | |||
for y in range(nrow): | |||
for x in range(ncol): | |||
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+colspan, 1, 1) | |||
counter += 1 | |||
|
r210 | def __getTimeLim(self, x, xmin, xmax): | |
thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |||
thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |||
#################################################### | |||
#If the x is out of xrange | |||
if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |||
xmin = None | |||
xmax = None | |||
if xmin == None: | |||
td = thisdatetime - thisdate | |||
xmin = td.seconds/(60*60.) | |||
if xmax == None: | |||
xmax = xmin + self.__timerange/(60*60.) | |||
mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |||
tmin = time.mktime(mindt.timetuple()) | |||
maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |||
tmax = time.mktime(maxdt.timetuple()) | |||
self.__timerange = tmax - tmin | |||
return tmin, tmax | |||
|
r207 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
|
r210 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
timerange=None, | |||
|
r212 | save=False, figpath='./', figfile=None): | |
|
r207 | ||
""" | |||
Input: | |||
dataOut : | |||
idfigure : | |||
wintitle : | |||
channelList : | |||
showProfile : | |||
xmin : None, | |||
xmax : None, | |||
ymin : None, | |||
ymax : None, | |||
zmin : None, | |||
zmax : None | |||
""" | |||
if channelList == None: | |||
channelIndexList = dataOut.channelIndexList | |||
else: | |||
channelIndexList = [] | |||
for channel in channelList: | |||
if channel not in dataOut.channelList: | |||
raise ValueError, "Channel %d is not in dataOut.channelList" | |||
|
r215 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
r207 | ||
|
r210 | if timerange != None: | |
self.__timerange = timerange | |||
tmin = None | |||
tmax = None | |||
|
r207 | x = dataOut.getDatatime() | |
y = dataOut.getHeiRange() | |||
z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |||
avg = numpy.average(z, axis=1) | |||
noise = dataOut.getNoise() | |||
|
r210 | ||
|
r207 | if not self.__isConfig: | |
nplots = len(channelIndexList) | |||
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle, | |||
showprofile=showprofile) | |||
|
r210 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) | |
|
r207 | if ymin == None: ymin = numpy.nanmin(y) | |
if ymax == None: ymax = numpy.nanmax(y) | |||
if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |||
if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |||
self.__isConfig = True | |||
thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |||
|
r210 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
r207 | xlabel = "Velocity (m/s)" | |
ylabel = "Range (Km)" | |||
self.setWinTitle(title) | |||
for i in range(self.nplots): | |||
|
r210 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
r207 | axes = self.axesList[i*self.__nsubplots] | |
z = avg[i].reshape((1,-1)) | |||
axes.pcolor(x, y, z, | |||
|
r210 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
r209 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
r211 | ticksize=9, cblabel='', cbsize="1%") | |
|
r207 | ||
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') | |||
self.draw() | |||
|
r209 | if save: | |
|
r212 | date = thisDatetime.strftime("%Y%m%d") | |
if figfile == None: | |||
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r210 | ||
if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |||
self.__isConfig = False | |||
|
r209 | ||
|
r192 | class SpectraPlot(Figure): | |
|
r199 | ||
|
r192 | __isConfig = None | |
|
r204 | __nsubplots = None | |
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
|
r212 | PREFIX = 'spc' | |
|
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 | |||
|
r210 | ||
self.createFigure(idfigure = idfigure, | |||
wintitle = wintitle, | |||
widthplot = self.WIDTH + self.WIDTHPROF, | |||
heightplot = self.HEIGHT + self.HEIGHTPROF) | |||
|
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: | |||
|
r207 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
|
r204 | ||
|
r192 | counter += 1 | |
|
r204 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
|
r212 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
save=False, figpath='./', figfile=None): | |||
|
r201 | ||
""" | |||
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" | |||
|
r214 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
r192 | ||
|
r201 | x = dataOut.getVelRange(1) | |
|
r207 | y = dataOut.getHeiRange() | |
|
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() | |
|
r209 | ||
if save: | |||
|
r212 | date = thisDatetime.strftime("%Y%m%d") | |
if figfile == None: | |||
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r192 | ||
|
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, | |
|
r209 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): | |
|
r201 | ||
""" | |||
Input: | |||
dataOut : | |||
idfigure : | |||
wintitle : | |||
channelList : | |||
xmin : None, | |||
xmax : None, | |||
ymin : None, | |||
ymax : None, | |||
""" | |||
|
r190 | ||
if channelList == None: | |||
|
r214 | channelIndexList = dataOut.channelIndexList | |
else: | |||
channelIndexList = [] | |||
for channel in channelList: | |||
if channel not in dataOut.channelList: | |||
raise ValueError, "Channel %d is not in dataOut.channelList" | |||
|
r215 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
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() | |||
|
r209 | if save: | |
self.saveFigure(filename) | |||
|
r190 |