@@ -1,323 +1,351 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import mpldriver |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | class Figure: |
|
7 | 7 | |
|
8 | 8 | __driver = mpldriver |
|
9 | 9 | fig = None |
|
10 | 10 | |
|
11 | 11 | idfigure = None |
|
12 | 12 | wintitle = None |
|
13 | 13 | width = None |
|
14 | 14 | height = None |
|
15 | 15 | nplots = None |
|
16 | 16 | |
|
17 | 17 | axesObjList = [] |
|
18 | 18 | |
|
19 | 19 | WIDTH = None |
|
20 | 20 | HEIGHT = None |
|
21 | 21 | PREFIX = 'fig' |
|
22 | 22 | |
|
23 | 23 | def __init__(self): |
|
24 | 24 | |
|
25 | 25 | raise ValueError, "This method is not implemented" |
|
26 | 26 | |
|
27 | 27 | def __del__(self): |
|
28 | 28 | |
|
29 | 29 | self.__driver.closeFigure() |
|
30 | 30 | |
|
31 | 31 | def getFilename(self, name, ext='.png'): |
|
32 | 32 | |
|
33 | 33 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
34 | 34 | |
|
35 | 35 | return filename |
|
36 | 36 | |
|
37 | 37 | def getAxesObjList(self): |
|
38 | 38 | |
|
39 | 39 | return self.axesObjList |
|
40 | 40 | |
|
41 | 41 | def getSubplots(self): |
|
42 | 42 | |
|
43 | 43 | raise ValueError, "Abstract method: This method should be defined" |
|
44 | 44 | |
|
45 | 45 | def getScreenDim(self, widthplot, heightplot): |
|
46 | 46 | |
|
47 | 47 | nrow, ncol = self.getSubplots() |
|
48 | 48 | |
|
49 | 49 | widthscreen = widthplot*ncol |
|
50 | 50 | heightscreen = heightplot*nrow |
|
51 | 51 | |
|
52 | 52 | return widthscreen, heightscreen |
|
53 | ||
|
54 | def getTimeLim(self, x, xmin, xmax): | |
|
55 | ||
|
56 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
57 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
58 | ||
|
59 | #################################################### | |
|
60 | #If the x is out of xrange | |
|
61 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
|
62 | xmin = None | |
|
63 | xmax = None | |
|
64 | ||
|
65 | if xmin == None: | |
|
66 | td = thisdatetime - thisdate | |
|
67 | xmin = td.seconds/(60*60.) | |
|
68 | ||
|
69 | if xmax == None: | |
|
70 | xmax = xmin + self.__timerange/(60*60.) | |
|
53 | 71 | |
|
72 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
|
73 | tmin = time.mktime(mindt.timetuple()) | |
|
74 | ||
|
75 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
|
76 | tmax = time.mktime(maxdt.timetuple()) | |
|
77 | ||
|
78 | self.__timerange = tmax - tmin | |
|
79 | ||
|
80 | return tmin, tmax | |
|
81 | ||
|
54 | 82 | def init(self, idfigure, nplots, wintitle): |
|
55 | 83 | |
|
56 | 84 | raise ValueError, "This method has been replaced with createFigure" |
|
57 | 85 | |
|
58 | 86 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): |
|
59 | 87 | |
|
60 | 88 | """ |
|
61 | 89 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
62 | 90 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
63 | 91 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
64 | 92 | |
|
65 | 93 | Input: |
|
66 | 94 | idfigure : Los parametros necesarios son |
|
67 | 95 | wintitle : |
|
68 | 96 | |
|
69 | 97 | """ |
|
70 | 98 | |
|
71 | 99 | if widthplot == None: |
|
72 | 100 | widthplot = self.WIDTH |
|
73 | 101 | |
|
74 | 102 | if heightplot == None: |
|
75 | 103 | heightplot = self.HEIGHT |
|
76 | 104 | |
|
77 | 105 | self.idfigure = idfigure |
|
78 | 106 | |
|
79 | 107 | self.wintitle = wintitle |
|
80 | 108 | |
|
81 | 109 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
82 | 110 | |
|
83 | 111 | self.fig = self.__driver.createFigure(self.idfigure, |
|
84 | 112 | self.wintitle, |
|
85 | 113 | self.widthscreen, |
|
86 | 114 | self.heightscreen) |
|
87 | 115 | |
|
88 | 116 | self.axesObjList = [] |
|
89 | 117 | |
|
90 | 118 | def setDriver(self, driver=mpldriver): |
|
91 | 119 | |
|
92 | 120 | self.__driver = driver |
|
93 | 121 | |
|
94 | 122 | def setTitle(self, title): |
|
95 | 123 | |
|
96 | 124 | self.__driver.setTitle(self.fig, title) |
|
97 | 125 | |
|
98 | 126 | def setWinTitle(self, title): |
|
99 | 127 | |
|
100 | 128 | self.__driver.setWinTitle(self.fig, title=title) |
|
101 | 129 | |
|
102 | 130 | def setTextFromAxes(self, text): |
|
103 | 131 | |
|
104 | 132 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
105 | 133 | |
|
106 | 134 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
107 | 135 | |
|
108 | 136 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
109 | 137 | |
|
110 | 138 | def addAxes(self, *args): |
|
111 | 139 | """ |
|
112 | 140 | |
|
113 | 141 | Input: |
|
114 | 142 | *args : Los parametros necesarios son |
|
115 | 143 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
116 | 144 | """ |
|
117 | 145 | |
|
118 | 146 | axesObj = Axes(self.fig, *args) |
|
119 | 147 | self.axesObjList.append(axesObj) |
|
120 | 148 | |
|
121 | 149 | def saveFigure(self, figpath, figfile, *args): |
|
122 | 150 | |
|
123 | 151 | filename = os.path.join(figpath, figfile) |
|
124 | 152 | self.__driver.saveFigure(self.fig, filename, *args) |
|
125 | 153 | |
|
126 | 154 | def draw(self): |
|
127 | 155 | |
|
128 | 156 | self.__driver.draw(self.fig) |
|
129 | 157 | |
|
130 | 158 | def run(self): |
|
131 | 159 | |
|
132 | 160 | raise ValueError, "This method is not implemented" |
|
133 | 161 | |
|
134 | 162 | axesList = property(getAxesObjList) |
|
135 | 163 | |
|
136 | 164 | |
|
137 | 165 | class Axes: |
|
138 | 166 | |
|
139 | 167 | __driver = mpldriver |
|
140 | 168 | fig = None |
|
141 | 169 | ax = None |
|
142 | 170 | plot = None |
|
143 | 171 | |
|
144 | 172 | __firsttime = None |
|
145 | 173 | |
|
146 | 174 | __showprofile = False |
|
147 | 175 | |
|
148 | 176 | xmin = None |
|
149 | 177 | xmax = None |
|
150 | 178 | ymin = None |
|
151 | 179 | ymax = None |
|
152 | 180 | zmin = None |
|
153 | 181 | zmax = None |
|
154 | 182 | |
|
155 | 183 | def __init__(self, *args): |
|
156 | 184 | |
|
157 | 185 | """ |
|
158 | 186 | |
|
159 | 187 | Input: |
|
160 | 188 | *args : Los parametros necesarios son |
|
161 | 189 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
162 | 190 | """ |
|
163 | 191 | |
|
164 | 192 | ax = self.__driver.createAxes(*args) |
|
165 | 193 | self.fig = args[0] |
|
166 | 194 | self.ax = ax |
|
167 | 195 | self.plot = None |
|
168 | 196 | |
|
169 | 197 | self.__firsttime = True |
|
170 | 198 | |
|
171 | 199 | def setText(self, text): |
|
172 | 200 | |
|
173 | 201 | self.__driver.setAxesText(self.ax, text) |
|
174 | 202 | |
|
175 | 203 | def setXAxisAsTime(self): |
|
176 | 204 | pass |
|
177 | 205 | |
|
178 | 206 | def pline(self, x, y, |
|
179 | 207 | xmin=None, xmax=None, |
|
180 | 208 | ymin=None, ymax=None, |
|
181 | 209 | xlabel='', ylabel='', |
|
182 | 210 | title='', |
|
183 | 211 | **kwargs): |
|
184 | 212 | |
|
185 | 213 | """ |
|
186 | 214 | |
|
187 | 215 | Input: |
|
188 | 216 | x : |
|
189 | 217 | y : |
|
190 | 218 | xmin : |
|
191 | 219 | xmax : |
|
192 | 220 | ymin : |
|
193 | 221 | ymax : |
|
194 | 222 | xlabel : |
|
195 | 223 | ylabel : |
|
196 | 224 | title : |
|
197 | 225 | **kwargs : Los parametros aceptados son |
|
198 | 226 | |
|
199 | 227 | ticksize |
|
200 | 228 | ytick_visible |
|
201 | 229 | """ |
|
202 | 230 | |
|
203 | 231 | if self.__firsttime: |
|
204 | 232 | |
|
205 | 233 | if xmin == None: xmin = numpy.nanmin(x) |
|
206 | 234 | if xmax == None: xmax = numpy.nanmax(x) |
|
207 | 235 | if ymin == None: ymin = numpy.nanmin(y) |
|
208 | 236 | if ymax == None: ymax = numpy.nanmax(y) |
|
209 | 237 | |
|
210 | 238 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
211 | 239 | xmin, xmax, |
|
212 | 240 | ymin, ymax, |
|
213 | 241 | xlabel=xlabel, |
|
214 | 242 | ylabel=ylabel, |
|
215 | 243 | title=title, |
|
216 | 244 | **kwargs) |
|
217 | 245 | self.__firsttime = False |
|
218 | 246 | return |
|
219 | 247 | |
|
220 | 248 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
221 | 249 | ylabel=ylabel, |
|
222 | 250 | title=title) |
|
223 | 251 | |
|
224 | 252 | def pmultiline(self, x, y, |
|
225 | 253 | xmin=None, xmax=None, |
|
226 | 254 | ymin=None, ymax=None, |
|
227 | 255 | xlabel='', ylabel='', |
|
228 | 256 | title='', |
|
229 | 257 | **kwargs): |
|
230 | 258 | |
|
231 | 259 | if self.__firsttime: |
|
232 | 260 | |
|
233 | 261 | if xmin == None: xmin = numpy.nanmin(x) |
|
234 | 262 | if xmax == None: xmax = numpy.nanmax(x) |
|
235 | 263 | if ymin == None: ymin = numpy.nanmin(y) |
|
236 | 264 | if ymax == None: ymax = numpy.nanmax(y) |
|
237 | 265 | |
|
238 | 266 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
239 | 267 | xmin, xmax, |
|
240 | 268 | ymin, ymax, |
|
241 | 269 | xlabel=xlabel, |
|
242 | 270 | ylabel=ylabel, |
|
243 | 271 | title=title, |
|
244 | 272 | **kwargs) |
|
245 | 273 | self.__firsttime = False |
|
246 | 274 | return |
|
247 | 275 | |
|
248 | 276 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
249 | 277 | ylabel=ylabel, |
|
250 | 278 | title=title) |
|
251 | 279 | |
|
252 | 280 | def pcolor(self, x, y, z, |
|
253 | 281 | xmin=None, xmax=None, |
|
254 | 282 | ymin=None, ymax=None, |
|
255 | 283 | zmin=None, zmax=None, |
|
256 | 284 | xlabel='', ylabel='', |
|
257 | 285 | title='', rti = False, colormap='jet', |
|
258 | 286 | **kwargs): |
|
259 | 287 | |
|
260 | 288 | """ |
|
261 | 289 | Input: |
|
262 | 290 | x : |
|
263 | 291 | y : |
|
264 | 292 | x : |
|
265 | 293 | xmin : |
|
266 | 294 | xmax : |
|
267 | 295 | ymin : |
|
268 | 296 | ymax : |
|
269 | 297 | zmin : |
|
270 | 298 | zmax : |
|
271 | 299 | xlabel : |
|
272 | 300 | ylabel : |
|
273 | 301 | title : |
|
274 | 302 | **kwargs : Los parametros aceptados son |
|
275 | 303 | ticksize=9, |
|
276 | 304 | cblabel='' |
|
277 | 305 | rti = True or False |
|
278 | 306 | """ |
|
279 | 307 | |
|
280 | 308 | if self.__firsttime: |
|
281 | 309 | |
|
282 | 310 | if xmin == None: xmin = numpy.nanmin(x) |
|
283 | 311 | if xmax == None: xmax = numpy.nanmax(x) |
|
284 | 312 | if ymin == None: ymin = numpy.nanmin(y) |
|
285 | 313 | if ymax == None: ymax = numpy.nanmax(y) |
|
286 | 314 | if zmin == None: zmin = numpy.nanmin(z) |
|
287 | 315 | if zmax == None: zmax = numpy.nanmax(z) |
|
288 | 316 | |
|
289 | 317 | |
|
290 | 318 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
291 | 319 | xmin, xmax, |
|
292 | 320 | ymin, ymax, |
|
293 | 321 | zmin, zmax, |
|
294 | 322 | xlabel=xlabel, |
|
295 | 323 | ylabel=ylabel, |
|
296 | 324 | title=title, |
|
297 | 325 | colormap=colormap, |
|
298 | 326 | **kwargs) |
|
299 | 327 | |
|
300 | 328 | if self.xmin == None: self.xmin = xmin |
|
301 | 329 | if self.xmax == None: self.xmax = xmax |
|
302 | 330 | if self.ymin == None: self.ymin = ymin |
|
303 | 331 | if self.ymax == None: self.ymax = ymax |
|
304 | 332 | if self.zmin == None: self.zmin = zmin |
|
305 | 333 | if self.zmax == None: self.zmax = zmax |
|
306 | 334 | |
|
307 | 335 | self.__firsttime = False |
|
308 | 336 | return |
|
309 | 337 | |
|
310 | 338 | if rti: |
|
311 | 339 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
312 | 340 | xlabel=xlabel, |
|
313 | 341 | ylabel=ylabel, |
|
314 | 342 | title=title, |
|
315 | 343 | colormap=colormap) |
|
316 | 344 | return |
|
317 | 345 | |
|
318 | 346 | self.__driver.pcolor(self.plot, z, |
|
319 | 347 | xlabel=xlabel, |
|
320 | 348 | ylabel=ylabel, |
|
321 | 349 | title=title) |
|
322 | 350 | |
|
323 | 351 | No newline at end of file |
@@ -1,874 +1,818 | |||
|
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 | WIDTHPROF = None |
|
11 | 11 | HEIGHTPROF = None |
|
12 | 12 | PREFIX = 'cspc' |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | |
|
16 | 16 | self.__isConfig = False |
|
17 | 17 | self.__nsubplots = 4 |
|
18 | 18 | |
|
19 | 19 | self.WIDTH = 300 |
|
20 | 20 | self.HEIGHT = 400 |
|
21 | 21 | self.WIDTHPROF = 0 |
|
22 | 22 | self.HEIGHTPROF = 0 |
|
23 | 23 | |
|
24 | 24 | def getSubplots(self): |
|
25 | 25 | |
|
26 | 26 | ncol = 4 |
|
27 | 27 | nrow = self.nplots |
|
28 | 28 | |
|
29 | 29 | return nrow, ncol |
|
30 | 30 | |
|
31 | 31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
32 | 32 | |
|
33 | 33 | self.__showprofile = showprofile |
|
34 | 34 | self.nplots = nplots |
|
35 | 35 | |
|
36 | 36 | ncolspan = 1 |
|
37 | 37 | colspan = 1 |
|
38 | 38 | |
|
39 | 39 | self.createFigure(idfigure = idfigure, |
|
40 | 40 | wintitle = wintitle, |
|
41 | 41 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
42 | 42 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
43 | 43 | |
|
44 | 44 | nrow, ncol = self.getSubplots() |
|
45 | 45 | |
|
46 | 46 | counter = 0 |
|
47 | 47 | for y in range(nrow): |
|
48 | 48 | for x in range(ncol): |
|
49 | 49 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
50 | 50 | |
|
51 | 51 | counter += 1 |
|
52 | 52 | |
|
53 | 53 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
54 | 54 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
55 | 55 | save=False, figpath='./', figfile=None): |
|
56 | 56 | |
|
57 | 57 | """ |
|
58 | 58 | |
|
59 | 59 | Input: |
|
60 | 60 | dataOut : |
|
61 | 61 | idfigure : |
|
62 | 62 | wintitle : |
|
63 | 63 | channelList : |
|
64 | 64 | showProfile : |
|
65 | 65 | xmin : None, |
|
66 | 66 | xmax : None, |
|
67 | 67 | ymin : None, |
|
68 | 68 | ymax : None, |
|
69 | 69 | zmin : None, |
|
70 | 70 | zmax : None |
|
71 | 71 | """ |
|
72 | 72 | |
|
73 | 73 | if pairsList == None: |
|
74 | 74 | pairsIndexList = dataOut.pairsIndexList |
|
75 | 75 | else: |
|
76 | 76 | pairsIndexList = [] |
|
77 | 77 | for pair in pairsList: |
|
78 | 78 | if pair not in dataOut.pairsList: |
|
79 | 79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
80 | 80 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
81 | 81 | |
|
82 | 82 | if pairsIndexList == []: |
|
83 | 83 | return |
|
84 | 84 | |
|
85 | 85 | if len(pairsIndexList) > 4: |
|
86 | 86 | pairsIndexList = pairsIndexList[0:4] |
|
87 | 87 | |
|
88 | 88 | x = dataOut.getFreqRange(1) |
|
89 | 89 | y = dataOut.getHeiRange() |
|
90 | 90 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
|
91 | 91 | avg = numpy.average(numpy.abs(z), axis=1) |
|
92 | 92 | |
|
93 | 93 | noise = dataOut.getNoise() |
|
94 | 94 | |
|
95 | 95 | if not self.__isConfig: |
|
96 | 96 | |
|
97 | 97 | nplots = len(pairsIndexList) |
|
98 | 98 | |
|
99 | 99 | self.setup(idfigure=idfigure, |
|
100 | 100 | nplots=nplots, |
|
101 | 101 | wintitle=wintitle, |
|
102 | 102 | showprofile=showprofile) |
|
103 | 103 | |
|
104 | 104 | if xmin == None: xmin = numpy.nanmin(x) |
|
105 | 105 | if xmax == None: xmax = numpy.nanmax(x) |
|
106 | 106 | if ymin == None: ymin = numpy.nanmin(y) |
|
107 | 107 | if ymax == None: ymax = numpy.nanmax(y) |
|
108 | 108 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
109 | 109 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
110 | 110 | |
|
111 | 111 | self.__isConfig = True |
|
112 | 112 | |
|
113 | 113 | thisDatetime = dataOut.datatime |
|
114 | 114 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
115 | 115 | xlabel = "Velocity (m/s)" |
|
116 | 116 | ylabel = "Range (Km)" |
|
117 | 117 | |
|
118 | 118 | self.setWinTitle(title) |
|
119 | 119 | |
|
120 | 120 | for i in range(self.nplots): |
|
121 | 121 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
122 | 122 | |
|
123 | 123 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) |
|
124 | 124 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
125 | 125 | axes0 = self.axesList[i*self.__nsubplots] |
|
126 | 126 | axes0.pcolor(x, y, z, |
|
127 | 127 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
128 | 128 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
129 | 129 | ticksize=9, cblabel='') |
|
130 | 130 | |
|
131 | 131 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) |
|
132 | 132 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
133 | 133 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
134 | 134 | axes0.pcolor(x, y, z, |
|
135 | 135 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
136 | 136 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
137 | 137 | ticksize=9, cblabel='') |
|
138 | 138 | |
|
139 | 139 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
140 | 140 | coherence = numpy.abs(coherenceComplex) |
|
141 | 141 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
142 | 142 | |
|
143 | 143 | |
|
144 | 144 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
145 | 145 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
146 | 146 | axes0.pcolor(x, y, coherence, |
|
147 | 147 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
148 | 148 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
149 | 149 | ticksize=9, cblabel='') |
|
150 | 150 | |
|
151 | 151 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
152 | 152 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
153 | 153 | axes0.pcolor(x, y, phase, |
|
154 | 154 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
155 | 155 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
156 | 156 | ticksize=9, cblabel='', colormap='RdBu') |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | self.draw() |
|
161 | 161 | |
|
162 | 162 | if save: |
|
163 | 163 | date = thisDatetime.strftime("%Y%m%d") |
|
164 | 164 | if figfile == None: |
|
165 | 165 | figfile = self.getFilename(name = date) |
|
166 | 166 | |
|
167 | 167 | self.saveFigure(figpath, figfile) |
|
168 | 168 | |
|
169 | 169 | |
|
170 | 170 | class RTIPlot(Figure): |
|
171 | 171 | |
|
172 | 172 | __isConfig = None |
|
173 | 173 | __nsubplots = None |
|
174 | 174 | |
|
175 | 175 | WIDTHPROF = None |
|
176 | 176 | HEIGHTPROF = None |
|
177 | 177 | PREFIX = 'rti' |
|
178 | 178 | |
|
179 | 179 | def __init__(self): |
|
180 | 180 | |
|
181 | 181 | self.__timerange = 24*60*60 |
|
182 | 182 | self.__isConfig = False |
|
183 | 183 | self.__nsubplots = 1 |
|
184 | 184 | |
|
185 | 185 | self.WIDTH = 800 |
|
186 | 186 | self.HEIGHT = 200 |
|
187 | 187 | self.WIDTHPROF = 120 |
|
188 | 188 | self.HEIGHTPROF = 0 |
|
189 | 189 | |
|
190 | 190 | def getSubplots(self): |
|
191 | 191 | |
|
192 | 192 | ncol = 1 |
|
193 | 193 | nrow = self.nplots |
|
194 | 194 | |
|
195 | 195 | return nrow, ncol |
|
196 | 196 | |
|
197 | 197 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
198 | 198 | |
|
199 | 199 | self.__showprofile = showprofile |
|
200 | 200 | self.nplots = nplots |
|
201 | 201 | |
|
202 | 202 | ncolspan = 1 |
|
203 | 203 | colspan = 1 |
|
204 | 204 | if showprofile: |
|
205 | 205 | ncolspan = 7 |
|
206 | 206 | colspan = 6 |
|
207 | 207 | self.__nsubplots = 2 |
|
208 | 208 | |
|
209 | 209 | self.createFigure(idfigure = idfigure, |
|
210 | 210 | wintitle = wintitle, |
|
211 | 211 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
212 | 212 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
213 | 213 | |
|
214 | 214 | nrow, ncol = self.getSubplots() |
|
215 | 215 | |
|
216 | 216 | counter = 0 |
|
217 | 217 | for y in range(nrow): |
|
218 | 218 | for x in range(ncol): |
|
219 | 219 | |
|
220 | 220 | if counter >= self.nplots: |
|
221 | 221 | break |
|
222 | 222 | |
|
223 | 223 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
224 | 224 | |
|
225 | 225 | if showprofile: |
|
226 | 226 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
227 | 227 | |
|
228 | 228 | counter += 1 |
|
229 | 229 | |
|
230 | def __getTimeLim(self, x, xmin, xmax): | |
|
231 | ||
|
232 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
233 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
234 | ||
|
235 | #################################################### | |
|
236 | #If the x is out of xrange | |
|
237 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
|
238 | xmin = None | |
|
239 | xmax = None | |
|
240 | ||
|
241 | if xmin == None: | |
|
242 | td = thisdatetime - thisdate | |
|
243 | xmin = td.seconds/(60*60.) | |
|
244 | ||
|
245 | if xmax == None: | |
|
246 | xmax = xmin + self.__timerange/(60*60.) | |
|
247 | ||
|
248 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
|
249 | tmin = time.mktime(mindt.timetuple()) | |
|
250 | ||
|
251 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
|
252 | tmax = time.mktime(maxdt.timetuple()) | |
|
253 | ||
|
254 | self.__timerange = tmax - tmin | |
|
255 | ||
|
256 | return tmin, tmax | |
|
257 | ||
|
258 | 230 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
259 | 231 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
260 | 232 | timerange=None, |
|
261 | 233 | save=False, figpath='./', figfile=None): |
|
262 | 234 | |
|
263 | 235 | """ |
|
264 | 236 | |
|
265 | 237 | Input: |
|
266 | 238 | dataOut : |
|
267 | 239 | idfigure : |
|
268 | 240 | wintitle : |
|
269 | 241 | channelList : |
|
270 | 242 | showProfile : |
|
271 | 243 | xmin : None, |
|
272 | 244 | xmax : None, |
|
273 | 245 | ymin : None, |
|
274 | 246 | ymax : None, |
|
275 | 247 | zmin : None, |
|
276 | 248 | zmax : None |
|
277 | 249 | """ |
|
278 | 250 | |
|
279 | 251 | if channelList == None: |
|
280 | 252 | channelIndexList = dataOut.channelIndexList |
|
281 | 253 | else: |
|
282 | 254 | channelIndexList = [] |
|
283 | 255 | for channel in channelList: |
|
284 | 256 | if channel not in dataOut.channelList: |
|
285 | 257 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
286 | 258 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
287 | 259 | |
|
288 | 260 | if timerange != None: |
|
289 | 261 | self.__timerange = timerange |
|
290 | 262 | |
|
291 | 263 | tmin = None |
|
292 | 264 | tmax = None |
|
293 | 265 | x = dataOut.getTimeRange() |
|
294 | 266 | y = dataOut.getHeiRange() |
|
295 | 267 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
296 | 268 | avg = numpy.average(z, axis=1) |
|
297 | 269 | |
|
298 | 270 | noise = dataOut.getNoise() |
|
299 | 271 | |
|
300 | 272 | if not self.__isConfig: |
|
301 | 273 | |
|
302 | 274 | nplots = len(channelIndexList) |
|
303 | 275 | |
|
304 | 276 | self.setup(idfigure=idfigure, |
|
305 | 277 | nplots=nplots, |
|
306 | 278 | wintitle=wintitle, |
|
307 | 279 | showprofile=showprofile) |
|
308 | 280 | |
|
309 |
tmin, tmax = self. |
|
|
281 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
310 | 282 | if ymin == None: ymin = numpy.nanmin(y) |
|
311 | 283 | if ymax == None: ymax = numpy.nanmax(y) |
|
312 | 284 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
313 | 285 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
314 | 286 | |
|
315 | 287 | self.__isConfig = True |
|
316 | 288 | |
|
317 | 289 | thisDatetime = dataOut.datatime |
|
318 | 290 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
319 | 291 | xlabel = "Velocity (m/s)" |
|
320 | 292 | ylabel = "Range (Km)" |
|
321 | 293 | |
|
322 | 294 | self.setWinTitle(title) |
|
323 | 295 | |
|
324 | 296 | for i in range(self.nplots): |
|
325 | 297 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
326 | 298 | axes = self.axesList[i*self.__nsubplots] |
|
327 | 299 | z = avg[i].reshape((1,-1)) |
|
328 | 300 | axes.pcolor(x, y, z, |
|
329 | 301 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
330 | 302 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
331 | 303 | ticksize=9, cblabel='', cbsize="1%") |
|
332 | 304 | |
|
333 | 305 | if self.__showprofile: |
|
334 | 306 | axes = self.axesList[i*self.__nsubplots +1] |
|
335 | 307 | axes.pline(avg[i], y, |
|
336 | 308 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
337 | 309 | xlabel='dB', ylabel='', title='', |
|
338 | 310 | ytick_visible=False, |
|
339 | 311 | grid='x') |
|
340 | 312 | |
|
341 | 313 | self.draw() |
|
342 | 314 | |
|
343 | 315 | if save: |
|
344 | 316 | date = thisDatetime.strftime("%Y%m%d") |
|
345 | 317 | if figfile == None: |
|
346 | 318 | figfile = self.getFilename(name = date) |
|
347 | 319 | |
|
348 | 320 | self.saveFigure(figpath, figfile) |
|
349 | 321 | |
|
350 | 322 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
351 | 323 | self.__isConfig = False |
|
352 | 324 | |
|
353 | 325 | class SpectraPlot(Figure): |
|
354 | 326 | |
|
355 | 327 | __isConfig = None |
|
356 | 328 | __nsubplots = None |
|
357 | 329 | |
|
358 | 330 | WIDTHPROF = None |
|
359 | 331 | HEIGHTPROF = None |
|
360 | 332 | PREFIX = 'spc' |
|
361 | 333 | |
|
362 | 334 | def __init__(self): |
|
363 | 335 | |
|
364 | 336 | self.__isConfig = False |
|
365 | 337 | self.__nsubplots = 1 |
|
366 | 338 | |
|
367 | 339 | self.WIDTH = 300 |
|
368 | 340 | self.HEIGHT = 400 |
|
369 | 341 | self.WIDTHPROF = 120 |
|
370 | 342 | self.HEIGHTPROF = 0 |
|
371 | 343 | |
|
372 | 344 | def getSubplots(self): |
|
373 | 345 | |
|
374 | 346 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
375 | 347 | nrow = int(self.nplots*1./ncol + 0.9) |
|
376 | 348 | |
|
377 | 349 | return nrow, ncol |
|
378 | 350 | |
|
379 | 351 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
380 | 352 | |
|
381 | 353 | self.__showprofile = showprofile |
|
382 | 354 | self.nplots = nplots |
|
383 | 355 | |
|
384 | 356 | ncolspan = 1 |
|
385 | 357 | colspan = 1 |
|
386 | 358 | if showprofile: |
|
387 | 359 | ncolspan = 3 |
|
388 | 360 | colspan = 2 |
|
389 | 361 | self.__nsubplots = 2 |
|
390 | 362 | |
|
391 | 363 | self.createFigure(idfigure = idfigure, |
|
392 | 364 | wintitle = wintitle, |
|
393 | 365 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
394 | 366 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
395 | 367 | |
|
396 | 368 | nrow, ncol = self.getSubplots() |
|
397 | 369 | |
|
398 | 370 | counter = 0 |
|
399 | 371 | for y in range(nrow): |
|
400 | 372 | for x in range(ncol): |
|
401 | 373 | |
|
402 | 374 | if counter >= self.nplots: |
|
403 | 375 | break |
|
404 | 376 | |
|
405 | 377 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
406 | 378 | |
|
407 | 379 | if showprofile: |
|
408 | 380 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
409 | 381 | |
|
410 | 382 | counter += 1 |
|
411 | 383 | |
|
412 | 384 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
413 | 385 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
414 | 386 | save=False, figpath='./', figfile=None): |
|
415 | 387 | |
|
416 | 388 | """ |
|
417 | 389 | |
|
418 | 390 | Input: |
|
419 | 391 | dataOut : |
|
420 | 392 | idfigure : |
|
421 | 393 | wintitle : |
|
422 | 394 | channelList : |
|
423 | 395 | showProfile : |
|
424 | 396 | xmin : None, |
|
425 | 397 | xmax : None, |
|
426 | 398 | ymin : None, |
|
427 | 399 | ymax : None, |
|
428 | 400 | zmin : None, |
|
429 | 401 | zmax : None |
|
430 | 402 | """ |
|
431 | 403 | |
|
432 | 404 | if channelList == None: |
|
433 | 405 | channelIndexList = dataOut.channelIndexList |
|
434 | 406 | else: |
|
435 | 407 | channelIndexList = [] |
|
436 | 408 | for channel in channelList: |
|
437 | 409 | if channel not in dataOut.channelList: |
|
438 | 410 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
439 | 411 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
440 | 412 | |
|
441 | 413 | x = dataOut.getVelRange(1) |
|
442 | 414 | y = dataOut.getHeiRange() |
|
443 | 415 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
444 | 416 | avg = numpy.average(z, axis=1) |
|
445 | 417 | |
|
446 | 418 | noise = dataOut.getNoise() |
|
447 | 419 | |
|
448 | 420 | if not self.__isConfig: |
|
449 | 421 | |
|
450 | 422 | nplots = len(channelIndexList) |
|
451 | 423 | |
|
452 | 424 | self.setup(idfigure=idfigure, |
|
453 | 425 | nplots=nplots, |
|
454 | 426 | wintitle=wintitle, |
|
455 | 427 | showprofile=showprofile) |
|
456 | 428 | |
|
457 | 429 | if xmin == None: xmin = numpy.nanmin(x) |
|
458 | 430 | if xmax == None: xmax = numpy.nanmax(x) |
|
459 | 431 | if ymin == None: ymin = numpy.nanmin(y) |
|
460 | 432 | if ymax == None: ymax = numpy.nanmax(y) |
|
461 | 433 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
462 | 434 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
463 | 435 | |
|
464 | 436 | self.__isConfig = True |
|
465 | 437 | |
|
466 | 438 | thisDatetime = dataOut.datatime |
|
467 | 439 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
468 | 440 | xlabel = "Velocity (m/s)" |
|
469 | 441 | ylabel = "Range (Km)" |
|
470 | 442 | |
|
471 | 443 | self.setWinTitle(title) |
|
472 | 444 | |
|
473 | 445 | for i in range(self.nplots): |
|
474 | 446 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
475 | 447 | axes = self.axesList[i*self.__nsubplots] |
|
476 | 448 | axes.pcolor(x, y, z[i,:,:], |
|
477 | 449 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
478 | 450 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
479 | 451 | ticksize=9, cblabel='') |
|
480 | 452 | |
|
481 | 453 | if self.__showprofile: |
|
482 | 454 | axes = self.axesList[i*self.__nsubplots +1] |
|
483 | 455 | axes.pline(avg[i], y, |
|
484 | 456 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
485 | 457 | xlabel='dB', ylabel='', title='', |
|
486 | 458 | ytick_visible=False, |
|
487 | 459 | grid='x') |
|
488 | 460 | |
|
489 | 461 | self.draw() |
|
490 | 462 | |
|
491 | 463 | if save: |
|
492 | 464 | date = thisDatetime.strftime("%Y%m%d") |
|
493 | 465 | if figfile == None: |
|
494 | 466 | figfile = self.getFilename(name = date) |
|
495 | 467 | |
|
496 | 468 | self.saveFigure(figpath, figfile) |
|
497 | 469 | |
|
498 | 470 | class Scope(Figure): |
|
499 | 471 | |
|
500 | 472 | __isConfig = None |
|
501 | 473 | |
|
502 | 474 | def __init__(self): |
|
503 | 475 | |
|
504 | 476 | self.__isConfig = False |
|
505 | 477 | self.WIDTH = 600 |
|
506 | 478 | self.HEIGHT = 200 |
|
507 | 479 | |
|
508 | 480 | def getSubplots(self): |
|
509 | 481 | |
|
510 | 482 | nrow = self.nplots |
|
511 | 483 | ncol = 3 |
|
512 | 484 | return nrow, ncol |
|
513 | 485 | |
|
514 | 486 | def setup(self, idfigure, nplots, wintitle): |
|
515 | 487 | |
|
516 | 488 | self.createFigure(idfigure, wintitle) |
|
517 | 489 | |
|
518 | 490 | nrow,ncol = self.getSubplots() |
|
519 | 491 | colspan = 3 |
|
520 | 492 | rowspan = 1 |
|
521 | 493 | |
|
522 | 494 | for i in range(nplots): |
|
523 | 495 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
524 | 496 | |
|
525 | 497 | self.nplots = nplots |
|
526 | 498 | |
|
527 | 499 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
528 | 500 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
529 | 501 | |
|
530 | 502 | """ |
|
531 | 503 | |
|
532 | 504 | Input: |
|
533 | 505 | dataOut : |
|
534 | 506 | idfigure : |
|
535 | 507 | wintitle : |
|
536 | 508 | channelList : |
|
537 | 509 | xmin : None, |
|
538 | 510 | xmax : None, |
|
539 | 511 | ymin : None, |
|
540 | 512 | ymax : None, |
|
541 | 513 | """ |
|
542 | 514 | |
|
543 | 515 | if channelList == None: |
|
544 | 516 | channelIndexList = dataOut.channelIndexList |
|
545 | 517 | else: |
|
546 | 518 | channelIndexList = [] |
|
547 | 519 | for channel in channelList: |
|
548 | 520 | if channel not in dataOut.channelList: |
|
549 | 521 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
550 | 522 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
551 | 523 | |
|
552 | 524 | x = dataOut.heightList |
|
553 | 525 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
554 | 526 | y = y.real |
|
555 | 527 | |
|
556 | 528 | noise = dataOut.getNoise() |
|
557 | 529 | |
|
558 | 530 | if not self.__isConfig: |
|
559 | 531 | nplots = len(channelList) |
|
560 | 532 | |
|
561 | 533 | self.setup(idfigure=idfigure, |
|
562 | 534 | nplots=nplots, |
|
563 | 535 | wintitle=wintitle) |
|
564 | 536 | |
|
565 | 537 | if xmin == None: xmin = numpy.nanmin(x) |
|
566 | 538 | if xmax == None: xmax = numpy.nanmax(x) |
|
567 | 539 | if ymin == None: ymin = numpy.nanmin(y) |
|
568 | 540 | if ymax == None: ymax = numpy.nanmax(y) |
|
569 | 541 | |
|
570 | 542 | self.__isConfig = True |
|
571 | 543 | |
|
572 | 544 | |
|
573 | 545 | thisDatetime = dataOut.datatime |
|
574 | 546 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
575 | 547 | xlabel = "Range (Km)" |
|
576 | 548 | ylabel = "Intensity" |
|
577 | 549 | |
|
578 | 550 | self.setWinTitle(title) |
|
579 | 551 | |
|
580 | 552 | for i in range(len(self.axesList)): |
|
581 | 553 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
582 | 554 | axes = self.axesList[i] |
|
583 | 555 | ychannel = y[i,:] |
|
584 | 556 | axes.pline(x, ychannel, |
|
585 | 557 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
586 | 558 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
587 | 559 | |
|
588 | 560 | self.draw() |
|
589 | 561 | |
|
590 | 562 | if save: |
|
591 | 563 | self.saveFigure(filename) |
|
592 | 564 | |
|
593 | 565 | class ProfilePlot(Figure): |
|
594 | 566 | __isConfig = None |
|
595 | 567 | __nsubplots = None |
|
596 | 568 | |
|
597 | 569 | WIDTHPROF = None |
|
598 | 570 | HEIGHTPROF = None |
|
599 | 571 | PREFIX = 'spcprofile' |
|
600 | 572 | |
|
601 | 573 | def __init__(self): |
|
602 | 574 | self.__isConfig = False |
|
603 | 575 | self.__nsubplots = 1 |
|
604 | 576 | |
|
605 | 577 | self.WIDTH = 300 |
|
606 | 578 | self.HEIGHT = 500 |
|
607 | 579 | |
|
608 | 580 | def getSubplots(self): |
|
609 | 581 | ncol = 1 |
|
610 | 582 | nrow = 1 |
|
611 | 583 | |
|
612 | 584 | return nrow, ncol |
|
613 | 585 | |
|
614 | 586 | def setup(self, idfigure, nplots, wintitle): |
|
615 | 587 | |
|
616 | 588 | self.nplots = nplots |
|
617 | 589 | |
|
618 | 590 | ncolspan = 1 |
|
619 | 591 | colspan = 1 |
|
620 | 592 | |
|
621 | 593 | self.createFigure(idfigure = idfigure, |
|
622 | 594 | wintitle = wintitle, |
|
623 | 595 | widthplot = self.WIDTH, |
|
624 | 596 | heightplot = self.HEIGHT) |
|
625 | 597 | |
|
626 | 598 | nrow, ncol = self.getSubplots() |
|
627 | 599 | |
|
628 | 600 | counter = 0 |
|
629 | 601 | for y in range(nrow): |
|
630 | 602 | for x in range(ncol): |
|
631 | 603 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
632 | 604 | |
|
633 | 605 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
634 | 606 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
635 | 607 | save=False, figpath='./', figfile=None): |
|
636 | 608 | |
|
637 | 609 | if channelList == None: |
|
638 | 610 | channelIndexList = dataOut.channelIndexList |
|
639 | 611 | channelList = dataOut.channelList |
|
640 | 612 | else: |
|
641 | 613 | channelIndexList = [] |
|
642 | 614 | for channel in channelList: |
|
643 | 615 | if channel not in dataOut.channelList: |
|
644 | 616 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
645 | 617 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
646 | 618 | |
|
647 | 619 | |
|
648 | 620 | y = dataOut.getHeiRange() |
|
649 | 621 | x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
650 | 622 | avg = numpy.average(x, axis=1) |
|
651 | 623 | |
|
652 | 624 | |
|
653 | 625 | if not self.__isConfig: |
|
654 | 626 | |
|
655 | 627 | nplots = 1 |
|
656 | 628 | |
|
657 | 629 | self.setup(idfigure=idfigure, |
|
658 | 630 | nplots=nplots, |
|
659 | 631 | wintitle=wintitle) |
|
660 | 632 | |
|
661 | 633 | if ymin == None: ymin = numpy.nanmin(y) |
|
662 | 634 | if ymax == None: ymax = numpy.nanmax(y) |
|
663 | 635 | if xmin == None: xmin = numpy.nanmin(avg)*0.9 |
|
664 | 636 | if xmax == None: xmax = numpy.nanmax(avg)*0.9 |
|
665 | 637 | |
|
666 | 638 | self.__isConfig = True |
|
667 | 639 | |
|
668 | 640 | thisDatetime = dataOut.datatime |
|
669 | 641 | title = "Power Profile" |
|
670 | 642 | xlabel = "dB" |
|
671 | 643 | ylabel = "Range (Km)" |
|
672 | 644 | |
|
673 | 645 | self.setWinTitle(title) |
|
674 | 646 | |
|
675 | 647 | |
|
676 | 648 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
677 | 649 | axes = self.axesList[0] |
|
678 | 650 | |
|
679 | 651 | legendlabels = ["channel %d"%x for x in channelList] |
|
680 | 652 | axes.pmultiline(avg, y, |
|
681 | 653 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
682 | 654 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
683 | 655 | ytick_visible=True, nxticks=5, |
|
684 | 656 | grid='x') |
|
685 | 657 | |
|
686 | 658 | self.draw() |
|
687 | 659 | |
|
688 | 660 | if save: |
|
689 | 661 | date = thisDatetime.strftime("%Y%m%d") |
|
690 | 662 | if figfile == None: |
|
691 | 663 | figfile = self.getFilename(name = date) |
|
692 | 664 | |
|
693 | 665 | self.saveFigure(figpath, figfile) |
|
694 | 666 | |
|
695 | 667 | class CoherencePlot(Figure): |
|
696 | 668 | __isConfig = None |
|
697 | 669 | __nsubplots = None |
|
698 | 670 | |
|
699 | 671 | WIDTHPROF = None |
|
700 | 672 | HEIGHTPROF = None |
|
701 | 673 | PREFIX = 'coherencemap' |
|
702 | 674 | |
|
703 | 675 | def __init__(self): |
|
704 | 676 | self.__timerange = 24*60*60 |
|
705 | 677 | self.__isConfig = False |
|
706 | 678 | self.__nsubplots = 1 |
|
707 | 679 | |
|
708 | 680 | self.WIDTH = 800 |
|
709 | 681 | self.HEIGHT = 200 |
|
710 | 682 | self.WIDTHPROF = 120 |
|
711 | 683 | self.HEIGHTPROF = 0 |
|
712 | 684 | |
|
713 | 685 | def getSubplots(self): |
|
714 | 686 | ncol = 1 |
|
715 | 687 | nrow = self.nplots*2 |
|
716 | 688 | |
|
717 | 689 | return nrow, ncol |
|
718 | 690 | |
|
719 | 691 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
720 | 692 | self.__showprofile = showprofile |
|
721 | 693 | self.nplots = nplots |
|
722 | 694 | |
|
723 | 695 | ncolspan = 1 |
|
724 | 696 | colspan = 1 |
|
725 | 697 | if showprofile: |
|
726 | 698 | ncolspan = 7 |
|
727 | 699 | colspan = 6 |
|
728 | 700 | self.__nsubplots = 2 |
|
729 | 701 | |
|
730 | 702 | self.createFigure(idfigure = idfigure, |
|
731 | 703 | wintitle = wintitle, |
|
732 | 704 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
733 | 705 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
734 | 706 | |
|
735 | 707 | nrow, ncol = self.getSubplots() |
|
736 | 708 | |
|
737 | 709 | for y in range(nrow): |
|
738 | 710 | for x in range(ncol): |
|
739 | 711 | |
|
740 | 712 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
741 | 713 | |
|
742 | 714 | if showprofile: |
|
743 | 715 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
744 | ||
|
745 | def __getTimeLim(self, x, xmin, xmax): | |
|
746 | ||
|
747 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
748 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
749 | ||
|
750 | #################################################### | |
|
751 | #If the x is out of xrange | |
|
752 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
|
753 | xmin = None | |
|
754 | xmax = None | |
|
755 | ||
|
756 | if xmin == None: | |
|
757 | td = thisdatetime - thisdate | |
|
758 | xmin = td.seconds/(60*60.) | |
|
759 | ||
|
760 | if xmax == None: | |
|
761 | xmax = xmin + self.__timerange/(60*60.) | |
|
762 | ||
|
763 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
|
764 | tmin = time.mktime(mindt.timetuple()) | |
|
765 | ||
|
766 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
|
767 | tmax = time.mktime(maxdt.timetuple()) | |
|
768 | ||
|
769 | self.__timerange = tmax - tmin | |
|
770 | ||
|
771 | return tmin, tmax | |
|
772 | 716 | |
|
773 | 717 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
774 | 718 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
775 | 719 | timerange=None, |
|
776 | 720 | save=False, figpath='./', figfile=None): |
|
777 | 721 | |
|
778 | 722 | if pairsList == None: |
|
779 | 723 | pairsIndexList = dataOut.pairsIndexList |
|
780 | 724 | else: |
|
781 | 725 | pairsIndexList = [] |
|
782 | 726 | for pair in pairsList: |
|
783 | 727 | if pair not in dataOut.pairsList: |
|
784 | 728 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
785 | 729 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
786 | 730 | |
|
787 | 731 | if timerange != None: |
|
788 | 732 | self.__timerange = timerange |
|
789 | 733 | |
|
790 | 734 | tmin = None |
|
791 | 735 | tmax = None |
|
792 | 736 | x = dataOut.getTimeRange() |
|
793 | 737 | y = dataOut.getHeiRange() |
|
794 | 738 | |
|
795 | 739 | if not self.__isConfig: |
|
796 | 740 | nplots = len(pairsIndexList) |
|
797 | 741 | self.setup(idfigure=idfigure, |
|
798 | 742 | nplots=nplots, |
|
799 | 743 | wintitle=wintitle, |
|
800 | 744 | showprofile=showprofile) |
|
801 | 745 | |
|
802 |
tmin, tmax = self. |
|
|
746 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
803 | 747 | if ymin == None: ymin = numpy.nanmin(y) |
|
804 | 748 | if ymax == None: ymax = numpy.nanmax(y) |
|
805 | 749 | |
|
806 | 750 | self.__isConfig = True |
|
807 | 751 | |
|
808 | 752 | thisDatetime = dataOut.datatime |
|
809 | 753 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
810 | 754 | xlabel = "" |
|
811 | 755 | ylabel = "Range (Km)" |
|
812 | 756 | |
|
813 | 757 | self.setWinTitle(title) |
|
814 | 758 | |
|
815 | 759 | for i in range(self.nplots): |
|
816 | 760 | |
|
817 | 761 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
818 | 762 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
819 | 763 | coherence = numpy.abs(coherenceComplex) |
|
820 | 764 | avg = numpy.average(coherence, axis=0) |
|
821 | 765 | z = avg.reshape((1,-1)) |
|
822 | 766 | |
|
823 | 767 | counter = 0 |
|
824 | 768 | |
|
825 | 769 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
826 | 770 | axes = self.axesList[i*self.__nsubplots*2] |
|
827 | 771 | axes.pcolor(x, y, z, |
|
828 | 772 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
829 | 773 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
830 | 774 | ticksize=9, cblabel='', cbsize="1%") |
|
831 | 775 | |
|
832 | 776 | if self.__showprofile: |
|
833 | 777 | counter += 1 |
|
834 | 778 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
835 | 779 | axes.pline(avg, y, |
|
836 | 780 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
837 | 781 | xlabel='', ylabel='', title='', ticksize=7, |
|
838 | 782 | ytick_visible=False, nxticks=5, |
|
839 | 783 | grid='x') |
|
840 | 784 | |
|
841 | 785 | counter += 1 |
|
842 | 786 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
843 | 787 | avg = numpy.average(phase, axis=0) |
|
844 | 788 | z = avg.reshape((1,-1)) |
|
845 | 789 | |
|
846 | 790 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
847 | 791 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
848 | 792 | axes.pcolor(x, y, z, |
|
849 | 793 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
850 | 794 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
851 | 795 | ticksize=9, cblabel='', colormap='RdBu', cbsize="1%") |
|
852 | 796 | |
|
853 | 797 | if self.__showprofile: |
|
854 | 798 | counter += 1 |
|
855 | 799 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
856 | 800 | axes.pline(avg, y, |
|
857 | 801 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
858 | 802 | xlabel='', ylabel='', title='', ticksize=7, |
|
859 | 803 | ytick_visible=False, nxticks=4, |
|
860 | 804 | grid='x') |
|
861 | 805 | |
|
862 | 806 | self.draw() |
|
863 | 807 | |
|
864 | 808 | if save: |
|
865 | 809 | date = thisDatetime.strftime("%Y%m%d") |
|
866 | 810 | if figfile == None: |
|
867 | 811 | figfile = self.getFilename(name = date) |
|
868 | 812 | |
|
869 | 813 | self.saveFigure(figpath, figfile) |
|
870 | 814 | |
|
871 | 815 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
872 | 816 | self.__isConfig = False |
|
873 | 817 | |
|
874 | 818 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now