@@ -0,0 +1,95 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | path = os.path.split(os.getcwd())[0] | |
|
4 | sys.path.append(path) | |
|
5 | ||
|
6 | from controller import * | |
|
7 | ||
|
8 | desc = "EWDrifts Experiment Test" | |
|
9 | filename = "ewdrifts.xml" | |
|
10 | ||
|
11 | controllerObj = Project() | |
|
12 | ||
|
13 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
14 | ||
|
15 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
|
16 | path='/Users/dsuarez/Remote/EW_DRIFTS_Sep2012', | |
|
17 | startDate='2011/01/01', | |
|
18 | endDate='2012/12/31', | |
|
19 | startTime='00:00:00', | |
|
20 | endTime='23:59:59', | |
|
21 | online=0, | |
|
22 | walk=0) | |
|
23 | ||
|
24 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
25 | ||
|
26 | opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') | |
|
27 | opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') | |
|
28 | ||
|
29 | opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
30 | opObj11.addParameter(name='window', value='3', format='int') | |
|
31 | ||
|
32 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
33 | ||
|
34 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
35 | procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') | |
|
36 | procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(2,3)', format='pairslist') | |
|
37 | ||
|
38 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
39 | opObj11.addParameter(name='n', value='10', format='float') | |
|
40 | #opObj11.addParameter(name='timeInterval', value='0.33', format='float') | |
|
41 | ||
|
42 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
43 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
|
44 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
45 | #opObj11.addParameter(name='channelList', value='0,6', format='intlist') | |
|
46 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
47 | opObj11.addParameter(name='zmax', value='120', format='int') | |
|
48 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
49 | ||
|
50 | ||
|
51 | #opObj11 = procUnitConfObj1.addOperation(name='RTIfromNoise', optype='other') | |
|
52 | #opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
53 | #opObj11.addParameter(name='timerange', value='10', format='int') | |
|
54 | #opObj11.addParameter(name='ymin', value='20', format='int') | |
|
55 | #opObj11.addParameter(name='ymax', value='120', format='int') | |
|
56 | ||
|
57 | opObj11 = procUnitConfObj1.addOperation(name='ProfilePlot', optype='other') | |
|
58 | opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
59 | #opObj11.addParameter(name='wintitle', value='Prof', format='str') | |
|
60 | opObj11.addParameter(name='xmin', value='30', format='int') | |
|
61 | opObj11.addParameter(name='xmax', value='120', format='int') | |
|
62 | ||
|
63 | opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
|
64 | opObj11.addParameter(name='idfigure', value='3', format='int') | |
|
65 | opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
|
66 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
67 | opObj11.addParameter(name='zmax', value='120', format='int') | |
|
68 | #opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') | |
|
69 | ||
|
70 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
71 | opObj11.addParameter(name='idfigure', value='4', format='int') | |
|
72 | opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') | |
|
73 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
74 | opObj11.addParameter(name='zmax', value='120', format='int') | |
|
75 | opObj11.addParameter(name='timerange', value='3600', format='int') | |
|
76 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
77 | opObj11.addParameter(name='save', value='1', format='bool') | |
|
78 | opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures', format='str') | |
|
79 | ||
|
80 | opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') | |
|
81 | opObj11.addParameter(name='idfigure', value='5', format='int') | |
|
82 | #opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') | |
|
83 | opObj11.addParameter(name='timerange', value='300', format='int') | |
|
84 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
85 | ||
|
86 | print "Escribiendo el archivo XML" | |
|
87 | controllerObj.writeXml(filename) | |
|
88 | print "Leyendo el archivo XML" | |
|
89 | controllerObj.readXml(filename) | |
|
90 | ||
|
91 | controllerObj.createObjects() | |
|
92 | controllerObj.connectObjects() | |
|
93 | controllerObj.run() | |
|
94 | ||
|
95 | No newline at end of file |
@@ -0,0 +1,62 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | path = os.path.split(os.getcwd())[0] | |
|
4 | sys.path.append(path) | |
|
5 | ||
|
6 | from controller import * | |
|
7 | ||
|
8 | desc = "Faraday Experiment Test" | |
|
9 | filename = "faraday.xml" | |
|
10 | ||
|
11 | controllerObj = Project() | |
|
12 | ||
|
13 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
14 | ||
|
15 | path = '' | |
|
16 | ||
|
17 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
|
18 | path=path, | |
|
19 | startDate='2011/01/01', | |
|
20 | endDate='2012/12/31', | |
|
21 | startTime='00:00:00', | |
|
22 | endTime='23:59:59', | |
|
23 | online=0, | |
|
24 | walk=0) | |
|
25 | ||
|
26 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
27 | ||
|
28 | opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') | |
|
29 | opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') | |
|
30 | ||
|
31 | opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
32 | opObj11.addParameter(name='window', value='3', format='int') | |
|
33 | ||
|
34 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
35 | ||
|
36 | opObj11 = procUnitConfObj0.addOperation(name='deFlip') | |
|
37 | ||
|
38 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
39 | procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') | |
|
40 | procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
41 | ||
|
42 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
43 | opObj11.addParameter(name='n', value='10', format='float') | |
|
44 | #opObj11.addParameter(name='timeInterval', value='0.33', format='float') | |
|
45 | ||
|
46 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
47 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
|
48 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
49 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
50 | opObj11.addParameter(name='zmax', value='120', format='int') | |
|
51 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
52 | ||
|
53 | ||
|
54 | print "Escribiendo el archivo XML" | |
|
55 | controllerObj.writeXml(filename) | |
|
56 | print "Leyendo el archivo XML" | |
|
57 | controllerObj.readXml(filename) | |
|
58 | ||
|
59 | controllerObj.createObjects() | |
|
60 | controllerObj.connectObjects() | |
|
61 | controllerObj.run() | |
|
62 |
@@ -0,0 +1,83 | |||
|
1 | import sys | |
|
2 | ||
|
3 | from controller import * | |
|
4 | ||
|
5 | desc = "Imaging Experiment Test" | |
|
6 | filename = "imaging.xml" | |
|
7 | ||
|
8 | controllerObj = Project() | |
|
9 | ||
|
10 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
11 | ||
|
12 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', | |
|
13 | path='/Users/dsuarez/Remote/IMAGING/D2012080', | |
|
14 | startDate='2011/01/01', | |
|
15 | endDate='2012/12/31', | |
|
16 | startTime='00:00:00', | |
|
17 | endTime='23:59:59', | |
|
18 | online=0, | |
|
19 | walk=0) | |
|
20 | ||
|
21 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) | |
|
22 | ||
|
23 | #opObj11 = procUnitConfObj0.addOperation(name='selectChannels') | |
|
24 | #opObj11.addParameter(name='channelList', value='0,2,6', format='intlist') | |
|
25 | ||
|
26 | ||
|
27 | ## | |
|
28 | #procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
29 | #procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
|
30 | #procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
31 | ||
|
32 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
33 | opObj11.addParameter(name='n', value='2', format='int') | |
|
34 | ||
|
35 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
36 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
|
37 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
38 | #opObj11.addParameter(name='channelList', value='0,6', format='intlist') | |
|
39 | opObj11.addParameter(name='zmin', value='30', format='int') | |
|
40 | opObj11.addParameter(name='zmax', value='120', format='int') | |
|
41 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
42 | ||
|
43 | opObj11 = procUnitConfObj1.addOperation(name='ProfilePlot', optype='other') | |
|
44 | opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
45 | opObj11.addParameter(name='wintitle', value='O', format='str') | |
|
46 | opObj11.addParameter(name='xmin', value='30', format='int') | |
|
47 | opObj11.addParameter(name='xmax', value='120', format='int') | |
|
48 | ||
|
49 | ||
|
50 | ||
|
51 | #opObj11 = procUnitConfObj0.addOperation(name='CrossSpectraPlot', optype='other') | |
|
52 | #opObj11.addParameter(name='idfigure', value='3', format='int') | |
|
53 | #opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
|
54 | #opObj11.addParameter(name='zmin', value='30', format='int') | |
|
55 | #opObj11.addParameter(name='zmax', value='120', format='int') | |
|
56 | #opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') | |
|
57 | ||
|
58 | #opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
59 | #opObj11.addParameter(name='idfigure', value='4', format='int') | |
|
60 | #opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') | |
|
61 | #opObj11.addParameter(name='zmin', value='30', format='int') | |
|
62 | #opObj11.addParameter(name='zmax', value='120', format='int') | |
|
63 | #opObj11.addParameter(name='timerange', value='3600', format='int') | |
|
64 | #opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
65 | #opObj11.addParameter(name='save', value='1', format='bool') | |
|
66 | #opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures', format='str') | |
|
67 | ||
|
68 | #opObj11 = procUnitConfObj0.addOperation(name='CoherencePlot', optype='other') | |
|
69 | #opObj11.addParameter(name='idfigure', value='5', format='int') | |
|
70 | #opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') | |
|
71 | #opObj11.addParameter(name='timerange', value='300', format='int') | |
|
72 | #opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
73 | ||
|
74 | print "Escribiendo el archivo XML" | |
|
75 | controllerObj.writeXml(filename) | |
|
76 | print "Leyendo el archivo XML" | |
|
77 | controllerObj.readXml(filename) | |
|
78 | ||
|
79 | controllerObj.createObjects() | |
|
80 | controllerObj.connectObjects() | |
|
81 | controllerObj.run() | |
|
82 | ||
|
83 | No newline at end of file |
@@ -1,368 +1,396 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | class Figure: |
|
8 | 8 | |
|
9 | 9 | __driver = mpldriver |
|
10 | 10 | fig = None |
|
11 | 11 | |
|
12 | 12 | idfigure = None |
|
13 | 13 | wintitle = None |
|
14 | 14 | width = None |
|
15 | 15 | height = None |
|
16 | 16 | nplots = None |
|
17 | 17 | timerange = None |
|
18 | 18 | |
|
19 | 19 | axesObjList = [] |
|
20 | 20 | |
|
21 | 21 | WIDTH = None |
|
22 | 22 | HEIGHT = None |
|
23 | 23 | PREFIX = 'fig' |
|
24 | 24 | |
|
25 | 25 | def __init__(self): |
|
26 | 26 | |
|
27 | 27 | raise ValueError, "This method is not implemented" |
|
28 | 28 | |
|
29 | 29 | def __del__(self): |
|
30 | 30 | |
|
31 | 31 | self.__driver.closeFigure() |
|
32 | 32 | |
|
33 | 33 | def getFilename(self, name, ext='.png'): |
|
34 | 34 | |
|
35 | 35 | filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext) |
|
36 | 36 | |
|
37 | 37 | return filename |
|
38 | 38 | |
|
39 | 39 | def getAxesObjList(self): |
|
40 | 40 | |
|
41 | 41 | return self.axesObjList |
|
42 | 42 | |
|
43 | 43 | def getSubplots(self): |
|
44 | 44 | |
|
45 | 45 | raise ValueError, "Abstract method: This method should be defined" |
|
46 | 46 | |
|
47 | 47 | def getScreenDim(self, widthplot, heightplot): |
|
48 | 48 | |
|
49 | 49 | nrow, ncol = self.getSubplots() |
|
50 | 50 | |
|
51 | 51 | widthscreen = widthplot*ncol |
|
52 | 52 | heightscreen = heightplot*nrow |
|
53 | 53 | |
|
54 | 54 | return widthscreen, heightscreen |
|
55 | 55 | |
|
56 | 56 | def getTimeLim(self, x, xmin, xmax): |
|
57 | 57 | |
|
58 | 58 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
59 | 59 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
60 | 60 | |
|
61 | 61 | #################################################### |
|
62 | 62 | #If the x is out of xrange |
|
63 | 63 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
64 | 64 | xmin = None |
|
65 | 65 | xmax = None |
|
66 | 66 | |
|
67 | 67 | if xmin == None: |
|
68 | 68 | td = thisdatetime - thisdate |
|
69 | 69 | xmin = td.seconds/(60*60.) |
|
70 | 70 | |
|
71 | 71 | if xmax == None: |
|
72 | 72 | xmax = xmin + self.timerange/(60*60.) |
|
73 | 73 | |
|
74 | 74 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
75 | 75 | tmin = time.mktime(mindt.timetuple()) |
|
76 | 76 | |
|
77 | 77 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
78 | 78 | tmax = time.mktime(maxdt.timetuple()) |
|
79 | 79 | |
|
80 | 80 | self.timerange = tmax - tmin |
|
81 | 81 | |
|
82 | 82 | return tmin, tmax |
|
83 | 83 | |
|
84 | 84 | def init(self, idfigure, nplots, wintitle): |
|
85 | 85 | |
|
86 | 86 | raise ValueError, "This method has been replaced with createFigure" |
|
87 | 87 | |
|
88 | 88 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
92 | 92 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
93 | 93 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
94 | 94 | |
|
95 | 95 | Input: |
|
96 | 96 | idfigure : Los parametros necesarios son |
|
97 | 97 | wintitle : |
|
98 | 98 | |
|
99 | 99 | """ |
|
100 | 100 | |
|
101 | 101 | if widthplot == None: |
|
102 | 102 | widthplot = self.WIDTH |
|
103 | 103 | |
|
104 | 104 | if heightplot == None: |
|
105 | 105 | heightplot = self.HEIGHT |
|
106 | 106 | |
|
107 | 107 | self.idfigure = idfigure |
|
108 | 108 | |
|
109 | 109 | self.wintitle = wintitle |
|
110 | 110 | |
|
111 | 111 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
112 | 112 | |
|
113 | 113 | self.fig = self.__driver.createFigure(self.idfigure, |
|
114 | 114 | self.wintitle, |
|
115 | 115 | self.widthscreen, |
|
116 | 116 | self.heightscreen) |
|
117 | 117 | |
|
118 | 118 | self.axesObjList = [] |
|
119 | 119 | |
|
120 | 120 | def setDriver(self, driver=mpldriver): |
|
121 | 121 | |
|
122 | 122 | self.__driver = driver |
|
123 | 123 | |
|
124 | 124 | def setTitle(self, title): |
|
125 | 125 | |
|
126 | 126 | self.__driver.setTitle(self.fig, title) |
|
127 | 127 | |
|
128 | 128 | def setWinTitle(self, title): |
|
129 | 129 | |
|
130 | 130 | self.__driver.setWinTitle(self.fig, title=title) |
|
131 | 131 | |
|
132 | 132 | def setTextFromAxes(self, text): |
|
133 | 133 | |
|
134 | 134 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
135 | 135 | |
|
136 | 136 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
137 | 137 | |
|
138 | 138 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
139 | 139 | |
|
140 | 140 | def addAxes(self, *args): |
|
141 | 141 | """ |
|
142 | 142 | |
|
143 | 143 | Input: |
|
144 | 144 | *args : Los parametros necesarios son |
|
145 | 145 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
146 | 146 | """ |
|
147 | 147 | |
|
148 | 148 | axesObj = Axes(self.fig, *args) |
|
149 | 149 | self.axesObjList.append(axesObj) |
|
150 | 150 | |
|
151 | 151 | def saveFigure(self, figpath, figfile, *args): |
|
152 | 152 | |
|
153 | 153 | filename = os.path.join(figpath, figfile) |
|
154 | 154 | self.__driver.saveFigure(self.fig, filename, *args) |
|
155 | 155 | |
|
156 | 156 | def draw(self): |
|
157 | 157 | |
|
158 | 158 | self.__driver.draw(self.fig) |
|
159 | 159 | |
|
160 | 160 | def run(self): |
|
161 | 161 | |
|
162 | 162 | raise ValueError, "This method is not implemented" |
|
163 | 163 | |
|
164 | 164 | axesList = property(getAxesObjList) |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | class Axes: |
|
168 | 168 | |
|
169 | 169 | __driver = mpldriver |
|
170 | 170 | fig = None |
|
171 | 171 | ax = None |
|
172 | 172 | plot = None |
|
173 | 173 | |
|
174 | 174 | __firsttime = None |
|
175 | 175 | |
|
176 | 176 | __showprofile = False |
|
177 | 177 | |
|
178 | 178 | xmin = None |
|
179 | 179 | xmax = None |
|
180 | 180 | ymin = None |
|
181 | 181 | ymax = None |
|
182 | 182 | zmin = None |
|
183 | 183 | zmax = None |
|
184 | 184 | |
|
185 | 185 | def __init__(self, *args): |
|
186 | 186 | |
|
187 | 187 | """ |
|
188 | 188 | |
|
189 | 189 | Input: |
|
190 | 190 | *args : Los parametros necesarios son |
|
191 | 191 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
192 | 192 | """ |
|
193 | 193 | |
|
194 | 194 | ax = self.__driver.createAxes(*args) |
|
195 | 195 | self.fig = args[0] |
|
196 | 196 | self.ax = ax |
|
197 | 197 | self.plot = None |
|
198 | 198 | |
|
199 | 199 | self.__firsttime = True |
|
200 | 200 | self.idlineList = [] |
|
201 | 201 | |
|
202 | 202 | def setText(self, text): |
|
203 | 203 | |
|
204 | 204 | self.__driver.setAxesText(self.ax, text) |
|
205 | 205 | |
|
206 | 206 | def setXAxisAsTime(self): |
|
207 | 207 | pass |
|
208 | 208 | |
|
209 | 209 | def pline(self, x, y, |
|
210 | 210 | xmin=None, xmax=None, |
|
211 | 211 | ymin=None, ymax=None, |
|
212 | 212 | xlabel='', ylabel='', |
|
213 | 213 | title='', |
|
214 | 214 | **kwargs): |
|
215 | 215 | |
|
216 | 216 | """ |
|
217 | 217 | |
|
218 | 218 | Input: |
|
219 | 219 | x : |
|
220 | 220 | y : |
|
221 | 221 | xmin : |
|
222 | 222 | xmax : |
|
223 | 223 | ymin : |
|
224 | 224 | ymax : |
|
225 | 225 | xlabel : |
|
226 | 226 | ylabel : |
|
227 | 227 | title : |
|
228 | 228 | **kwargs : Los parametros aceptados son |
|
229 | 229 | |
|
230 | 230 | ticksize |
|
231 | 231 | ytick_visible |
|
232 | 232 | """ |
|
233 | 233 | |
|
234 | 234 | if self.__firsttime: |
|
235 | 235 | |
|
236 | 236 | if xmin == None: xmin = numpy.nanmin(x) |
|
237 | 237 | if xmax == None: xmax = numpy.nanmax(x) |
|
238 | 238 | if ymin == None: ymin = numpy.nanmin(y) |
|
239 | 239 | if ymax == None: ymax = numpy.nanmax(y) |
|
240 | 240 | |
|
241 | 241 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
242 | 242 | xmin, xmax, |
|
243 | 243 | ymin, ymax, |
|
244 | 244 | xlabel=xlabel, |
|
245 | 245 | ylabel=ylabel, |
|
246 | 246 | title=title, |
|
247 | 247 | **kwargs) |
|
248 | 248 | |
|
249 | 249 | self.idlineList.append(0) |
|
250 | 250 | self.__firsttime = False |
|
251 | 251 | return |
|
252 | 252 | |
|
253 | 253 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
254 | 254 | ylabel=ylabel, |
|
255 | 255 | title=title) |
|
256 | 256 | |
|
257 | 257 | def addpline(self, x, y, idline, **kwargs): |
|
258 | 258 | lines = self.ax.lines |
|
259 | 259 | |
|
260 | 260 | if idline in self.idlineList: |
|
261 | 261 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
262 | 262 | |
|
263 | 263 | if idline not in(self.idlineList): |
|
264 | 264 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
265 | 265 | self.idlineList.append(idline) |
|
266 | 266 | |
|
267 | 267 | return |
|
268 | 268 | |
|
269 | 269 | def pmultiline(self, x, y, |
|
270 | 270 | xmin=None, xmax=None, |
|
271 | 271 | ymin=None, ymax=None, |
|
272 | 272 | xlabel='', ylabel='', |
|
273 | 273 | title='', |
|
274 | 274 | **kwargs): |
|
275 | 275 | |
|
276 | 276 | if self.__firsttime: |
|
277 | 277 | |
|
278 | 278 | if xmin == None: xmin = numpy.nanmin(x) |
|
279 | 279 | if xmax == None: xmax = numpy.nanmax(x) |
|
280 | 280 | if ymin == None: ymin = numpy.nanmin(y) |
|
281 | 281 | if ymax == None: ymax = numpy.nanmax(y) |
|
282 | 282 | |
|
283 | 283 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
284 | 284 | xmin, xmax, |
|
285 | 285 | ymin, ymax, |
|
286 | 286 | xlabel=xlabel, |
|
287 | 287 | ylabel=ylabel, |
|
288 | 288 | title=title, |
|
289 | 289 | **kwargs) |
|
290 | 290 | self.__firsttime = False |
|
291 | 291 | return |
|
292 | 292 | |
|
293 | 293 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
294 | 294 | ylabel=ylabel, |
|
295 | 295 | title=title) |
|
296 | ||
|
297 | def pmultilineyaxis(self, x, y, | |
|
298 | xmin=None, xmax=None, | |
|
299 | ymin=None, ymax=None, | |
|
300 | xlabel='', ylabel='', | |
|
301 | title='', | |
|
302 | **kwargs): | |
|
296 | 303 | |
|
304 | if self.__firsttime: | |
|
305 | ||
|
306 | if xmin == None: xmin = numpy.nanmin(x) | |
|
307 | if xmax == None: xmax = numpy.nanmax(x) | |
|
308 | if ymin == None: ymin = numpy.nanmin(y) | |
|
309 | if ymax == None: ymax = numpy.nanmax(y) | |
|
310 | ||
|
311 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, | |
|
312 | xmin, xmax, | |
|
313 | ymin, ymax, | |
|
314 | xlabel=xlabel, | |
|
315 | ylabel=ylabel, | |
|
316 | title=title, | |
|
317 | **kwargs) | |
|
318 | self.__firsttime = False | |
|
319 | return | |
|
320 | ||
|
321 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, | |
|
322 | ylabel=ylabel, | |
|
323 | title=title) | |
|
324 | ||
|
297 | 325 | def pcolor(self, x, y, z, |
|
298 | 326 | xmin=None, xmax=None, |
|
299 | 327 | ymin=None, ymax=None, |
|
300 | 328 | zmin=None, zmax=None, |
|
301 | 329 | xlabel='', ylabel='', |
|
302 | 330 | title='', rti = False, colormap='jet', |
|
303 | 331 | **kwargs): |
|
304 | 332 | |
|
305 | 333 | """ |
|
306 | 334 | Input: |
|
307 | 335 | x : |
|
308 | 336 | y : |
|
309 | 337 | x : |
|
310 | 338 | xmin : |
|
311 | 339 | xmax : |
|
312 | 340 | ymin : |
|
313 | 341 | ymax : |
|
314 | 342 | zmin : |
|
315 | 343 | zmax : |
|
316 | 344 | xlabel : |
|
317 | 345 | ylabel : |
|
318 | 346 | title : |
|
319 | 347 | **kwargs : Los parametros aceptados son |
|
320 | 348 | ticksize=9, |
|
321 | 349 | cblabel='' |
|
322 | 350 | rti = True or False |
|
323 | 351 | """ |
|
324 | 352 | |
|
325 | 353 | if self.__firsttime: |
|
326 | 354 | |
|
327 | 355 | if xmin == None: xmin = numpy.nanmin(x) |
|
328 | 356 | if xmax == None: xmax = numpy.nanmax(x) |
|
329 | 357 | if ymin == None: ymin = numpy.nanmin(y) |
|
330 | 358 | if ymax == None: ymax = numpy.nanmax(y) |
|
331 | 359 | if zmin == None: zmin = numpy.nanmin(z) |
|
332 | 360 | if zmax == None: zmax = numpy.nanmax(z) |
|
333 | 361 | |
|
334 | 362 | |
|
335 | 363 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
336 | 364 | xmin, xmax, |
|
337 | 365 | ymin, ymax, |
|
338 | 366 | zmin, zmax, |
|
339 | 367 | xlabel=xlabel, |
|
340 | 368 | ylabel=ylabel, |
|
341 | 369 | title=title, |
|
342 | 370 | colormap=colormap, |
|
343 | 371 | **kwargs) |
|
344 | 372 | |
|
345 | 373 | if self.xmin == None: self.xmin = xmin |
|
346 | 374 | if self.xmax == None: self.xmax = xmax |
|
347 | 375 | if self.ymin == None: self.ymin = ymin |
|
348 | 376 | if self.ymax == None: self.ymax = ymax |
|
349 | 377 | if self.zmin == None: self.zmin = zmin |
|
350 | 378 | if self.zmax == None: self.zmax = zmax |
|
351 | 379 | |
|
352 | 380 | self.__firsttime = False |
|
353 | 381 | return |
|
354 | 382 | |
|
355 | 383 | if rti: |
|
356 | 384 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
357 | 385 | xlabel=xlabel, |
|
358 | 386 | ylabel=ylabel, |
|
359 | 387 | title=title, |
|
360 | 388 | colormap=colormap) |
|
361 | 389 | return |
|
362 | 390 | |
|
363 | 391 | self.__driver.pcolor(self.plot, z, |
|
364 | 392 | xlabel=xlabel, |
|
365 | 393 | ylabel=ylabel, |
|
366 | 394 | title=title) |
|
367 | 395 | |
|
368 | 396 | No newline at end of file |
@@ -1,275 +1,342 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import matplotlib |
|
4 | 4 | matplotlib.use("TKAgg") |
|
5 | 5 | import matplotlib.pyplot |
|
6 | 6 | import matplotlib.dates |
|
7 | 7 | #import scitools.numpyutils |
|
8 | 8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
9 | 9 | |
|
10 | 10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
11 | 11 | from matplotlib.ticker import FuncFormatter |
|
12 | 12 | from matplotlib.ticker import * |
|
13 | 13 | |
|
14 | 14 | ########################################### |
|
15 | 15 | #Actualizacion de las funciones del driver |
|
16 | 16 | ########################################### |
|
17 | 17 | |
|
18 | 18 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
19 | 19 | |
|
20 | 20 | matplotlib.pyplot.ioff() |
|
21 | 21 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
22 | 22 | fig.canvas.manager.set_window_title(wintitle) |
|
23 | 23 | fig.canvas.manager.resize(width, height) |
|
24 | 24 | matplotlib.pyplot.ion() |
|
25 | 25 | |
|
26 | 26 | return fig |
|
27 | 27 | |
|
28 | 28 | def closeFigure(): |
|
29 | 29 | |
|
30 | 30 | matplotlib.pyplot.ioff() |
|
31 | 31 | matplotlib.pyplot.show() |
|
32 | 32 | |
|
33 | 33 | return |
|
34 | 34 | |
|
35 | 35 | def saveFigure(fig, filename): |
|
36 | 36 | fig.savefig(filename) |
|
37 | 37 | |
|
38 | 38 | def setWinTitle(fig, title): |
|
39 | 39 | |
|
40 | 40 | fig.canvas.manager.set_window_title(title) |
|
41 | 41 | |
|
42 | 42 | def setTitle(fig, title): |
|
43 | 43 | |
|
44 | 44 | fig.suptitle(title) |
|
45 | 45 | |
|
46 | 46 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
47 | 47 | |
|
48 | 48 | matplotlib.pyplot.figure(fig.number) |
|
49 | 49 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
50 | 50 | (xpos, ypos), |
|
51 | 51 | colspan=colspan, |
|
52 | 52 | rowspan=rowspan) |
|
53 | 53 | return axes |
|
54 | 54 | |
|
55 | 55 | def setAxesText(ax, text): |
|
56 | 56 | |
|
57 | 57 | ax.annotate(text, |
|
58 | 58 | xy = (.1, .99), |
|
59 | 59 | xycoords = 'figure fraction', |
|
60 | 60 | horizontalalignment = 'left', |
|
61 | 61 | verticalalignment = 'top', |
|
62 | 62 | fontsize = 10) |
|
63 | 63 | |
|
64 | 64 | def printLabels(ax, xlabel, ylabel, title): |
|
65 | 65 | |
|
66 | 66 | ax.set_xlabel(xlabel, size=11) |
|
67 | 67 | ax.set_ylabel(ylabel, size=11) |
|
68 | 68 | ax.set_title(title, size=12) |
|
69 | 69 | |
|
70 | 70 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
71 | 71 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
72 | 72 | nxticks=4, nyticks=10, |
|
73 | 73 | grid=None): |
|
74 | 74 | |
|
75 | 75 | """ |
|
76 | 76 | |
|
77 | 77 | Input: |
|
78 | 78 | grid : None, 'both', 'x', 'y' |
|
79 | 79 | """ |
|
80 | 80 | |
|
81 | 81 | ax.plot(x, y) |
|
82 | 82 | ax.set_xlim([xmin,xmax]) |
|
83 | 83 | ax.set_ylim([ymin,ymax]) |
|
84 | 84 | |
|
85 | 85 | printLabels(ax, xlabel, ylabel, title) |
|
86 | 86 | |
|
87 | 87 | ###################################################### |
|
88 | 88 | if (xmax-xmin)<=1: |
|
89 | 89 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
90 | 90 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
91 | 91 | ax.set_xticks(xtickspos) |
|
92 | 92 | else: |
|
93 | 93 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
94 | 94 | ax.set_xticks(xtickspos) |
|
95 | 95 | |
|
96 | 96 | for tick in ax.get_xticklabels(): |
|
97 | 97 | tick.set_visible(xtick_visible) |
|
98 | 98 | |
|
99 | 99 | for tick in ax.xaxis.get_major_ticks(): |
|
100 | 100 | tick.label.set_fontsize(ticksize) |
|
101 | 101 | |
|
102 | 102 | ###################################################### |
|
103 | 103 | for tick in ax.get_yticklabels(): |
|
104 | 104 | tick.set_visible(ytick_visible) |
|
105 | 105 | |
|
106 | 106 | for tick in ax.yaxis.get_major_ticks(): |
|
107 | 107 | tick.label.set_fontsize(ticksize) |
|
108 | 108 | |
|
109 | 109 | iplot = ax.lines[-1] |
|
110 | 110 | |
|
111 | 111 | ###################################################### |
|
112 | 112 | if '0.' in matplotlib.__version__[0:2]: |
|
113 | 113 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
114 | 114 | return iplot |
|
115 | 115 | |
|
116 | 116 | if '1.0.' in matplotlib.__version__[0:4]: |
|
117 | 117 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
118 | 118 | return iplot |
|
119 | 119 | |
|
120 | 120 | if grid != None: |
|
121 | 121 | ax.grid(b=True, which='major', axis=grid) |
|
122 | 122 | |
|
123 | 123 | matplotlib.pyplot.tight_layout() |
|
124 | 124 | |
|
125 | 125 | return iplot |
|
126 | 126 | |
|
127 | 127 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
128 | 128 | |
|
129 | 129 | ax = iplot.get_axes() |
|
130 | 130 | |
|
131 | 131 | printLabels(ax, xlabel, ylabel, title) |
|
132 | 132 | |
|
133 | 133 | set_linedata(ax, x, y, idline=0) |
|
134 | 134 | |
|
135 | 135 | def addpline(ax, x, y, color, linestyle, lw): |
|
136 | 136 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
137 | 137 | |
|
138 | 138 | |
|
139 | 139 | def set_linedata(ax, x, y, idline): |
|
140 | 140 | ax.lines[idline].set_data(x,y) |
|
141 | 141 | |
|
142 | 142 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
143 | 143 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
144 | 144 | nxticks=4, nyticks=10, |
|
145 | 145 | grid=None): |
|
146 | 146 | |
|
147 | 147 | """ |
|
148 | 148 | |
|
149 | 149 | Input: |
|
150 | 150 | grid : None, 'both', 'x', 'y' |
|
151 | 151 | """ |
|
152 | 152 | |
|
153 | 153 | lines = ax.plot(x.T, y) |
|
154 |
leg = ax.legend(lines, legendlabels, loc='upper |
|
|
154 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
|
155 | 155 | leg.get_frame().set_alpha(0.5) |
|
156 | 156 | ax.set_xlim([xmin,xmax]) |
|
157 | 157 | ax.set_ylim([ymin,ymax]) |
|
158 | 158 | printLabels(ax, xlabel, ylabel, title) |
|
159 | 159 | |
|
160 | 160 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
161 | 161 | ax.set_xticks(xtickspos) |
|
162 | 162 | |
|
163 | 163 | for tick in ax.get_xticklabels(): |
|
164 | 164 | tick.set_visible(xtick_visible) |
|
165 | 165 | |
|
166 | 166 | for tick in ax.xaxis.get_major_ticks(): |
|
167 | 167 | tick.label.set_fontsize(ticksize) |
|
168 | 168 | |
|
169 | 169 | for tick in ax.get_yticklabels(): |
|
170 | 170 | tick.set_visible(ytick_visible) |
|
171 | 171 | |
|
172 | 172 | for tick in ax.yaxis.get_major_ticks(): |
|
173 | 173 | tick.label.set_fontsize(ticksize) |
|
174 | 174 | |
|
175 | 175 | iplot = ax.lines[-1] |
|
176 | 176 | |
|
177 | 177 | if '0.' in matplotlib.__version__[0:2]: |
|
178 | 178 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
179 | 179 | return iplot |
|
180 | 180 | |
|
181 | 181 | if '1.0.' in matplotlib.__version__[0:4]: |
|
182 | 182 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
183 | 183 | return iplot |
|
184 | 184 | |
|
185 | 185 | if grid != None: |
|
186 | 186 | ax.grid(b=True, which='major', axis=grid) |
|
187 | 187 | |
|
188 | 188 | matplotlib.pyplot.tight_layout() |
|
189 | 189 | |
|
190 | 190 | return iplot |
|
191 | 191 | |
|
192 | 192 | |
|
193 | 193 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
194 | 194 | |
|
195 | 195 | ax = iplot.get_axes() |
|
196 | 196 | |
|
197 | 197 | printLabels(ax, xlabel, ylabel, title) |
|
198 | 198 | |
|
199 | 199 | for i in range(len(ax.lines)): |
|
200 | 200 | line = ax.lines[i] |
|
201 | 201 | line.set_data(x[i,:],y) |
|
202 | ||
|
203 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
|
204 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
|
205 | nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid", | |
|
206 | grid=None, XAxisAsTime=False): | |
|
207 | ||
|
208 | """ | |
|
209 | ||
|
210 | Input: | |
|
211 | grid : None, 'both', 'x', 'y' | |
|
212 | """ | |
|
213 | ||
|
214 | lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
|
215 | leg = ax.legend(lines, legendlabels, bbox_to_anchor=(1.05, 1), loc='upper right', numpoints=1, handlelength=1.5, \ | |
|
216 | handletextpad=0.5, borderpad=0.2, labelspacing=0.2, borderaxespad=0.) | |
|
217 | ||
|
218 | ax.set_xlim([xmin,xmax]) | |
|
219 | ax.set_ylim([ymin,ymax]) | |
|
220 | printLabels(ax, xlabel, ylabel, title) | |
|
221 | ||
|
222 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
|
223 | # ax.set_xticks(xtickspos) | |
|
224 | ||
|
225 | for tick in ax.get_xticklabels(): | |
|
226 | tick.set_visible(xtick_visible) | |
|
227 | ||
|
228 | for tick in ax.xaxis.get_major_ticks(): | |
|
229 | tick.label.set_fontsize(ticksize) | |
|
230 | ||
|
231 | for tick in ax.get_yticklabels(): | |
|
232 | tick.set_visible(ytick_visible) | |
|
233 | ||
|
234 | for tick in ax.yaxis.get_major_ticks(): | |
|
235 | tick.label.set_fontsize(ticksize) | |
|
236 | ||
|
237 | iplot = ax.lines[-1] | |
|
238 | ||
|
239 | if '0.' in matplotlib.__version__[0:2]: | |
|
240 | print "The matplotlib version has to be updated to 1.1 or newer" | |
|
241 | return iplot | |
|
242 | ||
|
243 | if '1.0.' in matplotlib.__version__[0:4]: | |
|
244 | print "The matplotlib version has to be updated to 1.1 or newer" | |
|
245 | return iplot | |
|
246 | ||
|
247 | if grid != None: | |
|
248 | ax.grid(b=True, which='major', axis=grid) | |
|
249 | ||
|
250 | matplotlib.pyplot.tight_layout() | |
|
251 | ||
|
252 | if XAxisAsTime: | |
|
253 | ||
|
254 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
255 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
256 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
|
257 | ||
|
258 | return iplot | |
|
259 | ||
|
260 | def pmultilineinyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
|
261 | ||
|
262 | ax = iplot.get_axes() | |
|
263 | ||
|
264 | printLabels(ax, xlabel, ylabel, title) | |
|
265 | ||
|
266 | for i in range(len(ax.lines)): | |
|
267 | line = ax.lines[i] | |
|
268 | line.set_data(x,y[i,:]) | |
|
202 | 269 | |
|
203 | 270 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
204 | 271 | xlabel='', ylabel='', title='', ticksize = 9, |
|
205 | 272 | colormap='jet',cblabel='', cbsize="5%", |
|
206 | 273 | XAxisAsTime=False): |
|
207 | 274 | |
|
208 | 275 | divider = make_axes_locatable(ax) |
|
209 | 276 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
210 | 277 | fig = ax.get_figure() |
|
211 | 278 | fig.add_axes(ax_cb) |
|
212 | 279 | |
|
213 | 280 | ax.set_xlim([xmin,xmax]) |
|
214 | 281 | ax.set_ylim([ymin,ymax]) |
|
215 | 282 | |
|
216 | 283 | printLabels(ax, xlabel, ylabel, title) |
|
217 | 284 | |
|
218 | 285 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
219 | 286 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
220 | 287 | cb.set_label(cblabel) |
|
221 | 288 | |
|
222 | 289 | # for tl in ax_cb.get_yticklabels(): |
|
223 | 290 | # tl.set_visible(True) |
|
224 | 291 | |
|
225 | 292 | for tick in ax.yaxis.get_major_ticks(): |
|
226 | 293 | tick.label.set_fontsize(ticksize) |
|
227 | 294 | |
|
228 | 295 | for tick in ax.xaxis.get_major_ticks(): |
|
229 | 296 | tick.label.set_fontsize(ticksize) |
|
230 | 297 | |
|
231 | 298 | for tick in cb.ax.get_yticklabels(): |
|
232 | 299 | tick.set_fontsize(ticksize) |
|
233 | 300 | |
|
234 | 301 | ax_cb.yaxis.tick_right() |
|
235 | 302 | |
|
236 | 303 | if '0.' in matplotlib.__version__[0:2]: |
|
237 | 304 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
238 | 305 | return imesh |
|
239 | 306 | |
|
240 | 307 | if '1.0.' in matplotlib.__version__[0:4]: |
|
241 | 308 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
242 | 309 | return imesh |
|
243 | 310 | |
|
244 | 311 | matplotlib.pyplot.tight_layout() |
|
245 | 312 | |
|
246 | 313 | if XAxisAsTime: |
|
247 | 314 | |
|
248 | 315 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
249 | 316 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
250 | 317 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
251 | 318 | |
|
252 | 319 | return imesh |
|
253 | 320 | |
|
254 | 321 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
255 | 322 | |
|
256 | 323 | z = z.T |
|
257 | 324 | |
|
258 | 325 | ax = imesh.get_axes() |
|
259 | 326 | |
|
260 | 327 | printLabels(ax, xlabel, ylabel, title) |
|
261 | 328 | |
|
262 | 329 | imesh.set_array(z.ravel()) |
|
263 | 330 | |
|
264 | 331 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
265 | 332 | |
|
266 | 333 | printLabels(ax, xlabel, ylabel, title) |
|
267 | 334 | |
|
268 | 335 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
269 | 336 | |
|
270 | 337 | def draw(fig): |
|
271 | 338 | |
|
272 | 339 | if type(fig) == 'int': |
|
273 | 340 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
274 | 341 | |
|
275 | 342 | fig.canvas.draw() No newline at end of file |
@@ -1,986 +1,954 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTH = None |
|
11 | 11 | HEIGHT = None |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'cspc' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.__isConfig = False |
|
19 | 19 | self.__nsubplots = 4 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 250 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 0 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | ncol = 4 |
|
29 | 29 | nrow = self.nplots |
|
30 | 30 | |
|
31 | 31 | return nrow, ncol |
|
32 | 32 | |
|
33 | 33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
34 | 34 | |
|
35 | 35 | self.__showprofile = showprofile |
|
36 | 36 | self.nplots = nplots |
|
37 | 37 | |
|
38 | 38 | ncolspan = 1 |
|
39 | 39 | colspan = 1 |
|
40 | 40 | |
|
41 | 41 | self.createFigure(idfigure = idfigure, |
|
42 | 42 | wintitle = wintitle, |
|
43 | 43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
44 | 44 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
45 | 45 | |
|
46 | 46 | nrow, ncol = self.getSubplots() |
|
47 | 47 | |
|
48 | 48 | counter = 0 |
|
49 | 49 | for y in range(nrow): |
|
50 | 50 | for x in range(ncol): |
|
51 | 51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
52 | 52 | |
|
53 | 53 | counter += 1 |
|
54 | 54 | |
|
55 | 55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
56 | 56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
57 | 57 | save=False, figpath='./', figfile=None): |
|
58 | 58 | |
|
59 | 59 | """ |
|
60 | 60 | |
|
61 | 61 | Input: |
|
62 | 62 | dataOut : |
|
63 | 63 | idfigure : |
|
64 | 64 | wintitle : |
|
65 | 65 | channelList : |
|
66 | 66 | showProfile : |
|
67 | 67 | xmin : None, |
|
68 | 68 | xmax : None, |
|
69 | 69 | ymin : None, |
|
70 | 70 | ymax : None, |
|
71 | 71 | zmin : None, |
|
72 | 72 | zmax : None |
|
73 | 73 | """ |
|
74 | 74 | |
|
75 | 75 | if pairsList == None: |
|
76 | 76 | pairsIndexList = dataOut.pairsIndexList |
|
77 | 77 | else: |
|
78 | 78 | pairsIndexList = [] |
|
79 | 79 | for pair in pairsList: |
|
80 | 80 | if pair not in dataOut.pairsList: |
|
81 | 81 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
82 | 82 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
83 | 83 | |
|
84 | 84 | if pairsIndexList == []: |
|
85 | 85 | return |
|
86 | 86 | |
|
87 | 87 | if len(pairsIndexList) > 4: |
|
88 | 88 | pairsIndexList = pairsIndexList[0:4] |
|
89 | 89 | |
|
90 | 90 | x = dataOut.getVelRange(1) |
|
91 | 91 | y = dataOut.getHeiRange() |
|
92 | 92 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
|
93 | 93 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
94 | 94 | avg = numpy.average(numpy.abs(z), axis=1) |
|
95 | 95 | |
|
96 | 96 | noise = dataOut.getNoise() |
|
97 | 97 | |
|
98 | 98 | thisDatetime = dataOut.datatime |
|
99 | 99 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
100 | 100 | xlabel = "Velocity (m/s)" |
|
101 | 101 | ylabel = "Range (Km)" |
|
102 | 102 | |
|
103 | 103 | if not self.__isConfig: |
|
104 | 104 | |
|
105 | 105 | nplots = len(pairsIndexList) |
|
106 | 106 | |
|
107 | 107 | self.setup(idfigure=idfigure, |
|
108 | 108 | nplots=nplots, |
|
109 | 109 | wintitle=wintitle, |
|
110 | 110 | showprofile=showprofile) |
|
111 | 111 | |
|
112 | 112 | if xmin == None: xmin = numpy.nanmin(x) |
|
113 | 113 | if xmax == None: xmax = numpy.nanmax(x) |
|
114 | 114 | if ymin == None: ymin = numpy.nanmin(y) |
|
115 | 115 | if ymax == None: ymax = numpy.nanmax(y) |
|
116 | 116 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
117 | 117 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
118 | 118 | |
|
119 | 119 | self.__isConfig = True |
|
120 | 120 | |
|
121 | 121 | self.setWinTitle(title) |
|
122 | 122 | |
|
123 | 123 | for i in range(self.nplots): |
|
124 | 124 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
125 | 125 | |
|
126 | 126 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) |
|
127 | 127 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
128 | 128 | axes0 = self.axesList[i*self.__nsubplots] |
|
129 | 129 | axes0.pcolor(x, y, z, |
|
130 | 130 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
131 | 131 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
132 | 132 | ticksize=9, cblabel='') |
|
133 | 133 | |
|
134 | 134 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) |
|
135 | 135 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
136 | 136 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
137 | 137 | axes0.pcolor(x, y, z, |
|
138 | 138 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
139 | 139 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
140 | 140 | ticksize=9, cblabel='') |
|
141 | 141 | |
|
142 | 142 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
143 | 143 | coherence = numpy.abs(coherenceComplex) |
|
144 | 144 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
145 | 145 | |
|
146 | 146 | |
|
147 | 147 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
148 | 148 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
149 | 149 | axes0.pcolor(x, y, coherence, |
|
150 | 150 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
151 | 151 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
152 | 152 | ticksize=9, cblabel='') |
|
153 | 153 | |
|
154 | 154 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
155 | 155 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
156 | 156 | axes0.pcolor(x, y, phase, |
|
157 | 157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
158 | 158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
159 | 159 | ticksize=9, cblabel='', colormap='RdBu_r') |
|
160 | 160 | |
|
161 | 161 | |
|
162 | 162 | |
|
163 | 163 | self.draw() |
|
164 | 164 | |
|
165 | 165 | if save: |
|
166 | 166 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
167 | 167 | if figfile == None: |
|
168 | 168 | figfile = self.getFilename(name = date) |
|
169 | 169 | |
|
170 | 170 | self.saveFigure(figpath, figfile) |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | class RTIPlot(Figure): |
|
174 | 174 | |
|
175 | 175 | __isConfig = None |
|
176 | 176 | __nsubplots = None |
|
177 | 177 | |
|
178 | 178 | WIDTHPROF = None |
|
179 | 179 | HEIGHTPROF = None |
|
180 | 180 | PREFIX = 'rti' |
|
181 | 181 | |
|
182 | 182 | def __init__(self): |
|
183 | 183 | |
|
184 | 184 | self.timerange = 2*60*60 |
|
185 | 185 | self.__isConfig = False |
|
186 | 186 | self.__nsubplots = 1 |
|
187 | 187 | |
|
188 | 188 | self.WIDTH = 800 |
|
189 | 189 | self.HEIGHT = 200 |
|
190 | 190 | self.WIDTHPROF = 120 |
|
191 | 191 | self.HEIGHTPROF = 0 |
|
192 | 192 | |
|
193 | 193 | def getSubplots(self): |
|
194 | 194 | |
|
195 | 195 | ncol = 1 |
|
196 | 196 | nrow = self.nplots |
|
197 | 197 | |
|
198 | 198 | return nrow, ncol |
|
199 | 199 | |
|
200 | 200 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
201 | 201 | |
|
202 | 202 | self.__showprofile = showprofile |
|
203 | 203 | self.nplots = nplots |
|
204 | 204 | |
|
205 | 205 | ncolspan = 1 |
|
206 | 206 | colspan = 1 |
|
207 | 207 | if showprofile: |
|
208 | 208 | ncolspan = 7 |
|
209 | 209 | colspan = 6 |
|
210 | 210 | self.__nsubplots = 2 |
|
211 | 211 | |
|
212 | 212 | self.createFigure(idfigure = idfigure, |
|
213 | 213 | wintitle = wintitle, |
|
214 | 214 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
215 | 215 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
216 | 216 | |
|
217 | 217 | nrow, ncol = self.getSubplots() |
|
218 | 218 | |
|
219 | 219 | counter = 0 |
|
220 | 220 | for y in range(nrow): |
|
221 | 221 | for x in range(ncol): |
|
222 | 222 | |
|
223 | 223 | if counter >= self.nplots: |
|
224 | 224 | break |
|
225 | 225 | |
|
226 | 226 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
227 | 227 | |
|
228 | 228 | if showprofile: |
|
229 | 229 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
230 | 230 | |
|
231 | 231 | counter += 1 |
|
232 | 232 | |
|
233 | 233 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
234 | 234 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
235 | 235 | timerange=None, |
|
236 | 236 | save=False, figpath='./', figfile=None): |
|
237 | 237 | |
|
238 | 238 | """ |
|
239 | 239 | |
|
240 | 240 | Input: |
|
241 | 241 | dataOut : |
|
242 | 242 | idfigure : |
|
243 | 243 | wintitle : |
|
244 | 244 | channelList : |
|
245 | 245 | showProfile : |
|
246 | 246 | xmin : None, |
|
247 | 247 | xmax : None, |
|
248 | 248 | ymin : None, |
|
249 | 249 | ymax : None, |
|
250 | 250 | zmin : None, |
|
251 | 251 | zmax : None |
|
252 | 252 | """ |
|
253 | 253 | |
|
254 | 254 | if channelList == None: |
|
255 | 255 | channelIndexList = dataOut.channelIndexList |
|
256 | 256 | else: |
|
257 | 257 | channelIndexList = [] |
|
258 | 258 | for channel in channelList: |
|
259 | 259 | if channel not in dataOut.channelList: |
|
260 | 260 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
261 | 261 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
262 | 262 | |
|
263 | 263 | if timerange != None: |
|
264 | 264 | self.timerange = timerange |
|
265 | 265 | |
|
266 | 266 | tmin = None |
|
267 | 267 | tmax = None |
|
268 | 268 | x = dataOut.getTimeRange() |
|
269 | 269 | y = dataOut.getHeiRange() |
|
270 | 270 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
271 | 271 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
272 | 272 | avg = numpy.average(z, axis=1) |
|
273 | 273 | |
|
274 | 274 | noise = dataOut.getNoise() |
|
275 | 275 | |
|
276 | 276 | thisDatetime = dataOut.datatime |
|
277 | 277 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
278 | 278 | xlabel = "Velocity (m/s)" |
|
279 | 279 | ylabel = "Range (Km)" |
|
280 | 280 | |
|
281 | 281 | if not self.__isConfig: |
|
282 | 282 | |
|
283 | 283 | nplots = len(channelIndexList) |
|
284 | 284 | |
|
285 | 285 | self.setup(idfigure=idfigure, |
|
286 | 286 | nplots=nplots, |
|
287 | 287 | wintitle=wintitle, |
|
288 | 288 | showprofile=showprofile) |
|
289 | 289 | |
|
290 | 290 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
291 | 291 | if ymin == None: ymin = numpy.nanmin(y) |
|
292 | 292 | if ymax == None: ymax = numpy.nanmax(y) |
|
293 | 293 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
294 | 294 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
295 | 295 | |
|
296 | 296 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
297 | 297 | self.__isConfig = True |
|
298 | 298 | |
|
299 | 299 | |
|
300 | 300 | self.setWinTitle(title) |
|
301 | 301 | |
|
302 | 302 | for i in range(self.nplots): |
|
303 | 303 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
304 | 304 | axes = self.axesList[i*self.__nsubplots] |
|
305 | 305 | z = avg[i].reshape((1,-1)) |
|
306 | 306 | axes.pcolor(x, y, z, |
|
307 | 307 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
308 | 308 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
309 | 309 | ticksize=9, cblabel='', cbsize="1%") |
|
310 | 310 | |
|
311 | 311 | if self.__showprofile: |
|
312 | 312 | axes = self.axesList[i*self.__nsubplots +1] |
|
313 | 313 | axes.pline(avg[i], y, |
|
314 | 314 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
315 | 315 | xlabel='dB', ylabel='', title='', |
|
316 | 316 | ytick_visible=False, |
|
317 | 317 | grid='x') |
|
318 | 318 | |
|
319 | 319 | self.draw() |
|
320 | 320 | |
|
321 | 321 | if save: |
|
322 | 322 | |
|
323 | 323 | if figfile == None: |
|
324 | 324 | figfile = self.getFilename(name = self.name) |
|
325 | 325 | |
|
326 | 326 | self.saveFigure(figpath, figfile) |
|
327 | 327 | |
|
328 | 328 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
329 | 329 | self.__isConfig = False |
|
330 | 330 | |
|
331 | 331 | class SpectraPlot(Figure): |
|
332 | 332 | |
|
333 | 333 | __isConfig = None |
|
334 | 334 | __nsubplots = None |
|
335 | 335 | |
|
336 | 336 | WIDTHPROF = None |
|
337 | 337 | HEIGHTPROF = None |
|
338 | 338 | PREFIX = 'spc' |
|
339 | 339 | |
|
340 | 340 | def __init__(self): |
|
341 | 341 | |
|
342 | 342 | self.__isConfig = False |
|
343 | 343 | self.__nsubplots = 1 |
|
344 | 344 | |
|
345 | 345 | self.WIDTH = 230 |
|
346 | 346 | self.HEIGHT = 250 |
|
347 | 347 | self.WIDTHPROF = 120 |
|
348 | 348 | self.HEIGHTPROF = 0 |
|
349 | 349 | |
|
350 | 350 | def getSubplots(self): |
|
351 | 351 | |
|
352 | 352 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
353 | 353 | nrow = int(self.nplots*1./ncol + 0.9) |
|
354 | 354 | |
|
355 | 355 | return nrow, ncol |
|
356 | 356 | |
|
357 | 357 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
358 | 358 | |
|
359 | 359 | self.__showprofile = showprofile |
|
360 | 360 | self.nplots = nplots |
|
361 | 361 | |
|
362 | 362 | ncolspan = 1 |
|
363 | 363 | colspan = 1 |
|
364 | 364 | if showprofile: |
|
365 | 365 | ncolspan = 3 |
|
366 | 366 | colspan = 2 |
|
367 | 367 | self.__nsubplots = 2 |
|
368 | 368 | |
|
369 | 369 | self.createFigure(idfigure = idfigure, |
|
370 | 370 | wintitle = wintitle, |
|
371 | 371 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
372 | 372 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
373 | 373 | |
|
374 | 374 | nrow, ncol = self.getSubplots() |
|
375 | 375 | |
|
376 | 376 | counter = 0 |
|
377 | 377 | for y in range(nrow): |
|
378 | 378 | for x in range(ncol): |
|
379 | 379 | |
|
380 | 380 | if counter >= self.nplots: |
|
381 | 381 | break |
|
382 | 382 | |
|
383 | 383 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
384 | 384 | |
|
385 | 385 | if showprofile: |
|
386 | 386 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
387 | 387 | |
|
388 | 388 | counter += 1 |
|
389 | 389 | |
|
390 | 390 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
391 | 391 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
392 | 392 | save=False, figpath='./', figfile=None): |
|
393 | 393 | |
|
394 | 394 | """ |
|
395 | 395 | |
|
396 | 396 | Input: |
|
397 | 397 | dataOut : |
|
398 | 398 | idfigure : |
|
399 | 399 | wintitle : |
|
400 | 400 | channelList : |
|
401 | 401 | showProfile : |
|
402 | 402 | xmin : None, |
|
403 | 403 | xmax : None, |
|
404 | 404 | ymin : None, |
|
405 | 405 | ymax : None, |
|
406 | 406 | zmin : None, |
|
407 | 407 | zmax : None |
|
408 | 408 | """ |
|
409 | 409 | |
|
410 | 410 | if channelList == None: |
|
411 | 411 | channelIndexList = dataOut.channelIndexList |
|
412 | 412 | else: |
|
413 | 413 | channelIndexList = [] |
|
414 | 414 | for channel in channelList: |
|
415 | 415 | if channel not in dataOut.channelList: |
|
416 | 416 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
417 | 417 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
418 | 418 | |
|
419 | 419 | x = dataOut.getVelRange(1) |
|
420 | 420 | y = dataOut.getHeiRange() |
|
421 | 421 | |
|
422 | 422 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
423 | 423 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
424 | 424 | avg = numpy.average(z, axis=1) |
|
425 | 425 | |
|
426 | 426 | noise = dataOut.getNoise() |
|
427 | 427 | |
|
428 | 428 | thisDatetime = dataOut.datatime |
|
429 | 429 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
430 | 430 | xlabel = "Velocity (m/s)" |
|
431 | 431 | ylabel = "Range (Km)" |
|
432 | 432 | |
|
433 | 433 | if not self.__isConfig: |
|
434 | 434 | |
|
435 | 435 | nplots = len(channelIndexList) |
|
436 | 436 | |
|
437 | 437 | self.setup(idfigure=idfigure, |
|
438 | 438 | nplots=nplots, |
|
439 | 439 | wintitle=wintitle, |
|
440 | 440 | showprofile=showprofile) |
|
441 | 441 | |
|
442 | 442 | if xmin == None: xmin = numpy.nanmin(x) |
|
443 | 443 | if xmax == None: xmax = numpy.nanmax(x) |
|
444 | 444 | if ymin == None: ymin = numpy.nanmin(y) |
|
445 | 445 | if ymax == None: ymax = numpy.nanmax(y) |
|
446 | 446 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
447 | 447 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
448 | 448 | |
|
449 | 449 | self.__isConfig = True |
|
450 | 450 | |
|
451 | 451 | self.setWinTitle(title) |
|
452 | 452 | |
|
453 | 453 | for i in range(self.nplots): |
|
454 | 454 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
455 | 455 | axes = self.axesList[i*self.__nsubplots] |
|
456 | 456 | axes.pcolor(x, y, z[i,:,:], |
|
457 | 457 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
458 | 458 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
459 | 459 | ticksize=9, cblabel='') |
|
460 | 460 | |
|
461 | 461 | if self.__showprofile: |
|
462 | 462 | axes = self.axesList[i*self.__nsubplots +1] |
|
463 | 463 | axes.pline(avg[i], y, |
|
464 | 464 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
465 | 465 | xlabel='dB', ylabel='', title='', |
|
466 | 466 | ytick_visible=False, |
|
467 | 467 | grid='x') |
|
468 | 468 | |
|
469 | 469 | noiseline = numpy.repeat(noise[i], len(y)) |
|
470 | 470 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
471 | 471 | |
|
472 | 472 | self.draw() |
|
473 | 473 | |
|
474 | 474 | if save: |
|
475 | 475 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
476 | 476 | if figfile == None: |
|
477 | 477 | figfile = self.getFilename(name = date) |
|
478 | 478 | |
|
479 | 479 | self.saveFigure(figpath, figfile) |
|
480 | 480 | |
|
481 | 481 | class Scope(Figure): |
|
482 | 482 | |
|
483 | 483 | __isConfig = None |
|
484 | 484 | |
|
485 | 485 | def __init__(self): |
|
486 | 486 | |
|
487 | 487 | self.__isConfig = False |
|
488 | 488 | self.WIDTH = 600 |
|
489 | 489 | self.HEIGHT = 200 |
|
490 | 490 | |
|
491 | 491 | def getSubplots(self): |
|
492 | 492 | |
|
493 | 493 | nrow = self.nplots |
|
494 | 494 | ncol = 3 |
|
495 | 495 | return nrow, ncol |
|
496 | 496 | |
|
497 | 497 | def setup(self, idfigure, nplots, wintitle): |
|
498 | 498 | |
|
499 | 499 | self.nplots = nplots |
|
500 | 500 | |
|
501 | 501 | self.createFigure(idfigure, wintitle) |
|
502 | 502 | |
|
503 | 503 | nrow,ncol = self.getSubplots() |
|
504 | 504 | colspan = 3 |
|
505 | 505 | rowspan = 1 |
|
506 | 506 | |
|
507 | 507 | for i in range(nplots): |
|
508 | 508 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
509 | 509 | |
|
510 | 510 | |
|
511 | 511 | |
|
512 | 512 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
513 | 513 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
514 | 514 | figpath='./', figfile=None): |
|
515 | 515 | |
|
516 | 516 | """ |
|
517 | 517 | |
|
518 | 518 | Input: |
|
519 | 519 | dataOut : |
|
520 | 520 | idfigure : |
|
521 | 521 | wintitle : |
|
522 | 522 | channelList : |
|
523 | 523 | xmin : None, |
|
524 | 524 | xmax : None, |
|
525 | 525 | ymin : None, |
|
526 | 526 | ymax : None, |
|
527 | 527 | """ |
|
528 | 528 | |
|
529 | 529 | if channelList == None: |
|
530 | 530 | channelIndexList = dataOut.channelIndexList |
|
531 | 531 | else: |
|
532 | 532 | channelIndexList = [] |
|
533 | 533 | for channel in channelList: |
|
534 | 534 | if channel not in dataOut.channelList: |
|
535 | 535 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
536 | 536 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
537 | 537 | |
|
538 | 538 | x = dataOut.heightList |
|
539 | 539 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
540 | 540 | y = y.real |
|
541 | 541 | |
|
542 | 542 | thisDatetime = dataOut.datatime |
|
543 | 543 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
544 | 544 | xlabel = "Range (Km)" |
|
545 | 545 | ylabel = "Intensity" |
|
546 | 546 | |
|
547 | 547 | if not self.__isConfig: |
|
548 | 548 | nplots = len(channelIndexList) |
|
549 | 549 | |
|
550 | 550 | self.setup(idfigure=idfigure, |
|
551 | 551 | nplots=nplots, |
|
552 | 552 | wintitle=wintitle) |
|
553 | 553 | |
|
554 | 554 | if xmin == None: xmin = numpy.nanmin(x) |
|
555 | 555 | if xmax == None: xmax = numpy.nanmax(x) |
|
556 | 556 | if ymin == None: ymin = numpy.nanmin(y) |
|
557 | 557 | if ymax == None: ymax = numpy.nanmax(y) |
|
558 | 558 | |
|
559 | 559 | self.__isConfig = True |
|
560 | 560 | |
|
561 | 561 | self.setWinTitle(title) |
|
562 | 562 | |
|
563 | 563 | for i in range(len(self.axesList)): |
|
564 | 564 | title = "Channel %d" %(i) |
|
565 | 565 | axes = self.axesList[i] |
|
566 | 566 | ychannel = y[i,:] |
|
567 | 567 | axes.pline(x, ychannel, |
|
568 | 568 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
569 | 569 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
570 | 570 | |
|
571 | 571 | self.draw() |
|
572 | 572 | |
|
573 | 573 | if save: |
|
574 | 574 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
575 | 575 | if figfile == None: |
|
576 | 576 | figfile = self.getFilename(name = date) |
|
577 | 577 | |
|
578 | 578 | self.saveFigure(figpath, figfile) |
|
579 | 579 | |
|
580 | 580 | class ProfilePlot(Figure): |
|
581 | 581 | __isConfig = None |
|
582 | 582 | __nsubplots = None |
|
583 | 583 | |
|
584 | 584 | WIDTHPROF = None |
|
585 | 585 | HEIGHTPROF = None |
|
586 | 586 | PREFIX = 'spcprofile' |
|
587 | 587 | |
|
588 | 588 | def __init__(self): |
|
589 | 589 | self.__isConfig = False |
|
590 | 590 | self.__nsubplots = 1 |
|
591 | 591 | |
|
592 | 592 | self.WIDTH = 300 |
|
593 | 593 | self.HEIGHT = 500 |
|
594 | 594 | |
|
595 | 595 | def getSubplots(self): |
|
596 | 596 | ncol = 1 |
|
597 | 597 | nrow = 1 |
|
598 | 598 | |
|
599 | 599 | return nrow, ncol |
|
600 | 600 | |
|
601 | 601 | def setup(self, idfigure, nplots, wintitle): |
|
602 | 602 | |
|
603 | 603 | self.nplots = nplots |
|
604 | 604 | |
|
605 | 605 | ncolspan = 1 |
|
606 | 606 | colspan = 1 |
|
607 | 607 | |
|
608 | 608 | self.createFigure(idfigure = idfigure, |
|
609 | 609 | wintitle = wintitle, |
|
610 | 610 | widthplot = self.WIDTH, |
|
611 | 611 | heightplot = self.HEIGHT) |
|
612 | 612 | |
|
613 | 613 | nrow, ncol = self.getSubplots() |
|
614 | 614 | |
|
615 | 615 | counter = 0 |
|
616 | 616 | for y in range(nrow): |
|
617 | 617 | for x in range(ncol): |
|
618 | 618 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
619 | 619 | |
|
620 | 620 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
621 | 621 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
622 | 622 | save=False, figpath='./', figfile=None): |
|
623 | 623 | |
|
624 | 624 | if channelList == None: |
|
625 | 625 | channelIndexList = dataOut.channelIndexList |
|
626 | 626 | channelList = dataOut.channelList |
|
627 | 627 | else: |
|
628 | 628 | channelIndexList = [] |
|
629 | 629 | for channel in channelList: |
|
630 | 630 | if channel not in dataOut.channelList: |
|
631 | 631 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
632 | 632 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
633 | 633 | |
|
634 | 634 | |
|
635 | 635 | y = dataOut.getHeiRange() |
|
636 | 636 | x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
637 | 637 | avg = numpy.average(x, axis=1) |
|
638 | 638 | |
|
639 | 639 | thisDatetime = dataOut.datatime |
|
640 | 640 | title = "Power Profile" |
|
641 | 641 | xlabel = "dB" |
|
642 | 642 | ylabel = "Range (Km)" |
|
643 | 643 | |
|
644 | 644 | if not self.__isConfig: |
|
645 | 645 | |
|
646 | 646 | nplots = 1 |
|
647 | 647 | |
|
648 | 648 | self.setup(idfigure=idfigure, |
|
649 | 649 | nplots=nplots, |
|
650 | 650 | wintitle=wintitle) |
|
651 | 651 | |
|
652 | 652 | if ymin == None: ymin = numpy.nanmin(y) |
|
653 | 653 | if ymax == None: ymax = numpy.nanmax(y) |
|
654 | 654 | if xmin == None: xmin = numpy.nanmin(avg)*0.9 |
|
655 | 655 | if xmax == None: xmax = numpy.nanmax(avg)*0.9 |
|
656 | 656 | |
|
657 | 657 | self.__isConfig = True |
|
658 | 658 | |
|
659 | 659 | self.setWinTitle(title) |
|
660 | 660 | |
|
661 | 661 | |
|
662 | 662 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
663 | 663 | axes = self.axesList[0] |
|
664 | 664 | |
|
665 | 665 | legendlabels = ["channel %d"%x for x in channelList] |
|
666 | 666 | axes.pmultiline(avg, y, |
|
667 | 667 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
668 | 668 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
669 | 669 | ytick_visible=True, nxticks=5, |
|
670 | 670 | grid='x') |
|
671 | 671 | |
|
672 | 672 | self.draw() |
|
673 | 673 | |
|
674 | 674 | if save: |
|
675 | 675 | date = thisDatetime.strftime("%Y%m%d") |
|
676 | 676 | if figfile == None: |
|
677 | 677 | figfile = self.getFilename(name = date) |
|
678 | 678 | |
|
679 | 679 | self.saveFigure(figpath, figfile) |
|
680 | 680 | |
|
681 | 681 | class CoherenceMap(Figure): |
|
682 | 682 | __isConfig = None |
|
683 | 683 | __nsubplots = None |
|
684 | 684 | |
|
685 | 685 | WIDTHPROF = None |
|
686 | 686 | HEIGHTPROF = None |
|
687 | 687 | PREFIX = 'coherencemap' |
|
688 | 688 | |
|
689 | 689 | def __init__(self): |
|
690 | 690 | self.timerange = 2*60*60 |
|
691 | 691 | self.__isConfig = False |
|
692 | 692 | self.__nsubplots = 1 |
|
693 | 693 | |
|
694 | 694 | self.WIDTH = 800 |
|
695 | 695 | self.HEIGHT = 200 |
|
696 | 696 | self.WIDTHPROF = 120 |
|
697 | 697 | self.HEIGHTPROF = 0 |
|
698 | 698 | |
|
699 | 699 | def getSubplots(self): |
|
700 | 700 | ncol = 1 |
|
701 | 701 | nrow = self.nplots*2 |
|
702 | 702 | |
|
703 | 703 | return nrow, ncol |
|
704 | 704 | |
|
705 | 705 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
706 | 706 | self.__showprofile = showprofile |
|
707 | 707 | self.nplots = nplots |
|
708 | 708 | |
|
709 | 709 | ncolspan = 1 |
|
710 | 710 | colspan = 1 |
|
711 | 711 | if showprofile: |
|
712 | 712 | ncolspan = 7 |
|
713 | 713 | colspan = 6 |
|
714 | 714 | self.__nsubplots = 2 |
|
715 | 715 | |
|
716 | 716 | self.createFigure(idfigure = idfigure, |
|
717 | 717 | wintitle = wintitle, |
|
718 | 718 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
719 | 719 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
720 | 720 | |
|
721 | 721 | nrow, ncol = self.getSubplots() |
|
722 | 722 | |
|
723 | 723 | for y in range(nrow): |
|
724 | 724 | for x in range(ncol): |
|
725 | 725 | |
|
726 | 726 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
727 | 727 | |
|
728 | 728 | if showprofile: |
|
729 | 729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
730 | 730 | |
|
731 | 731 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
732 | 732 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
733 | 733 | timerange=None, |
|
734 | 734 | save=False, figpath='./', figfile=None): |
|
735 | 735 | |
|
736 | 736 | if pairsList == None: |
|
737 | 737 | pairsIndexList = dataOut.pairsIndexList |
|
738 | 738 | else: |
|
739 | 739 | pairsIndexList = [] |
|
740 | 740 | for pair in pairsList: |
|
741 | 741 | if pair not in dataOut.pairsList: |
|
742 | 742 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
743 | 743 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
744 | 744 | |
|
745 | 745 | if timerange != None: |
|
746 | 746 | self.timerange = timerange |
|
747 | 747 | |
|
748 | 748 | if pairsIndexList == []: |
|
749 | 749 | return |
|
750 | 750 | |
|
751 | 751 | if len(pairsIndexList) > 4: |
|
752 | 752 | pairsIndexList = pairsIndexList[0:4] |
|
753 | 753 | |
|
754 | 754 | tmin = None |
|
755 | 755 | tmax = None |
|
756 | 756 | x = dataOut.getTimeRange() |
|
757 | 757 | y = dataOut.getHeiRange() |
|
758 | 758 | |
|
759 | 759 | thisDatetime = dataOut.datatime |
|
760 | 760 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
761 | 761 | xlabel = "" |
|
762 | 762 | ylabel = "Range (Km)" |
|
763 | 763 | |
|
764 | 764 | if not self.__isConfig: |
|
765 | 765 | nplots = len(pairsIndexList) |
|
766 | 766 | self.setup(idfigure=idfigure, |
|
767 | 767 | nplots=nplots, |
|
768 | 768 | wintitle=wintitle, |
|
769 | 769 | showprofile=showprofile) |
|
770 | 770 | |
|
771 | 771 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
772 | 772 | if ymin == None: ymin = numpy.nanmin(y) |
|
773 | 773 | if ymax == None: ymax = numpy.nanmax(y) |
|
774 | 774 | |
|
775 | 775 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
776 | 776 | |
|
777 | 777 | self.__isConfig = True |
|
778 | 778 | |
|
779 | 779 | self.setWinTitle(title) |
|
780 | 780 | |
|
781 | 781 | for i in range(self.nplots): |
|
782 | 782 | |
|
783 | 783 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
784 | 784 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
785 | 785 | coherence = numpy.abs(coherenceComplex) |
|
786 | 786 | avg = numpy.average(coherence, axis=0) |
|
787 | 787 | z = avg.reshape((1,-1)) |
|
788 | 788 | |
|
789 | 789 | counter = 0 |
|
790 | 790 | |
|
791 | 791 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
792 | 792 | axes = self.axesList[i*self.__nsubplots*2] |
|
793 | 793 | axes.pcolor(x, y, z, |
|
794 | 794 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
795 | 795 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
796 | 796 | ticksize=9, cblabel='', cbsize="1%") |
|
797 | 797 | |
|
798 | 798 | if self.__showprofile: |
|
799 | 799 | counter += 1 |
|
800 | 800 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
801 | 801 | axes.pline(avg, y, |
|
802 | 802 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
803 | 803 | xlabel='', ylabel='', title='', ticksize=7, |
|
804 | 804 | ytick_visible=False, nxticks=5, |
|
805 | 805 | grid='x') |
|
806 | 806 | |
|
807 | 807 | counter += 1 |
|
808 | 808 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
809 | 809 | avg = numpy.average(phase, axis=0) |
|
810 | 810 | z = avg.reshape((1,-1)) |
|
811 | 811 | |
|
812 | 812 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
813 | 813 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
814 | 814 | axes.pcolor(x, y, z, |
|
815 | 815 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
816 | 816 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
817 | 817 | ticksize=9, cblabel='', colormap='RdBu', cbsize="1%") |
|
818 | 818 | |
|
819 | 819 | if self.__showprofile: |
|
820 | 820 | counter += 1 |
|
821 | 821 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
822 | 822 | axes.pline(avg, y, |
|
823 | 823 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
824 | 824 | xlabel='', ylabel='', title='', ticksize=7, |
|
825 | 825 | ytick_visible=False, nxticks=4, |
|
826 | 826 | grid='x') |
|
827 | 827 | |
|
828 | 828 | self.draw() |
|
829 | 829 | |
|
830 | 830 | if save: |
|
831 | 831 | |
|
832 | 832 | if figfile == None: |
|
833 | 833 | figfile = self.getFilename(name = self.name) |
|
834 | 834 | |
|
835 | 835 | self.saveFigure(figpath, figfile) |
|
836 | 836 | |
|
837 | 837 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
838 | 838 | self.__isConfig = False |
|
839 | 839 | |
|
840 | 840 | class RTIfromNoise(Figure): |
|
841 | 841 | |
|
842 | 842 | __isConfig = None |
|
843 | 843 | __nsubplots = None |
|
844 | ||
|
845 | WIDTHPROF = None | |
|
846 | HEIGHTPROF = None | |
|
847 | PREFIX = 'rti' | |
|
844 | ||
|
845 | PREFIX = 'rtinoise' | |
|
848 | 846 | |
|
849 | 847 | def __init__(self): |
|
850 | 848 | |
|
851 |
self. |
|
|
849 | self.timerange = 24*60*60 | |
|
852 | 850 | self.__isConfig = False |
|
853 | 851 | self.__nsubplots = 1 |
|
854 | 852 | |
|
855 |
self.WIDTH = 8 |
|
|
853 | self.WIDTH = 820 | |
|
856 | 854 | self.HEIGHT = 200 |
|
857 | 855 | |
|
858 | 856 | def getSubplots(self): |
|
859 | 857 | |
|
860 | 858 | ncol = 1 |
|
861 |
nrow = |
|
|
859 | nrow = 1 | |
|
862 | 860 | |
|
863 | 861 | return nrow, ncol |
|
864 | 862 | |
|
865 | 863 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
866 | 864 | |
|
867 | 865 | self.__showprofile = showprofile |
|
868 | 866 | self.nplots = nplots |
|
869 | 867 | |
|
870 | 868 | ncolspan = 1 |
|
871 | 869 | colspan = 1 |
|
872 | 870 | |
|
873 | 871 | self.createFigure(idfigure = idfigure, |
|
874 | 872 | wintitle = wintitle, |
|
875 |
widthplot = self.WIDTH |
|
|
876 |
heightplot = self.HEIGHT |
|
|
873 | widthplot = self.WIDTH, | |
|
874 | heightplot = self.HEIGHT) | |
|
877 | 875 | |
|
878 | 876 | nrow, ncol = self.getSubplots() |
|
879 | 877 | |
|
880 | 878 | self.addAxes(nrow, ncol, 0, 0, 1, 1) |
|
881 | ||
|
882 | ||
|
883 | ||
|
884 | def __getTimeLim(self, x, xmin, xmax): | |
|
885 | ||
|
886 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
887 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
888 | ||
|
889 | #################################################### | |
|
890 | #If the x is out of xrange | |
|
891 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
|
892 | xmin = None | |
|
893 | xmax = None | |
|
894 | ||
|
895 | if xmin == None: | |
|
896 | td = thisdatetime - thisdate | |
|
897 | xmin = td.seconds/(60*60.) | |
|
898 | ||
|
899 | if xmax == None: | |
|
900 | xmax = xmin + self.__timerange/(60*60.) | |
|
901 | ||
|
902 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
|
903 | tmin = time.mktime(mindt.timetuple()) | |
|
904 | ||
|
905 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
|
906 | tmax = time.mktime(maxdt.timetuple()) | |
|
907 | ||
|
908 | self.__timerange = tmax - tmin | |
|
909 | ||
|
910 | return tmin, tmax | |
|
911 | ||
|
879 | ||
|
912 | 880 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
913 |
xmin=None, xmax=None, ymin=None, ymax=None, |
|
|
881 | xmin=None, xmax=None, ymin=None, ymax=None, | |
|
914 | 882 | timerange=None, |
|
915 | 883 | save=False, figpath='./', figfile=None): |
|
916 | 884 | |
|
917 | 885 | if channelList == None: |
|
918 | 886 | channelIndexList = dataOut.channelIndexList |
|
887 | channelList = dataOut.channelList | |
|
919 | 888 | else: |
|
920 | 889 | channelIndexList = [] |
|
921 | 890 | for channel in channelList: |
|
922 | 891 | if channel not in dataOut.channelList: |
|
923 | 892 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
924 | 893 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
925 | 894 | |
|
926 | 895 | if timerange != None: |
|
927 |
self. |
|
|
896 | self.timerange = timerange | |
|
928 | 897 | |
|
929 | 898 | tmin = None |
|
930 | 899 | tmax = None |
|
931 | 900 | x = dataOut.getTimeRange() |
|
932 | 901 | y = dataOut.getHeiRange() |
|
933 | x1 = dataOut.datatime | |
|
934 | # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
|
935 | # avg = numpy.average(z, axis=1) | |
|
936 | ||
|
902 | ||
|
937 | 903 | noise = dataOut.getNoise() |
|
938 | 904 | |
|
939 | 905 | thisDatetime = dataOut.datatime |
|
940 | 906 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
941 | 907 | xlabel = "Velocity (m/s)" |
|
942 | 908 | ylabel = "Range (Km)" |
|
943 | 909 | |
|
944 | ||
|
945 | 910 | if not self.__isConfig: |
|
946 | 911 | |
|
947 |
nplots = |
|
|
912 | nplots = 1 | |
|
948 | 913 | |
|
949 | 914 | self.setup(idfigure=idfigure, |
|
950 | 915 | nplots=nplots, |
|
951 | 916 | wintitle=wintitle, |
|
952 | 917 | showprofile=showprofile) |
|
953 | 918 | |
|
954 |
tmin, tmax = self. |
|
|
955 |
if ymin == None: ymin = numpy.nanmin( |
|
|
956 |
if ymax == None: ymax = numpy.nanmax( |
|
|
957 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
|
958 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
|
919 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
920 | if ymin == None: ymin = numpy.nanmin(noise) | |
|
921 | if ymax == None: ymax = numpy.nanmax(noise) | |
|
959 | 922 | |
|
923 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
960 | 924 | self.__isConfig = True |
|
961 |
|
|
|
925 | ||
|
962 | 926 | |
|
963 | 927 | self.setWinTitle(title) |
|
964 | 928 | |
|
965 | for i in range(self.nplots): | |
|
966 |
|
|
|
967 | axes = self.axesList[i*self.__nsubplots] | |
|
968 | z = avg[i].reshape((1,-1)) | |
|
969 | axes.pcolor(x, y, z, | |
|
970 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
971 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
972 | ticksize=9, cblabel='', cbsize="1%") | |
|
973 | ||
|
929 | ||
|
930 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
931 | ||
|
932 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
|
933 | axes = self.axesList[0] | |
|
934 | xdata = x[0:1] | |
|
935 | ydata = noise[channelIndexList].reshape(-1,1) | |
|
936 | axes.pmultilineyaxis(x=xdata, y=ydata, | |
|
937 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
|
938 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
|
939 | XAxisAsTime=True | |
|
940 | ) | |
|
941 | ||
|
974 | 942 | |
|
975 | 943 | self.draw() |
|
976 | 944 | |
|
977 | 945 | if save: |
|
978 | date = thisDatetime.strftime("%Y%m%d") | |
|
946 | ||
|
979 | 947 | if figfile == None: |
|
980 |
figfile = self.getFilename(name = |
|
|
948 | figfile = self.getFilename(name = self.name) | |
|
981 | 949 | |
|
982 | 950 | self.saveFigure(figpath, figfile) |
|
983 | 951 | |
|
984 | 952 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
985 | 953 | self.__isConfig = False |
|
986 | 954 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now