##// END OF EJS Templates
Se mejora el metodo para grabar graficos de RTI y Spectra....
Miguel Valdez -
r212:857509399418
parent child
Show More
@@ -1,3 +1,4
1 import os
1 2 import numpy
2 3 import mpldriver
3 4
@@ -17,6 +18,7 class Figure:
17 18
18 19 WIDTH = None
19 20 HEIGHT = None
21 PREFIX = 'fig'
20 22
21 23 def __init__(self):
22 24
@@ -25,6 +27,12 class Figure:
25 27 def __del__(self):
26 28
27 29 self.__driver.closeFigure()
30
31 def getFilename(self, name, ext='.png'):
32
33 filename = '%s_%s%s' %(self.PREFIX, name, ext)
34
35 return filename
28 36
29 37 def getAxesObjList(self):
30 38
@@ -110,8 +118,10 class Figure:
110 118 axesObj = Axes(self.fig, *args)
111 119 self.axesObjList.append(axesObj)
112 120
113 def saveFigure(self, *args):
114 self.__driver.saveFigure(self.fig, *args)
121 def saveFigure(self, figpath, figfile, *args):
122
123 filename = os.path.join(figpath, figfile)
124 self.__driver.saveFigure(self.fig, filename, *args)
115 125
116 126 def draw(self):
117 127
@@ -183,15 +183,23 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title=''
183 183
184 184 for tick in ax.yaxis.get_major_ticks():
185 185 tick.label.set_fontsize(ticksize)
186
187 iplot = ax.lines[-1]
186 188
187 189 ######################################################
190 if '0.' in matplotlib.__version__[0:2]:
191 print "The matplotlib version has to be updated to 1.1 or newer"
192 return iplot
193
194 if '1.0.' in matplotlib.__version__[0:4]:
195 print "The matplotlib version has to be updated to 1.1 or newer"
196 return iplot
197
188 198 if grid != None:
189 199 ax.grid(b=True, which='major', axis=grid)
190 200
191 201 matplotlib.pyplot.tight_layout()
192 202
193 iplot = ax.lines[-1]
194
195 203 return iplot
196 204
197 205 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
@@ -234,6 +242,15 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
234 242 tick.set_fontsize(ticksize)
235 243
236 244 ax_cb.yaxis.tick_right()
245
246 if '0.' in matplotlib.__version__[0:2]:
247 print "The matplotlib version has to be updated to 1.1 or newer"
248 return imesh
249
250 if '1.0.' in matplotlib.__version__[0:4]:
251 print "The matplotlib version has to be updated to 1.1 or newer"
252 return imesh
253
237 254 matplotlib.pyplot.tight_layout()
238 255
239 256 if XAxisAsTime:
@@ -9,6 +9,7 class RTIPlot(Figure):
9 9
10 10 WIDTHPROF = None
11 11 HEIGHTPROF = None
12 PREFIX = 'rti'
12 13
13 14 def __init__(self):
14 15
@@ -17,7 +18,7 class RTIPlot(Figure):
17 18 self.__nsubplots = 1
18 19
19 20 self.WIDTH = 800
20 self.HEIGHT = 300
21 self.HEIGHT = 200
21 22 self.WIDTHPROF = 120
22 23 self.HEIGHTPROF = 0
23 24
@@ -92,7 +93,7 class RTIPlot(Figure):
92 93 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
93 94 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
94 95 timerange=None,
95 save=False, filename=None):
96 save=False, figpath='./', figfile=None):
96 97
97 98 """
98 99
@@ -175,7 +176,11 class RTIPlot(Figure):
175 176 self.draw()
176 177
177 178 if save:
178 self.saveFigure(filename)
179 date = thisDatetime.strftime("%Y%m%d")
180 if figfile == None:
181 figfile = self.getFilename(name = date)
182
183 self.saveFigure(figpath, figfile)
179 184
180 185 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
181 186 self.__isConfig = False
@@ -187,6 +192,7 class SpectraPlot(Figure):
187 192
188 193 WIDTHPROF = None
189 194 HEIGHTPROF = None
195 PREFIX = 'spc'
190 196
191 197 def __init__(self):
192 198
@@ -239,7 +245,8 class SpectraPlot(Figure):
239 245 counter += 1
240 246
241 247 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
242 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
248 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
249 save=False, figpath='./', figfile=None):
243 250
244 251 """
245 252
@@ -317,7 +324,11 class SpectraPlot(Figure):
317 324 self.draw()
318 325
319 326 if save:
320 self.saveFigure(filename)
327 date = thisDatetime.strftime("%Y%m%d")
328 if figfile == None:
329 figfile = self.getFilename(name = date)
330
331 self.saveFigure(figpath, figfile)
321 332
322 333 class Scope(Figure):
323 334
@@ -494,7 +494,7 class SpectraProc(ProcessingUnit):
494 494 self.dataOut.nCohInt = self.dataIn.nCohInt
495 495 self.dataOut.nIncohInt = 1
496 496 self.dataOut.ippSeconds = self.dataIn.ippSeconds
497 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints
497 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints**self.dataOut.nConInt**self.dataOut.nIncohInt
498 498
499 499 def __getFft(self):
500 500 """
@@ -650,7 +650,9 class IncohInt(Operation):
650 650 __lastdatatime = None
651 651 __integrationtime = None
652 652
653 __buffer = None
653 __buffer_spc = None
654 __buffer_cspc = None
655 __buffer_dc = None
654 656
655 657 __dataReady = False
656 658
@@ -675,7 +677,9 class IncohInt(Operation):
675 677
676 678 self.__initime = None
677 679 self.__lastdatatime = 0
678 self.__buffer = None
680 self.__buffer_spc = None
681 self.__buffer_cspc = None
682 self.__buffer_dc = None
679 683 self.__dataReady = False
680 684
681 685
@@ -692,44 +696,83 class IncohInt(Operation):
692 696
693 697 if overlapping:
694 698 self.__withOverapping = True
695 self.__buffer = None
696 699 else:
697 700 self.__withOverapping = False
698 self.__buffer = 0
701 self.__buffer_spc = 0
702 self.__buffer_cspc = 0
703 self.__buffer_dc = 0
699 704
700 705 self.__profIndex = 0
701 706
702 def putData(self, data):
707 def putData(self, data_spc, data_cspc, data_dc):
703 708
704 709 """
705 Add a profile to the __buffer and increase in one the __profileIndex
710 Add a profile to the __buffer_spc and increase in one the __profileIndex
706 711
707 712 """
708 713
709 714 if not self.__withOverapping:
710 self.__buffer += data.copy()
715 self.__buffer_spc += data_spc
716
717 if data_cspc == None:
718 self.__buffer_cspc = None
719 else:
720 self.__buffer_cspc += data_cspc
721
722 if data_dc == None:
723 self.__buffer_dc = None
724 else:
725 self.__buffer_dc += data_dc
726
711 727 self.__profIndex += 1
712 728 return
713 729
714 730 #Overlapping data
715 nChannels, nFFTPoints, nHeis = data.shape
716 data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis))
731 nChannels, nFFTPoints, nHeis = data_spc.shape
732 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
733 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
734 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
717 735
718 736 #If the buffer is empty then it takes the data value
719 if self.__buffer == None:
720 self.__buffer = data
737 if self.__buffer_spc == None:
738 self.__buffer_spc = data_spc.copy()
739
740 if data_cspc == None:
741 self.__buffer_cspc = None
742 else:
743 self.__buffer_cspc += data_cspc.copy()
744
745 if data_dc == None:
746 self.__buffer_dc = None
747 else:
748 self.__buffer_dc += data_dc.copy()
749
721 750 self.__profIndex += 1
722 751 return
723 752
724 753 #If the buffer length is lower than n then stakcing the data value
725 754 if self.__profIndex < self.n:
726 self.__buffer = numpy.vstack((self.__buffer, data))
755 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
756
757 if self.__buffer_cspc != None:
758 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
759
760 if self.__buffer_dc != None:
761 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
762
727 763 self.__profIndex += 1
728 764 return
729 765
730 766 #If the buffer length is equal to n then replacing the last buffer value with the data value
731 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
732 self.__buffer[self.n-1] = data
767 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
768 self.__buffer_spc[self.n-1] = data_spc
769
770 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
771 self.__buffer_cspc[self.n-1] = data_cspc
772
773 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
774 self.__buffer_dc[self.n-1] = data_dc
775
733 776 self.__profIndex = self.n
734 777 return
735 778
@@ -743,67 +786,85 class IncohInt(Operation):
743 786 self.__profileIndex
744 787
745 788 """
789 data_spc = None
790 data_cspc = None
791 data_dc = None
746 792
747 793 if not self.__withOverapping:
748 data = self.__buffer
794 data_spc = self.__buffer_spc
795 data_cspc = self.__buffer_cspc
796 data_dc = self.__buffer_dc
797
749 798 n = self.__profIndex
750 799
751 self.__buffer = 0
800 self.__buffer_spc = 0
801 self.__buffer_cspc = 0
802 self.__buffer_dc = 0
752 803 self.__profIndex = 0
753 804
754 return data, n
805 return data_spc, data_cspc, data_dc, n
755 806
756 807 #Integration with Overlapping
757 data = numpy.sum(self.__buffer, axis=0)
808 data_spc = numpy.sum(self.__buffer_spc, axis=0)
809
810 if self.__buffer_cspc != None:
811 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
812
813 if self.__buffer_dc != None:
814 data_dc = numpy.sum(self.__buffer_dc, axis=0)
815
758 816 n = self.__profIndex
759 817
760 return data, n
818 return data_spc, data_cspc, data_dc, n
761 819
762 def byProfiles(self, data):
820 def byProfiles(self, *args):
763 821
764 822 self.__dataReady = False
765 avgdata = None
823 avgdata_spc = None
824 avgdata_cspc = None
825 avgdata_dc = None
766 826 n = None
767 827
768 self.putData(data)
828 self.putData(*args)
769 829
770 830 if self.__profIndex == self.n:
771 831
772 avgdata, n = self.pushData()
832 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
773 833 self.__dataReady = True
774 834
775 return avgdata
835 return avgdata_spc, avgdata_cspc, avgdata_dc
776 836
777 def byTime(self, data, datatime):
837 def byTime(self, datatime, *args):
778 838
779 839 self.__dataReady = False
780 avgdata = None
840 avgdata_spc = None
841 avgdata_cspc = None
842 avgdata_dc = None
781 843 n = None
782 844
783 self.putData(data)
845 self.putData(*args)
784 846
785 847 if (datatime - self.__initime) >= self.__integrationtime:
786 avgdata, n = self.pushData()
848 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
787 849 self.n = n
788 850 self.__dataReady = True
789 851
790 return avgdata
852 return avgdata_spc, avgdata_cspc, avgdata_dc
791 853
792 def integrate(self, data, datatime=None):
854 def integrate(self, datatime, *args):
793 855
794 856 if self.__initime == None:
795 857 self.__initime = datatime
796 858
797 859 if self.__byTime:
798 avgdata = self.byTime(data, datatime)
860 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
799 861 else:
800 avgdata = self.byProfiles(data)
801
862 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
802 863
803 864 self.__lastdatatime = datatime
804 865
805 if avgdata == None:
806 return None, None
866 if avgdata_spc == None:
867 return None, None, None, None
807 868
808 869 avgdatatime = self.__initime
809 870
@@ -814,7 +875,7 class IncohInt(Operation):
814 875 else:
815 876 self.__initime += deltatime
816 877
817 return avgdata, avgdatatime
878 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
818 879
819 880 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
820 881
@@ -822,13 +883,19 class IncohInt(Operation):
822 883 self.setup(n, timeInterval, overlapping)
823 884 self.__isConfig = True
824 885
825 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
886 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
887 dataOut.data_spc,
888 dataOut.data_cspc,
889 dataOut.data_dc)
826 890
827 891 # dataOut.timeInterval *= n
828 892 dataOut.flagNoData = True
829 893
830 894 if self.__dataReady:
831 dataOut.data_spc = avgdata
895 dataOut.data_spc = avgdata_spc
896 dataOut.data_cspc = avgdata_cspc
897 dataOut.data_dc = avgdata_dc
898
832 899 dataOut.nIncohInt *= self.n
833 900 dataOut.utctime = avgdatatime
834 901 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
General Comments 0
You need to be logged in to leave comments. Login now