##// END OF EJS Templates
Cambio en la forma de generacion de graficos espectrales
Miguel Valdez -
r112:a4769f3a76cc
parent child
Show More
@@ -199,7 +199,6 def savePlplot(filename,width,height):
199 199 plplot.plsfnam(filename)
200 200 plplot.plcpstrm(curr_strm,0)
201 201 plplot.plreplot()
202 plplot.plclear()
203 202 plplot.plend1()
204 203 plplot.plsstrm(curr_strm)
205 204
@@ -215,6 +214,13 def initPlplot(indexPlot,ncol,nrow,winTitle,width,height):
215 214 plplot.plspause(False)
216 215 plplot.plssub(ncol,nrow)
217 216
217 def setNewPage():
218 plplot.plbop()
219 plplot.pladv(0)
220
221 def closePage():
222 plplot.pleop()
223
218 224 def clearData(objGraph):
219 225 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc")
220 226
@@ -238,7 +244,7 def setStrm(indexPlot):
238 244 def plFlush():
239 245 plplot.plflush()
240 246
241 def setPlTitle(pltitle,color):
247 def setPlTitle(pltitle,color, szchar=0.7):
242 248 setSubpages(1, 0)
243 249 plplot.pladv(0)
244 250 plplot.plvpor(0., 1., 0., 1.)
@@ -248,12 +254,14 def setPlTitle(pltitle,color):
248 254 if color == "white":
249 255 plplot.plcol0(15)
250 256
257 plplot.plschr(0.0,szchar)
251 258 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
252 259
253 260 def setSubpages(ncol,nrow):
254 261 plplot.plssub(ncol,nrow)
255 262
256 263 class BaseGraph:
264
257 265 __name = None
258 266 __xpos = None
259 267 __ypos = None
@@ -267,7 +275,9 class BaseGraph:
267 275 deltax = None
268 276 xmin = None
269 277 xmax = None
278
270 279 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
280
271 281 self.setName(name)
272 282 self.setScreenPos(xpos, ypos)
273 283 self.setLabels(xlabel,ylabel,title)
@@ -553,7 +563,7 class LinearPlot:
553 563
554 564
555 565
556 class SpectraPlot:
566 class PcolorPlot:
557 567 pcolorObjDic = {}
558 568 colorbarObjDic = {}
559 569 pwprofileObjDic = {}
@@ -577,11 +587,9 class SpectraPlot:
577 587 self.showPowerProfile = showPowerProfile
578 588 self.XAxisAsTime = XAxisAsTime
579 589
580 nrow = 2
581 if (nsubplot%2)==0:
582 ncol = nsubplot/nrow
583 else:
584 ncol = int(nsubplot)/nrow + 1
590
591 ncol = int(numpy.sqrt(nsubplot)+0.9)
592 nrow = int(nsubplot*1./ncol + 0.9)
585 593
586 594 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
587 595 setColormap(colormap)
@@ -630,8 +638,13 class SpectraPlot:
630 638
631 639 return xpos,ypos
632 640
633 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
641 def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
642 """
643 Crea los objetos necesarios para un subplot
644 """
645
634 646 # Config Spectra plot
647
635 648 szchar = 0.7
636 649 name = "spc"
637 650 key = name + "%d"%subplot
@@ -641,7 +654,6 class SpectraPlot:
641 654
642 655 xpos,ypos = self.setSpectraPos()
643 656 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
644 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv")
645 657 self.pcolorObjDic[key] = pcolorObj
646 658
647 659 # Config Colorbar
@@ -654,9 +666,6 class SpectraPlot:
654 666 xrange = [0.,1.]
655 667 yrange = [zmin,zmax]
656 668 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
657 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
658 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
659 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
660 669 self.colorbarObjDic[key] = cmapObj
661 670
662 671 # Config Power profile
@@ -669,21 +678,59 class SpectraPlot:
669 678 xrange = [zmin,zmax]
670 679 yrange = [ymin,ymax]
671 680 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
681 self.pwprofileObjDic[key] = powObj
682
683 def setNewPage(self, pltitle='No title'):
684 szchar = 0.7
685 setNewPage()
686 setPlTitle(pltitle,"black", szchar=szchar)
687 setSubpages(self.ncol, self.nrow)
688
689 def closePage(self):
690 closePage()
691
692 def iniPlot(self,subplot):
693 """
694 Inicializa los subplots con su frame, titulo, etc
695 """
696
697 # Config Spectra plot
698 name = "spc"
699 key = name + "%d"%subplot
700
701 pcolorObj = self.pcolorObjDic[key]
702 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv")
703
704 # Config Colorbar
705 if self.showColorbar:
706 name = "colorbar"
707 key = name + "%d"%subplot
708
709 cmapObj = self.colorbarObjDic[key]
710 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
711 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
712 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
713
714 # Config Power profile
715 if self.showPowerProfile:
716 name = "pwprofile"
717 key = name + "%d"%subplot
718
719 powObj = self.pwprofileObjDic[key]
672 720 powObj.setLineStyle(2)
673 721 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
674 722 powObj.setLineStyle(1)
675 723 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
676 self.pwprofileObjDic[key] = powObj
677 724
678 725 def printTitle(self,pltitle):
679 if self.__lastTitle != None:
680 setPlTitle(self.__lastTitle,"white")
681
682 self.__lastTitle = pltitle
726 # if self.__lastTitle != None:
727 # setPlTitle(self.__lastTitle,"white")
728 #
729 # self.__lastTitle = pltitle
683 730
684 731 setPlTitle(pltitle,"black")
685 732
686 setSubpages(self.ncol,self.nrow)
733 # setSubpages(self.ncol,self.nrow)
687 734
688 735 def plot(self,subplot,x,y,z,subtitle):
689 736 # Spectra plot
@@ -693,8 +740,10 class SpectraPlot:
693 740
694 741 # newx = [x[0],x[-1]]
695 742 pcolorObj = self.pcolorObjDic[key]
743
696 744 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
697 pcolorObj.delLabels()
745
746 #pcolorObj.delLabels()
698 747 pcolorObj.setLabels(title=subtitle)
699 748
700 749 deltax = None; deltay = None
@@ -712,9 +761,10 class SpectraPlot:
712 761 deltay=deltay,
713 762 getGrid=pcolorObj.getGrid)
714 763
764 #Solo se calcula la primera vez que se ingresa a la funcion
715 765 pcolorObj.getGrid = False
716 766
717 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
767 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst", nolabels=True)
718 768
719 769 # Power Profile
720 770 if self.showPowerProfile:
@@ -724,7 +774,7 class SpectraPlot:
724 774 powObj = self.pwprofileObjDic[key]
725 775
726 776 if powObj.setXYData() != None:
727 clearData(powObj)
777 #clearData(powObj)
728 778 powObj.setLineStyle(2)
729 779 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
730 780 powObj.setLineStyle(1)
@@ -735,16 +785,11 class SpectraPlot:
735 785 powObj.basicXYPlot(power,y)
736 786 powObj.setXYData(power,y)
737 787
738 def savePlot(self,indexPlot,path):
788 def savePlot(self,indexPlot,filename):
739 789
740 now = datetime.datetime.now().timetuple()
741 file = "spc_img%02d_%03d_%02d%02d%02d"%(indexPlot,now[7],now[3],now[4],now[5])
742 filename = os.path.join(path,file+".png")
743 790 width = self.width*self.ncol
744 791 hei = self.height*self.nrow
745 792 savePlplot(filename,width,hei)
746
747
748 793
749 794 def refresh(self):
750 795 plFlush()
@@ -25,22 +25,45 class Spectrum:
25 25 self.__isPlotIni = False
26 26 self.__xrange = None
27 27 self.__yrange = None
28 self.nGraphs = 0
28 self.nsubplots = 0
29 29 self.indexPlot = index
30 30 self.spectraObj = Spectra
31 31
32 def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False):
33 self.colorplotObj = SpectraPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
34
35 def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList):
36 nsubplot = self.spectraObj.nChannels
32 def setup(self,indexPlot, nsubplots, winTitle='', colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
33 """
34 Crea un objeto colorPlot con las opciones seleccinoadas
35 """
36
37 self.nsubplots = nsubplots
38 self.colorplotObj = PcolorPlot(indexPlot,
39 nsubplots,
40 winTitle,
41 colormap,
42 showColorbar,
43 showPowerProfile,
44 XAxisAsTime)
45
46 def createObjects(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList):
47 """
48 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
49 """
37 50
38 for index in range(nsubplot):
51 for index in range(self.nsubplots):
39 52 title = titleList[index]
40 53 xlabel = xlabelList[index]
41 54 ylabel = ylabelList[index]
42 55 subplot = index
43 self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
56 self.colorplotObj.createObjects(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
57
58 def initPlot(self):
59 """
60 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
61 """
62
63
64 for index in range(self.nsubplots):
65 subplot = index
66 self.colorplotObj.iniPlot(subplot+1)
44 67
45 68
46 69 def plotData(self,
@@ -58,13 +81,24 class Spectrum:
58 81 showColorbar = True,
59 82 showPowerProfile = True,
60 83 XAxisAsTime = False,
61 save = False):
84 save = False,
85 channelList=[]):
86
87 if channelList == []:
88 channelList = numpy.arange(self.spectraObj.nChannels)
89
62 90
63 databuffer = 10.*numpy.log10(self.spectraObj.data_spc)
64 noise = 10.*numpy.log10(self.spectraObj.noise)
91 nsubplots = len(channelList)
92 nX = self.spectraObj.nFFTPoints
93 nY = self.spectraObj.nHeights
65 94
66 nsubplot = self.spectraObj.nChannels
67 nsubplot, nX, nY = numpy.shape(databuffer)
95 if self.spectraObj.noise == None:
96 noise = numpy.ones(nsubplots)
97 else:
98 noise = 10.*numpy.log10(self.spectraObj.noise[channelList])
99
100 datadB = 10.*numpy.log10(self.spectraObj.data_spc[channelList,:,:])
101 noisedB = 10.*numpy.log10(noise)
68 102
69 103 x = numpy.arange(nX)
70 104 y = self.spectraObj.heightList
@@ -72,23 +106,31 class Spectrum:
72 106 indexPlot = self.indexPlot
73 107
74 108 if not(self.__isPlotConfig):
75 self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
109 self.setup(indexPlot,
110 nsubplots,
111 winTitle,
112 colormap,
113 showColorbar,
114 showPowerProfile,
115 XAxisAsTime)
116
117
76 118 self.__isPlotConfig = True
77
119
78 120 if not(self.__isPlotIni):
79 121 if titleList == None:
80 122 titleList = []
81 for i in range(nsubplot):
123 for i in range(nsubplots):
82 124 titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i]))
83 125
84 126 if xlabelList == None:
85 127 xlabelList = []
86 for i in range(nsubplot):
128 for i in range(nsubplots):
87 129 xlabelList.append("")
88 130
89 131 if ylabelList == None:
90 132 ylabelList = []
91 for i in range(nsubplot):
133 for i in range(nsubplots):
92 134 ylabelList.append("Range (Km)")
93 135
94 136 if xmin == None: xmin = x[0]
@@ -98,29 +140,31 class Spectrum:
98 140 if zmin == None: zmin = 0
99 141 if zmax == None: zmax = 120
100 142
101 self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList)
143 self.createObjects(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList)
102 144 self.__isPlotIni = True
103 145
104 self.colorplotObj.setFigure(indexPlot)
105
106 146 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
107 147 pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
108 148
109 self.colorplotObj.printTitle(pltitle) #setPlTitle(pltitle)
110
111 for index in range(nsubplot):
112 data = databuffer[index,:,:]
113 subtitle = "Channel: %d - Noise: %.2f" %(index, noise[index])
114 self.colorplotObj.plot(index+1,x,y,data,subtitle)
115
149 self.colorplotObj.setFigure(indexPlot)
150 self.colorplotObj.setNewPage(pltitle)
151 self.initPlot()
116 152
153 for channel in range(nsubplots):
154 data = datadB[channel,:,:]
155 subtitle = "Channel: %d - Noise: %.2f" %(channel, noise[channel])
156 self.colorplotObj.plot(channel+1, x, y, data, subtitle)
117 157
118 158 self.colorplotObj.refresh()
119 159
120 160 if save:
121 161 self.colorplotObj.setFigure(indexPlot)
122 path4plot = "/Users/jro/Pictures"
123 self.colorplotObj.savePlot(indexPlot,path4plot)
124
162 path = "/home/roj-idl71/tmp/"
163 now = datetime.datetime.now().timetuple()
164 file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
165 filename = os.path.join(path,file)
166 self.colorplotObj.savePlot(indexPlot, filename)
167
168 self.colorplotObj.closePage()
125 169
126 170
@@ -94,13 +94,6 class Osciloscope:
94 94
95 95 self.linearplotObj.refresh()
96 96
97
98
99
100
101
102
103
104 97 class RTI:
105 98 colorplotObj = None
106 99
@@ -1,7 +1,6
1 1 import numpy
2 from Model.Spectra import Spectra
3 2
4 def hildebrand_sekhon(Data, navg):
3 def hildebrand_sekhon(data, navg):
5 4 """
6 5 This method is for the objective determination of de noise level in Doppler spectra. This
7 6 implementation technique is based on the fact that the standard deviation of the spectral
@@ -16,51 +15,39 def hildebrand_sekhon(Data, navg):
16 15 anoise : noise's level
17 16 """
18 17
19 divisor = 8
20 ratio = 7 / divisor
21 data = Data.reshape(-1)
22 npts = data.size #numbers of points of the data
18 dataflat = data.reshape(-1)
19 dataflat.sort()
20 npts = dataflat.size #numbers of points of the data
23 21
24 22 if npts < 32:
25 23 print "error in noise - requires at least 32 points"
26 24 return -1.0
27 25
26 dataflat2 = numpy.power(dataflat,2)
27
28 cs = numpy.cumsum(dataflat)
29 cs2 = numpy.cumsum(dataflat2)
30
28 31 # data sorted in ascending order
29 nmin = int(npts/divisor + ratio);
30 s = 0.0
31 s2 = 0.0
32 data2 = data[:npts]
33 data2.sort()
34
35 for i in range(nmin):
36 s += data2[i]
37 s2 += data2[i]**2;
38
39 icount = nmin
40 iflag = 0
32 nmin = int((npts + 7.)/8)
41 33
42 34 for i in range(nmin, npts):
43 s += data2[i];
44 s2 += data2[i]**2
45 icount=icount+1;
46 p = s / float(icount);
35 s = cs[i]
36 s2 = cs2[i]
37 p = s / float(i);
47 38 p2 = p**2;
48 q = s2 / float(icount) - p2;
39 q = s2 / float(i) - p2;
49 40 leftc = p2;
50 41 rightc = q * float(navg);
51
52 if leftc > rightc:
53 iflag = 1; #No weather signal
42 R2 = leftc/rightc
43
54 44 # Signal detect: R2 < 1 (R2 = leftc/rightc)
55 if(leftc < rightc):
56 if iflag:
57 break
58
59 anoise = 0.0;
60 for j in range(i):
61 anoise += data2[j];
62
63 anoise = anoise / float(i);
45 if R2 < 1:
46 npts_noise = i
47 break
48
49
50 anoise = numpy.average(dataflat[0:npts_noise])
64 51
65 52 return anoise;
66 53
@@ -6,6 +6,7 Created on Feb 7, 2012
6 6 '''
7 7 import os, sys
8 8 import numpy
9 import time
9 10
10 11 path = os.path.split(os.getcwd())[0]
11 12 sys.path.append(path)
@@ -163,7 +164,7 class SpectraProcessor:
163 164 self.buffer[:,self.profIndex,:] = self.dataInObj.data
164 165 self.profIndex += 1
165 166
166 if self.profIndex == self.nFFTPoints:
167 if self.profIndex == self.nFFTPoints:
167 168 self.__getFft()
168 169 self.dataOutObj.flagNoData = False
169 170
@@ -210,6 +211,7 class SpectraProcessor:
210 211 self.dataOutObj.m_ProcessingHeader.spectraComb
211 212 self.dataOutObj.m_ProcessingHeader.shif_fft
212 213 """
214
213 215 if self.dataInObj.flagNoData:
214 216 return 0
215 217
@@ -218,7 +220,8 class SpectraProcessor:
218 220
219 221 #calculo de self-spectra
220 222 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
223 spc = fft_volt * numpy.conjugate(fft_volt)
224 spc = spc.real
222 225
223 226 blocksize = 0
224 227 blocksize += dc.size
@@ -240,7 +243,7 class SpectraProcessor:
240 243 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
241 244 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
242 245
243 self.getNoise()
246 # self.getNoise()
244 247
245 248 def addWriter(self,wrpath):
246 249 objWriter = SpectraWriter(self.dataOutObj)
@@ -286,7 +289,8 class SpectraProcessor:
286 289 showPowerProfile=False,
287 290 XAxisAsTime=False,
288 291 save=False,
289 index=None):
292 index=None,
293 channelList=[]):
290 294
291 295 if self.dataOutObj.flagNoData:
292 296 return 0
@@ -308,7 +312,8 class SpectraProcessor:
308 312 showColorbar,
309 313 showPowerProfile,
310 314 XAxisAsTime,
311 save)
315 save,
316 channelList)
312 317
313 318 self.plotterObjIndex += 1
314 319
@@ -330,16 +335,14 class SpectraProcessor:
330 335 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
331 336 self.dataOutObj.flagNoData = False
332 337
333 self.getNoise(type="hildebrand")
334 # self.getNoise(type="sort", parm=16)
335
338 """Calcular el ruido"""
339 self.getNoise()
336 340 else:
337 341 self.dataOutObj.flagNoData = True
338 342
339 343 self.integratorObjIndex += 1
340 344
341 """Calcular el ruido"""
342 # self.getNoise(type="hildebrand", parm=1)
345
343 346
344 347 def removeDC(self, type):
345 348
General Comments 0
You need to be logged in to leave comments. Login now