From a87a6795637a146814fc7b03e0704527ca8f0099 2012-05-09 16:21:31 From: Miguel Valdez Date: 2012-05-09 16:21:31 Subject: [PATCH] --- diff --git a/schainpy/Graphics/BaseGraph.py b/schainpy/Graphics/BaseGraph.py index 3118976..3b7ce6a 100644 --- a/schainpy/Graphics/BaseGraph.py +++ b/schainpy/Graphics/BaseGraph.py @@ -11,6 +11,9 @@ import plplot def cmap1_init(colormap="gray"): + if colormap == None: + return + ncolor = None rgb_lvl = None @@ -144,12 +147,45 @@ def cmap1_init(colormap="gray"): return rgb_lvl +def setColormap(colormap="br_green"): + cmap1_init(colormap) + class BaseGraph: """ """ + hasNotRange = True + + xrange = None + yrange = None + zrange = None - + xlabel = None + ylabel = None + title = None + + legends = None + + __name = None + + __colormap = None + __colbox = None + __colleg = None + + __xpos = None + __ypos = None + + __xopt = None #"bcnst" + __yopt = None #"bcnstv" + + __xlpos = None + __ylpos = None + + __xrangeIsTime = False + + #Advanced + __xg = None + __yg = None def __init__(self): """ @@ -323,31 +359,31 @@ class BaseGraph: plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) -class LinearPlot(): +class LinearPlot: + + linearGraphObj = BaseGraph() __szchar = 1.0 + __xrange = None + __yrange = None - m_BaseGraph = None + __subpage = 0 + m_BaseGraph= BaseGraph() + + def __init__(self): key = "linearplot" - self.m_BaseGraph = BaseGraph() - self.m_BaseGraph.setName(key) + self.linearGraphObj = BaseGraph() + self.linearGraphObj.setName(key) self.__subpage = 0 - def setColormap(self, colormap="br_green"): - - if colormap == None: - colormap = self.__colormap - - cmap1_init(colormap) - - def iniSubpage(self): + def __iniSubpage(self): if plplot.plgdev() == '': raise ValueError, "Plot device has not been initialize" @@ -355,7 +391,7 @@ class LinearPlot(): plplot.pladv(self.__subpage) plplot.plschr(0.0, self.__szchar) - self.setColormap() + setColormap() def setScreenPos(self, width='small'): @@ -368,14 +404,14 @@ class LinearPlot(): xf = xi + xw yf = yi + yw - self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) + self.linearGraphObj.setScreenPos([xi, xf], [yi, yf]) def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): """ """ - self.m_BaseGraph.setOpt("bcnts","bcntsv") - self.m_BaseGraph.setup(title, + self.linearGraphObj.setOpt("bcnts","bcntsv") + self.linearGraphObj.setup(title, xlabel, ylabel ) @@ -383,12 +419,12 @@ class LinearPlot(): self.setScreenPos(width='medium') if XAxisAsTime: - self.m_BaseGraph.setXAxisAsTime() + self.linearGraphObj.setXAxisAsTime() self.__subpage = subpage # def setRanges(self, xrange, yrange, zrange): # -# self.m_BaseGraph.setRanges(xrange, yrange, zrange) +# self.linearGraphObj.setRanges(xrange, yrange, zrange) def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): """ @@ -411,8 +447,9 @@ class LinearPlot(): if ymin == None: ymin = y[0] if ymax == None: ymax = y[-1] - self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) - self.m_BaseGraph.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) + self.__iniSubpage() + self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) + self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): """ @@ -438,18 +475,40 @@ class LinearPlot(): if ymin == None: ymin = y[0] if ymax == None: ymax = y[-1] - self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) + self.__iniSubpage() + self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) if type.lower() == 'power': - self.m_BaseGraph.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) + self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) if type.lower() == 'iq': - self.m_BaseGraph.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) - self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) + self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) + self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) -class ColorPlot(): +class ColorPlot: + + colorGraphObj = BaseGraph() + + graphObjDict = {} + __subpage = 0 + + __showColorbar = False + + __showPowerProfile = True + + __szchar = 0.65 + + __xrange = None + + __yrange = None + + __zrange = None + m_BaseGraph= BaseGraph() + + + def __init__(self): self.graphObjDict = {} @@ -464,15 +523,15 @@ class ColorPlot(): self.__zrange = None key = "colorplot" - self.m_BaseGraph = BaseGraph() - self.m_BaseGraph.setName(key) + self.colorGraphObj = BaseGraph() + self.colorGraphObj.setName(key) - def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): + def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): """ """ - self.m_BaseGraph.setOpt("bcnts","bcntsv") - self.m_BaseGraph.setup(title, + self.colorGraphObj.setOpt("bcnts","bcntsv") + self.colorGraphObj.setup(title, xlabel, ylabel ) @@ -511,18 +570,9 @@ class ColorPlot(): self.setScreenPos(width='small') if XAxisAsTime: - self.m_BaseGraph.setXAxisAsTime() + self.colorGraphObj.setXAxisAsTime() - - - def setColormap(self, colormap="br_green"): - - if colormap == None: - colormap = self.__colormap - - cmap1_init(colormap) - - def iniSubpage(self): + def __iniSubpage(self): if plplot.plgdev() == '': raise ValueError, "Plot device has not been initialize" @@ -530,7 +580,7 @@ class ColorPlot(): plplot.pladv(self.__subpage) plplot.plschr(0.0, self.__szchar) - self.setColormap() + setColormap(self.__colormap) def setScreenPos(self, width='small'): @@ -550,7 +600,7 @@ class ColorPlot(): yf = yi + yw xcmapf = xf - self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) + self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) if self.__showColorbar: xcmapi = xf + deltaxcmap @@ -596,9 +646,9 @@ class ColorPlot(): if zmax == None: zmax = numpy.nanmax(data) plplot.plschr(0.0, self.__szchar) - - self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) - self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) + self.__iniSubpage() + self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax) + self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) if self.__showColorbar: @@ -632,7 +682,7 @@ class ColorPlot(): plplot.plcol0(1) -class ColorPlotX(): +class ColorPlotX: graphObjDict = {} @@ -644,25 +694,18 @@ class ColorPlotX(): __yrange = None __zrange = None - m_BaseGraph = BaseGraph() + colorGraphObj = BaseGraph() def __init__(self): key = "colorplot" - self.m_BaseGraph.setName(key) + self.colorGraphObj.setName(key) self.__subpage = 0 - self.graphObjDict[key] = self.m_BaseGraph + self.graphObjDict[key] = self.colorGraphObj - def setColormap(self, colormap="br_green"): - - if colormap == None: - colormap = self.__colormap - - cmap1_init(colormap) - - def iniSubpage(self): + def __iniSubpage(self): if plplot.plgdev() == '': raise ValueError, "Plot device has not been initialize" @@ -670,16 +713,63 @@ class ColorPlotX(): plplot.pladv(self.__subpage) plplot.plschr(0.0, self.__szchar) - self.setColormap() + setColormap(self.__colormap) + + def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): + + if self.showColorbar: + xw -= xcmapw + deltaxcmap + + if self.showPowerProfile: + xw -= xpoww + deltaxpow + xf = xi + xw + yf = yi + yw + xcmapf = xf + + self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) + + if self.showColorbar: + xcmapi = xf + deltaxcmap + xcmapf = xcmapi + xcmapw + + key = "colorbar" + cmapObj = self.graphObjDict[key] + cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) + + if self.showPowerProfile: + + xpowi = xcmapf + deltaxpow + xpowf = xpowi + xpoww + + key = "powerprof" + powObj = self.graphObjDict[key] + powObj.setScreenPos([xpowi, xpowf], [yi, yf]) + + def setRanges(self, xrange, yrange, zrange): + + self.colorGraphObj.setRanges(xrange, yrange, zrange) + + keyList = self.graphObjDict.keys() + + key = "colorbar" + if key in keyList: + cmapObj = self.graphObjDict[key] + cmapObj.setRanges([0., 1.], zrange) + + key = "powerprof" + if key in keyList: + powObj = self.graphObjDict[key] + powObj.setRanges(zrange, yrange) + def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): """ """ - self.m_BaseGraph.setSubpage(subpage) - self.m_BaseGraph.setSzchar(self.__szchar) - self.m_BaseGraph.setOpt("bcnts","bcntsv") - self.m_BaseGraph.setup(title, + self.colorGraphObj.setSubpage(subpage) + self.colorGraphObj.setSzchar(self.__szchar) + self.colorGraphObj.setOpt("bcnts","bcntsv") + self.colorGraphObj.setup(title, xlabel, ylabel, colormap) @@ -721,57 +811,10 @@ class ColorPlotX(): self.setScreenPos() if XAxisAsTime: - self.m_BaseGraph.setXAxisAsTime() + self.colorGraphObj.setXAxisAsTime() #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) - - def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): - - if self.showColorbar: - xw -= xcmapw + deltaxcmap - - if self.showPowerProfile: - xw -= xpoww + deltaxpow - - xf = xi + xw - yf = yi + yw - xcmapf = xf - - self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) - - if self.showColorbar: - xcmapi = xf + deltaxcmap - xcmapf = xcmapi + xcmapw - - key = "colorbar" - cmapObj = self.graphObjDict[key] - cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) - - if self.showPowerProfile: - - xpowi = xcmapf + deltaxpow - xpowf = xpowi + xpoww - - key = "powerprof" - powObj = self.graphObjDict[key] - powObj.setScreenPos([xpowi, xpowf], [yi, yf]) - - def setRanges(self, xrange, yrange, zrange): - - self.m_BaseGraph.setRanges(xrange, yrange, zrange) - keyList = self.graphObjDict.keys() - - key = "colorbar" - if key in keyList: - cmapObj = self.graphObjDict[key] - cmapObj.setRanges([0., 1.], zrange) - - key = "powerprof" - if key in keyList: - powObj = self.graphObjDict[key] - powObj.setRanges(zrange, yrange) - def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): """ """ @@ -791,11 +834,11 @@ class ColorPlotX(): if zmin == None: zmin = numpy.nanmin(data) if zmax == None: zmax = numpy.nanmax(data) - if self.m_BaseGraph.hasNotRange: + if self.colorGraphObj.hasNotRange: self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) - self.m_BaseGraph.initSubpage() - self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1]) + self.colorGraphObj.initSubpage() + self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1]) if self.showColorbar: key = "colorbar" @@ -842,16 +885,12 @@ if __name__ == '__main__': data = numpy.random.uniform(-50,50,(nx,ny)) plplot.plbop() - baseObj.iniSubpage() baseObj.plotData(data) - specObj.iniSubpage() specObj.plotData(data) - baseObj1.iniSubpage() baseObj1.plotData(data) - specObj1.iniSubpage() specObj1.plotData(data) plplot.plflush() diff --git a/schainpy/Graphics/SpectraPlot.py b/schainpy/Graphics/SpectraPlot.py index 62d400e..20bc75d 100644 --- a/schainpy/Graphics/SpectraPlot.py +++ b/schainpy/Graphics/SpectraPlot.py @@ -16,8 +16,34 @@ sys.path.append(path) from Graphics.BaseGraph import * from Model.Spectra import Spectra -class Spectrum(): +class Spectrum: + + __isPlotConfig = False + + __isPlotIni = False + + __xrange = None + + __yrange = None + nGraphs = 0 + + indexPlot = None + + graphObjList = [] + + spectraObj = Spectra + + colorGraphObj = ColorPlot() + m_Spectra= Spectra() + + + m_ColorPlot= ColorPlot() + + + + + def __init__(self, Spectra, index=0): """ @@ -42,7 +68,7 @@ class Spectrum(): self.graphObjList = [] - self.m_Spectra = Spectra + self.spectraObj = Spectra def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): @@ -61,7 +87,7 @@ class Spectrum(): def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): - nChan = int(self.m_Spectra.m_SystemHeader.numChannels) + nChan = int(self.spectraObj.m_SystemHeader.numChannels) channels = range(nChan) myXlabel = "Radial Velocity (m/s)" @@ -73,8 +99,8 @@ class Spectrum(): myXlabel = xlabelList[i] myYlabel = ylabelList[i] -# if self.m_Spectra.m_NoiseObj != None: -# noise = '%4.2fdB' %(self.m_Spectra.m_NoiseObj[i]) +# if self.spectraObj.m_NoiseObj != None: +# noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i]) # else: noise = '--' @@ -127,7 +153,7 @@ class Spectrum(): plplot.plsstrm(self.indexPlot) - data = 10.*numpy.log10(self.m_Spectra.data_spc) + data = 10.*numpy.log10(self.spectraObj.data_spc) #data.shape = Channels x Heights x Profiles # data = numpy.transpose( data, (0,2,1) ) @@ -136,9 +162,9 @@ class Spectrum(): nChan, nX, nY = numpy.shape(data) x = numpy.arange(nX) - y = self.m_Spectra.heightList + y = self.spectraObj.heightList - thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc) + thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) if xmin == None: xmin = x[0] @@ -152,7 +178,6 @@ class Spectrum(): plplot.plssub(self.__nx, self.__ny) for i in range(self.nGraphs): - self.graphObjList[i].iniSubpage() self.graphObjList[i].plotData(data[i,:,:], x, y, @@ -172,7 +197,7 @@ class Spectrum(): def end(self): plplot.plend() - + if __name__ == '__main__': pass \ No newline at end of file diff --git a/schainpy/Graphics/VoltagePlot.py b/schainpy/Graphics/VoltagePlot.py index a94e6c6..8f5295a 100644 --- a/schainpy/Graphics/VoltagePlot.py +++ b/schainpy/Graphics/VoltagePlot.py @@ -1,182 +1,207 @@ -''' -Created on Feb 7, 2012 - -@author $Author$ -@version $Id$ -''' -import os, sys -import numpy -import plplot - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from Graphics.BaseGraph import * -from Model.Voltage import Voltage - -class Osciloscope(): - - def __init__(self, Voltage, index=0): - - """ - - Inputs: - - type: "power" ->> Potencia - "iq" ->> Real + Imaginario - """ - - self.__isPlotConfig = False - - self.__isPlotIni = False - - self.__xrange = None - - self.__yrange = None - - self.m_Voltage = None - - self.nGraphs = 0 - - self.indexPlot = index - - self.graphObjList = [] - - self.m_Voltage = Voltage - - - def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): - - graphObj = LinearPlot() - graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) - #graphObj.setScreenPos() - - self.graphObjList.append(graphObj) - - del graphObj - -# def setXRange(self, xmin, xmax): -# self.__xrange = (xmin, xmax) -# -# def setYRange(self, ymin, ymax): -# self.__yrange = (ymin, ymax) - - - def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): - - nChan = int(self.m_Voltage.m_SystemHeader.numChannels) - - myTitle = "" - myXlabel = "" - myYlabel = "" - - for chan in range(nChan): - if titleList != None: - myTitle = titleList[chan] - myXlabel = xlabelList[chan] - myYlabel = ylabelList[chan] - - self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) - - self.nGraphs = nChan - self.__isPlotConfig = True - - def iniPlot(self, winTitle=""): - - plplot.plsstrm(self.indexPlot) - plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) - plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) - plplot.plsdev("xwin") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plspause(False) - plplot.plssub(1, self.nGraphs) - - self.__isPlotIni = True - - def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): - - if idProfile != None and idProfile != self.m_Voltage.idProfile: - return - - if not(self.__isPlotConfig): - self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) - - if not(self.__isPlotIni): - self.iniPlot(winTitle) - - plplot.plsstrm(self.indexPlot) - - data = self.m_Voltage.data - - x = self.m_Voltage.heights - - if xmin == None: xmin = x[0] - if xmax == None: xmax = x[-1] - if ymin == None: ymin = numpy.nanmin(abs(data)) - if ymax == None: ymax = numpy.nanmax(abs(data)) - - plplot.plbop() - for chan in range(self.nGraphs): - y = data[chan,:] - - self.graphObjList[chan].iniSubpage() - self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) - - plplot.plflush() - plplot.pleop() - - def end(self): - plplot.plend() - -class VoltagePlot(object): - ''' - classdocs - ''' - - __m_Voltage = None - - def __init__(self, m_Voltage): - ''' - Constructor - ''' - self.__m_Voltage = m_Voltage - - def setup(self): - pass - - def addGraph(self, type, xrange=None, yrange=None, zrange=None): - pass - - def plotData(self): - pass - -if __name__ == '__main__': - - import numpy - - plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) - plplot.plsdev("xcairo") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plssub(1, 2) - - nx = 64 - ny = 100 - - data = numpy.random.uniform(-50,50,(nx,ny)) - - baseObj = RTI() - baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) - baseObj.plotData(data) - - data = numpy.random.uniform(-50,50,(nx,ny)) - - base2Obj = RTI() - base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) - base2Obj.plotData(data) - - plplot.plend() +''' +Created on Feb 7, 2012 + +@author $Author$ +@version $Id$ +''' +import os, sys +import numpy +import plplot + +path = os.path.split(os.getcwd())[0] +sys.path.append(path) + +from Graphics.BaseGraph import * +from Model.Voltage import Voltage + +class Osciloscope: + + voltageObj = Voltage() + + linearGraphObj = LinearPlot() + + __isPlotConfig = False + + __isPlotIni = False + + __xrange = None + + __yrange = None + + voltageObj = Voltage() + + nGraphs = 0 + + indexPlot = None + + graphObjList = [] + m_LinearPlot= LinearPlot() + + + m_Voltage= Voltage() + + + + def __init__(self, Voltage, index=0): + + """ + + Inputs: + + type: "power" ->> Potencia + "iq" ->> Real + Imaginario + """ + + self.__isPlotConfig = False + + self.__isPlotIni = False + + self.__xrange = None + + self.__yrange = None + + self.voltageObj = None + + self.nGraphs = 0 + + self.indexPlot = index + + self.graphObjList = [] + + self.voltageObj = Voltage + + + def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): + + graphObj = LinearPlot() + graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) + #graphObj.setScreenPos() + + self.graphObjList.append(graphObj) + + del graphObj + +# def setXRange(self, xmin, xmax): +# self.__xrange = (xmin, xmax) +# +# def setYRange(self, ymin, ymax): +# self.__yrange = (ymin, ymax) + + + def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): + + nChan = int(self.voltageObj.m_SystemHeader.numChannels) + + myTitle = "" + myXlabel = "" + myYlabel = "" + + for chan in range(nChan): + if titleList != None: + myTitle = titleList[chan] + myXlabel = xlabelList[chan] + myYlabel = ylabelList[chan] + + self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) + + self.nGraphs = nChan + self.__isPlotConfig = True + + def iniPlot(self, winTitle=""): + + plplot.plsstrm(self.indexPlot) + plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) + plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) + plplot.plsdev("xwin") + plplot.plscolbg(255,255,255) + plplot.plscol0(1,0,0,0) + plplot.plinit() + plplot.plspause(False) + plplot.plssub(1, self.nGraphs) + + self.__isPlotIni = True + + def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): + + if idProfile != None and idProfile != self.voltageObj.idProfile: + return + + if not(self.__isPlotConfig): + self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) + + if not(self.__isPlotIni): + self.iniPlot(winTitle) + + plplot.plsstrm(self.indexPlot) + + data = self.voltageObj.data + + x = self.voltageObj.heights + + if xmin == None: xmin = x[0] + if xmax == None: xmax = x[-1] + if ymin == None: ymin = numpy.nanmin(abs(data)) + if ymax == None: ymax = numpy.nanmax(abs(data)) + + plplot.plbop() + for chan in range(self.nGraphs): + y = data[chan,:] + + self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) + + plplot.plflush() + plplot.pleop() + + def end(self): + plplot.plend() + +class VoltagePlot(object): + ''' + classdocs + ''' + + __m_Voltage = None + + def __init__(self, voltageObj): + ''' + Constructor + ''' + self.__m_Voltage = voltageObj + + def setup(self): + pass + + def addGraph(self, type, xrange=None, yrange=None, zrange=None): + pass + + def plotData(self): + pass + +if __name__ == '__main__': + + import numpy + + plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) + plplot.plsdev("xcairo") + plplot.plscolbg(255,255,255) + plplot.plscol0(1,0,0,0) + plplot.plinit() + plplot.plssub(1, 2) + + nx = 64 + ny = 100 + + data = numpy.random.uniform(-50,50,(nx,ny)) + + baseObj = RTI() + baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) + baseObj.plotData(data) + + data = numpy.random.uniform(-50,50,(nx,ny)) + + base2Obj = RTI() + base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) + base2Obj.plotData(data) + + plplot.plend() exit(0) \ No newline at end of file diff --git a/schainpy/IO/TestIO.py b/schainpy/IO/TestIO.py deleted file mode 100644 index ed7cdf6..0000000 --- a/schainpy/IO/TestIO.py +++ /dev/null @@ -1,57 +0,0 @@ -''' -Created on 23/01/2012 - -@author $Author$ -@version $Id$ -''' -import os -import sys -import datetime -import time - -class TestIO: - - def __init__(self): - self.setValues() - self.createVoltageObjects() - self.testReadVoltage() - pass - - def setValues(self): - - - self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR' - self.startDateTime = datetime.datetime(2007,5,1,17,49,0) - self.endDateTime = datetime.datetime(2007,5,1,18,15,0) - - def createVoltageObjects(self): - path = os.path.split(os.getcwd())[0] - sys.path.append(path) - - from IO.VoltageIO import VoltageReader - from IO.VoltageIO import VoltageWriter - from Model.Voltage import Voltage - - self.voltageModelObj = Voltage() - self.voltageReaderObj = VoltageReader(self.voltageModelObj) - self.voltageReaderObj.setup(self.path, self.startDateTime, self.endDateTime) - -# self.voltageWriterObj = VoltageWriter(self.voltageModelObj) -# self.voltageWriterObj.setup('/Users/danielangelsuarezmunoz/Documents/Projects/testWR') - - - def testReadVoltage(self): - while(not(self.voltageReaderObj.noMoreFiles)): - - self.voltageReaderObj.getData() - if self.voltageReaderObj.flagResetProcessing: - print 'jump' - - if self.voltageReaderObj.flagIsNewBlock: - print 'Block No %04d, Time: %s'%(self.voltageReaderObj.nTotalBlocks, - datetime.datetime.fromtimestamp(self.voltageReaderObj.m_BasicHeader.utc)) - -# self.voltageWriterObj.putData() - -if __name__ == '__main__': - TestIO() \ No newline at end of file diff --git a/schainpy/Processing/CorrelationProcessor.py b/schainpy/Processing/CorrelationProcessor.py index 76aea48..469d0c5 100644 --- a/schainpy/Processing/CorrelationProcessor.py +++ b/schainpy/Processing/CorrelationProcessor.py @@ -15,4 +15,8 @@ class CorrelationProcessor: ''' Constructor ''' - pass \ No newline at end of file + pass + m_Correlation= Correlation() + + m_Voltage= Voltage() + diff --git a/schainpy/Processing/Noise.py b/schainpy/Processing/Noise.py index f6a75c9..fde1858 100644 --- a/schainpy/Processing/Noise.py +++ b/schainpy/Processing/Noise.py @@ -1,112 +1,112 @@ -import numpy -from Model.Spectra import Spectra - -def hildebrand_sekhon(Data, navg=1): - """ - This method is for the objective determination of de noise level in Doppler spectra. This - implementation technique is based on the fact that the standard deviation of the spectral - densities is equal to the mean spectral density for white Gaussian noise - - Inputs: - Data : heights - navg : numbers of averages - - Return: - -1 : any error - anoise : noise's level - """ - divisor = 8 - ratio = 7 / divisor - data = Data.reshape(-1) - npts = data.size #numbers of points of the data - - if npts < 32: - print "error in noise - requires at least 32 points" - return -1.0 - - # data sorted in ascending order - nmin = int(npts/divisor + ratio); - s = 0.0 - s2 = 0.0 - data2 = data[:npts] - data2.sort() - - for i in range(nmin): - s += data2[i] - s2 += data2[i]**2; - - icount = nmin - iflag = 0 - - for i in range(nmin, npts): - s += data2[i]; - s2 += data2[i]**2 - icount=icount+1; - p = s / float(icount); - p2 = p**2; - q = s2 / float(icount) - p2; - leftc = p2; - rightc = q * float(navg); - - if leftc > rightc: - iflag = 1; #No weather signal - # Signal detect: R2 < 1 (R2 = leftc/rightc) - if(leftc < rightc): - if iflag: - break - - anoise = 0.0; - for j in range(i): - anoise += data2[j]; - - anoise = anoise / float(i); - - return anoise; - - -class Noise(): - """ - Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler - """ - m_DataObj = None - - - def __init__(self, m_Spectra=None): - """ - Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. - - Affected: - self.m_DataObj - - Return: - None - """ - if m_Spectra == None: - m_Spectra = Spectra() - - if not(isinstance(m_Spectra, Spectra)): - raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" - - self.m_DataObj = m_Spectra - - - def getNoiseLevelByHildebrandSekhon(self): - """ - Determino el nivel de ruido usando el metodo Hildebrand-Sekhon - - Return: - noise level - """ - data = self.m_DataObj.data_spc - daux = None - - for channel in range(self.m_DataObj.nChannels): - daux = data[channel,:,:] - noiselevel = hildebrand_sekhon(daux) - print noiselevel - - - for pair in range(self.m_DataObj.nPairs): - daux = data[pair,:,:] - noiselevel = hildebrand_sekhon(daux) - print noiselevel +import numpy +from Model.Spectra import Spectra + +def hildebrand_sekhon(Data, navg=1): + """ + This method is for the objective determination of de noise level in Doppler spectra. This + implementation technique is based on the fact that the standard deviation of the spectral + densities is equal to the mean spectral density for white Gaussian noise + + Inputs: + Data : heights + navg : numbers of averages + + Return: + -1 : any error + anoise : noise's level + """ + divisor = 8 + ratio = 7 / divisor + data = Data.reshape(-1) + npts = data.size #numbers of points of the data + + if npts < 32: + print "error in noise - requires at least 32 points" + return -1.0 + + # data sorted in ascending order + nmin = int(npts/divisor + ratio); + s = 0.0 + s2 = 0.0 + data2 = data[:npts] + data2.sort() + + for i in range(nmin): + s += data2[i] + s2 += data2[i]**2; + + icount = nmin + iflag = 0 + + for i in range(nmin, npts): + s += data2[i]; + s2 += data2[i]**2 + icount=icount+1; + p = s / float(icount); + p2 = p**2; + q = s2 / float(icount) - p2; + leftc = p2; + rightc = q * float(navg); + + if leftc > rightc: + iflag = 1; #No weather signal + # Signal detect: R2 < 1 (R2 = leftc/rightc) + if(leftc < rightc): + if iflag: + break + + anoise = 0.0; + for j in range(i): + anoise += data2[j]; + + anoise = anoise / float(i); + + return anoise; + + +class Noise: + """ + Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler + """ + m_DataObj = None + + + def __init__(self, m_Spectra=None): + """ + Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. + + Affected: + self.m_DataObj + + Return: + None + """ + if m_Spectra == None: + m_Spectra = Spectra() + + if not(isinstance(m_Spectra, Spectra)): + raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" + + self.m_DataObj = m_Spectra + + + def getNoiseLevelByHildebrandSekhon(self): + """ + Determino el nivel de ruido usando el metodo Hildebrand-Sekhon + + Return: + noise level + """ + data = self.m_DataObj.data_spc + daux = None + + for channel in range(self.m_DataObj.nChannels): + daux = data[channel,:,:] + noiselevel = hildebrand_sekhon(daux) + print noiselevel + + + for pair in range(self.m_DataObj.nPairs): + daux = data[pair,:,:] + noiselevel = hildebrand_sekhon(daux) + print noiselevel diff --git a/schainpy/Processing/SpectraProcessor.py b/schainpy/Processing/SpectraProcessor.py index cb3d369..e4991e8 100644 --- a/schainpy/Processing/SpectraProcessor.py +++ b/schainpy/Processing/SpectraProcessor.py @@ -20,6 +20,40 @@ class SpectraProcessor: classdocs ''' + dataInObj = None + + dataOutObj = None + + integratorObjIndex = None + + decoderObjIndex = None + + writerObjIndex = None + + plotterObjIndex = None + + integratorObjList = [] + + decoderObjList = [] + + writerObjList = [] + + plotterObjList = [] + + buffer = None + + ptsId = 0 + + nFFTPoints = None + + pairList = None + m_Spectra= Spectra() + + m_Voltage= Voltage() + + m_IncoherentIntegration= IncoherentIntegration() + + def __init__(self, dataInObj, dataOutObj=None): ''' Constructor @@ -31,25 +65,25 @@ class SpectraProcessor: else: self.dataOutObj = dataOutObj - self.integratorIndex = None - self.decoderIndex = None - self.writerIndex = None - self.plotterIndex = None + self.integratorObjIndex = None + self.decoderObjIndex = None + self.writerObjIndex = None + self.plotterObjIndex = None - self.integratorList = [] - self.decoderList = [] - self.writerList = [] - self.plotterList = [] + self.integratorObjList = [] + self.decoderObjList = [] + self.writerObjList = [] + self.plotterObjList = [] self.buffer = None self.ptsId = 0 def init(self, nFFTPoints, pairList=None): - self.integratorIndex = 0 - self.decoderIndex = 0 - self.writerIndex = 0 - self.plotterIndex = 0 + self.integratorObjIndex = 0 + self.decoderObjIndex = 0 + self.writerObjIndex = 0 + self.plotterObjIndex = 0 if nFFTPoints == None: nFFTPoints = self.dataOutObj.nFFTPoints @@ -179,54 +213,54 @@ class SpectraProcessor: def addWriter(self,wrpath): objWriter = SpectraWriter(self.dataOutObj) objWriter.setup(wrpath) - self.writerList.append(objWriter) + self.writerObjList.append(objWriter) def addPlotter(self, index=None): if index==None: - index = self.plotterIndex + index = self.plotterObjIndex plotObj = Spectrum(self.dataOutObj, index) - self.plotterList.append(plotObj) + self.plotterObjList.append(plotObj) def addIntegrator(self,N): objIncohInt = IncoherentIntegration(N) - self.integratorList.append(objIncohInt) + self.integratorObjList.append(objIncohInt) def writeData(self, wrpath): if self.dataOutObj.flagNoData: return 0 - if len(self.writerList) <= self.writerIndex: + if len(self.writerObjList) <= self.writerObjIndex: self.addWriter(wrpath) - self.writerList[self.writerIndex].putData() + self.writerObjList[self.writerObjIndex].putData() - self.writerIndex += 1 + self.writerObjIndex += 1 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): if self.dataOutObj.flagNoData: return 0 - if len(self.plotterList) <= self.plotterIndex: + if len(self.plotterObjList) <= self.plotterObjIndex: self.addPlotter(index) - self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) + self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) - self.plotterIndex += 1 + self.plotterObjIndex += 1 def integrator(self, N): if self.dataOutObj.flagNoData: return 0 - if len(self.integratorList) <= self.integratorIndex: + if len(self.integratorObjList) <= self.integratorObjIndex: self.addIntegrator(N) - myCohIntObj = self.integratorList[self.integratorIndex] + myCohIntObj = self.integratorObjList[self.integratorObjIndex] myCohIntObj.exe(self.dataOutObj.data_spc) if myCohIntObj.flag: @@ -237,7 +271,7 @@ class SpectraProcessor: else: self.dataOutObj.flagNoData = True - self.integratorIndex += 1 + self.integratorObjIndex += 1 def removeDC(self, type): @@ -485,7 +519,15 @@ class SpectraProcessor: class IncoherentIntegration: + + profCounter = 1 + data = None + buffer = None + flag = False + nIncohInt = None + def __init__(self, N): + self.profCounter = 1 self.data = None self.buffer = None diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py index c58d5a4..bda65a8 100644 --- a/schainpy/Processing/VoltageProcessor.py +++ b/schainpy/Processing/VoltageProcessor.py @@ -19,134 +19,157 @@ class VoltageProcessor: ''' classdocs ''' + + dataInObj = None + dataOutObj = None + + integratorObjIndex = None + decoderObjIndex = None + profSelectorObjIndex = None + writerObjIndex = None + plotterObjIndex = None + + integratorObjList = [] + decoderObjList = [] + profileSelectorObjList = [] + writerObjList = [] + plotterObjList = [] + m_Voltage= Voltage() + + m_ProfileSelector= ProfileSelector() - def __init__(self, voltageInObj, voltageOutObj=None): + m_Decoder= Decoder() + + m_CoherentIntegrator= CoherentIntegrator() + + + def __init__(self, dataInObj, dataOutObj=None): ''' Constructor ''' - self.voltageInObj = voltageInObj + self.dataInObj = dataInObj - if voltageOutObj == None: - self.voltageOutObj = Voltage() + if dataOutObj == None: + self.dataOutObj = Voltage() else: - self.voltageOutObj = voltageOutObj + self.dataOutObj = dataOutObj - self.integratorIndex = None - self.decoderIndex = None - self.profSelectorIndex = None - self.writerIndex = None - self.plotterIndex = None - - self.integratorList = [] - self.decoderList = [] - self.profileSelectorList = [] - self.writerList = [] - self.plotterList = [] + self.integratorObjIndex = None + self.decoderObjIndex = None + self.profSelectorObjIndex = None + self.writerObjIndex = None + self.plotterObjIndex = None + + self.integratorObjList = [] + self.decoderObjList = [] + self.profileSelectorObjList = [] + self.writerObjList = [] + self.plotterObjList = [] def init(self): - self.integratorIndex = 0 - self.decoderIndex = 0 - self.profSelectorIndex = 0 - self.writerIndex = 0 - self.plotterIndex = 0 - self.voltageOutObj.copy(self.voltageInObj) + self.integratorObjIndex = 0 + self.decoderObjIndex = 0 + self.profSelectorObjIndex = 0 + self.writerObjIndex = 0 + self.plotterObjIndex = 0 + self.dataOutObj.copy(self.dataInObj) def addWriter(self, wrpath): - objWriter = VoltageWriter(self.voltageOutObj) + objWriter = VoltageWriter(self.dataOutObj) objWriter.setup(wrpath) - self.writerList.append(objWriter) + self.writerObjList.append(objWriter) def addPlotter(self): - plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex) - self.plotterList.append(plotObj) + plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex) + self.plotterObjList.append(plotObj) def addIntegrator(self, nCohInt): objCohInt = CoherentIntegrator(nCohInt) - self.integratorList.append(objCohInt) + self.integratorObjList.append(objCohInt) def addDecoder(self, code, ncode, nbaud): objDecoder = Decoder(code,ncode,nbaud) - self.decoderList.append(objDecoder) + self.decoderObjList.append(objDecoder) def addProfileSelector(self, nProfiles): objProfSelector = ProfileSelector(nProfiles) - self.profileSelectorList.append(objProfSelector) + self.profileSelectorObjList.append(objProfSelector) def writeData(self,wrpath): - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if len(self.writerList) <= self.writerIndex: + if len(self.writerObjList) <= self.writerObjIndex: self.addWriter(wrpath) - self.writerList[self.writerIndex].putData() + self.writerObjList[self.writerObjIndex].putData() -# myWrObj = self.writerList[self.writerIndex] +# myWrObj = self.writerObjList[self.writerObjIndex] # myWrObj.putData() - self.writerIndex += 1 + self.writerObjIndex += 1 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if len(self.plotterList) <= self.plotterIndex: + if len(self.plotterObjList) <= self.plotterObjIndex: self.addPlotter() - self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) + self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) - self.plotterIndex += 1 + self.plotterObjIndex += 1 def integrator(self, N): - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if len(self.integratorList) <= self.integratorIndex: + if len(self.integratorObjList) <= self.integratorObjIndex: self.addIntegrator(N) - myCohIntObj = self.integratorList[self.integratorIndex] - myCohIntObj.exe(self.voltageOutObj.data) + myCohIntObj = self.integratorObjList[self.integratorObjIndex] + myCohIntObj.exe(self.dataOutObj.data) if myCohIntObj.flag: - self.voltageOutObj.data = myCohIntObj.data - self.voltageOutObj.m_ProcessingHeader.coherentInt *= N - self.voltageOutObj.flagNoData = False + self.dataOutObj.data = myCohIntObj.data + self.dataOutObj.m_ProcessingHeader.coherentInt *= N + self.dataOutObj.flagNoData = False else: - self.voltageOutObj.flagNoData = True + self.dataOutObj.flagNoData = True - self.integratorIndex += 1 + self.integratorObjIndex += 1 def decoder(self,code=None,type = 0): - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 if code == None: - code = self.voltageOutObj.m_RadarControllerHeader.code + code = self.dataOutObj.m_RadarControllerHeader.code ncode, nbaud = code.shape - if len(self.decoderList) <= self.decoderIndex: + if len(self.decoderObjList) <= self.decoderObjIndex: self.addDecoder(code,ncode,nbaud) - myDecodObj = self.decoderList[self.decoderIndex] - myDecodObj.exe(data=self.voltageOutObj.data,type=type) + myDecodObj = self.decoderObjList[self.decoderObjIndex] + myDecodObj.exe(data=self.dataOutObj.data,type=type) if myDecodObj.flag: - self.voltageOutObj.data = myDecodObj.data - self.voltageOutObj.flagNoData = False + self.dataOutObj.data = myDecodObj.data + self.dataOutObj.flagNoData = False else: - self.voltageOutObj.flagNoData = True + self.dataOutObj.flagNoData = True - self.decoderIndex += 1 + self.decoderObjIndex += 1 def filterByHei(self, window): @@ -162,36 +185,36 @@ class VoltageProcessor: Affected: self.dataOutObj.data - self.voltageOutObj.channelList + self.dataOutObj.channelList self.dataOutObj.nChannels - self.voltageOutObj.m_ProcessingHeader.totalSpectra + self.dataOutObj.m_ProcessingHeader.totalSpectra self.dataOutObj.m_SystemHeader.numChannels - self.voltageOutObj.m_ProcessingHeader.blockSize + self.dataOutObj.m_ProcessingHeader.blockSize Return: None """ - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 for channel in channelList: - if channel not in self.voltageOutObj.channelList: + if channel not in self.dataOutObj.channelList: raise ValueError, "The value %d in channelList is not valid" %channel nchannels = len(channelList) - profiles = self.voltageOutObj.nProfiles - heights = self.voltageOutObj.nHeights #m_ProcessingHeader.numHeights + profiles = self.dataOutObj.nProfiles + heights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights data = numpy.zeros( (nchannels,heights), dtype='complex' ) for index,channel in enumerate(channelList): - data[index,:] = self.voltageOutObj.data[channel,:] + data[index,:] = self.dataOutObj.data[channel,:] - self.voltageOutObj.data = data - self.voltageOutObj.channelList = channelList - self.voltageOutObj.nChannels = nchannels - self.voltageOutObj.m_ProcessingHeader.totalSpectra = nchannels - self.voltageOutObj.m_SystemHeader.numChannels = nchannels - self.voltageOutObj.m_ProcessingHeader.blockSize = data.size + self.dataOutObj.data = data + self.dataOutObj.channelList = channelList + self.dataOutObj.nChannels = nchannels + self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels + self.dataOutObj.m_SystemHeader.numChannels = nchannels + self.dataOutObj.m_ProcessingHeader.blockSize = data.size return 1 @@ -210,18 +233,18 @@ class VoltageProcessor: Return: 1 si el metodo se ejecuto con exito caso contrario devuelve 0 """ - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if (minHei < self.voltageOutObj.heightList[0]) or (minHei > maxHei): + if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) - if (maxHei > self.voltageOutObj.heightList[-1]): + if (maxHei > self.dataOutObj.heightList[-1]): raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) minIndex = 0 maxIndex = 0 - data = self.voltageOutObj.heightList + data = self.dataOutObj.heightList for i,val in enumerate(data): if val < minHei: @@ -250,41 +273,41 @@ class VoltageProcessor: maxIndex : valor de indice maximo de altura a considerar Affected: - self.voltageOutObj.data - self.voltageOutObj.heightList - self.voltageOutObj.nHeights - self.voltageOutObj.m_ProcessingHeader.blockSize - self.voltageOutObj.m_ProcessingHeader.numHeights - self.voltageOutObj.m_ProcessingHeader.firstHeight - self.voltageOutObj.m_RadarControllerHeader + self.dataOutObj.data + self.dataOutObj.heightList + self.dataOutObj.nHeights + self.dataOutObj.m_ProcessingHeader.blockSize + self.dataOutObj.m_ProcessingHeader.numHeights + self.dataOutObj.m_ProcessingHeader.firstHeight + self.dataOutObj.m_RadarControllerHeader Return: 1 si el metodo se ejecuto con exito caso contrario devuelve 0 """ - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 if (minIndex < 0) or (minIndex > maxIndex): raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) - if (maxIndex >= self.voltageOutObj.nHeights): + if (maxIndex >= self.dataOutObj.nHeights): raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) nHeights = maxIndex - minIndex + 1 firstHeight = 0 #voltage - data = self.voltageOutObj.data[:,minIndex:maxIndex+1] + data = self.dataOutObj.data[:,minIndex:maxIndex+1] - firstHeight = self.voltageOutObj.heightList[minIndex] + firstHeight = self.dataOutObj.heightList[minIndex] - self.voltageOutObj.data = data - self.voltageOutObj.heightList = self.voltageOutObj.heightList[minIndex:maxIndex+1] - self.voltageOutObj.nHeights = nHeights - self.voltageOutObj.m_ProcessingHeader.blockSize = data.size - self.voltageOutObj.m_ProcessingHeader.numHeights = nHeights - self.voltageOutObj.m_ProcessingHeader.firstHeight = firstHeight - self.voltageOutObj.m_RadarControllerHeader.numHeights = nHeights + self.dataOutObj.data = data + self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] + self.dataOutObj.nHeights = nHeights + self.dataOutObj.m_ProcessingHeader.blockSize = data.size + self.dataOutObj.m_ProcessingHeader.numHeights = nHeights + self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight + self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights return 1 @@ -299,28 +322,28 @@ class VoltageProcessor: nProfiles : numero de profiles Affected: - self.voltageOutObj.flagNoData - self.profSelectorIndex + self.dataOutObj.flagNoData + self.profSelectorObjIndex Return: 1 si el metodo se ejecuto con exito caso contrario devuelve 0 """ - if self.voltageOutObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if self.profSelectorIndex >= len(self.profileSelectorList): + if self.profSelectorObjIndex >= len(self.profileSelectorObjList): self.addProfileSelector(nProfiles) - profileSelectorObj = self.profileSelectorList[self.profSelectorIndex] + profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] if profileSelectorObj.isProfileInRange(minIndex, maxIndex): - self.voltageOutObj.flagNoData = False - self.profSelectorIndex += 1 + self.dataOutObj.flagNoData = False + self.profSelectorObjIndex += 1 return 1 - self.voltageOutObj.flagNoData = True - self.profSelectorIndex += 1 + self.dataOutObj.flagNoData = True + self.profSelectorObjIndex += 1 return 0 @@ -329,10 +352,20 @@ class VoltageProcessor: class Decoder: + + data = None + profCounter = 1 + nCode = ncode + nBaud = nbaud + codeIndex = 0 + code = code #this is a List + fft_code = None + flag = False + setCodeFft = False def __init__(self,code, ncode, nbaud): - self.buffer = None + self.data = None self.profCounter = 1 self.nCode = ncode self.nBaud = nbaud @@ -400,6 +433,12 @@ class Decoder: class CoherentIntegrator: + profCounter = 1 + data = None + buffer = None + flag = False + nCohInt = N + def __init__(self, N): self.profCounter = 1 @@ -425,7 +464,7 @@ class CoherentIntegrator: self.profCounter += 1 -class ProfileSelector(): +class ProfileSelector: indexProfile = None # Tamanho total de los perfiles diff --git a/schainpy/TestDataSChain.py b/schainpy/TestDataSChain.py deleted file mode 100644 index 8ac8fcf..0000000 --- a/schainpy/TestDataSChain.py +++ /dev/null @@ -1,73 +0,0 @@ -''' -Created on 23/01/2012 - -@author $Author$ -@version $Id$ -''' -import os, sys -import time, datetime - -from Model.JROData import JROData -from IO.DataIO import * -#=============================================================================== -# from Graphics.DataPlot import Osciloscope -# -# from Model.Spectra import Spectra -# from IO.SpectraIO import * -# from Graphics.SpectraPlot import Spectrum -#=============================================================================== - -class TestSChain(): - - - def __init__(self): - self.setValues() - self.createObjects() - self.testSChain() - pass - - def setValues(self): - - #self.path = "/home/valentin/Tmp/RAWDATA" - self.path = "/home/dsuarez/Projects" - #self.wrpath = "/home/dsuarez/Projects/testWR" - self.startDateTime = datetime.datetime(2007,5,1,15,49,0) - self.endDateTime = datetime.datetime(2007,5,1,16,0,0) - - def createObjects(self): - - self.Obj = JROData() - self.readerObj = JRODataReader(self.Obj) - #self.plotObj = Spectrum(self.Obj) - - if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, ext = '.pdata', expLabel='', online =1)): - sys.exit(0) - - def testSChain(self): - - ini = time.time() - while(True): - if self.readerObj.getData(): - print "", - #self.plotObj.plotData(zmin=40, zmax=140, showColorbar=True, showPowerProfile=True) - -# self.writerObj.putData() - - - if self.readerObj.noMoreFiles: - break - - if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks: - print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, - datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) - #=============================================================== - # fin = time.time() - # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) - # ini = time.time() - #=============================================================== - - #time.sleep(0.5) - self.plotObj.end() - -if __name__ == '__main__': - TestSChain() \ No newline at end of file diff --git a/schainpy/TestSpectraSChain.py b/schainpy/TestSpectraSChain.py deleted file mode 100644 index d3b3712..0000000 --- a/schainpy/TestSpectraSChain.py +++ /dev/null @@ -1,72 +0,0 @@ -''' -Created on 23/01/2012 - -@author $Author$ -@version $Id$ -''' -import os, sys -import time, datetime - -from Model.Voltage import Voltage -from IO.VoltageIO import * -from Graphics.VoltagePlot import Osciloscope - -from Model.Spectra import Spectra -from IO.SpectraIO import * -from Graphics.SpectraPlot import Spectrum - -class TestSChain(): - - def __init__(self): - self.setValues() - self.createObjects() - self.testSChain() - pass - - def setValues(self): - - #self.path = "/home/valentin/Tmp/RAWDATA" - self.path = "/home/valentin/Tmp/RAWDATA" - self.startDateTime = datetime.datetime(2009,11,2,00,00,0) - self.endDateTime = datetime.datetime(2009,11,30,18,10,0) - - def createObjects(self): - - self.Obj = Spectra() - self.readerObj = SpectraReader(self.Obj) - self.plotObj = Spectrum(self.Obj) -# self.writerObj = SpectraWriter(self.Obj) - - if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='', online =1)): #self.startDateTime - sys.exit(0) - -# if not(self.writerObj.setup(self.ppath)): -# sys.exit(0) - - def testSChain(self): - - ini = time.time() - while(True): - if self.readerObj.getData(): - self.plotObj.plotData(showColorbar=True, showPowerProfile=True) #zmin=40, zmax=140, - -# self.writerObj.putData() - - - if self.readerObj.flagNoMoreFiles: - break - - if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks: - print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, - datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) - #=============================================================== - # fin = time.time() - # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) - # ini = time.time() - #=============================================================== - - #time.sleep(0.5) - self.plotObj.end() - -if __name__ == '__main__': - TestSChain() \ No newline at end of file diff --git a/schainpy/TestSpectraWriteChain.py b/schainpy/TestSpectraWriteChain.py deleted file mode 100644 index 16fe995..0000000 --- a/schainpy/TestSpectraWriteChain.py +++ /dev/null @@ -1,73 +0,0 @@ -''' -Created on 20/03/2012 - -@author $Author$ -@version $Id$ -''' -import os, sys -import time, datetime - -from Model.Voltage import Voltage -from IO.VoltageIO import * -from Graphics.VoltagePlot import Osciloscope - -from Model.Spectra import Spectra -from IO.SpectraIO import * -from Graphics.SpectraPlot import Spectrum - -class TestSChain(): - - def __init__(self): - self.setValues() - self.createObjects() - self.testSChain() - pass - - def setValues(self): - self.srcPath = "/home/valentin/Tmp/RAWDATA" - self.dstPath = "/home/valentin/Tmp/RAWDATA2" - self.startDateTime = datetime.datetime(2009,11,1,00,00,0) #4 - self.endDateTime = datetime.datetime(2009,11,30,18,10,0) - - def createObjects(self): - - self.Obj = Spectra() - self.readerObj = SpectraReader(self.Obj) - self.writerObj = SpectraWriter(self.Obj) - self.plotObj = Spectrum(self.Obj) - - if not( self.readerObj.setup(self.srcPath, self.startDateTime, self.endDateTime, expLabel='', online =0) ): - sys.exit(0) - - if not( self.writerObj.setup(path=self.dstPath) ): sys.exit(0) - - - def testSChain(self): - - ini = time.time() - while(True): - if self.readerObj.getData(): - self.plotObj.plotData( zmin=35, zmax=100, showColorbar=True, showPowerProfile=True) - -################################################################################### - #time.sleep( 2 ) - self.writerObj.putData() -################################################################################### - - if self.readerObj.flagNoMoreFiles: - break - - if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks: - print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, - datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc)) - #=============================================================== - # fin = time.time() - # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) - # ini = time.time() - #=============================================================== - - #time.sleep(0.5) - self.plotObj.end() - -if __name__ == '__main__': - TestSChain() \ No newline at end of file diff --git a/schainpy/TestVoltageWriteChain.py b/schainpy/TestVoltageWriteChain.py deleted file mode 100644 index b60eb29..0000000 --- a/schainpy/TestVoltageWriteChain.py +++ /dev/null @@ -1,67 +0,0 @@ -''' -Created on 20/03/2012 - -@author $Author$ -@version $Id$ -''' -import os, sys -import time, datetime - -from Model.Voltage import Voltage -from IO.VoltageIO import * -from Graphics.VoltagePlot import Osciloscope - -class TestSChain(): - - def __init__(self): - self.setValues() - self.createObjects() - self.testSChain() - pass - - def setValues(self): - self.srcPath = "/home/valentin/Tmp/VOLTAGE" - self.dstPath = "/home/valentin/Tmp/VOLTAGE2" - self.startDateTime = datetime.datetime(2011,10,4,00,00,0) - self.endDateTime = datetime.datetime(2011,10,31,23,59,59) - - def createObjects(self): - - self.Obj = Voltage() - self.readerObj = VoltageReader(self.Obj) - self.writerObj = VoltageWriter(self.Obj) - self.plotObj = Osciloscope(self.Obj) - - if not( self.readerObj.setup(self.srcPath, self.startDateTime, self.endDateTime, expLabel='', ext = '.r', online =0) ): - sys.exit(0) - - if not( self.writerObj.setup(path=self.dstPath) ): sys.exit(0) - - def testSChain( self ): - - n = 0 - ini = time.time() - while(True): - if self.readerObj.getData(): - self.plotObj.plotData(idProfile=0, type='power' ) - -################################################################################### - #time.sleep( 0.001 ) - self.writerObj.putData() -################################################################################### - - if self.readerObj.flagNoMoreFiles: - break - - if self.readerObj.flagIsNewBlock: - print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks, - datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) - #fin = time.time() - #print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) - #ini = time.time() - - #time.sleep(0.5) - self.plotObj.end() - -if __name__ == '__main__': - TestSChain() \ No newline at end of file