jroplot.py
1005 lines
| 33.0 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 | |||
|
r234 | WIDTH = None | |
HEIGHT = None | |||
|
r215 | WIDTHPROF = None | |
HEIGHTPROF = None | |||
|
r228 | PREFIX = 'cspc' | |
|
r215 | ||
def __init__(self): | |||
self.__isConfig = False | |||
self.__nsubplots = 4 | |||
|
r234 | self.WIDTH = 250 | |
self.HEIGHT = 250 | |||
|
r215 | 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)) | |||
|
r227 | if pairsIndexList == []: | |
|
r224 | return | |
|
r228 | if len(pairsIndexList) > 4: | |
pairsIndexList = pairsIndexList[0:4] | |||
|
r245 | factor = dataOut.normFactor | |
|
r237 | x = dataOut.getVelRange(1) | |
|
r215 | y = dataOut.getHeiRange() | |
|
r245 | z = dataOut.data_spc[:,:,:]/factor | |
|
r232 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
|
r215 | avg = numpy.average(numpy.abs(z), axis=1) | |
|
r245 | noise = dataOut.getNoise()/factor | |
zdB = 10*numpy.log10(z) | |||
avgdB = 10*numpy.log10(avg) | |||
noisedB = 10*numpy.log10(noise) | |||
|
r215 | ||
|
r238 | thisDatetime = dataOut.datatime | |
title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
xlabel = "Velocity (m/s)" | |||
ylabel = "Range (Km)" | |||
|
r215 | 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) | |||
|
r245 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |||
|
r215 | ||
self.__isConfig = True | |||
self.setWinTitle(title) | |||
for i in range(self.nplots): | |||
pair = dataOut.pairsList[pairsIndexList[i]] | |||
|
r245 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) | |
zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |||
|
r215 | axes0 = self.axesList[i*self.__nsubplots] | |
|
r245 | axes0.pcolor(x, y, zdB, | |
|
r215 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
xlabel=xlabel, ylabel=ylabel, title=title, | |||
ticksize=9, cblabel='') | |||
|
r245 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) | |
zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |||
|
r215 | axes0 = self.axesList[i*self.__nsubplots+1] | |
|
r245 | axes0.pcolor(x, y, zdB, | |
|
r215 | 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, | |||
|
r227 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
|
r215 | 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, | |||
|
r237 | ticksize=9, cblabel='', colormap='RdBu_r') | |
|
r215 | ||
self.draw() | |||
if save: | |||
|
r238 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
r215 | if figfile == None: | |
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r207 | class RTIPlot(Figure): | |
__isConfig = None | |||
__nsubplots = None | |||
|
r254 | __missing = 1E30 | |
|
r207 | WIDTHPROF = None | |
HEIGHTPROF = None | |||
|
r212 | PREFIX = 'rti' | |
|
r207 | ||
def __init__(self): | |||
|
r237 | self.timerange = 2*60*60 | |
|
r207 | self.__isConfig = False | |
self.__nsubplots = 1 | |||
self.WIDTH = 800 | |||
|
r212 | self.HEIGHT = 200 | |
|
r207 | self.WIDTHPROF = 120 | |
self.HEIGHTPROF = 0 | |||
|
r254 | self.x_buffer = None | |
self.avgdB_buffer = None | |||
|
r207 | ||
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 | |||
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: | |
|
r231 | self.timerange = timerange | |
|
r210 | ||
tmin = None | |||
tmax = None | |||
|
r245 | factor = dataOut.normFactor | |
|
r224 | x = dataOut.getTimeRange() | |
|
r207 | y = dataOut.getHeiRange() | |
|
r245 | ||
z = dataOut.data_spc[channelIndexList,:,:]/factor | |||
z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |||
|
r207 | avg = numpy.average(z, axis=1) | |
|
r245 | avgdB = 10.*numpy.log10(avg) | |
|
r254 | ||
|
r232 | ||
|
r234 | thisDatetime = dataOut.datatime | |
title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |||
xlabel = "Velocity (m/s)" | |||
ylabel = "Range (Km)" | |||
|
r207 | if not self.__isConfig: | |
nplots = len(channelIndexList) | |||
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle, | |||
showprofile=showprofile) | |||
|
r230 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
r207 | if ymin == None: ymin = numpy.nanmin(y) | |
if ymax == None: ymax = numpy.nanmax(y) | |||
|
r245 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |||
|
r207 | ||
|
r232 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
r254 | self.x_buffer = numpy.array([]) | |
self.avgdB_buffer = numpy.array([]) | |||
|
r207 | self.__isConfig = True | |
|
r234 | ||
|
r207 | ||
self.setWinTitle(title) | |||
|
r254 | ||
if len(self.avgdB_buffer)==0: | |||
self.avgdB_buffer = avgdB | |||
newxdim = 1 | |||
newydim = -1 | |||
else: | |||
if x[0]>self.x_buffer[-1]: | |||
gap = avgdB.copy() | |||
gap[:] = self.__missing | |||
self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap)) | |||
|
r207 | ||
|
r254 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB)) | |
newxdim = -1 | |||
newydim = len(y) | |||
self.x_buffer = numpy.hstack((self.x_buffer, x)) | |||
self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing) | |||
|
r207 | 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] | |
|
r254 | zdB = self.avgdB_buffer[i].reshape(newxdim,newydim) | |
axes.pcolor(self.x_buffer, y, zdB, | |||
|
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] | |||
|
r245 | axes.pline(avgdB[i], y, | |
|
r207 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
xlabel='dB', ylabel='', title='', | |||
ytick_visible=False, | |||
grid='x') | |||
self.draw() | |||
|
r209 | if save: | |
|
r232 | ||
|
r212 | if figfile == None: | |
|
r232 | figfile = self.getFilename(name = self.name) | |
|
r212 | ||
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 | |
|
r234 | self.WIDTH = 230 | |
self.HEIGHT = 250 | |||
|
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)) | |
|
r245 | factor = dataOut.normFactor | |
|
r201 | x = dataOut.getVelRange(1) | |
|
r207 | y = dataOut.getHeiRange() | |
|
r232 | ||
|
r245 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |||
|
r205 | avg = numpy.average(z, axis=1) | |
|
r245 | noise = dataOut.getNoise()/factor | |
|
r192 | ||
|
r245 | zdB = 10*numpy.log10(z) | |
avgdB = 10*numpy.log10(avg) | |||
noisedB = 10*numpy.log10(noise) | |||
|
r199 | ||
|
r238 | thisDatetime = dataOut.datatime | |
title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
xlabel = "Velocity (m/s)" | |||
ylabel = "Range (Km)" | |||
|
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) | |||
|
r245 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |||
|
r199 | ||
|
r192 | self.__isConfig = True | |
|
r196 | ||
self.setWinTitle(title) | |||
|
r204 | ||
|
r201 | for i in range(self.nplots): | |
|
r245 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) | |
|
r204 | axes = self.axesList[i*self.__nsubplots] | |
|
r245 | axes.pcolor(x, y, zdB[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] | |||
|
r245 | axes.pline(avgdB[i], y, | |
|
r204 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
xlabel='dB', ylabel='', title='', | |||
ytick_visible=False, | |||
grid='x') | |||
|
r239 | ||
|
r245 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
|
r239 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
|
r199 | ||
|
r192 | self.draw() | |
|
r209 | ||
if save: | |||
|
r238 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
r212 | 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): | |
|
r232 | self.nplots = nplots | |
|
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 | ||
|
r232 | ||
|
r190 | ||
|
r201 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
|
r238 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
figpath='./', figfile=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 | |
|
r232 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
|
r190 | y = y.real | |
|
r238 | thisDatetime = dataOut.datatime | |
title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
xlabel = "Range (Km)" | |||
ylabel = "Intensity" | |||
|
r190 | if not self.__isConfig: | |
|
r232 | nplots = len(channelIndexList) | |
|
r201 | ||
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 | |||
|
r201 | self.setWinTitle(title) | |
|
r190 | ||
for i in range(len(self.axesList)): | |||
|
r232 | title = "Channel %d" %(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: | |
|
r238 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
if figfile == None: | |||
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r229 | ||
class ProfilePlot(Figure): | |||
__isConfig = None | |||
__nsubplots = None | |||
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
PREFIX = 'spcprofile' | |||
def __init__(self): | |||
self.__isConfig = False | |||
self.__nsubplots = 1 | |||
self.WIDTH = 300 | |||
self.HEIGHT = 500 | |||
def getSubplots(self): | |||
ncol = 1 | |||
nrow = 1 | |||
return nrow, ncol | |||
def setup(self, idfigure, nplots, wintitle): | |||
self.nplots = nplots | |||
ncolspan = 1 | |||
colspan = 1 | |||
self.createFigure(idfigure = idfigure, | |||
wintitle = wintitle, | |||
widthplot = self.WIDTH, | |||
heightplot = self.HEIGHT) | |||
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) | |||
def run(self, dataOut, idfigure, wintitle="", channelList=None, | |||
xmin=None, xmax=None, ymin=None, ymax=None, | |||
save=False, figpath='./', figfile=None): | |||
if channelList == None: | |||
channelIndexList = dataOut.channelIndexList | |||
channelList = dataOut.channelList | |||
else: | |||
channelIndexList = [] | |||
for channel in channelList: | |||
if channel not in dataOut.channelList: | |||
raise ValueError, "Channel %d is not in dataOut.channelList" | |||
channelIndexList.append(dataOut.channelList.index(channel)) | |||
|
r245 | factor = dataOut.normFactor | |
y = dataOut.getHeiRange() | |||
x = dataOut.data_spc[channelIndexList,:,:]/factor | |||
x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |||
|
r229 | avg = numpy.average(x, axis=1) | |
|
r245 | avgdB = 10*numpy.log10(avg) | |
|
r238 | thisDatetime = dataOut.datatime | |
title = "Power Profile" | |||
xlabel = "dB" | |||
ylabel = "Range (Km)" | |||
|
r229 | ||
if not self.__isConfig: | |||
nplots = 1 | |||
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle) | |||
if ymin == None: ymin = numpy.nanmin(y) | |||
if ymax == None: ymax = numpy.nanmax(y) | |||
|
r245 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |||
|
r229 | ||
self.__isConfig = True | |||
self.setWinTitle(title) | |||
title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
axes = self.axesList[0] | |||
legendlabels = ["channel %d"%x for x in channelList] | |||
|
r245 | axes.pmultiline(avgdB, y, | |
|
r229 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |||
ytick_visible=True, nxticks=5, | |||
grid='x') | |||
self.draw() | |||
if save: | |||
date = thisDatetime.strftime("%Y%m%d") | |||
if figfile == None: | |||
figfile = self.getFilename(name = date) | |||
self.saveFigure(figpath, figfile) | |||
|
r234 | class CoherenceMap(Figure): | |
|
r229 | __isConfig = None | |
__nsubplots = None | |||
WIDTHPROF = None | |||
HEIGHTPROF = None | |||
PREFIX = 'coherencemap' | |||
def __init__(self): | |||
|
r237 | self.timerange = 2*60*60 | |
|
r229 | self.__isConfig = False | |
self.__nsubplots = 1 | |||
self.WIDTH = 800 | |||
self.HEIGHT = 200 | |||
self.WIDTHPROF = 120 | |||
self.HEIGHTPROF = 0 | |||
def getSubplots(self): | |||
ncol = 1 | |||
nrow = self.nplots*2 | |||
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 | |||
self.createFigure(idfigure = idfigure, | |||
wintitle = wintitle, | |||
widthplot = self.WIDTH + self.WIDTHPROF, | |||
heightplot = self.HEIGHT + self.HEIGHTPROF) | |||
nrow, ncol = self.getSubplots() | |||
for y in range(nrow): | |||
for x in range(ncol): | |||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
if showprofile: | |||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |||
def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |||
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |||
timerange=None, | |||
save=False, figpath='./', figfile=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)) | |||
if timerange != None: | |||
|
r231 | self.timerange = timerange | |
|
r229 | ||
|
r234 | if pairsIndexList == []: | |
return | |||
if len(pairsIndexList) > 4: | |||
pairsIndexList = pairsIndexList[0:4] | |||
|
r229 | tmin = None | |
tmax = None | |||
x = dataOut.getTimeRange() | |||
y = dataOut.getHeiRange() | |||
|
r238 | thisDatetime = dataOut.datatime | |
title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |||
xlabel = "" | |||
ylabel = "Range (Km)" | |||
|
r229 | if not self.__isConfig: | |
nplots = len(pairsIndexList) | |||
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle, | |||
showprofile=showprofile) | |||
|
r230 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
r229 | if ymin == None: ymin = numpy.nanmin(y) | |
if ymax == None: ymax = numpy.nanmax(y) | |||
|
r238 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
r229 | self.__isConfig = True | |
self.setWinTitle(title) | |||
for i in range(self.nplots): | |||
pair = dataOut.pairsList[pairsIndexList[i]] | |||
coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |||
coherence = numpy.abs(coherenceComplex) | |||
avg = numpy.average(coherence, axis=0) | |||
z = avg.reshape((1,-1)) | |||
counter = 0 | |||
title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
axes = self.axesList[i*self.__nsubplots*2] | |||
axes.pcolor(x, y, z, | |||
xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |||
xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |||
ticksize=9, cblabel='', cbsize="1%") | |||
if self.__showprofile: | |||
counter += 1 | |||
axes = self.axesList[i*self.__nsubplots*2 + counter] | |||
axes.pline(avg, y, | |||
xmin=0, xmax=1, ymin=ymin, ymax=ymax, | |||
xlabel='', ylabel='', title='', ticksize=7, | |||
ytick_visible=False, nxticks=5, | |||
grid='x') | |||
counter += 1 | |||
phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |||
avg = numpy.average(phase, axis=0) | |||
z = avg.reshape((1,-1)) | |||
title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
axes = self.axesList[i*self.__nsubplots*2 + counter] | |||
axes.pcolor(x, y, z, | |||
xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |||
xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |||
ticksize=9, cblabel='', colormap='RdBu', cbsize="1%") | |||
if self.__showprofile: | |||
counter += 1 | |||
axes = self.axesList[i*self.__nsubplots*2 + counter] | |||
axes.pline(avg, y, | |||
xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |||
xlabel='', ylabel='', title='', ticksize=7, | |||
ytick_visible=False, nxticks=4, | |||
grid='x') | |||
self.draw() | |||
if save: | |||
|
r238 | ||
|
r229 | if figfile == None: | |
|
r238 | figfile = self.getFilename(name = self.name) | |
|
r229 | ||
self.saveFigure(figpath, figfile) | |||
if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |||
self.__isConfig = False | |||
|
r233 | class RTIfromNoise(Figure): | |
__isConfig = None | |||
__nsubplots = None | |||
|
r240 | ||
PREFIX = 'rtinoise' | |||
|
r233 | ||
def __init__(self): | |||
|
r240 | self.timerange = 24*60*60 | |
|
r233 | self.__isConfig = False | |
self.__nsubplots = 1 | |||
|
r240 | self.WIDTH = 820 | |
|
r233 | self.HEIGHT = 200 | |
|
r245 | self.WIDTHPROF = 120 | |
self.HEIGHTPROF = 0 | |||
self.xdata = None | |||
self.ydata = None | |||
|
r233 | ||
def getSubplots(self): | |||
ncol = 1 | |||
|
r240 | nrow = 1 | |
|
r233 | ||
return nrow, ncol | |||
def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
self.__showprofile = showprofile | |||
self.nplots = nplots | |||
|
r245 | ncolspan = 7 | |
colspan = 6 | |||
self.__nsubplots = 2 | |||
|
r233 | self.createFigure(idfigure = idfigure, | |
wintitle = wintitle, | |||
|
r245 | widthplot = self.WIDTH+self.WIDTHPROF, | |
heightplot = self.HEIGHT+self.HEIGHTPROF) | |||
|
r233 | ||
nrow, ncol = self.getSubplots() | |||
|
r245 | ||
self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |||
|
r240 | ||
|
r233 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
|
r240 | xmin=None, xmax=None, ymin=None, ymax=None, | |
|
r233 | timerange=None, | |
save=False, figpath='./', figfile=None): | |||
if channelList == None: | |||
channelIndexList = dataOut.channelIndexList | |||
|
r240 | channelList = dataOut.channelList | |
|
r233 | else: | |
channelIndexList = [] | |||
for channel in channelList: | |||
if channel not in dataOut.channelList: | |||
raise ValueError, "Channel %d is not in dataOut.channelList" | |||
channelIndexList.append(dataOut.channelList.index(channel)) | |||
if timerange != None: | |||
|
r240 | self.timerange = timerange | |
|
r233 | ||
tmin = None | |||
tmax = None | |||
x = dataOut.getTimeRange() | |||
y = dataOut.getHeiRange() | |||
|
r245 | factor = dataOut.normFactor | |
noise = dataOut.getNoise()/factor | |||
noisedB = 10*numpy.log10(noise) | |||
|
r238 | ||
thisDatetime = dataOut.datatime | |||
|
r246 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
r245 | xlabel = "" | |
|
r238 | ylabel = "Range (Km)" | |
|
r233 | if not self.__isConfig: | |
|
r240 | nplots = 1 | |
|
r233 | ||
self.setup(idfigure=idfigure, | |||
nplots=nplots, | |||
wintitle=wintitle, | |||
showprofile=showprofile) | |||
|
r240 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
r245 | if ymin == None: ymin = numpy.nanmin(noisedB) | |
if ymax == None: ymax = numpy.nanmax(noisedB) | |||
|
r233 | ||
|
r240 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
r233 | self.__isConfig = True | |
|
r240 | ||
|
r245 | self.xdata = numpy.array([]) | |
self.ydata = numpy.array([]) | |||
|
r233 | ||
self.setWinTitle(title) | |||
|
r240 | ||
title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |||
legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |||
axes = self.axesList[0] | |||
|
r245 | ||
self.xdata = numpy.hstack((self.xdata, x[0:1])) | |||
if len(self.ydata)==0: | |||
self.ydata = noisedB[channelIndexList].reshape(-1,1) | |||
else: | |||
self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |||
axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |||
|
r240 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |||
XAxisAsTime=True | |||
) | |||
|
r233 | self.draw() | |
if save: | |||
|
r240 | ||
|
r233 | if figfile == None: | |
|
r240 | figfile = self.getFilename(name = self.name) | |
|
r233 | ||
self.saveFigure(figpath, figfile) | |||
if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |||
self.__isConfig = False | |||
|
r245 | del self.xdata | |
del self.ydata | |||
|
r233 |