diff --git a/schainpy/Graphics/BaseGraph.py b/schainpy/Graphics/BaseGraph.py index 74d4b52..6fe6017 100644 --- a/schainpy/Graphics/BaseGraph.py +++ b/schainpy/Graphics/BaseGraph.py @@ -9,6 +9,141 @@ Created on Feb 7, 2012 import numpy import plplot +def cmap1_init(colormap="gray"): + + ncolor = None + rgb_lvl = None + + # Routine for defining a specific color map 1 in HLS space. + # if gray is true, use basic grayscale variation from half-dark to light. + # otherwise use false color variation from blue (240 deg) to red (360 deg). + + # Independent variable of control points. + i = numpy.array((0., 1.)) + if colormap=="gray": + ncolor = 256 + # Hue for control points. Doesn't matter since saturation is zero. + h = numpy.array((0., 0.)) + # Lightness ranging from half-dark (for interest) to light. + l = numpy.array((0.5, 1.)) + # Gray scale has zero saturation + s = numpy.array((0., 0.)) + + # number of cmap1 colours is 256 in this case. + plplot.plscmap1n(ncolor) + # Interpolate between control points to set up cmap1. + plplot.plscmap1l(0, i, h, l, s) + + return None + + if colormap=="br_green": + ncolor = 256 + # Hue ranges from blue (240 deg) to red (0 or 360 deg) + h = numpy.array((240., 0.)) + # Lightness and saturation are constant (values taken from C example). + l = numpy.array((0.6, 0.6)) + s = numpy.array((0.8, 0.8)) + + # number of cmap1 colours is 256 in this case. + plplot.plscmap1n(ncolor) + # Interpolate between control points to set up cmap1. + plplot.plscmap1l(0, i, h, l, s) + + return None + + if colormap=="tricolor": + ncolor = 3 + # Hue ranges from blue (240 deg) to red (0 or 360 deg) + h = numpy.array((240., 0.)) + # Lightness and saturation are constant (values taken from C example). + l = numpy.array((0.6, 0.6)) + s = numpy.array((0.8, 0.8)) + + # number of cmap1 colours is 256 in this case. + plplot.plscmap1n(ncolor) + # Interpolate between control points to set up cmap1. + plplot.plscmap1l(0, i, h, l, s) + + return None + + if colormap == 'rgb' or colormap == 'rgb666': + + color_sz = 6 + ncolor = color_sz*color_sz*color_sz + pos = numpy.zeros((ncolor)) + r = numpy.zeros((ncolor)) + g = numpy.zeros((ncolor)) + b = numpy.zeros((ncolor)) + ind = 0 + for ri in range(color_sz): + for gi in range(color_sz): + for bi in range(color_sz): + r[ind] = ri/(color_sz-1.0) + g[ind] = gi/(color_sz-1.0) + b[ind] = bi/(color_sz-1.0) + pos[ind] = ind/(ncolor-1.0) + ind += 1 + rgb_lvl = [6,6,6] #Levels for RGB colors + + if colormap == 'rgb676': + ncolor = 6*7*6 + pos = numpy.zeros((ncolor)) + r = numpy.zeros((ncolor)) + g = numpy.zeros((ncolor)) + b = numpy.zeros((ncolor)) + ind = 0 + for ri in range(8): + for gi in range(8): + for bi in range(4): + r[ind] = ri/(6-1.0) + g[ind] = gi/(7-1.0) + b[ind] = bi/(6-1.0) + pos[ind] = ind/(ncolor-1.0) + ind += 1 + rgb_lvl = [6,7,6] #Levels for RGB colors + + if colormap == 'rgb685': + ncolor = 6*8*5 + pos = numpy.zeros((ncolor)) + r = numpy.zeros((ncolor)) + g = numpy.zeros((ncolor)) + b = numpy.zeros((ncolor)) + ind = 0 + for ri in range(8): + for gi in range(8): + for bi in range(4): + r[ind] = ri/(6-1.0) + g[ind] = gi/(8-1.0) + b[ind] = bi/(5-1.0) + pos[ind] = ind/(ncolor-1.0) + ind += 1 + rgb_lvl = [6,8,5] #Levels for RGB colors + + if colormap == 'rgb884': + ncolor = 8*8*4 + pos = numpy.zeros((ncolor)) + r = numpy.zeros((ncolor)) + g = numpy.zeros((ncolor)) + b = numpy.zeros((ncolor)) + ind = 0 + for ri in range(8): + for gi in range(8): + for bi in range(4): + r[ind] = ri/(8-1.0) + g[ind] = gi/(8-1.0) + b[ind] = bi/(4-1.0) + pos[ind] = ind/(ncolor-1.0) + ind += 1 + rgb_lvl = [8,8,4] #Levels for RGB colors + + if ncolor == None: + raise ValueError, "The colormap selected is not valid" + + plplot.plscmap1n(ncolor) + plplot.plscmap1l(1, pos, r, g, b) + + return rgb_lvl + class BaseGraph: """ @@ -97,7 +232,6 @@ class BaseGraph: data = numpy.arange(256) data = numpy.reshape(data, (1,-1)) - self.plotBox(xmin, xmax, ymin, ymax) plplot.plimage(data, float(xmin), float(xmax), @@ -197,7 +331,9 @@ class LinearPlot(): key = "linearplot" self.m_BaseGraph = BaseGraph() self.m_BaseGraph.setName(key) - + + self.__subpage = 0 + def setColormap(self, colormap="br_green"): if colormap == None: @@ -307,6 +443,177 @@ class LinearPlot(): self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) class ColorPlot(): + + def __init__(self): + + self.graphObjDict = {} + + self.__subpage = 0 + self.__showColorbar = False + self.__showPowerProfile = True + + self.__szchar = 0.7 + self.__xrange = None + self.__yrange = None + self.__zrange = None + + key = "colorplot" + self.m_BaseGraph = BaseGraph() + self.m_BaseGraph.setName(key) + + def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): + """ + """ + + self.m_BaseGraph.setOpt("bcnts","bcntsv") + self.m_BaseGraph.setup(title, + xlabel, + ylabel + ) + + self.__subpage = subpage + self.__colormap = colormap + self.__showColorbar = showColorbar + self.__showPowerProfile = showPowerProfile + + if showColorbar: + key = "colorbar" + + cmapObj = BaseGraph() + cmapObj.setName(key) + cmapObj.setOpt("bc","bcmt") + cmapObj.setup(title="dBs", + xlabel="", + ylabel="", + colormap=colormap) + + self.graphObjDict[key] = cmapObj + + + if showPowerProfile: + key = "powerprof" + + powObj = BaseGraph() + powObj.setName(key) + powObj.setOpt("bcntg","bc") + powObj.setup(title="Power Profile", + xlabel="dBs", + ylabel="") + + self.graphObjDict[key] = powObj + + self.setScreenPos(width='small') + + if XAxisAsTime: + self.m_BaseGraph.setXAxisAsTime() + + + + def setColormap(self, colormap="br_green"): + + if colormap == None: + colormap = self.__colormap + + cmap1_init(colormap) + + def iniSubpage(self): + + if plplot.plgdev() == '': + raise ValueError, "Plot device has not been initialize" + + plplot.pladv(self.__subpage) + plplot.plschr(0.0, self.__szchar) + + self.setColormap() + + def setScreenPos(self, width='small'): + + if width == 'small': + xi = 0.12; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.05; xpoww = 0.26; deltaxcmap = 0.02; deltaxpow = 0.06 + + if width == 'medium': + xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; 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 plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + """ + Inputs: + + x : Numpy array of dimension 1 + y : Numpy array of dimension 1 + + """ + + try: + nX, nY = numpy.shape(data) + except: + raise ValueError, "data is not a numpy array" + + if x == None: x = numpy.arange(nX) + if y == None: y = numpy.arange(nY) + + if xmin == None: xmin = x[0] + if xmax == None: xmax = x[-1] + if ymin == None: ymin = y[0] + if ymax == None: ymax = y[-1] + if zmin == None: zmin = numpy.nanmin(data) + if zmax == None: zmax = numpy.nanmax(data) + + self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) + self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) + + if self.__showColorbar: + key = "colorbar" + cmapObj = self.graphObjDict[key] + cmapObj.plotBox(0., 1., zmin, zmax) + cmapObj.colorbarPlot(0., 1., zmin, zmax) + + if self.__showPowerProfile: + power = numpy.average(data, axis=0) + + step = (ymax - ymin)/(nY-1) + heis = numpy.arange(ymin, ymax + step, step) + + key = "powerprof" + powObj = self.graphObjDict[key] + + plplot.pllsty(2) + powObj.plotBox(zmin, zmax, ymin, ymax) + plplot.pllsty(1) + powObj.basicXYPlot(power, heis) + + +class ColorPlotX(): graphObjDict = {} @@ -325,8 +632,27 @@ class ColorPlot(): key = "colorplot" self.m_BaseGraph.setName(key) + self.__subpage = 0 + self.graphObjDict[key] = self.m_BaseGraph - + + def setColormap(self, colormap="br_green"): + + if colormap == None: + colormap = self.__colormap + + cmap1_init(colormap) + + def iniSubpage(self): + + if plplot.plgdev() == '': + raise ValueError, "Plot device has not been initialize" + + plplot.pladv(self.__subpage) + plplot.plschr(0.0, self.__szchar) + + self.setColormap() + def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): """ """ @@ -467,137 +793,52 @@ class ColorPlot(): powObj = self.graphObjDict[key] powObj.basicXYPlot(power, heis) -def cmap1_init(colormap="gray"): +if __name__ == '__main__': - ncolor = None - rgb_lvl = None + import numpy + plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) + plplot.plsdev("xwin") + plplot.plscolbg(255,255,255) + plplot.plscol0(1,0,0,0) + plplot.plspause(False) + plplot.plinit() + plplot.plssub(2, 2) - # Routine for defining a specific color map 1 in HLS space. - # if gray is true, use basic grayscale variation from half-dark to light. - # otherwise use false color variation from blue (240 deg) to red (360 deg). - - # Independent variable of control points. - i = numpy.array((0., 1.)) - if colormap=="gray": - ncolor = 256 - # Hue for control points. Doesn't matter since saturation is zero. - h = numpy.array((0., 0.)) - # Lightness ranging from half-dark (for interest) to light. - l = numpy.array((0.5, 1.)) - # Gray scale has zero saturation - s = numpy.array((0., 0.)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) - - return None - - if colormap=="br_green": - ncolor = 256 - # Hue ranges from blue (240 deg) to red (0 or 360 deg) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) - - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) - - return None + nx = 64 + ny = 100 - if colormap=="tricolor": - ncolor = 3 - # Hue ranges from blue (240 deg) to red (0 or 360 deg) - h = numpy.array((240., 0.)) - # Lightness and saturation are constant (values taken from C example). - l = numpy.array((0.6, 0.6)) - s = numpy.array((0.8, 0.8)) + data = numpy.random.uniform(-50,50,(nx,ny)) + + baseObj = ColorPlot() + specObj = ColorPlot() + baseObj1 = ColorPlot() + specObj1 = ColorPlot() + + baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) + specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) - # number of cmap1 colours is 256 in this case. - plplot.plscmap1n(ncolor) - # Interpolate between control points to set up cmap1. - plplot.plscmap1l(0, i, h, l, s) + baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) + specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) - return None + data = numpy.random.uniform(-50,50,(nx,ny)) - if colormap == 'rgb' or colormap == 'rgb666': - - color_sz = 6 - ncolor = color_sz*color_sz*color_sz - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(color_sz): - for gi in range(color_sz): - for bi in range(color_sz): - r[ind] = ri/(color_sz-1.0) - g[ind] = gi/(color_sz-1.0) - b[ind] = bi/(color_sz-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,6,6] #Levels for RGB colors - - if colormap == 'rgb676': - ncolor = 6*7*6 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(7-1.0) - b[ind] = bi/(6-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,7,6] #Levels for RGB colors + plplot.plbop() + baseObj.iniSubpage() + baseObj.plotData(data) - if colormap == 'rgb685': - ncolor = 6*8*5 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(6-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(5-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [6,8,5] #Levels for RGB colors - - if colormap == 'rgb884': - ncolor = 8*8*4 - pos = numpy.zeros((ncolor)) - r = numpy.zeros((ncolor)) - g = numpy.zeros((ncolor)) - b = numpy.zeros((ncolor)) - ind = 0 - for ri in range(8): - for gi in range(8): - for bi in range(4): - r[ind] = ri/(8-1.0) - g[ind] = gi/(8-1.0) - b[ind] = bi/(4-1.0) - pos[ind] = ind/(ncolor-1.0) - ind += 1 - rgb_lvl = [8,8,4] #Levels for RGB colors + specObj.iniSubpage() + specObj.plotData(data) - if ncolor == None: - raise ValueError, "The colormap selected is not valid" + baseObj1.iniSubpage() + baseObj1.plotData(data) - plplot.plscmap1n(ncolor) - plplot.plscmap1l(1, pos, r, g, b) + specObj1.iniSubpage() + specObj1.plotData(data) - return rgb_lvl \ No newline at end of file + plplot.plflush() + + plplot.plspause(1) + plplot.plend() + exit(0) + + diff --git a/schainpy/Graphics/SpectraPlot.py b/schainpy/Graphics/SpectraPlot.py index 9255b6a..918971b 100644 --- a/schainpy/Graphics/SpectraPlot.py +++ b/schainpy/Graphics/SpectraPlot.py @@ -5,230 +5,145 @@ Created on Feb 7, 2012 @version $Id$ ''' +import os, sys import numpy import plplot -from BaseGraph import * +path = os.path.split(os.getcwd())[0] +sys.path.append(path) -class Spectrum: - - graphObjDict = {} - showColorbar = False - showPowerProfile = True - - __szchar = 0.7 - __xrange = None - __yrange = None - __zrange = None - baseObj = BaseGraph() +from Graphics.BaseGraph import * +from Model.Spectra import Spectra +class Spectrum(): - def __init__(self): - - key = "spec" + def __init__(self, Spectra): - baseObj = BaseGraph() - baseObj.setName(key) - - self.graphObjDict[key] = baseObj - - - def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False): """ - """ - - xi = 0.12; xw = 0.78; xf = xi + xw - yi = 0.14; yw = 0.80; yf = yi + yw - - xcmapi = xcmapf = 0.; xpowi = xpowf = 0. - - key = "spec" - baseObj = self.graphObjDict[key] - baseObj.setSubpage(subpage) - baseObj.setSzchar(self.__szchar) - baseObj.setOpt("bcnts","bcnts") - baseObj.setup(title, - xlabel, - ylabel, - colormap) - - if showColorbar: - key = "colorbar" - - cmapObj = BaseGraph() - cmapObj.setName(key) - cmapObj.setSubpage(subpage) - cmapObj.setSzchar(self.__szchar) - cmapObj.setOpt("bc","bcmt") - cmapObj.setup(title="dBs", - xlabel="", - ylabel="", - colormap=colormap) - - self.graphObjDict[key] = cmapObj - - xcmapi = 0. - xcmapw = 0.05 - xw -= xcmapw - if showPowerProfile: - key = "powerprof" + Inputs: - powObj = BaseGraph() - powObj.setName(key) - powObj.setSubpage(subpage) - powObj.setSzchar(self.__szchar) - plplot.pllsty(2) - powObj.setOpt("bcntg","bc") - plplot.pllsty(1) - powObj.setup(title="Power Profile", - xlabel="dBs", - ylabel="") - - self.graphObjDict[key] = powObj - - xpowi = 0. - xpoww = 0.24 - xw -= xpoww - - xf = xi + xw - yf = yi + yw - xcmapf = xf + type: "power" ->> Potencia + "iq" ->> Real + Imaginario + """ - baseObj.setScreenPos([xi, xf], [yi, yf]) + self.__isPlotConfig = False - if showColorbar: - xcmapi = xf + 0.02 - xcmapf = xcmapi + xcmapw - cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) - - if showPowerProfile: - xpowi = xcmapf + 0.06 - xpowf = xpowi + xpoww - powObj.setScreenPos([xpowi, xpowf], [yi, yf]) - + self.__isPlotIni = False -# baseObj.initSubpage() -# -# if showColorbar: -# cmapObj.initPlot() -# -# if showPowerProfile: -# powObj.initPlot() - - self.showColorbar = showColorbar - self.showPowerProfile = showPowerProfile - - def setRanges(self, xrange, yrange, zrange): + self.__xrange = None - key = "spec" - baseObj = self.graphObjDict[key] - baseObj.setRanges(xrange, yrange, zrange) + self.__yrange = None - keyList = self.graphObjDict.keys() + self.nGraphs = 0 - key = "colorbar" - if key in keyList: - cmapObj = self.graphObjDict[key] - cmapObj.setRanges([0., 1.], zrange) + self.graphObjList = [] + + self.m_Spectra = Spectra - key = "powerprof" - if key in keyList: - powObj = self.graphObjDict[key] - powObj.setRanges(zrange, yrange) - def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): + + graphObj = ColorPlot() + graphObj.setup(subpage, + title, + xlabel, + ylabel, + showColorbar=showColorbar, + showPowerProfile=showPowerProfile, + XAxisAsTime=XAxisAsTime) + + self.graphObjList.append(graphObj) + + + def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): - key = "spec" - baseObj = self.graphObjDict[key] - baseObj.initSubpage() + nChan = int(self.m_Spectra.m_SystemHeader.numChannels) - if xmin == None: - xmin = 0. + myTitle = "" + myXlabel = "" + myYlabel = "" - if xmax == None: - xmax = 1. + for i in range(nChan): + if titleList != None: + myTitle = titleList[i] + myXlabel = xlabelList[i] + myYlabel = ylabelList[i] + + self.__addGraph(i+1, + title=myTitle, + xlabel=myXlabel, + ylabel=myYlabel, + showColorbar=showColorbar, + showPowerProfile=showPowerProfile, + XAxisAsTime=XAxisAsTime) + + self.nGraphs = nChan + self.__isPlotConfig = True - if ymin == None: - ymin = 0. + def iniPlot(self): - if ymax == None: - ymax = 1. + nx = int(numpy.sqrt(self.nGraphs)+1) + #ny = int(self.nGraphs/nx) - if zmin == None: - zmin = numpy.nanmin(data) + plplot.plsetopt("geometry", "%dx%d" %(400*nx, 300*nx)) + plplot.plsdev("xcairo") + plplot.plscolbg(255,255,255) + plplot.plscol0(1,0,0,0) + plplot.plinit() + plplot.plspause(False) + plplot.pladv(0) + plplot.plssub(nx, nx) - if zmax == None: - zmax = numpy.nanmax(data) + self.__isPlotIni = True - if not(baseObj.hasRange): - self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) - - baseObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, baseObj.zrange[0], baseObj.zrange[1]) - - if self.showColorbar: - key = "colorbar" - cmapObj = self.graphObjDict[key] - cmapObj.colorbarPlot() - - if self.showPowerProfile: - power = numpy.average(data, axis=1) - - step = (ymax - ymin)/(power.shape[0]-1) - heis = numpy.arange(ymin, ymax + step, step) + def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): + + if not(self.__isPlotConfig): + self.setup(titleList, + xlabelList, + ylabelList, + showColorbar, + showPowerProfile, + XAxisAsTime) + + if not(self.__isPlotIni): + self.iniPlot() + + data = numpy.log10(self.m_Spectra.data_spc) + + nX, nY, nChan = numpy.shape(data) + + x = numpy.arange(nX) + y = self.m_Spectra.heights + + if xmin == None: xmin = x[0] + if xmax == None: xmax = x[-1] + if ymin == None: ymin = y[0] + if ymax == None: ymax = y[-1] + if zmin == None: zmin = numpy.nanmin(abs(data)) + if zmax == None: zmax = numpy.nanmax(abs(data)) + + plplot.plbop() + for i in range(self.nGraphs): + self.graphObjList[i].iniSubpage() + self.graphObjList[i].plotData(data[:,:,i], + x, + y, + xmin=xmin, + xmax=xmax, + ymin=ymin, + ymax=ymax, + zmin=zmin, + zmax=zmax) - key = "powerprof" - powObj = self.graphObjDict[key] - powObj.basicXYPlot(power, heis) - -class CrossSpectrum: - graphObjDict = {} - showColorbar = False - showPowerProfile = True + + plplot.plflush() + plplot.pleop() - __szchar = 0.7 - __showPhase = False - __xrange = None - __yrange = None - __zrange = None - m_BaseGraph= BaseGraph() - - def __init__(self): - pass - - def setup(self, subpage, title, xlabel, ylabel, colormap, showColorbar, showPowerProfile): - pass - - def setRanges(self, xrange, yrange, zrange): - pass - - def plotData(self, data, xmin, xmax, ymin, ymax, zmin, zmax): - pass + def end(self): + plplot.plend() + if __name__ == '__main__': - - import numpy - plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) - plplot.plsdev("xcairo") - plplot.plscolbg(255,255,255) - plplot.plscol0(1,0,0,0) - plplot.plinit() - plplot.plssub(2, 2) - - nx = 64 - ny = 100 - - data = numpy.random.uniform(-50,50,(nx,ny)) - - baseObj = ColorPlot() - baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) - baseObj.plotData(data) - - data = numpy.random.uniform(-50,50,(nx,ny)) - - spec2Obj = ColorPlot() - spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) - spec2Obj.plotData(data) - - plplot.plend() - exit(0) \ No newline at end of file + pass \ No newline at end of file diff --git a/schainpy/IO/SpectraIO.py b/schainpy/IO/SpectraIO.py index fe24b6c..ce230cb 100644 --- a/schainpy/IO/SpectraIO.py +++ b/schainpy/IO/SpectraIO.py @@ -383,11 +383,11 @@ class SpectraReader(DataReader): spc = numpy.fromfile(self.__fp, self.__dataType[0], int(pts2read*Npair_SelfSpectra)) cspc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*Npair_CrossSpectra)) - dc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*self.m_SystemHeader.numChannels) ) + dc = numpy.fromfile(self.__fp, self.__dataType, int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) ) spc = spc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_SelfSpectra)) cspc = cspc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_CrossSpectra)) - dc = dc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) + dc = dc.reshape((self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) data_spc = spc data_cspc = cspc['real'] + cspc['imag']*1j diff --git a/schainpy/IO/VoltageIO.py b/schainpy/IO/VoltageIO.py index 0a1d698..6f38091 100644 --- a/schainpy/IO/VoltageIO.py +++ b/schainpy/IO/VoltageIO.py @@ -84,9 +84,14 @@ class VoltageReader(DataReader): while(True): - readerObj.getData() + #to get one profile + profile = readerObj.getData() - print readerObj.m_Voltage.data + #print the profile + print profile + + #If you want to see all datablock + print readerObj.datablock if readerObj.noMoreFiles: break @@ -180,9 +185,9 @@ class VoltageReader(DataReader): self.idProfile = 0 - self.__buffer = None + self.datablock = None - self.__buffer_id = 9999 + self.datablock_id = 9999 def __rdSystemHeader(self,fp=None): if fp == None: @@ -349,9 +354,9 @@ class VoltageReader(DataReader): Variables afectadas: - self.__buffer_id + self.datablock_id - self.__buffer + self.datablock self.__flagIsNewFile @@ -371,9 +376,9 @@ class VoltageReader(DataReader): data = junk['real'] + junk['imag']*1j - self.__buffer_id = 0 + self.datablock_id = 0 - self.__buffer = data + self.datablock = data self.__flagIsNewFile = 0 @@ -384,7 +389,7 @@ class VoltageReader(DataReader): self.nReadBlocks += 1 def __hasNotDataInBuffer(self): - if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: + if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock: return 1 return 0 @@ -577,7 +582,7 @@ class VoltageReader(DataReader): Variables afectadas: self.m_Voltage - self.__buffer_id + self.datablock_id self.idProfile Excepciones: @@ -603,21 +608,21 @@ class VoltageReader(DataReader): #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) - time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds + time = self.m_BasicHeader.utc + self.datablock_id*self.__ippSeconds self.m_Voltage.m_BasicHeader.utc = time - self.m_Voltage.data = self.__buffer[self.__buffer_id,:,:] + self.m_Voltage.data = self.datablock[self.datablock_id,:,:] self.m_Voltage.flagNoData = False self.m_Voltage.flagResetProcessing = self.flagResetProcessing self.m_Voltage.idProfile = self.idProfile - self.__buffer_id += 1 + self.datablock_id += 1 self.idProfile += 1 #call setData - to Data Object - return 1 + return self.m_Voltage.data class VoltageWriter(DataWriter): __configHeaderFile = 'wrSetHeadet.txt' @@ -641,9 +646,9 @@ class VoltageWriter(DataWriter): self.__flagIsNewFile = 1 - self.__buffer = None + self.datablock = None - self.__buffer_id = 0 + self.datablock_id = 0 self.__dataType = None @@ -757,16 +762,16 @@ class VoltageWriter(DataWriter): data = numpy.zeros(self.__shapeBuffer, self.__dataType) - data['real'] = self.__buffer.real - data['imag'] = self.__buffer.imag + data['real'] = self.datablock.real + data['imag'] = self.datablock.imag data = data.reshape((-1)) data.tofile(self.__fp) - self.__buffer.fill(0) + self.datablock.fill(0) - self.__buffer_id = 0 + self.datablock_id = 0 self.__flagIsNewFile = 0 @@ -787,7 +792,7 @@ class VoltageWriter(DataWriter): return 1 def __hasAllDataInBuffer(self): - if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: + if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock: return 1 return 0 @@ -801,14 +806,14 @@ class VoltageWriter(DataWriter): if self.m_Voltage.flagResetProcessing: - self.__buffer.fill(0) + self.datablock.fill(0) - self.__buffer_id = 0 + self.datablock_id = 0 self.__setNextFile() - self.__buffer[self.__buffer_id,:,:] = self.m_Voltage.data + self.datablock[self.datablock_id,:,:] = self.m_Voltage.data - self.__buffer_id += 1 + self.datablock_id += 1 if self.__hasAllDataInBuffer(): @@ -933,7 +938,7 @@ class VoltageWriter(DataWriter): self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels ) - self.__buffer = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex')) + self.datablock = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex')) # if not(self.__setNextFile()): # return 0 diff --git a/schainpy/TestSChain.py b/schainpy/TestSChain.py index 1e07420..73d69c7 100644 --- a/schainpy/TestSChain.py +++ b/schainpy/TestSChain.py @@ -11,6 +11,10 @@ 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(): @@ -25,32 +29,32 @@ class TestSChain(): self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/' self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR' self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING' - self.path = '/home/roj-idl71/tmp/data' +# self.path = '/home/roj-idl71/tmp/data' #self.path = '/remote/puma/2004_11/DVD/' self.ppath = "/home/roj-idl71/tmp/data" - self.startDateTime = datetime.datetime(2004,5,1,17,49,0) - self.endDateTime = datetime.datetime(2012,5,1,18,10,0) + self.startDateTime = datetime.datetime(2011,1,1,17,49,0) + self.endDateTime = datetime.datetime(2011,1,30,18,10,0) def createObjects(self): - self.voltageObj = Voltage() - self.readerObj = VoltageReader(self.voltageObj) - self.plotObj = Osciloscope(self.voltageObj) - self.writerObj = VoltageWriter(self.voltageObj) + 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)): + if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='')): sys.exit(0) - if not(self.writerObj.setup(self.ppath)): - sys.exit(0) +# if not(self.writerObj.setup(self.ppath)): +# sys.exit(0) def testSChain(self): ini = time.time() while(True): self.readerObj.getData() - self.plotObj.plotData(idProfile = 1, type='iq', ymin = -100, ymax = 100) + self.plotObj.plotData(showColorbar=False, showPowerProfile=True) # self.writerObj.putData() @@ -62,12 +66,9 @@ class TestSChain(): 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() - - - - + ini = time.time() + #time.sleep(0.5) self.plotObj.end() if __name__ == '__main__':