@@ -1,3 +1,4 | |||||
|
1 | import os | |||
1 | import numpy |
|
2 | import numpy | |
2 | import mpldriver |
|
3 | import mpldriver | |
3 |
|
4 | |||
@@ -17,6 +18,7 class Figure: | |||||
17 |
|
18 | |||
18 | WIDTH = None |
|
19 | WIDTH = None | |
19 | HEIGHT = None |
|
20 | HEIGHT = None | |
|
21 | PREFIX = 'fig' | |||
20 |
|
22 | |||
21 | def __init__(self): |
|
23 | def __init__(self): | |
22 |
|
24 | |||
@@ -25,6 +27,12 class Figure: | |||||
25 | def __del__(self): |
|
27 | def __del__(self): | |
26 |
|
28 | |||
27 | self.__driver.closeFigure() |
|
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 | def getAxesObjList(self): |
|
37 | def getAxesObjList(self): | |
30 |
|
38 | |||
@@ -110,8 +118,10 class Figure: | |||||
110 | axesObj = Axes(self.fig, *args) |
|
118 | axesObj = Axes(self.fig, *args) | |
111 | self.axesObjList.append(axesObj) |
|
119 | self.axesObjList.append(axesObj) | |
112 |
|
120 | |||
113 | def saveFigure(self, *args): |
|
121 | def saveFigure(self, figpath, figfile, *args): | |
114 | self.__driver.saveFigure(self.fig, *args) |
|
122 | ||
|
123 | filename = os.path.join(figpath, figfile) | |||
|
124 | self.__driver.saveFigure(self.fig, filename, *args) | |||
115 |
|
125 | |||
116 | def draw(self): |
|
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 | for tick in ax.yaxis.get_major_ticks(): |
|
184 | for tick in ax.yaxis.get_major_ticks(): | |
185 | tick.label.set_fontsize(ticksize) |
|
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 | if grid != None: |
|
198 | if grid != None: | |
189 | ax.grid(b=True, which='major', axis=grid) |
|
199 | ax.grid(b=True, which='major', axis=grid) | |
190 |
|
200 | |||
191 | matplotlib.pyplot.tight_layout() |
|
201 | matplotlib.pyplot.tight_layout() | |
192 |
|
202 | |||
193 | iplot = ax.lines[-1] |
|
|||
194 |
|
||||
195 | return iplot |
|
203 | return iplot | |
196 |
|
204 | |||
197 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
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 | tick.set_fontsize(ticksize) |
|
242 | tick.set_fontsize(ticksize) | |
235 |
|
243 | |||
236 | ax_cb.yaxis.tick_right() |
|
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 | matplotlib.pyplot.tight_layout() |
|
254 | matplotlib.pyplot.tight_layout() | |
238 |
|
255 | |||
239 | if XAxisAsTime: |
|
256 | if XAxisAsTime: |
@@ -9,6 +9,7 class RTIPlot(Figure): | |||||
9 |
|
9 | |||
10 | WIDTHPROF = None |
|
10 | WIDTHPROF = None | |
11 | HEIGHTPROF = None |
|
11 | HEIGHTPROF = None | |
|
12 | PREFIX = 'rti' | |||
12 |
|
13 | |||
13 | def __init__(self): |
|
14 | def __init__(self): | |
14 |
|
15 | |||
@@ -17,7 +18,7 class RTIPlot(Figure): | |||||
17 | self.__nsubplots = 1 |
|
18 | self.__nsubplots = 1 | |
18 |
|
19 | |||
19 | self.WIDTH = 800 |
|
20 | self.WIDTH = 800 | |
20 |
self.HEIGHT = |
|
21 | self.HEIGHT = 200 | |
21 | self.WIDTHPROF = 120 |
|
22 | self.WIDTHPROF = 120 | |
22 | self.HEIGHTPROF = 0 |
|
23 | self.HEIGHTPROF = 0 | |
23 |
|
24 | |||
@@ -92,7 +93,7 class RTIPlot(Figure): | |||||
92 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
93 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
93 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
94 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
94 | timerange=None, |
|
95 | timerange=None, | |
95 |
save=False, file |
|
96 | save=False, figpath='./', figfile=None): | |
96 |
|
97 | |||
97 | """ |
|
98 | """ | |
98 |
|
99 | |||
@@ -175,7 +176,11 class RTIPlot(Figure): | |||||
175 | self.draw() |
|
176 | self.draw() | |
176 |
|
177 | |||
177 | if save: |
|
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 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
185 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
181 | self.__isConfig = False |
|
186 | self.__isConfig = False | |
@@ -187,6 +192,7 class SpectraPlot(Figure): | |||||
187 |
|
192 | |||
188 | WIDTHPROF = None |
|
193 | WIDTHPROF = None | |
189 | HEIGHTPROF = None |
|
194 | HEIGHTPROF = None | |
|
195 | PREFIX = 'spc' | |||
190 |
|
196 | |||
191 | def __init__(self): |
|
197 | def __init__(self): | |
192 |
|
198 | |||
@@ -239,7 +245,8 class SpectraPlot(Figure): | |||||
239 | counter += 1 |
|
245 | counter += 1 | |
240 |
|
246 | |||
241 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
247 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
242 |
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=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 | self.draw() |
|
324 | self.draw() | |
318 |
|
325 | |||
319 | if save: |
|
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 | class Scope(Figure): |
|
333 | class Scope(Figure): | |
323 |
|
334 |
@@ -494,7 +494,7 class SpectraProc(ProcessingUnit): | |||||
494 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
494 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
495 | self.dataOut.nIncohInt = 1 |
|
495 | self.dataOut.nIncohInt = 1 | |
496 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
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 | def __getFft(self): |
|
499 | def __getFft(self): | |
500 | """ |
|
500 | """ | |
@@ -650,7 +650,9 class IncohInt(Operation): | |||||
650 | __lastdatatime = None |
|
650 | __lastdatatime = None | |
651 | __integrationtime = None |
|
651 | __integrationtime = None | |
652 |
|
652 | |||
653 | __buffer = None |
|
653 | __buffer_spc = None | |
|
654 | __buffer_cspc = None | |||
|
655 | __buffer_dc = None | |||
654 |
|
656 | |||
655 | __dataReady = False |
|
657 | __dataReady = False | |
656 |
|
658 | |||
@@ -675,7 +677,9 class IncohInt(Operation): | |||||
675 |
|
677 | |||
676 | self.__initime = None |
|
678 | self.__initime = None | |
677 | self.__lastdatatime = 0 |
|
679 | self.__lastdatatime = 0 | |
678 | self.__buffer = None |
|
680 | self.__buffer_spc = None | |
|
681 | self.__buffer_cspc = None | |||
|
682 | self.__buffer_dc = None | |||
679 | self.__dataReady = False |
|
683 | self.__dataReady = False | |
680 |
|
684 | |||
681 |
|
685 | |||
@@ -692,44 +696,83 class IncohInt(Operation): | |||||
692 |
|
696 | |||
693 | if overlapping: |
|
697 | if overlapping: | |
694 | self.__withOverapping = True |
|
698 | self.__withOverapping = True | |
695 | self.__buffer = None |
|
|||
696 | else: |
|
699 | else: | |
697 | self.__withOverapping = False |
|
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 | self.__profIndex = 0 |
|
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 | if not self.__withOverapping: |
|
714 | if not self.__withOverapping: | |
710 |
self.__buffer += data |
|
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 | self.__profIndex += 1 |
|
727 | self.__profIndex += 1 | |
712 | return |
|
728 | return | |
713 |
|
729 | |||
714 | #Overlapping data |
|
730 | #Overlapping data | |
715 | nChannels, nFFTPoints, nHeis = data.shape |
|
731 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
716 | data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis)) |
|
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 | #If the buffer is empty then it takes the data value |
|
736 | #If the buffer is empty then it takes the data value | |
719 | if self.__buffer == None: |
|
737 | if self.__buffer_spc == None: | |
720 | self.__buffer = data |
|
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 | self.__profIndex += 1 |
|
750 | self.__profIndex += 1 | |
722 | return |
|
751 | return | |
723 |
|
752 | |||
724 | #If the buffer length is lower than n then stakcing the data value |
|
753 | #If the buffer length is lower than n then stakcing the data value | |
725 | if self.__profIndex < self.n: |
|
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 | self.__profIndex += 1 |
|
763 | self.__profIndex += 1 | |
728 | return |
|
764 | return | |
729 |
|
765 | |||
730 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
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) |
|
767 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
732 | self.__buffer[self.n-1] = data |
|
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 | self.__profIndex = self.n |
|
776 | self.__profIndex = self.n | |
734 | return |
|
777 | return | |
735 |
|
778 | |||
@@ -743,67 +786,85 class IncohInt(Operation): | |||||
743 | self.__profileIndex |
|
786 | self.__profileIndex | |
744 |
|
787 | |||
745 | """ |
|
788 | """ | |
|
789 | data_spc = None | |||
|
790 | data_cspc = None | |||
|
791 | data_dc = None | |||
746 |
|
792 | |||
747 | if not self.__withOverapping: |
|
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 | n = self.__profIndex |
|
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 | self.__profIndex = 0 |
|
803 | self.__profIndex = 0 | |
753 |
|
804 | |||
754 | return data, n |
|
805 | return data_spc, data_cspc, data_dc, n | |
755 |
|
806 | |||
756 | #Integration with Overlapping |
|
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 | n = self.__profIndex |
|
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, |
|
820 | def byProfiles(self, *args): | |
763 |
|
821 | |||
764 | self.__dataReady = False |
|
822 | self.__dataReady = False | |
765 | avgdata = None |
|
823 | avgdata_spc = None | |
|
824 | avgdata_cspc = None | |||
|
825 | avgdata_dc = None | |||
766 | n = None |
|
826 | n = None | |
767 |
|
827 | |||
768 |
self.putData( |
|
828 | self.putData(*args) | |
769 |
|
829 | |||
770 | if self.__profIndex == self.n: |
|
830 | if self.__profIndex == self.n: | |
771 |
|
831 | |||
772 | avgdata, n = self.pushData() |
|
832 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
773 | self.__dataReady = True |
|
833 | self.__dataReady = True | |
774 |
|
834 | |||
775 | return avgdata |
|
835 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
776 |
|
836 | |||
777 |
def byTime(self, data, |
|
837 | def byTime(self, datatime, *args): | |
778 |
|
838 | |||
779 | self.__dataReady = False |
|
839 | self.__dataReady = False | |
780 | avgdata = None |
|
840 | avgdata_spc = None | |
|
841 | avgdata_cspc = None | |||
|
842 | avgdata_dc = None | |||
781 | n = None |
|
843 | n = None | |
782 |
|
844 | |||
783 |
self.putData( |
|
845 | self.putData(*args) | |
784 |
|
846 | |||
785 | if (datatime - self.__initime) >= self.__integrationtime: |
|
847 | if (datatime - self.__initime) >= self.__integrationtime: | |
786 | avgdata, n = self.pushData() |
|
848 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
787 | self.n = n |
|
849 | self.n = n | |
788 | self.__dataReady = True |
|
850 | self.__dataReady = True | |
789 |
|
851 | |||
790 | return avgdata |
|
852 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
791 |
|
853 | |||
792 |
def integrate(self, data, |
|
854 | def integrate(self, datatime, *args): | |
793 |
|
855 | |||
794 | if self.__initime == None: |
|
856 | if self.__initime == None: | |
795 | self.__initime = datatime |
|
857 | self.__initime = datatime | |
796 |
|
858 | |||
797 | if self.__byTime: |
|
859 | if self.__byTime: | |
798 |
avgdata = self.byTime(data, |
|
860 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
799 | else: |
|
861 | else: | |
800 |
avgdata = self.byProfiles( |
|
862 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
801 |
|
||||
802 |
|
863 | |||
803 | self.__lastdatatime = datatime |
|
864 | self.__lastdatatime = datatime | |
804 |
|
865 | |||
805 | if avgdata == None: |
|
866 | if avgdata_spc == None: | |
806 | return None, None |
|
867 | return None, None, None, None | |
807 |
|
868 | |||
808 | avgdatatime = self.__initime |
|
869 | avgdatatime = self.__initime | |
809 |
|
870 | |||
@@ -814,7 +875,7 class IncohInt(Operation): | |||||
814 | else: |
|
875 | else: | |
815 | self.__initime += deltatime |
|
876 | self.__initime += deltatime | |
816 |
|
877 | |||
817 |
return avgdata, avgdata |
|
878 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
818 |
|
879 | |||
819 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
880 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
820 |
|
881 | |||
@@ -822,13 +883,19 class IncohInt(Operation): | |||||
822 | self.setup(n, timeInterval, overlapping) |
|
883 | self.setup(n, timeInterval, overlapping) | |
823 | self.__isConfig = True |
|
884 | self.__isConfig = True | |
824 |
|
885 | |||
825 |
avgdata, avgdata |
|
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 | # dataOut.timeInterval *= n |
|
891 | # dataOut.timeInterval *= n | |
828 | dataOut.flagNoData = True |
|
892 | dataOut.flagNoData = True | |
829 |
|
893 | |||
830 | if self.__dataReady: |
|
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 | dataOut.nIncohInt *= self.n |
|
899 | dataOut.nIncohInt *= self.n | |
833 | dataOut.utctime = avgdatatime |
|
900 | dataOut.utctime = avgdatatime | |
834 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
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