diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 4e7366b..ff8b326 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -11,88 +11,88 @@ from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocat from matplotlib.ticker import FuncFormatter from matplotlib.ticker import * -def init(idfigure, wintitle, width, height, facecolor="w"): - - matplotlib.pyplot.ioff() - fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) - fig.canvas.manager.set_window_title(wintitle) - fig.canvas.manager.resize(width, height) - matplotlib.pyplot.ion() - - return fig - -def setWinTitle(fig, title): - - fig.canvas.manager.set_window_title(title) - -def setTitle(idfigure, title): - fig = matplotlib.pyplot.figure(idfigure) - fig.suptitle(title) - -def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): - fig = matplotlib.pyplot.figure(idfigure) - ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) - return ax - -def setTextFromAxes(idfigure, ax, title): - fig = matplotlib.pyplot.figure(idfigure) - ax.annotate(title, xy=(.1, .99), - xycoords='figure fraction', - horizontalalignment='left', verticalalignment='top', - fontsize=10) - -def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): - - if firsttime: - ax.plot(x, y) - ax.set_xlim([xmin,xmax]) - ax.set_ylim([ymin,ymax]) - ax.set_xlabel(xlabel, size=8) - ax.set_ylabel(ylabel, size=8) - ax.set_title(title, size=10) - matplotlib.pyplot.tight_layout() - else: - ax.lines[0].set_data(x,y) - -def draw(idfigure): - - fig = matplotlib.pyplot.figure(idfigure) - fig.canvas.draw() - -def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): - - if firsttime: - divider = make_axes_locatable(ax) - ax_cb = divider.new_horizontal(size="4%", pad=0.05) - fig1 = ax.get_figure() - fig1.add_axes(ax_cb) - - ax.set_xlim([xmin,xmax]) - ax.set_ylim([ymin,ymax]) - ax.set_xlabel(xlabel) - ax.set_ylabel(ylabel) - ax.set_title(title) - print x - imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) - matplotlib.pyplot.colorbar(imesh, cax=ax_cb) - ax_cb.yaxis.tick_right() - for tl in ax_cb.get_yticklabels(): - tl.set_visible(True) - ax_cb.yaxis.tick_right() - matplotlib.pyplot.tight_layout() - return imesh - else: +#def init(idfigure, wintitle, width, height, facecolor="w"): +# +# matplotlib.pyplot.ioff() +# fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) +# fig.canvas.manager.set_window_title(wintitle) +# fig.canvas.manager.resize(width, height) +# matplotlib.pyplot.ion() +# +# return fig +# +#def setWinTitle(fig, title): +# +# fig.canvas.manager.set_window_title(title) +# +#def setTitle(idfigure, title): +# fig = matplotlib.pyplot.figure(idfigure) +# fig.suptitle(title) +# +#def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): +# fig = matplotlib.pyplot.figure(idfigure) +# ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) +# return ax +# +#def setTextFromAxes(idfigure, ax, title): +# fig = matplotlib.pyplot.figure(idfigure) +# ax.annotate(title, xy=(.1, .99), +# xycoords='figure fraction', +# horizontalalignment='left', verticalalignment='top', +# fontsize=10) +# +#def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): +# +# if firsttime: +# ax.plot(x, y) # ax.set_xlim([xmin,xmax]) # ax.set_ylim([ymin,ymax]) - ax.set_xlabel(xlabel) - ax.set_ylabel(ylabel) - ax.set_title(title) - - z = z.T -# z = z[0:-1,0:-1] - mesh.set_array(z.ravel()) - - return mesh +# ax.set_xlabel(xlabel, size=8) +# ax.set_ylabel(ylabel, size=8) +# ax.set_title(title, size=10) +# matplotlib.pyplot.tight_layout() +# else: +# ax.lines[0].set_data(x,y) +# +#def draw(idfigure): +# +# fig = matplotlib.pyplot.figure(idfigure) +# fig.canvas.draw() +# +#def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): +# +# if firsttime: +# divider = make_axes_locatable(ax) +# ax_cb = divider.new_horizontal(size="4%", pad=0.05) +# fig1 = ax.get_figure() +# fig1.add_axes(ax_cb) +# +# ax.set_xlim([xmin,xmax]) +# ax.set_ylim([ymin,ymax]) +# ax.set_xlabel(xlabel) +# ax.set_ylabel(ylabel) +# ax.set_title(title) +# print x +# imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) +# matplotlib.pyplot.colorbar(imesh, cax=ax_cb) +# ax_cb.yaxis.tick_right() +# for tl in ax_cb.get_yticklabels(): +# tl.set_visible(True) +# ax_cb.yaxis.tick_right() +# matplotlib.pyplot.tight_layout() +# return imesh +# else: +## ax.set_xlim([xmin,xmax]) +## ax.set_ylim([ymin,ymax]) +# ax.set_xlabel(xlabel) +# ax.set_ylabel(ylabel) +# ax.set_title(title) +# +# z = z.T +## z = z[0:-1,0:-1] +# mesh.set_array(z.ravel()) +# +# return mesh ########################################### #Actualizacion de las funciones del driver diff --git a/schainpy/model/jrodata.py b/schainpy/model/jrodata.py index 8d804bb..bc7de26 100644 --- a/schainpy/model/jrodata.py +++ b/schainpy/model/jrodata.py @@ -373,20 +373,6 @@ class Spectra(JROData): self.nFFTPoints = None self.wavelength = None - - def getFreqRange(self, extrapoints=0): - - delfreq = 2 * self.getFmax() / self.nFFTPoints - freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 - - return freqrange - - def getVelRange(self, extrapoints=0): - - deltav = 2 * self.getVmax() / self.nFFTPoints - velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 - - return velrange def getNoisebyHildebrand(self): """ @@ -444,6 +430,32 @@ class Spectra(JROData): noise = self.getNoisebyWindow() return 10*numpy.log10(noise) + + + def getFreqRange(self, extrapoints=0): + + delfreq = 2 * self.getFmax() / self.nFFTPoints + freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 + + return freqrange + + def getVelRange(self, extrapoints=0): + + deltav = 2 * self.getVmax() / self.nFFTPoints + velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 + + return velrange + + def getNPairs(self): + + return len(self.pairsList) + + def getPairsIndexList(self): + + return range(self.nPairs) + + nPairs = property(getNPairs, "I'm the 'nPairs' property.") + pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") class SpectraHeis(JROData): diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index bd7c675..a186a19 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -2,6 +2,165 @@ import numpy import time, datetime from graphics.figure import * +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) + + class RTIPlot(Figure): __isConfig = None @@ -118,7 +277,7 @@ class RTIPlot(Figure): for channel in channelList: if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" - channelIndexList.append(dataOut.channelList.index(chachannel)) + channelIndexList.append(dataOut.channelList.index(channel)) if timerange != None: self.__timerange = timerange @@ -382,7 +541,7 @@ class Scope(Figure): for channel in channelList: if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" - channelIndexList.append(dataOut.channelList.index(chachannel)) + channelIndexList.append(dataOut.channelList.index(channel)) x = dataOut.heightList y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])