From 86bbb8030d3e478917a46f19234c6a017f82c4e4 2012-12-02 07:42:59 From: Miguel Valdez Date: 2012-12-02 07:42:59 Subject: [PATCH] Testeado con datos de Imagenes (Espectros) Se visualiza el ruido en los graficos y en la escala correcta de velocidad 1. Upgrade de la libreria grafica 2. Adicion de la clase IncohInt para los datos de tipo Spectra 3. Adicion de calculo de ruido, calculo de numero de canales, rangeo de velocidad a la clase JROData --- diff --git a/schainpy/controller.py b/schainpy/controller.py index bddf750..6a291a9 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -598,13 +598,22 @@ if __name__ == '__main__': procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) opObj10 = procUnitConfObj1.addOperation(name='selectChannels') - opObj10.addParameter(name='channelList', value='0,1,3', format='intlist') + opObj10.addParameter(name='channelList', value='0,1', format='intlist') opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') opObj11.addParameter(name='idfigure', value='1', format='int') opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') - opObj11.addParameter(name='zmin', value='60', format='int') - opObj11.addParameter(name='zmax', value='100', format='int') +# opObj11.addParameter(name='zmin', value='60', format='int') +# opObj11.addParameter(name='zmax', value='100', format='int') + + opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') + opObj12.addParameter(name='n', value='30', format='int') + + opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') + opObj11.addParameter(name='idfigure', value='2', format='int') + opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') +# opObj11.addParameter(name='zmin', value='60', format='int') +# opObj11.addParameter(name='zmax', value='100', format='int') # opObj12 = procUnitConfObj1.addOperation(name='decoder') # opObj12.addParameter(name='ncode', value='2', format='int') diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index 986186b..ced35cd 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -1,84 +1,231 @@ +import numpy import mpldriver + class Figure: - axesList = None + + __driver = mpldriver + + idfigure = None + wintitle = None width = None height = None - def __init__(self): - pass + nplots = None + + axesObjList = [] + + WIDTH = None + HEIGHT = None + + def __init__(self): + + raise ValueError, "This method is not implemented" + + def getAxesObjList(self): + + return self.axesObjList + + def getSubplots(self): + + raise ValueError, "Abstract method: This method should be defined" + + def getScreenDim(self): + + nrow, ncol = self.getSubplots() + + width = self.WIDTH*ncol + height = self.HEIGHT*nrow + + return width, height + + def init(self, idfigure, nplots, wintitle): + + """ + Inicializa la figura de acuerdo al driver seleccionado + Input: + *args : Los parametros necesarios son + idfigure, wintitle, width, height + """ - def init(self, idfigure, wintitle, width, height, nplots): self.idfigure = idfigure - self.wintitle = wintitle - self.width = width - self.height = height + self.nplots = nplots - self.fig = mpldriver.init(idfigure, wintitle, width, height) - self.axesList = [] + self.wintitle = wintitle + + self.width, self.height = self.getScreenDim() + + self.fig = self.__driver.createFigure(self.idfigure, + self.wintitle, + self.width, + self.height) + + self.axesObjList = [] + def setDriver(self, driver=mpldriver): + + self.__driver = driver + def setTitle(self, title): - mpldriver.setTitle(self.idfigure, title) + + self.__driver.setTitle(self.fig, title) - def setWinTitle(self,title): - mpldriver.setWinTitle(fig=self.fig, title=title) + def setWinTitle(self, title): + + self.__driver.setWinTitle(self.fig, title=title) - def setTextFromAxes(self, title): - mpldriver.setTextFromAxes(self.idfigure, self.axesList[0].ax, title) + def setTextFromAxes(self, text): + + raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): - ax = mpldriver.makeAxes(self.idfigure, nrow, ncol, xpos, ypos, colspan, rowspan) - axesObj = Axes(ax) - self.axesList.append(axesObj) + + raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" + + def addAxes(self, *args): + """ + + Input: + *args : Los parametros necesarios son + nrow, ncol, xpos, ypos, colspan, rowspan + """ + + axesObj = Axes(self.fig, *args) + self.axesObjList.append(axesObj) def draw(self): - mpldriver.draw(self.idfigure) + + self.__driver.draw(self.fig) def run(self): - pass + + raise ValueError, "This method is not implemented" + + axesList = property(getAxesObjList) class Axes: - firsttime = None + + __driver = mpldriver + fig = None ax = None - mesh = None + plot = None - def __init__(self, ax): - self.firsttime = True + firsttime = None + + def __init__(self, *args): + + """ + + Input: + *args : Los parametros necesarios son + fig, nrow, ncol, xpos, ypos, colspan, rowspan + """ + + ax = self.__driver.createAxes(*args) + self.fig = args[0] self.ax = ax - self.mesh = None - - def pline(self, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title): - - mpldriver.pline(ax=self.ax, - x=x, - y=y, - xmin=xmin, - xmax=xmax, - ymin=ymin, - ymax=ymax, - xlabel=xlabel, - ylabel=ylabel, - title=title, - firsttime=self.firsttime) - - self.firsttime = False - - def pcolor(self, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title): - meshfromaxes=mpldriver.pcolor(ax=self.ax, - x=x, - y=y, - z=z, - xmin=xmin, - xmax=xmax, - ymin=ymin, - ymax=ymax, - zmin=zmin, - zmax=zmax, - xlabel=xlabel, - ylabel=ylabel, - title=title, - firsttime=self.firsttime, - mesh=self.mesh) - self.mesh = meshfromaxes - self.firsttime = False + self.plot = None + + self.firsttime = True + + def setText(self, text): + + self.__driver.setAxesText(self.ax, text) + + def pline(self, x, y, + xmin=None, xmax=None, + ymin=None, ymax=None, + xlabel='', ylabel='', + title='', + **kwargs): + + """ + + Input: + x : + y : + xmin : + xmax : + ymin : + ymax : + xlabel : + ylabel : + title : + **kwargs : Los parametros aceptados son + + ticksize + """ + + if self.firsttime: + + 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) + + self.plot = self.__driver.createPline(self.ax, x, y, + xmin, xmax, + ymin, ymax, + xlabel=xlabel, + ylabel=ylabel, + title=title, + **kwargs) + self.firsttime = False + return + + self.__driver.pline(self.plot, x, y, xlabel=xlabel, + ylabel=ylabel, + title=title) + + + def pcolor(self, x, y, z, + xmin=None, xmax=None, + ymin=None, ymax=None, + zmin=None, zmax=None, + xlabel='', ylabel='', + title='', + **kwargs): + + """ + Input: + x : + y : + x : + xmin : + xmax : + ymin : + ymax : + zmin : + zmax : + xlabel : + ylabel : + title : + **kwargs : Los parametros aceptados son + ticksize=9, + cblabel='' + """ + + if self.firsttime: + + 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) + if zmax == None: zmax = numpy.nanmax(z) + + self.plot = self.__driver.createPcolor(self.ax, x, y, z, + xmin, xmax, + ymin, ymax, + zmin, zmax, + xlabel=xlabel, + ylabel=ylabel, + title=title, + **kwargs) + self.firsttime = False + return + + mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, + ylabel=ylabel, + title=title) diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 94682ea..70ae42c 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -1,27 +1,24 @@ +import numpy import matplotlib matplotlib.use("TKAgg") import matplotlib.pyplot #import scitools.numpyutils from mpl_toolkits.axes_grid1 import make_axes_locatable -def init(idfigure, wintitle, width, height): +def init(idfigure, wintitle, width, height, facecolor="w"): + matplotlib.pyplot.ioff() - fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor="w") + fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) fig.canvas.manager.set_window_title(wintitle) - fig.canvas.manager.resize(width,height) + fig.canvas.manager.resize(width, height) matplotlib.pyplot.ion() + return fig def setWinTitle(fig, title): + fig.canvas.manager.set_window_title(title) -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 setTitle(idfigure, title): fig = matplotlib.pyplot.figure(idfigure) fig.suptitle(title) @@ -31,7 +28,15 @@ def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): 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]) @@ -44,13 +49,15 @@ def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): 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="5%", pad=0.05) + ax_cb = divider.new_horizontal(size="4%", pad=0.05) fig1 = ax.get_figure() fig1.add_axes(ax_cb) @@ -59,7 +66,7 @@ def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl 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() @@ -69,18 +76,140 @@ def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl matplotlib.pyplot.tight_layout() return imesh else: - ax.set_xlim([xmin,xmax]) - ax.set_ylim([ymin,ymax]) +# 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] +# z = z[0:-1,0:-1] mesh.set_array(z.ravel()) return mesh +########################################### +#Actualizacion de las funciones del driver +########################################### + +def createFigure(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(fig, title): + + fig.suptitle(title) + +def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): + + matplotlib.pyplot.figure(fig.number) + axes = matplotlib.pyplot.subplot2grid((nrow, ncol), + (xpos, ypos), + colspan=colspan, + rowspan=rowspan) + return axes + +def setAxesText(ax, text): + + ax.annotate(text, + xy = (.1, .99), + xycoords = 'figure fraction', + horizontalalignment = 'left', + verticalalignment = 'top', + fontsize = 10) + +def printLabels(ax, xlabel, ylabel, title): + + ax.set_xlabel(xlabel, size=11) + ax.set_ylabel(ylabel, size=11) + ax.set_title(title, size=12) + +def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', ticksize = 9): + + ax.plot(x, y) + ax.set_xlim([xmin,xmax]) + ax.set_ylim([ymin,ymax]) + + printLabels(ax, xlabel, ylabel, title) + + for tick in ax.yaxis.get_major_ticks(): + tick.label.set_fontsize(ticksize) + + for tick in ax.xaxis.get_major_ticks(): + tick.label.set_fontsize(ticksize) + + matplotlib.pyplot.tight_layout() + + iplot = ax.lines[-1] + + return iplot + +def pline(iplot, x, y, xlabel='', ylabel='', title=''): + + ax = iplot.get_axes() + + printLabels(ax, xlabel, ylabel, title) + + iplot.set_data(x, y) + +def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): + + divider = make_axes_locatable(ax) + ax_cb = divider.new_horizontal(size="4%", pad=0.05) + fig = ax.get_figure() + fig.add_axes(ax_cb) + + ax.set_xlim([xmin,xmax]) + ax.set_ylim([ymin,ymax]) + + printLabels(ax, xlabel, ylabel, title) + + imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) + cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) + cb.set_label(cblabel) + + ax_cb.yaxis.tick_right() + + for tl in ax_cb.get_yticklabels(): + tl.set_visible(True) + + for tick in ax.yaxis.get_major_ticks(): + tick.label.set_fontsize(ticksize) + + for tick in ax.xaxis.get_major_ticks(): + tick.label.set_fontsize(ticksize) + + for tick in cb.ax.get_yticklabels(): + tick.set_fontsize(ticksize) + + ax_cb.yaxis.tick_right() + matplotlib.pyplot.tight_layout() + + return imesh +def pcolor(imesh, z, xlabel='', ylabel='', title=''): + + z = z.T + + ax = imesh.get_axes() + + printLabels(ax, xlabel, ylabel, title) + + imesh.set_array(z.ravel()) - \ No newline at end of file +def draw(fig): + + if type(fig) == 'int': + raise ValueError, "This parameter should be of tpye matplotlib figure" + + fig.canvas.draw() \ No newline at end of file diff --git a/schainpy/model/jrodata.py b/schainpy/model/jrodata.py index 4779b74..47b993a 100644 --- a/schainpy/model/jrodata.py +++ b/schainpy/model/jrodata.py @@ -25,7 +25,7 @@ def hildebrand_sekhon(data, navg): anoise : noise's level """ - dataflat = data.reshape(-1) + dataflat = data.copy().reshape(-1) dataflat.sort() npts = dataflat.size #numbers of points of the data @@ -61,9 +61,12 @@ def hildebrand_sekhon(data, navg): return anoise; -def sorting_bruce(Data, navg): - sortdata = numpy.sort(Data) - lenOfData = len(Data) +def sorting_bruce(data, navg): + + data = data.copy() + + sortdata = numpy.sort(data) + lenOfData = len(data) nums_min = lenOfData/10 if (lenOfData/10) > 0: @@ -155,6 +158,11 @@ class JROData: nCohInt = None noise = None + + #Speed of ligth + C = 3e8 + + frequency = 49.92e6 def __init__(self): @@ -318,11 +326,35 @@ class Spectra(JROData): self.wavelength = None - def getFrequencies(self): + def getFmax(self): + + PRF = 1./(self.ippSeconds * self.nCohInt) + + fmax = PRF/2. + + return fmax + + def getVmax(self): + + _lambda = self.C/self.frequency + + vmax = self.getFmax() * _lambda / 2. + + return vmax + + 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 - xrange = numpy.arange(self.nFFTPoints) - xrange = xrange - return None + return velrange def getNoisebyHildebrand(self): """ diff --git a/schainpy/model/jrodataIO.py b/schainpy/model/jrodataIO.py index 8da175e..ebc1811 100644 --- a/schainpy/model/jrodataIO.py +++ b/schainpy/model/jrodataIO.py @@ -1973,8 +1973,9 @@ class SpectraReader(JRODataReader): self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock - self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt + self.dataOut.nCohInt = self.processingHeaderObj.nCohInt + self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index 3c7c06a..21878f8 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -9,15 +9,15 @@ class SpectraPlot(Figure): def __init__(self): self.__isConfig = False - self.width = 850 - self.height = 800 - + self.WIDTH = 300 + self.HEIGHT = 400 + def getSubplots(self): ncol = int(numpy.sqrt(self.nplots)+0.9) nrow = int(self.nplots*1./ncol + 0.9) return nrow, ncol - + def setAxesWithOutProfiles(self, nrow, ncol): colspan = 1 @@ -27,7 +27,7 @@ class SpectraPlot(Figure): for y in range(nrow): for x in range(ncol): if counter < self.nplots: - self.makeAxes(nrow, ncol, y, x, colspan, rowspan) + self.addAxes(nrow, ncol, y, x, colspan, rowspan) counter += 1 def setAxesWithProfiles(self, nrow, ncol): @@ -42,150 +42,166 @@ class SpectraPlot(Figure): for x in range(ncol): if counter < self.nplots*factor: # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) - self.makeAxes(nrow, ncol, y, x, colspan, rowspan) + self.addAxes(nrow, ncol, y, x, colspan, rowspan) counter += 1 - def setup(self, idfigure, wintitle, width, height, nplots, profile): + def setup(self, idfigure, nplots, wintitle, showprofile=True): - self.init(idfigure, wintitle, width, height, nplots) + self.init(idfigure, nplots, wintitle) - nrow,ncol = self.getSubplots() + nrow, ncol = self.getSubplots() - if profile: + if showprofile: self.setAxesWithProfiles(nrow, ncol) else: self.setAxesWithOutProfiles(nrow, ncol) - def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, profile=False): + 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 + """ if channelList == None: channelList = dataOut.channelList - - nplots = len(channelList) - - z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) + x = dataOut.getVelRange(1) y = dataOut.heightList - - x = numpy.arange(dataOut.nFFTPoints) + z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) noise = dataOut.getNoise() if not self.__isConfig: - self.setup(idfigure=idfigure, - wintitle=wintitle, - width=self.width, - height=self.height, - nplots=nplots, - profile=profile) - if xmin == None: xmin = numpy.min(x) - if xmax == None: xmax = numpy.max(x) - if ymin == None: ymin = numpy.min(y) - if ymax == None: ymax = numpy.max(y) - if zmin == None: zmin = numpy.min(z) - if zmax == None: zmax = numpy.max(z) + nplots = len(channelList) - self.xmin = xmin - self.xmax = xmax - self.ymin = ymin - self.ymax = ymax - self.zmin = zmin - self.zmax = zmax + 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 self.__isConfig = True - + thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) - dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) - date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) - title = "Spectra: " + dateTime + title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + xlabel = "Velocity (m/s)" + ylabel = "Range (Km)" self.setWinTitle(title) - ylabel = "Range[Km]" - - xlabel = "m/s" - - for i in range(len(self.axesList)): + for i in range(self.nplots): title = "Channel %d: %4.2fdB" %(channelList[i], noise[i]) + zchannel = z[i,:,:] + axes = self.axesList[i] - z2 = z[i,:,:] - axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title) + 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') self.draw() class Scope(Figure): + __isConfig = None def __init__(self): + self.__isConfig = False - self.width = 850 - self.height = 800 + self.WIDTH = 600 + self.HEIGHT = 200 def getSubplots(self): + nrow = self.nplots ncol = 3 return nrow, ncol - def setup(self, idfigure, wintitle, width, height, nplots): - self.init(idfigure, wintitle, width, height, nplots) + def setup(self, idfigure, nplots, wintitle): + + self.init(idfigure, nplots, wintitle) nrow,ncol = self.getSubplots() colspan = 3 rowspan = 1 for i in range(nplots): - self.makeAxes(nrow, ncol, i, 0, colspan, rowspan) - - + self.addAxes(nrow, ncol, i, 0, colspan, rowspan) - def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None): - - if dataOut.isEmpty(): - return None + 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, + """ if channelList == None: - channelList = dataOut.channelList - - nplots = len(channelList) + channelList = dataOut.channelList + x = dataOut.heightList y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) y = y.real - x = dataOut.heightList + noise = dataOut.getNoise() if not self.__isConfig: - self.setup(idfigure=idfigure, - wintitle=wintitle, - width=self.width, - height=self.height, - nplots=nplots) + nplots = len(channelList) + + self.setup(idfigure=idfigure, + nplots=nplots, + wintitle=wintitle) - if xmin == None: self.xmin = numpy.min(x) - if xmax == None: self.xmax = numpy.max(x) - if ymin == None: self.ymin = numpy.min(y) - if ymax == None: self.ymax = numpy.max(y) + 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) self.__isConfig = True - thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) - dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) - date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) - title = "Scope: " + dateTime - - self.setWinTitle(title) - + title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + xlabel = "Range (Km)" ylabel = "Intensity" - xlabel = "Range[Km]" + self.setWinTitle(title) for i in range(len(self.axesList)): title = "Channel %d: %4.2fdB" %(i, noise[i]) axes = self.axesList[i] - y2 = y[i,:] - axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title) + ychannel = y[i,:] + axes.pline(x, ychannel, + xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, + xlabel=xlabel, ylabel=ylabel, title=title) self.draw() diff --git a/schainpy/model/jroprocessing.py b/schainpy/model/jroprocessing.py index 909e981..f7b0326 100644 --- a/schainpy/model/jroprocessing.py +++ b/schainpy/model/jroprocessing.py @@ -281,21 +281,21 @@ class CohInt(Operation): __dataReady = False - nCohInt = None + n = None def __init__(self): self.__isConfig = False - def setup(self, nCohInt=None, timeInterval=None, overlapping=False): + def setup(self, n=None, timeInterval=None, overlapping=False): """ Set the parameters of the integration class. Inputs: - nCohInt : Number of coherent integrations - timeInterval : Time of integration. If the parameter "nCohInt" is selected this one does not work + n : Number of coherent integrations + timeInterval : Time of integration. If the parameter "n" is selected this one does not work overlapping : """ @@ -306,15 +306,15 @@ class CohInt(Operation): self.__dataReady = False - if nCohInt == None and timeInterval == None: - raise ValueError, "nCohInt or timeInterval should be specified ..." + if n == None and timeInterval == None: + raise ValueError, "n or timeInterval should be specified ..." - if nCohInt != None: - self.nCohInt = nCohInt + if n != None: + self.n = n self.__byTime = False else: self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line - self.nCohInt = 9999 + self.n = 9999 self.__byTime = True if overlapping: @@ -334,7 +334,7 @@ class CohInt(Operation): """ if not self.__withOverapping: - self.__buffer += data + self.__buffer += data.copy() self.__profIndex += 1 return @@ -348,16 +348,16 @@ class CohInt(Operation): self.__profIndex += 1 return - #If the buffer length is lower than nCohInt then stakcing the data value - if self.__profIndex < self.nCohInt: + #If the buffer length is lower than n then stakcing the data value + if self.__profIndex < self.n: self.__buffer = numpy.vstack((self.__buffer, data)) self.__profIndex += 1 return - #If the buffer length is equal to nCohInt then replacing the last buffer value with the data value + #If the buffer length is equal to n then replacing the last buffer value with the data value self.__buffer = numpy.roll(self.__buffer, -1, axis=0) - self.__buffer[self.nCohInt-1] = data - self.__profIndex = self.nCohInt + self.__buffer[self.n-1] = data + self.__profIndex = self.n return @@ -373,30 +373,30 @@ class CohInt(Operation): if not self.__withOverapping: data = self.__buffer - nCohInt = self.__profIndex + n = self.__profIndex self.__buffer = 0 self.__profIndex = 0 - return data, nCohInt + return data, n #Integration with Overlapping data = numpy.sum(self.__buffer, axis=0) - nCohInt = self.__profIndex + n = self.__profIndex - return data, nCohInt + return data, n def byProfiles(self, data): self.__dataReady = False avgdata = None - nCohInt = None + n = None self.putData(data) - if self.__profIndex == self.nCohInt: + if self.__profIndex == self.n: - avgdata, nCohInt = self.pushData() + avgdata, n = self.pushData() self.__dataReady = True return avgdata @@ -405,13 +405,13 @@ class CohInt(Operation): self.__dataReady = False avgdata = None - nCohInt = None + n = None self.putData(data) if (datatime - self.__initime) >= self.__integrationtime: - avgdata, nCohInt = self.pushData() - self.nCohInt = nCohInt + avgdata, n = self.pushData() + self.n = n self.__dataReady = True return avgdata @@ -443,22 +443,22 @@ class CohInt(Operation): return avgdata, avgdatatime - def run(self, dataOut, nCohInt=None, timeInterval=None, overlapping=False): + def run(self, dataOut, n=None, timeInterval=None, overlapping=False): if not self.__isConfig: - self.setup(nCohInt, timeInterval, overlapping) + self.setup(n, timeInterval, overlapping) self.__isConfig = True avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) -# dataOut.timeInterval *= nCohInt +# dataOut.timeInterval *= n dataOut.flagNoData = True if self.__dataReady: dataOut.data = avgdata - dataOut.timeInterval *= self.nCohInt - dataOut.nCohInt *= self.nCohInt + dataOut.nCohInt *= self.n dataOut.utctime = avgdatatime + dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt dataOut.flagNoData = False @@ -615,12 +615,9 @@ class SpectraProc(ProcessingUnit): channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] Affected: - self.dataOut.data + self.dataOut.data_spc self.dataOut.channelIndexList self.dataOut.nChannels - self.dataOut.m_ProcessingHeader.totalSpectra - self.dataOut.systemHeaderObj.numChannels - self.dataOut.m_ProcessingHeader.blockSize Return: None @@ -633,9 +630,9 @@ class SpectraProc(ProcessingUnit): nChannels = len(channelIndexList) - data = self.dataOut.data_spc[channelIndexList,:] + data_spc = self.dataOut.data_spc[channelIndexList,:] - self.dataOut.data = data + self.dataOut.data_spc = data_spc self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] # self.dataOut.nChannels = nChannels @@ -644,5 +641,196 @@ class SpectraProc(ProcessingUnit): class IncohInt(Operation): - def __init__(self): - pass \ No newline at end of file + + __profIndex = 0 + __withOverapping = False + + __byTime = False + __initime = None + __lastdatatime = None + __integrationtime = None + + __buffer = None + + __dataReady = False + + n = None + + + def __init__(self): + + self.__isConfig = False + + def setup(self, n=None, timeInterval=None, overlapping=False): + """ + Set the parameters of the integration class. + + Inputs: + + n : Number of coherent integrations + timeInterval : Time of integration. If the parameter "n" is selected this one does not work + overlapping : + + """ + + self.__initime = None + self.__lastdatatime = 0 + self.__buffer = None + self.__dataReady = False + + + if n == None and timeInterval == None: + raise ValueError, "n or timeInterval should be specified ..." + + if n != None: + self.n = n + self.__byTime = False + else: + self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line + self.n = 9999 + self.__byTime = True + + if overlapping: + self.__withOverapping = True + self.__buffer = None + else: + self.__withOverapping = False + self.__buffer = 0 + + self.__profIndex = 0 + + def putData(self, data): + + """ + Add a profile to the __buffer and increase in one the __profileIndex + + """ + + if not self.__withOverapping: + self.__buffer += data.copy() + self.__profIndex += 1 + return + + #Overlapping data + nChannels, nFFTPoints, nHeis = data.shape + data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis)) + + #If the buffer is empty then it takes the data value + if self.__buffer == None: + self.__buffer = data + self.__profIndex += 1 + return + + #If the buffer length is lower than n then stakcing the data value + if self.__profIndex < self.n: + self.__buffer = numpy.vstack((self.__buffer, data)) + self.__profIndex += 1 + return + + #If the buffer length is equal to n then replacing the last buffer value with the data value + self.__buffer = numpy.roll(self.__buffer, -1, axis=0) + self.__buffer[self.n-1] = data + self.__profIndex = self.n + return + + + def pushData(self): + """ + Return the sum of the last profiles and the profiles used in the sum. + + Affected: + + self.__profileIndex + + """ + + if not self.__withOverapping: + data = self.__buffer + n = self.__profIndex + + self.__buffer = 0 + self.__profIndex = 0 + + return data, n + + #Integration with Overlapping + data = numpy.sum(self.__buffer, axis=0) + n = self.__profIndex + + return data, n + + def byProfiles(self, data): + + self.__dataReady = False + avgdata = None + n = None + + self.putData(data) + + if self.__profIndex == self.n: + + avgdata, n = self.pushData() + self.__dataReady = True + + return avgdata + + def byTime(self, data, datatime): + + self.__dataReady = False + avgdata = None + n = None + + self.putData(data) + + if (datatime - self.__initime) >= self.__integrationtime: + avgdata, n = self.pushData() + self.n = n + self.__dataReady = True + + return avgdata + + def integrate(self, data, datatime=None): + + if self.__initime == None: + self.__initime = datatime + + if self.__byTime: + avgdata = self.byTime(data, datatime) + else: + avgdata = self.byProfiles(data) + + + self.__lastdatatime = datatime + + if avgdata == None: + return None, None + + avgdatatime = self.__initime + + deltatime = datatime -self.__lastdatatime + + if not self.__withOverapping: + self.__initime = datatime + else: + self.__initime += deltatime + + return avgdata, avgdatatime + + def run(self, dataOut, n=None, timeInterval=None, overlapping=False): + + if not self.__isConfig: + self.setup(n, timeInterval, overlapping) + self.__isConfig = True + + avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) + +# dataOut.timeInterval *= n + dataOut.flagNoData = True + + if self.__dataReady: + dataOut.data_spc = avgdata + dataOut.nIncohInt *= self.n + dataOut.utctime = avgdatatime + dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt + dataOut.flagNoData = False + \ No newline at end of file