@@ -1,421 +1,427 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class RTIPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTHPROF = None |
|
11 | 11 | HEIGHTPROF = None |
|
12 | 12 | PREFIX = 'rti' |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | |
|
16 | 16 | self.__timerange = 24*60*60 |
|
17 | 17 | self.__isConfig = False |
|
18 | 18 | self.__nsubplots = 1 |
|
19 | 19 | |
|
20 | 20 | self.WIDTH = 800 |
|
21 | 21 | self.HEIGHT = 200 |
|
22 | 22 | self.WIDTHPROF = 120 |
|
23 | 23 | self.HEIGHTPROF = 0 |
|
24 | 24 | |
|
25 | 25 | def getSubplots(self): |
|
26 | 26 | |
|
27 | 27 | ncol = 1 |
|
28 | 28 | nrow = self.nplots |
|
29 | 29 | |
|
30 | 30 | return nrow, ncol |
|
31 | 31 | |
|
32 | 32 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
33 | 33 | |
|
34 | 34 | self.__showprofile = showprofile |
|
35 | 35 | self.nplots = nplots |
|
36 | 36 | |
|
37 | 37 | ncolspan = 1 |
|
38 | 38 | colspan = 1 |
|
39 | 39 | if showprofile: |
|
40 | 40 | ncolspan = 7 |
|
41 | 41 | colspan = 6 |
|
42 | 42 | self.__nsubplots = 2 |
|
43 | 43 | |
|
44 | 44 | self.createFigure(idfigure = idfigure, |
|
45 | 45 | wintitle = wintitle, |
|
46 | 46 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
47 | 47 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
48 | 48 | |
|
49 | 49 | nrow, ncol = self.getSubplots() |
|
50 | 50 | |
|
51 | 51 | counter = 0 |
|
52 | 52 | for y in range(nrow): |
|
53 | 53 | for x in range(ncol): |
|
54 | 54 | |
|
55 | 55 | if counter >= self.nplots: |
|
56 | 56 | break |
|
57 | 57 | |
|
58 | 58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
59 | 59 | |
|
60 | 60 | if showprofile: |
|
61 | 61 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
62 | 62 | |
|
63 | 63 | counter += 1 |
|
64 | 64 | |
|
65 | 65 | def __getTimeLim(self, x, xmin, xmax): |
|
66 | 66 | |
|
67 | 67 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
68 | 68 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
69 | 69 | |
|
70 | 70 | #################################################### |
|
71 | 71 | #If the x is out of xrange |
|
72 | 72 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
73 | 73 | xmin = None |
|
74 | 74 | xmax = None |
|
75 | 75 | |
|
76 | 76 | if xmin == None: |
|
77 | 77 | td = thisdatetime - thisdate |
|
78 | 78 | xmin = td.seconds/(60*60.) |
|
79 | 79 | |
|
80 | 80 | if xmax == None: |
|
81 | 81 | xmax = xmin + self.__timerange/(60*60.) |
|
82 | 82 | |
|
83 | 83 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
84 | 84 | tmin = time.mktime(mindt.timetuple()) |
|
85 | 85 | |
|
86 | 86 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
87 | 87 | tmax = time.mktime(maxdt.timetuple()) |
|
88 | 88 | |
|
89 | 89 | self.__timerange = tmax - tmin |
|
90 | 90 | |
|
91 | 91 | return tmin, tmax |
|
92 | 92 | |
|
93 | 93 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
94 | 94 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
95 | 95 | timerange=None, |
|
96 | 96 | save=False, figpath='./', figfile=None): |
|
97 | 97 | |
|
98 | 98 | """ |
|
99 | 99 | |
|
100 | 100 | Input: |
|
101 | 101 | dataOut : |
|
102 | 102 | idfigure : |
|
103 | 103 | wintitle : |
|
104 | 104 | channelList : |
|
105 | 105 | showProfile : |
|
106 | 106 | xmin : None, |
|
107 | 107 | xmax : None, |
|
108 | 108 | ymin : None, |
|
109 | 109 | ymax : None, |
|
110 | 110 | zmin : None, |
|
111 | 111 | zmax : None |
|
112 | 112 | """ |
|
113 | 113 | |
|
114 | 114 | if channelList == None: |
|
115 | 115 | channelIndexList = dataOut.channelIndexList |
|
116 | 116 | else: |
|
117 | 117 | channelIndexList = [] |
|
118 | 118 | for channel in channelList: |
|
119 | 119 | if channel not in dataOut.channelList: |
|
120 | 120 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
121 | channelIndexList.append(channel) | |
|
121 | channelIndexList.append(dataOut.channelList.index(chachannel)) | |
|
122 | 122 | |
|
123 | 123 | if timerange != None: |
|
124 | 124 | self.__timerange = timerange |
|
125 | 125 | |
|
126 | 126 | tmin = None |
|
127 | 127 | tmax = None |
|
128 | 128 | x = dataOut.getDatatime() |
|
129 | 129 | y = dataOut.getHeiRange() |
|
130 | 130 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
131 | 131 | avg = numpy.average(z, axis=1) |
|
132 | 132 | |
|
133 | 133 | noise = dataOut.getNoise() |
|
134 | 134 | |
|
135 | 135 | if not self.__isConfig: |
|
136 | 136 | |
|
137 | 137 | nplots = len(channelIndexList) |
|
138 | 138 | |
|
139 | 139 | self.setup(idfigure=idfigure, |
|
140 | 140 | nplots=nplots, |
|
141 | 141 | wintitle=wintitle, |
|
142 | 142 | showprofile=showprofile) |
|
143 | 143 | |
|
144 | 144 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
145 | 145 | if ymin == None: ymin = numpy.nanmin(y) |
|
146 | 146 | if ymax == None: ymax = numpy.nanmax(y) |
|
147 | 147 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
148 | 148 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
149 | 149 | |
|
150 | 150 | self.__isConfig = True |
|
151 | 151 | |
|
152 | 152 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
153 | 153 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
154 | 154 | xlabel = "Velocity (m/s)" |
|
155 | 155 | ylabel = "Range (Km)" |
|
156 | 156 | |
|
157 | 157 | self.setWinTitle(title) |
|
158 | 158 | |
|
159 | 159 | for i in range(self.nplots): |
|
160 | 160 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
161 | 161 | axes = self.axesList[i*self.__nsubplots] |
|
162 | 162 | z = avg[i].reshape((1,-1)) |
|
163 | 163 | axes.pcolor(x, y, z, |
|
164 | 164 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
165 | 165 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
166 | 166 | ticksize=9, cblabel='', cbsize="1%") |
|
167 | 167 | |
|
168 | 168 | if self.__showprofile: |
|
169 | 169 | axes = self.axesList[i*self.__nsubplots +1] |
|
170 | 170 | axes.pline(avg[i], y, |
|
171 | 171 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
172 | 172 | xlabel='dB', ylabel='', title='', |
|
173 | 173 | ytick_visible=False, |
|
174 | 174 | grid='x') |
|
175 | 175 | |
|
176 | 176 | self.draw() |
|
177 | 177 | |
|
178 | 178 | if save: |
|
179 | 179 | date = thisDatetime.strftime("%Y%m%d") |
|
180 | 180 | if figfile == None: |
|
181 | 181 | figfile = self.getFilename(name = date) |
|
182 | 182 | |
|
183 | 183 | self.saveFigure(figpath, figfile) |
|
184 | 184 | |
|
185 | 185 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
186 | 186 | self.__isConfig = False |
|
187 | 187 | |
|
188 | 188 | class SpectraPlot(Figure): |
|
189 | 189 | |
|
190 | 190 | __isConfig = None |
|
191 | 191 | __nsubplots = None |
|
192 | 192 | |
|
193 | 193 | WIDTHPROF = None |
|
194 | 194 | HEIGHTPROF = None |
|
195 | 195 | PREFIX = 'spc' |
|
196 | 196 | |
|
197 | 197 | def __init__(self): |
|
198 | 198 | |
|
199 | 199 | self.__isConfig = False |
|
200 | 200 | self.__nsubplots = 1 |
|
201 | 201 | |
|
202 | 202 | self.WIDTH = 300 |
|
203 | 203 | self.HEIGHT = 400 |
|
204 | 204 | self.WIDTHPROF = 120 |
|
205 | 205 | self.HEIGHTPROF = 0 |
|
206 | 206 | |
|
207 | 207 | def getSubplots(self): |
|
208 | 208 | |
|
209 | 209 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
210 | 210 | nrow = int(self.nplots*1./ncol + 0.9) |
|
211 | 211 | |
|
212 | 212 | return nrow, ncol |
|
213 | 213 | |
|
214 | 214 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
215 | 215 | |
|
216 | 216 | self.__showprofile = showprofile |
|
217 | 217 | self.nplots = nplots |
|
218 | 218 | |
|
219 | 219 | ncolspan = 1 |
|
220 | 220 | colspan = 1 |
|
221 | 221 | if showprofile: |
|
222 | 222 | ncolspan = 3 |
|
223 | 223 | colspan = 2 |
|
224 | 224 | self.__nsubplots = 2 |
|
225 | 225 | |
|
226 | 226 | self.createFigure(idfigure = idfigure, |
|
227 | 227 | wintitle = wintitle, |
|
228 | 228 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
229 | 229 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
230 | 230 | |
|
231 | 231 | nrow, ncol = self.getSubplots() |
|
232 | 232 | |
|
233 | 233 | counter = 0 |
|
234 | 234 | for y in range(nrow): |
|
235 | 235 | for x in range(ncol): |
|
236 | 236 | |
|
237 | 237 | if counter >= self.nplots: |
|
238 | 238 | break |
|
239 | 239 | |
|
240 | 240 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
241 | 241 | |
|
242 | 242 | if showprofile: |
|
243 | 243 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
244 | 244 | |
|
245 | 245 | counter += 1 |
|
246 | 246 | |
|
247 | 247 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
248 | 248 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
249 | 249 | save=False, figpath='./', figfile=None): |
|
250 | 250 | |
|
251 | 251 | """ |
|
252 | 252 | |
|
253 | 253 | Input: |
|
254 | 254 | dataOut : |
|
255 | 255 | idfigure : |
|
256 | 256 | wintitle : |
|
257 | 257 | channelList : |
|
258 | 258 | showProfile : |
|
259 | 259 | xmin : None, |
|
260 | 260 | xmax : None, |
|
261 | 261 | ymin : None, |
|
262 | 262 | ymax : None, |
|
263 | 263 | zmin : None, |
|
264 | 264 | zmax : None |
|
265 | 265 | """ |
|
266 | 266 | |
|
267 | 267 | if channelList == None: |
|
268 | 268 | channelIndexList = dataOut.channelIndexList |
|
269 | 269 | else: |
|
270 | 270 | channelIndexList = [] |
|
271 | 271 | for channel in channelList: |
|
272 | 272 | if channel not in dataOut.channelList: |
|
273 | 273 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
274 | channelIndexList.append(channelList.index(channel)) | |
|
274 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
275 | 275 | |
|
276 | 276 | x = dataOut.getVelRange(1) |
|
277 | 277 | y = dataOut.getHeiRange() |
|
278 | 278 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
279 | 279 | avg = numpy.average(z, axis=1) |
|
280 | 280 | |
|
281 | 281 | noise = dataOut.getNoise() |
|
282 | 282 | |
|
283 | 283 | if not self.__isConfig: |
|
284 | 284 | |
|
285 | 285 | nplots = len(channelIndexList) |
|
286 | 286 | |
|
287 | 287 | self.setup(idfigure=idfigure, |
|
288 | 288 | nplots=nplots, |
|
289 | 289 | wintitle=wintitle, |
|
290 | 290 | showprofile=showprofile) |
|
291 | 291 | |
|
292 | 292 | if xmin == None: xmin = numpy.nanmin(x) |
|
293 | 293 | if xmax == None: xmax = numpy.nanmax(x) |
|
294 | 294 | if ymin == None: ymin = numpy.nanmin(y) |
|
295 | 295 | if ymax == None: ymax = numpy.nanmax(y) |
|
296 | 296 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
297 | 297 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
298 | 298 | |
|
299 | 299 | self.__isConfig = True |
|
300 | 300 | |
|
301 | 301 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
302 | 302 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
303 | 303 | xlabel = "Velocity (m/s)" |
|
304 | 304 | ylabel = "Range (Km)" |
|
305 | 305 | |
|
306 | 306 | self.setWinTitle(title) |
|
307 | 307 | |
|
308 | 308 | for i in range(self.nplots): |
|
309 | 309 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
310 | 310 | axes = self.axesList[i*self.__nsubplots] |
|
311 | 311 | axes.pcolor(x, y, z[i,:,:], |
|
312 | 312 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
313 | 313 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
314 | 314 | ticksize=9, cblabel='') |
|
315 | 315 | |
|
316 | 316 | if self.__showprofile: |
|
317 | 317 | axes = self.axesList[i*self.__nsubplots +1] |
|
318 | 318 | axes.pline(avg[i], y, |
|
319 | 319 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
320 | 320 | xlabel='dB', ylabel='', title='', |
|
321 | 321 | ytick_visible=False, |
|
322 | 322 | grid='x') |
|
323 | 323 | |
|
324 | 324 | self.draw() |
|
325 | 325 | |
|
326 | 326 | if save: |
|
327 | 327 | date = thisDatetime.strftime("%Y%m%d") |
|
328 | 328 | if figfile == None: |
|
329 | 329 | figfile = self.getFilename(name = date) |
|
330 | 330 | |
|
331 | 331 | self.saveFigure(figpath, figfile) |
|
332 | 332 | |
|
333 | 333 | class Scope(Figure): |
|
334 | 334 | |
|
335 | 335 | __isConfig = None |
|
336 | 336 | |
|
337 | 337 | def __init__(self): |
|
338 | 338 | |
|
339 | 339 | self.__isConfig = False |
|
340 | 340 | self.WIDTH = 600 |
|
341 | 341 | self.HEIGHT = 200 |
|
342 | 342 | |
|
343 | 343 | def getSubplots(self): |
|
344 | 344 | |
|
345 | 345 | nrow = self.nplots |
|
346 | 346 | ncol = 3 |
|
347 | 347 | return nrow, ncol |
|
348 | 348 | |
|
349 | 349 | def setup(self, idfigure, nplots, wintitle): |
|
350 | 350 | |
|
351 | 351 | self.createFigure(idfigure, wintitle) |
|
352 | 352 | |
|
353 | 353 | nrow,ncol = self.getSubplots() |
|
354 | 354 | colspan = 3 |
|
355 | 355 | rowspan = 1 |
|
356 | 356 | |
|
357 | 357 | for i in range(nplots): |
|
358 | 358 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
359 | 359 | |
|
360 | 360 | self.nplots = nplots |
|
361 | 361 | |
|
362 | 362 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
363 | 363 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
364 | 364 | |
|
365 | 365 | """ |
|
366 | 366 | |
|
367 | 367 | Input: |
|
368 | 368 | dataOut : |
|
369 | 369 | idfigure : |
|
370 | 370 | wintitle : |
|
371 | 371 | channelList : |
|
372 | 372 | xmin : None, |
|
373 | 373 | xmax : None, |
|
374 | 374 | ymin : None, |
|
375 | 375 | ymax : None, |
|
376 | 376 | """ |
|
377 | 377 | |
|
378 | 378 | if channelList == None: |
|
379 | channelList = dataOut.channelList | |
|
379 | channelIndexList = dataOut.channelIndexList | |
|
380 | else: | |
|
381 | channelIndexList = [] | |
|
382 | for channel in channelList: | |
|
383 | if channel not in dataOut.channelList: | |
|
384 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
|
385 | channelIndexList.append(dataOut.channelList.index(chachannel)) | |
|
380 | 386 | |
|
381 | 387 | x = dataOut.heightList |
|
382 | 388 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
383 | 389 | y = y.real |
|
384 | 390 | |
|
385 | 391 | noise = dataOut.getNoise() |
|
386 | 392 | |
|
387 | 393 | if not self.__isConfig: |
|
388 | 394 | nplots = len(channelList) |
|
389 | 395 | |
|
390 | 396 | self.setup(idfigure=idfigure, |
|
391 | 397 | nplots=nplots, |
|
392 | 398 | wintitle=wintitle) |
|
393 | 399 | |
|
394 | 400 | if xmin == None: xmin = numpy.nanmin(x) |
|
395 | 401 | if xmax == None: xmax = numpy.nanmax(x) |
|
396 | 402 | if ymin == None: ymin = numpy.nanmin(y) |
|
397 | 403 | if ymax == None: ymax = numpy.nanmax(y) |
|
398 | 404 | |
|
399 | 405 | self.__isConfig = True |
|
400 | 406 | |
|
401 | 407 | |
|
402 | 408 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
403 | 409 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
404 | 410 | xlabel = "Range (Km)" |
|
405 | 411 | ylabel = "Intensity" |
|
406 | 412 | |
|
407 | 413 | self.setWinTitle(title) |
|
408 | 414 | |
|
409 | 415 | for i in range(len(self.axesList)): |
|
410 | 416 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
411 | 417 | axes = self.axesList[i] |
|
412 | 418 | ychannel = y[i,:] |
|
413 | 419 | axes.pline(x, ychannel, |
|
414 | 420 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
415 | 421 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
416 | 422 | |
|
417 | 423 | self.draw() |
|
418 | 424 | |
|
419 | 425 | if save: |
|
420 | 426 | self.saveFigure(filename) |
|
421 | 427 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now