##// END OF EJS Templates
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
Daniel Valdez -
r229:22aec8924dc0
parent child
Show More
@@ -221,13 +221,40 class Axes:
221 ylabel=ylabel,
221 ylabel=ylabel,
222 title=title)
222 title=title)
223
223
224 def pmultiline(self, x, y,
225 xmin=None, xmax=None,
226 ymin=None, ymax=None,
227 xlabel='', ylabel='',
228 title='',
229 **kwargs):
230
231 if self.__firsttime:
232
233 if xmin == None: xmin = numpy.nanmin(x)
234 if xmax == None: xmax = numpy.nanmax(x)
235 if ymin == None: ymin = numpy.nanmin(y)
236 if ymax == None: ymax = numpy.nanmax(y)
237
238 self.plot = self.__driver.createPmultiline(self.ax, x, y,
239 xmin, xmax,
240 ymin, ymax,
241 xlabel=xlabel,
242 ylabel=ylabel,
243 title=title,
244 **kwargs)
245 self.__firsttime = False
246 return
247
248 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
249 ylabel=ylabel,
250 title=title)
224
251
225 def pcolor(self, x, y, z,
252 def pcolor(self, x, y, z,
226 xmin=None, xmax=None,
253 xmin=None, xmax=None,
227 ymin=None, ymax=None,
254 ymin=None, ymax=None,
228 zmin=None, zmax=None,
255 zmin=None, zmax=None,
229 xlabel='', ylabel='',
256 xlabel='', ylabel='',
230 title='', rti = False,
257 title='', rti = False, colormap='jet',
231 **kwargs):
258 **kwargs):
232
259
233 """
260 """
@@ -267,6 +294,7 class Axes:
267 xlabel=xlabel,
294 xlabel=xlabel,
268 ylabel=ylabel,
295 ylabel=ylabel,
269 title=title,
296 title=title,
297 colormap=colormap,
270 **kwargs)
298 **kwargs)
271
299
272 if self.xmin == None: self.xmin = xmin
300 if self.xmin == None: self.xmin = xmin
@@ -283,7 +311,8 class Axes:
283 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
311 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
284 xlabel=xlabel,
312 xlabel=xlabel,
285 ylabel=ylabel,
313 ylabel=ylabel,
286 title=title)
314 title=title,
315 colormap=colormap)
287 return
316 return
288
317
289 self.__driver.pcolor(self.plot, z,
318 self.__driver.pcolor(self.plot, z,
@@ -85,8 +85,13 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title=''
85 printLabels(ax, xlabel, ylabel, title)
85 printLabels(ax, xlabel, ylabel, title)
86
86
87 ######################################################
87 ######################################################
88 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin)
88 if (xmax-xmin)<=1:
89 ax.set_xticks(xtickspos)
89 xtickspos = numpy.linspace(xmin,xmax,nxticks)
90 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
91 ax.set_xticks(xtickspos)
92 else:
93 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
94 ax.set_xticks(xtickspos)
90
95
91 for tick in ax.get_xticklabels():
96 for tick in ax.get_xticklabels():
92 tick.set_visible(xtick_visible)
97 tick.set_visible(xtick_visible)
@@ -126,7 +131,68 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
126 printLabels(ax, xlabel, ylabel, title)
131 printLabels(ax, xlabel, ylabel, title)
127
132
128 iplot.set_data(x, y)
133 iplot.set_data(x, y)
134
135 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
136 ticksize=9, xtick_visible=True, ytick_visible=True,
137 nxticks=4, nyticks=10,
138 grid=None):
139
140 """
141
142 Input:
143 grid : None, 'both', 'x', 'y'
144 """
145
146 lines = ax.plot(x.T, y)
147 leg = ax.legend(lines, legendlabels, loc='upper left')
148 leg.get_frame().set_alpha(0.5)
149 ax.set_xlim([xmin,xmax])
150 ax.set_ylim([ymin,ymax])
151 printLabels(ax, xlabel, ylabel, title)
152
153 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
154 ax.set_xticks(xtickspos)
155
156 for tick in ax.get_xticklabels():
157 tick.set_visible(xtick_visible)
158
159 for tick in ax.xaxis.get_major_ticks():
160 tick.label.set_fontsize(ticksize)
161
162 for tick in ax.get_yticklabels():
163 tick.set_visible(ytick_visible)
164
165 for tick in ax.yaxis.get_major_ticks():
166 tick.label.set_fontsize(ticksize)
167
168 iplot = ax.lines[-1]
169
170 if '0.' in matplotlib.__version__[0:2]:
171 print "The matplotlib version has to be updated to 1.1 or newer"
172 return iplot
173
174 if '1.0.' in matplotlib.__version__[0:4]:
175 print "The matplotlib version has to be updated to 1.1 or newer"
176 return iplot
177
178 if grid != None:
179 ax.grid(b=True, which='major', axis=grid)
180
181 matplotlib.pyplot.tight_layout()
182
183 return iplot
184
185
186 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
187
188 ax = iplot.get_axes()
189
190 printLabels(ax, xlabel, ylabel, title)
129
191
192 for i in range(len(ax.lines)):
193 line = ax.lines[i]
194 line.set_data(x[i,:],y)
195
130 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
196 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
131 xlabel='', ylabel='', title='', ticksize = 9,
197 xlabel='', ylabel='', title='', ticksize = 9,
132 colormap='jet',cblabel='', cbsize="5%",
198 colormap='jet',cblabel='', cbsize="5%",
@@ -188,11 +254,11 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
188
254
189 imesh.set_array(z.ravel())
255 imesh.set_array(z.ravel())
190
256
191 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''):
257 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
192
258
193 printLabels(ax, xlabel, ylabel, title)
259 printLabels(ax, xlabel, ylabel, title)
194
260
195 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
261 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
196
262
197 def draw(fig):
263 def draw(fig):
198
264
@@ -589,4 +589,286 class Scope(Figure):
589
589
590 if save:
590 if save:
591 self.saveFigure(filename)
591 self.saveFigure(filename)
592
593 class ProfilePlot(Figure):
594 __isConfig = None
595 __nsubplots = None
596
597 WIDTHPROF = None
598 HEIGHTPROF = None
599 PREFIX = 'spcprofile'
600
601 def __init__(self):
602 self.__isConfig = False
603 self.__nsubplots = 1
604
605 self.WIDTH = 300
606 self.HEIGHT = 500
607
608 def getSubplots(self):
609 ncol = 1
610 nrow = 1
611
612 return nrow, ncol
613
614 def setup(self, idfigure, nplots, wintitle):
615
616 self.nplots = nplots
617
618 ncolspan = 1
619 colspan = 1
620
621 self.createFigure(idfigure = idfigure,
622 wintitle = wintitle,
623 widthplot = self.WIDTH,
624 heightplot = self.HEIGHT)
625
626 nrow, ncol = self.getSubplots()
627
628 counter = 0
629 for y in range(nrow):
630 for x in range(ncol):
631 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
632
633 def run(self, dataOut, idfigure, wintitle="", channelList=None,
634 xmin=None, xmax=None, ymin=None, ymax=None,
635 save=False, figpath='./', figfile=None):
636
637 if channelList == None:
638 channelIndexList = dataOut.channelIndexList
639 channelList = dataOut.channelList
640 else:
641 channelIndexList = []
642 for channel in channelList:
643 if channel not in dataOut.channelList:
644 raise ValueError, "Channel %d is not in dataOut.channelList"
645 channelIndexList.append(dataOut.channelList.index(channel))
646
647
648 y = dataOut.getHeiRange()
649 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
650 avg = numpy.average(x, axis=1)
651
652
653 if not self.__isConfig:
654
655 nplots = 1
656
657 self.setup(idfigure=idfigure,
658 nplots=nplots,
659 wintitle=wintitle)
660
661 if ymin == None: ymin = numpy.nanmin(y)
662 if ymax == None: ymax = numpy.nanmax(y)
663 if xmin == None: xmin = numpy.nanmin(avg)*0.9
664 if xmax == None: xmax = numpy.nanmax(avg)*0.9
665
666 self.__isConfig = True
667
668 thisDatetime = dataOut.datatime
669 title = "Power Profile"
670 xlabel = "dB"
671 ylabel = "Range (Km)"
672
673 self.setWinTitle(title)
674
675
676 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
677 axes = self.axesList[0]
678
679 legendlabels = ["channel %d"%x for x in channelList]
680 axes.pmultiline(avg, y,
681 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
682 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
683 ytick_visible=True, nxticks=5,
684 grid='x')
685
686 self.draw()
687
688 if save:
689 date = thisDatetime.strftime("%Y%m%d")
690 if figfile == None:
691 figfile = self.getFilename(name = date)
692
693 self.saveFigure(figpath, figfile)
694
695 class CoherencePlot(Figure):
696 __isConfig = None
697 __nsubplots = None
698
699 WIDTHPROF = None
700 HEIGHTPROF = None
701 PREFIX = 'coherencemap'
702
703 def __init__(self):
704 self.__timerange = 24*60*60
705 self.__isConfig = False
706 self.__nsubplots = 1
707
708 self.WIDTH = 800
709 self.HEIGHT = 200
710 self.WIDTHPROF = 120
711 self.HEIGHTPROF = 0
712
713 def getSubplots(self):
714 ncol = 1
715 nrow = self.nplots*2
716
717 return nrow, ncol
718
719 def setup(self, idfigure, nplots, wintitle, showprofile=True):
720 self.__showprofile = showprofile
721 self.nplots = nplots
722
723 ncolspan = 1
724 colspan = 1
725 if showprofile:
726 ncolspan = 7
727 colspan = 6
728 self.__nsubplots = 2
729
730 self.createFigure(idfigure = idfigure,
731 wintitle = wintitle,
732 widthplot = self.WIDTH + self.WIDTHPROF,
733 heightplot = self.HEIGHT + self.HEIGHTPROF)
734
735 nrow, ncol = self.getSubplots()
736
737 for y in range(nrow):
738 for x in range(ncol):
739
740 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
741
742 if showprofile:
743 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
744
745 def __getTimeLim(self, x, xmin, xmax):
746
747 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
748 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
749
750 ####################################################
751 #If the x is out of xrange
752 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
753 xmin = None
754 xmax = None
755
756 if xmin == None:
757 td = thisdatetime - thisdate
758 xmin = td.seconds/(60*60.)
759
760 if xmax == None:
761 xmax = xmin + self.__timerange/(60*60.)
762
763 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
764 tmin = time.mktime(mindt.timetuple())
765
766 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
767 tmax = time.mktime(maxdt.timetuple())
768
769 self.__timerange = tmax - tmin
770
771 return tmin, tmax
772
773 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
774 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
775 timerange=None,
776 save=False, figpath='./', figfile=None):
777
778 if pairsList == None:
779 pairsIndexList = dataOut.pairsIndexList
780 else:
781 pairsIndexList = []
782 for pair in pairsList:
783 if pair not in dataOut.pairsList:
784 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
785 pairsIndexList.append(dataOut.pairsList.index(pair))
786
787 if timerange != None:
788 self.__timerange = timerange
789
790 tmin = None
791 tmax = None
792 x = dataOut.getTimeRange()
793 y = dataOut.getHeiRange()
794
795 if not self.__isConfig:
796 nplots = len(pairsIndexList)
797 self.setup(idfigure=idfigure,
798 nplots=nplots,
799 wintitle=wintitle,
800 showprofile=showprofile)
801
802 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
803 if ymin == None: ymin = numpy.nanmin(y)
804 if ymax == None: ymax = numpy.nanmax(y)
805
806 self.__isConfig = True
807
808 thisDatetime = dataOut.datatime
809 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
810 xlabel = ""
811 ylabel = "Range (Km)"
812
813 self.setWinTitle(title)
814
815 for i in range(self.nplots):
816
817 pair = dataOut.pairsList[pairsIndexList[i]]
818 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
819 coherence = numpy.abs(coherenceComplex)
820 avg = numpy.average(coherence, axis=0)
821 z = avg.reshape((1,-1))
822
823 counter = 0
824
825 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
826 axes = self.axesList[i*self.__nsubplots*2]
827 axes.pcolor(x, y, z,
828 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
829 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
830 ticksize=9, cblabel='', cbsize="1%")
831
832 if self.__showprofile:
833 counter += 1
834 axes = self.axesList[i*self.__nsubplots*2 + counter]
835 axes.pline(avg, y,
836 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
837 xlabel='', ylabel='', title='', ticksize=7,
838 ytick_visible=False, nxticks=5,
839 grid='x')
840
841 counter += 1
842 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
843 avg = numpy.average(phase, axis=0)
844 z = avg.reshape((1,-1))
845
846 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
847 axes = self.axesList[i*self.__nsubplots*2 + counter]
848 axes.pcolor(x, y, z,
849 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
850 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
851 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
852
853 if self.__showprofile:
854 counter += 1
855 axes = self.axesList[i*self.__nsubplots*2 + counter]
856 axes.pline(avg, y,
857 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
858 xlabel='', ylabel='', title='', ticksize=7,
859 ytick_visible=False, nxticks=4,
860 grid='x')
861
862 self.draw()
863
864 if save:
865 date = thisDatetime.strftime("%Y%m%d")
866 if figfile == None:
867 figfile = self.getFilename(name = date)
868
869 self.saveFigure(figpath, figfile)
870
871 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
872 self.__isConfig = False
873
592 No newline at end of file
874
General Comments 0
You need to be logged in to leave comments. Login now