@@ -1,661 +1,661 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | |
|
6 | 6 | from schainpy.model.proc.jroproc_base import Operation |
|
7 | 7 | |
|
8 | 8 | def isTimeInHourRange(datatime, xmin, xmax): |
|
9 | 9 | |
|
10 | 10 | if xmin == None or xmax == None: |
|
11 | 11 | return 1 |
|
12 | 12 | hour = datatime.hour + datatime.minute/60.0 |
|
13 | 13 | |
|
14 | 14 | if xmin < (xmax % 24): |
|
15 | 15 | |
|
16 | 16 | if hour >= xmin and hour <= xmax: |
|
17 | 17 | return 1 |
|
18 | 18 | else: |
|
19 | 19 | return 0 |
|
20 | 20 | |
|
21 | 21 | else: |
|
22 | 22 | |
|
23 | 23 | if hour >= xmin or hour <= (xmax % 24): |
|
24 | 24 | return 1 |
|
25 | 25 | else: |
|
26 | 26 | return 0 |
|
27 | 27 | |
|
28 | 28 | return 0 |
|
29 | 29 | |
|
30 | 30 | def isRealtime(utcdatatime): |
|
31 | 31 | |
|
32 | 32 | utcnow = time.mktime(time.localtime()) |
|
33 | 33 | delta = abs(utcnow - utcdatatime) # abs |
|
34 | 34 | if delta >= 30.: |
|
35 | 35 | return False |
|
36 | 36 | return True |
|
37 | 37 | |
|
38 | 38 | class Figure(Operation): |
|
39 | 39 | |
|
40 | 40 | __driver = mpldriver |
|
41 | 41 | fig = None |
|
42 | 42 | |
|
43 | 43 | id = None |
|
44 | 44 | wintitle = None |
|
45 | 45 | width = None |
|
46 | 46 | height = None |
|
47 | 47 | nplots = None |
|
48 | 48 | timerange = None |
|
49 | 49 | |
|
50 | 50 | axesObjList = [] |
|
51 | 51 | |
|
52 | 52 | WIDTH = 300 |
|
53 | 53 | HEIGHT = 200 |
|
54 | 54 | PREFIX = 'fig' |
|
55 | 55 | |
|
56 | 56 | xmin = None |
|
57 | 57 | xmax = None |
|
58 | 58 | |
|
59 | 59 | counter_imagwr = 0 |
|
60 | 60 | |
|
61 | 61 | figfile = None |
|
62 | 62 | |
|
63 | 63 | created = False |
|
64 | 64 | |
|
65 | 65 | def __init__(self): |
|
66 | 66 | |
|
67 | 67 | raise NotImplementedError |
|
68 | 68 | |
|
69 | 69 | def __del__(self): |
|
70 | 70 | |
|
71 | 71 | self.__driver.closeFigure() |
|
72 | 72 | |
|
73 | 73 | def getFilename(self, name, ext='.png'): |
|
74 | 74 | |
|
75 | 75 | path = '%s%03d' %(self.PREFIX, self.id) |
|
76 | 76 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
77 | 77 | return os.path.join(path, filename) |
|
78 | 78 | |
|
79 | 79 | def getAxesObjList(self): |
|
80 | 80 | |
|
81 | 81 | return self.axesObjList |
|
82 | 82 | |
|
83 | 83 | def getSubplots(self): |
|
84 | 84 | |
|
85 | 85 | raise NotImplementedError |
|
86 | 86 | |
|
87 | 87 | def getScreenDim(self, widthplot, heightplot): |
|
88 | 88 | |
|
89 | 89 | nrow, ncol = self.getSubplots() |
|
90 | 90 | |
|
91 | 91 | widthscreen = widthplot*ncol |
|
92 | 92 | heightscreen = heightplot*nrow |
|
93 | 93 | |
|
94 | 94 | return widthscreen, heightscreen |
|
95 | 95 | |
|
96 | 96 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): |
|
97 | 97 | |
|
98 | 98 | # if self.xmin != None and self.xmax != None: |
|
99 | 99 | # if timerange == None: |
|
100 | 100 | # timerange = self.xmax - self.xmin |
|
101 | 101 | # xmin = self.xmin + timerange |
|
102 | 102 | # xmax = self.xmax + timerange |
|
103 | 103 | # |
|
104 | 104 | # return xmin, xmax |
|
105 | 105 | |
|
106 | 106 | if timerange == None and (xmin==None or xmax==None): |
|
107 | 107 | timerange = 14400 #seconds |
|
108 | 108 | |
|
109 | 109 | if timerange != None: |
|
110 | 110 | txmin = x[0] #- x[0] % min(timerange/10, 10*60) |
|
111 | 111 | else: |
|
112 | 112 | txmin = x[0] #- x[0] % 10*60 |
|
113 | 113 | |
|
114 | 114 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
115 | 115 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
116 | 116 | |
|
117 | 117 | if timerange != None: |
|
118 | 118 | xmin = (thisdatetime - thisdate).seconds/(60*60.) |
|
119 | 119 | xmax = xmin + timerange/(60*60.) |
|
120 | 120 | |
|
121 | 121 | d1970 = datetime.datetime(1970,1,1) |
|
122 | 122 | |
|
123 | 123 | mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone) |
|
124 | 124 | xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone |
|
125 | 125 | |
|
126 | 126 | maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone) |
|
127 | 127 | xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone |
|
128 | 128 | |
|
129 | 129 | return xmin_sec, xmax_sec |
|
130 | 130 | |
|
131 | 131 | def init(self, id, nplots, wintitle): |
|
132 | 132 | |
|
133 |
raise NotImplementedError, "This method has been replaced |
|
|
133 | raise NotImplementedError, "This method has been replaced by createFigure" | |
|
134 | 134 | |
|
135 | 135 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
136 | 136 | |
|
137 | 137 | """ |
|
138 | 138 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
139 | 139 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
140 | 140 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
141 | 141 | |
|
142 | 142 | Input: |
|
143 | 143 | id : Los parametros necesarios son |
|
144 | 144 | wintitle : |
|
145 | 145 | |
|
146 | 146 | """ |
|
147 | 147 | |
|
148 | 148 | if widthplot == None: |
|
149 | 149 | widthplot = self.WIDTH |
|
150 | 150 | |
|
151 | 151 | if heightplot == None: |
|
152 | 152 | heightplot = self.HEIGHT |
|
153 | 153 | |
|
154 | 154 | self.id = id |
|
155 | 155 | |
|
156 | 156 | self.wintitle = wintitle |
|
157 | 157 | |
|
158 | 158 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
159 | 159 | |
|
160 | 160 | # if self.created: |
|
161 | 161 | # self.__driver.closeFigure(self.fig) |
|
162 | 162 | |
|
163 | 163 | if not self.created: |
|
164 | 164 | self.fig = self.__driver.createFigure(id=self.id, |
|
165 | 165 | wintitle=self.wintitle, |
|
166 | 166 | width=self.widthscreen, |
|
167 | 167 | height=self.heightscreen, |
|
168 | 168 | show=show) |
|
169 | 169 | else: |
|
170 | 170 | self.__driver.clearFigure(self.fig) |
|
171 | 171 | |
|
172 | 172 | self.axesObjList = [] |
|
173 | 173 | self.counter_imagwr = 0 |
|
174 | 174 | |
|
175 | 175 | self.created = True |
|
176 | 176 | |
|
177 | 177 | def setDriver(self, driver=mpldriver): |
|
178 | 178 | |
|
179 | 179 | self.__driver = driver |
|
180 | 180 | |
|
181 | 181 | def setTitle(self, title): |
|
182 | 182 | |
|
183 | 183 | self.__driver.setTitle(self.fig, title) |
|
184 | 184 | |
|
185 | 185 | def setWinTitle(self, title): |
|
186 | 186 | |
|
187 | 187 | self.__driver.setWinTitle(self.fig, title=title) |
|
188 | 188 | |
|
189 | 189 | def setTextFromAxes(self, text): |
|
190 | 190 | |
|
191 | 191 | raise NotImplementedError, "This method has been replaced with Axes.setText" |
|
192 | 192 | |
|
193 | 193 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
194 | 194 | |
|
195 | 195 | raise NotImplementedError, "This method has been replaced with Axes.addAxes" |
|
196 | 196 | |
|
197 | 197 | def addAxes(self, *args): |
|
198 | 198 | """ |
|
199 | 199 | |
|
200 | 200 | Input: |
|
201 | 201 | *args : Los parametros necesarios son |
|
202 | 202 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
203 | 203 | """ |
|
204 | 204 | |
|
205 | 205 | axesObj = Axes(self.fig, *args) |
|
206 | 206 | self.axesObjList.append(axesObj) |
|
207 | 207 | |
|
208 | 208 | def saveFigure(self, figpath, figfile, *args): |
|
209 | 209 | |
|
210 | 210 | filename = os.path.join(figpath, figfile) |
|
211 | 211 | |
|
212 | 212 | fullpath = os.path.split(filename)[0] |
|
213 | 213 | |
|
214 | 214 | if not os.path.exists(fullpath): |
|
215 | 215 | subpath = os.path.split(fullpath)[0] |
|
216 | 216 | |
|
217 | 217 | if not os.path.exists(subpath): |
|
218 | 218 | os.mkdir(subpath) |
|
219 | 219 | |
|
220 | 220 | os.mkdir(fullpath) |
|
221 | 221 | |
|
222 | 222 | self.__driver.saveFigure(self.fig, filename, *args) |
|
223 | 223 | |
|
224 | 224 | def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True): |
|
225 | 225 | |
|
226 | 226 | self.counter_imagwr += 1 |
|
227 | 227 | if self.counter_imagwr < wr_period: |
|
228 | 228 | return |
|
229 | 229 | |
|
230 | 230 | self.counter_imagwr = 0 |
|
231 | 231 | |
|
232 | 232 | if save: |
|
233 | 233 | |
|
234 | 234 | if not figfile: |
|
235 | 235 | |
|
236 | 236 | if not thisDatetime: |
|
237 | 237 | raise ValueError, "Saving figure: figfile or thisDatetime should be defined" |
|
238 | 238 | return |
|
239 | 239 | |
|
240 | 240 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
241 | 241 | figfile = self.getFilename(name = str_datetime) |
|
242 | 242 | |
|
243 | 243 | if self.figfile == None: |
|
244 | 244 | self.figfile = figfile |
|
245 | 245 | |
|
246 | 246 | if update_figfile: |
|
247 | 247 | self.figfile = figfile |
|
248 | 248 | |
|
249 | 249 | # store png plot to local folder |
|
250 | 250 | self.saveFigure(figpath, self.figfile) |
|
251 | 251 | |
|
252 | 252 | |
|
253 | 253 | if not ftp: |
|
254 | 254 | return |
|
255 | 255 | |
|
256 | 256 | if not thisDatetime: |
|
257 | 257 | return |
|
258 | 258 | |
|
259 | 259 | # store png plot to FTP server according to RT-Web format |
|
260 | 260 | ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
261 | 261 | # ftp_filename = os.path.join(figpath, name) |
|
262 | 262 | self.saveFigure(figpath, ftp_filename) |
|
263 | 263 | |
|
264 | 264 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
265 | 265 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
266 | 266 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
267 | 267 | FTP_WEI = '%2.2d'%FTP_WEI |
|
268 | 268 | EXP_CODE = '%3.3d'%EXP_CODE |
|
269 | 269 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
270 | 270 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
271 | 271 | PLOT_POS = '%2.2d'%PLOT_POS |
|
272 | 272 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
273 | 273 | return name |
|
274 | 274 | |
|
275 | 275 | def draw(self): |
|
276 | 276 | |
|
277 | 277 | self.__driver.draw(self.fig) |
|
278 | 278 | |
|
279 | 279 | def run(self): |
|
280 | 280 | |
|
281 | 281 | raise NotImplementedError |
|
282 | 282 | |
|
283 | 283 | def close(self, show=False): |
|
284 | 284 | |
|
285 | 285 | self.__driver.closeFigure(show=show, fig=self.fig) |
|
286 | 286 | |
|
287 | 287 | axesList = property(getAxesObjList) |
|
288 | 288 | |
|
289 | 289 | |
|
290 | 290 | class Axes: |
|
291 | 291 | |
|
292 | 292 | __driver = mpldriver |
|
293 | 293 | fig = None |
|
294 | 294 | ax = None |
|
295 | 295 | plot = None |
|
296 | 296 | __missing = 1E30 |
|
297 | 297 | __firsttime = None |
|
298 | 298 | |
|
299 | 299 | __showprofile = False |
|
300 | 300 | |
|
301 | 301 | xmin = None |
|
302 | 302 | xmax = None |
|
303 | 303 | ymin = None |
|
304 | 304 | ymax = None |
|
305 | 305 | zmin = None |
|
306 | 306 | zmax = None |
|
307 | 307 | |
|
308 | 308 | x_buffer = None |
|
309 | 309 | z_buffer = None |
|
310 | 310 | |
|
311 | 311 | decimationx = None |
|
312 | 312 | decimationy = None |
|
313 | 313 | |
|
314 | 314 | __MAXNUMX = 200 |
|
315 | 315 | __MAXNUMY = 400 |
|
316 | 316 | |
|
317 | 317 | __MAXNUMTIME = 500 |
|
318 | 318 | |
|
319 | 319 | def __init__(self, *args): |
|
320 | 320 | |
|
321 | 321 | """ |
|
322 | 322 | |
|
323 | 323 | Input: |
|
324 | 324 | *args : Los parametros necesarios son |
|
325 | 325 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
326 | 326 | """ |
|
327 | 327 | |
|
328 | 328 | ax = self.__driver.createAxes(*args) |
|
329 | 329 | self.fig = args[0] |
|
330 | 330 | self.ax = ax |
|
331 | 331 | self.plot = None |
|
332 | 332 | |
|
333 | 333 | self.__firsttime = True |
|
334 | 334 | self.idlineList = [] |
|
335 | 335 | |
|
336 | 336 | self.x_buffer = numpy.array([]) |
|
337 | 337 | self.z_buffer = numpy.array([]) |
|
338 | 338 | |
|
339 | 339 | def setText(self, text): |
|
340 | 340 | |
|
341 | 341 | self.__driver.setAxesText(self.ax, text) |
|
342 | 342 | |
|
343 | 343 | def setXAxisAsTime(self): |
|
344 | 344 | pass |
|
345 | 345 | |
|
346 | 346 | def pline(self, x, y, |
|
347 | 347 | xmin=None, xmax=None, |
|
348 | 348 | ymin=None, ymax=None, |
|
349 | 349 | xlabel='', ylabel='', |
|
350 | 350 | title='', |
|
351 | 351 | **kwargs): |
|
352 | 352 | |
|
353 | 353 | """ |
|
354 | 354 | |
|
355 | 355 | Input: |
|
356 | 356 | x : |
|
357 | 357 | y : |
|
358 | 358 | xmin : |
|
359 | 359 | xmax : |
|
360 | 360 | ymin : |
|
361 | 361 | ymax : |
|
362 | 362 | xlabel : |
|
363 | 363 | ylabel : |
|
364 | 364 | title : |
|
365 | 365 | **kwargs : Los parametros aceptados son |
|
366 | 366 | |
|
367 | 367 | ticksize |
|
368 | 368 | ytick_visible |
|
369 | 369 | """ |
|
370 | 370 | |
|
371 | 371 | if self.__firsttime: |
|
372 | 372 | |
|
373 | 373 | if xmin == None: xmin = numpy.nanmin(x) |
|
374 | 374 | if xmax == None: xmax = numpy.nanmax(x) |
|
375 | 375 | if ymin == None: ymin = numpy.nanmin(y) |
|
376 | 376 | if ymax == None: ymax = numpy.nanmax(y) |
|
377 | 377 | |
|
378 | 378 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
379 | 379 | xmin, xmax, |
|
380 | 380 | ymin, ymax, |
|
381 | 381 | xlabel=xlabel, |
|
382 | 382 | ylabel=ylabel, |
|
383 | 383 | title=title, |
|
384 | 384 | **kwargs) |
|
385 | 385 | |
|
386 | 386 | self.idlineList.append(0) |
|
387 | 387 | self.__firsttime = False |
|
388 | 388 | return |
|
389 | 389 | |
|
390 | 390 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
391 | 391 | ylabel=ylabel, |
|
392 | 392 | title=title) |
|
393 | 393 | |
|
394 | 394 | # self.__driver.pause() |
|
395 | 395 | |
|
396 | 396 | def addpline(self, x, y, idline, **kwargs): |
|
397 | 397 | lines = self.ax.lines |
|
398 | 398 | |
|
399 | 399 | if idline in self.idlineList: |
|
400 | 400 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
401 | 401 | |
|
402 | 402 | if idline not in(self.idlineList): |
|
403 | 403 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
404 | 404 | self.idlineList.append(idline) |
|
405 | 405 | |
|
406 | 406 | return |
|
407 | 407 | |
|
408 | 408 | def pmultiline(self, x, y, |
|
409 | 409 | xmin=None, xmax=None, |
|
410 | 410 | ymin=None, ymax=None, |
|
411 | 411 | xlabel='', ylabel='', |
|
412 | 412 | title='', |
|
413 | 413 | **kwargs): |
|
414 | 414 | |
|
415 | 415 | if self.__firsttime: |
|
416 | 416 | |
|
417 | 417 | if xmin == None: xmin = numpy.nanmin(x) |
|
418 | 418 | if xmax == None: xmax = numpy.nanmax(x) |
|
419 | 419 | if ymin == None: ymin = numpy.nanmin(y) |
|
420 | 420 | if ymax == None: ymax = numpy.nanmax(y) |
|
421 | 421 | |
|
422 | 422 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
423 | 423 | xmin, xmax, |
|
424 | 424 | ymin, ymax, |
|
425 | 425 | xlabel=xlabel, |
|
426 | 426 | ylabel=ylabel, |
|
427 | 427 | title=title, |
|
428 | 428 | **kwargs) |
|
429 | 429 | self.__firsttime = False |
|
430 | 430 | return |
|
431 | 431 | |
|
432 | 432 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
433 | 433 | ylabel=ylabel, |
|
434 | 434 | title=title) |
|
435 | 435 | |
|
436 | 436 | # self.__driver.pause() |
|
437 | 437 | |
|
438 | 438 | def pmultilineyaxis(self, x, y, |
|
439 | 439 | xmin=None, xmax=None, |
|
440 | 440 | ymin=None, ymax=None, |
|
441 | 441 | xlabel='', ylabel='', |
|
442 | 442 | title='', |
|
443 | 443 | **kwargs): |
|
444 | 444 | |
|
445 | 445 | if self.__firsttime: |
|
446 | 446 | |
|
447 | 447 | if xmin == None: xmin = numpy.nanmin(x) |
|
448 | 448 | if xmax == None: xmax = numpy.nanmax(x) |
|
449 | 449 | if ymin == None: ymin = numpy.nanmin(y) |
|
450 | 450 | if ymax == None: ymax = numpy.nanmax(y) |
|
451 | 451 | |
|
452 | 452 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
453 | 453 | xmin, xmax, |
|
454 | 454 | ymin, ymax, |
|
455 | 455 | xlabel=xlabel, |
|
456 | 456 | ylabel=ylabel, |
|
457 | 457 | title=title, |
|
458 | 458 | **kwargs) |
|
459 | 459 | if self.xmin == None: self.xmin = xmin |
|
460 | 460 | if self.xmax == None: self.xmax = xmax |
|
461 | 461 | if self.ymin == None: self.ymin = ymin |
|
462 | 462 | if self.ymax == None: self.ymax = ymax |
|
463 | 463 | |
|
464 | 464 | self.__firsttime = False |
|
465 | 465 | return |
|
466 | 466 | |
|
467 | 467 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
468 | 468 | ylabel=ylabel, |
|
469 | 469 | title=title) |
|
470 | 470 | |
|
471 | 471 | # self.__driver.pause() |
|
472 | 472 | |
|
473 | 473 | def pcolor(self, x, y, z, |
|
474 | 474 | xmin=None, xmax=None, |
|
475 | 475 | ymin=None, ymax=None, |
|
476 | 476 | zmin=None, zmax=None, |
|
477 | 477 | xlabel='', ylabel='', |
|
478 | 478 | title='', colormap='jet', |
|
479 | 479 | **kwargs): |
|
480 | 480 | |
|
481 | 481 | """ |
|
482 | 482 | Input: |
|
483 | 483 | x : |
|
484 | 484 | y : |
|
485 | 485 | x : |
|
486 | 486 | xmin : |
|
487 | 487 | xmax : |
|
488 | 488 | ymin : |
|
489 | 489 | ymax : |
|
490 | 490 | zmin : |
|
491 | 491 | zmax : |
|
492 | 492 | xlabel : |
|
493 | 493 | ylabel : |
|
494 | 494 | title : |
|
495 | 495 | **kwargs : Los parametros aceptados son |
|
496 | 496 | ticksize=9, |
|
497 | 497 | cblabel='' |
|
498 | 498 | """ |
|
499 | 499 | |
|
500 | 500 | #Decimating data |
|
501 | 501 | xlen = len(x) |
|
502 | 502 | ylen = len(y) |
|
503 | 503 | |
|
504 | 504 | decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1 |
|
505 | 505 | decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
506 | 506 | |
|
507 | 507 | x_buffer = x[::decimationx] |
|
508 | 508 | y_buffer = y[::decimationy] |
|
509 | 509 | z_buffer = z[::decimationx, ::decimationy] |
|
510 | 510 | #=================================================== |
|
511 | 511 | |
|
512 | 512 | if self.__firsttime: |
|
513 | 513 | |
|
514 | 514 | if xmin == None: xmin = numpy.nanmin(x) |
|
515 | 515 | if xmax == None: xmax = numpy.nanmax(x) |
|
516 | 516 | if ymin == None: ymin = numpy.nanmin(y) |
|
517 | 517 | if ymax == None: ymax = numpy.nanmax(y) |
|
518 | 518 | if zmin == None: zmin = numpy.nanmin(z) |
|
519 | 519 | if zmax == None: zmax = numpy.nanmax(z) |
|
520 | 520 | |
|
521 | 521 | |
|
522 | 522 | self.plot = self.__driver.createPcolor(self.ax, x_buffer, |
|
523 | 523 | y_buffer, |
|
524 | 524 | z_buffer, |
|
525 | 525 | xmin, xmax, |
|
526 | 526 | ymin, ymax, |
|
527 | 527 | zmin, zmax, |
|
528 | 528 | xlabel=xlabel, |
|
529 | 529 | ylabel=ylabel, |
|
530 | 530 | title=title, |
|
531 | 531 | colormap=colormap, |
|
532 | 532 | **kwargs) |
|
533 | 533 | |
|
534 | 534 | if self.xmin == None: self.xmin = xmin |
|
535 | 535 | if self.xmax == None: self.xmax = xmax |
|
536 | 536 | if self.ymin == None: self.ymin = ymin |
|
537 | 537 | if self.ymax == None: self.ymax = ymax |
|
538 | 538 | if self.zmin == None: self.zmin = zmin |
|
539 | 539 | if self.zmax == None: self.zmax = zmax |
|
540 | 540 | |
|
541 | 541 | self.__firsttime = False |
|
542 | 542 | return |
|
543 | 543 | |
|
544 | 544 | self.__driver.pcolor(self.plot, |
|
545 | 545 | z_buffer, |
|
546 | 546 | xlabel=xlabel, |
|
547 | 547 | ylabel=ylabel, |
|
548 | 548 | title=title) |
|
549 | 549 | |
|
550 | 550 | # self.__driver.pause() |
|
551 | 551 | |
|
552 | 552 | def pcolorbuffer(self, x, y, z, |
|
553 | 553 | xmin=None, xmax=None, |
|
554 | 554 | ymin=None, ymax=None, |
|
555 | 555 | zmin=None, zmax=None, |
|
556 | 556 | xlabel='', ylabel='', |
|
557 | 557 | title='', rti = True, colormap='jet', |
|
558 | 558 | maxNumX = None, maxNumY = None, |
|
559 | 559 | **kwargs): |
|
560 | 560 | |
|
561 | 561 | if maxNumX == None: |
|
562 | 562 | maxNumX = self.__MAXNUMTIME |
|
563 | 563 | |
|
564 | 564 | if maxNumY == None: |
|
565 | 565 | maxNumY = self.__MAXNUMY |
|
566 | 566 | |
|
567 | 567 | if self.__firsttime: |
|
568 | 568 | self.z_buffer = z |
|
569 | 569 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
570 | 570 | |
|
571 | 571 | if xmin == None: xmin = numpy.nanmin(x) |
|
572 | 572 | if xmax == None: xmax = numpy.nanmax(x) |
|
573 | 573 | if ymin == None: ymin = numpy.nanmin(y) |
|
574 | 574 | if ymax == None: ymax = numpy.nanmax(y) |
|
575 | 575 | if zmin == None: zmin = numpy.nanmin(z) |
|
576 | 576 | if zmax == None: zmax = numpy.nanmax(z) |
|
577 | 577 | |
|
578 | 578 | |
|
579 | 579 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
580 | 580 | xmin, xmax, |
|
581 | 581 | ymin, ymax, |
|
582 | 582 | zmin, zmax, |
|
583 | 583 | xlabel=xlabel, |
|
584 | 584 | ylabel=ylabel, |
|
585 | 585 | title=title, |
|
586 | 586 | colormap=colormap, |
|
587 | 587 | **kwargs) |
|
588 | 588 | |
|
589 | 589 | if self.xmin == None: self.xmin = xmin |
|
590 | 590 | if self.xmax == None: self.xmax = xmax |
|
591 | 591 | if self.ymin == None: self.ymin = ymin |
|
592 | 592 | if self.ymax == None: self.ymax = ymax |
|
593 | 593 | if self.zmin == None: self.zmin = zmin |
|
594 | 594 | if self.zmax == None: self.zmax = zmax |
|
595 | 595 | |
|
596 | 596 | self.__firsttime = False |
|
597 | 597 | return |
|
598 | 598 | |
|
599 | 599 | self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1])) |
|
600 | 600 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
601 | 601 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
602 | 602 | |
|
603 | 603 | #Decimating data |
|
604 | 604 | xlen = len(self.x_buffer) |
|
605 | 605 | ylen = len(y) |
|
606 | 606 | |
|
607 | 607 | decimationx = numpy.floor(xlen/maxNumX) + 1 |
|
608 | 608 | decimationy = numpy.floor(ylen/maxNumY) + 1 |
|
609 | 609 | |
|
610 | 610 | x_buffer = self.x_buffer[::decimationx] |
|
611 | 611 | y_buffer = y[::decimationy] |
|
612 | 612 | z_buffer = z_buffer[::decimationx, ::decimationy] |
|
613 | 613 | #=================================================== |
|
614 | 614 | |
|
615 | 615 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
616 | 616 | |
|
617 | 617 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
618 | 618 | xlabel=xlabel, |
|
619 | 619 | ylabel=ylabel, |
|
620 | 620 | title=title, |
|
621 | 621 | colormap=colormap) |
|
622 | 622 | |
|
623 | 623 | # self.__driver.pause() |
|
624 | 624 | |
|
625 | 625 | def polar(self, x, y, |
|
626 | 626 | title='', xlabel='',ylabel='',**kwargs): |
|
627 | 627 | |
|
628 | 628 | if self.__firsttime: |
|
629 | 629 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) |
|
630 | 630 | self.__firsttime = False |
|
631 | 631 | self.x_buffer = x |
|
632 | 632 | self.y_buffer = y |
|
633 | 633 | return |
|
634 | 634 | |
|
635 | 635 | self.x_buffer = numpy.hstack((self.x_buffer,x)) |
|
636 | 636 | self.y_buffer = numpy.hstack((self.y_buffer,y)) |
|
637 | 637 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, |
|
638 | 638 | ylabel=ylabel, |
|
639 | 639 | title=title) |
|
640 | 640 | |
|
641 | 641 | # self.__driver.pause() |
|
642 | 642 | |
|
643 | 643 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
644 | 644 | |
|
645 | 645 | if x_buffer.shape[0] < 2: |
|
646 | 646 | return x_buffer, y_buffer, z_buffer |
|
647 | 647 | |
|
648 | 648 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
649 | 649 | x_median = numpy.median(deltas) |
|
650 | 650 | |
|
651 | 651 | index = numpy.where(deltas > 5*x_median) |
|
652 | 652 | |
|
653 | 653 | if len(index[0]) != 0: |
|
654 | 654 | z_buffer[index[0],::] = self.__missing |
|
655 | 655 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
656 | 656 | |
|
657 | 657 | return x_buffer, y_buffer, z_buffer |
|
658 | 658 | |
|
659 | 659 | |
|
660 | 660 | |
|
661 | 661 | No newline at end of file |
@@ -1,1509 +1,1522 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from figure import Figure, isRealtime, isTimeInHourRange |
|
11 | 11 | from plotting_codes import * |
|
12 | 12 | |
|
13 | 13 | class SpectraPlot(Figure): |
|
14 | 14 | |
|
15 | 15 | isConfig = None |
|
16 | 16 | __nsubplots = None |
|
17 | 17 | |
|
18 | 18 | WIDTHPROF = None |
|
19 | 19 | HEIGHTPROF = None |
|
20 | 20 | PREFIX = 'spc' |
|
21 | 21 | |
|
22 | 22 | def __init__(self): |
|
23 | 23 | |
|
24 | 24 | self.isConfig = False |
|
25 | 25 | self.__nsubplots = 1 |
|
26 | 26 | |
|
27 | 27 | self.WIDTH = 250 |
|
28 | 28 | self.HEIGHT = 250 |
|
29 | 29 | self.WIDTHPROF = 120 |
|
30 | 30 | self.HEIGHTPROF = 0 |
|
31 | 31 | self.counter_imagwr = 0 |
|
32 | 32 | |
|
33 | 33 | self.PLOT_CODE = SPEC_CODE |
|
34 | 34 | |
|
35 | 35 | self.FTP_WEI = None |
|
36 | 36 | self.EXP_CODE = None |
|
37 | 37 | self.SUB_EXP_CODE = None |
|
38 | 38 | self.PLOT_POS = None |
|
39 | 39 | |
|
40 | 40 | self.__xfilter_ena = False |
|
41 | 41 | self.__yfilter_ena = False |
|
42 | 42 | |
|
43 | 43 | def getSubplots(self): |
|
44 | 44 | |
|
45 | 45 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
46 | 46 | nrow = int(self.nplots*1./ncol + 0.9) |
|
47 | 47 | |
|
48 | 48 | return nrow, ncol |
|
49 | 49 | |
|
50 | 50 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
51 | 51 | |
|
52 | 52 | self.__showprofile = showprofile |
|
53 | 53 | self.nplots = nplots |
|
54 | 54 | |
|
55 | 55 | ncolspan = 1 |
|
56 | 56 | colspan = 1 |
|
57 | 57 | if showprofile: |
|
58 | 58 | ncolspan = 3 |
|
59 | 59 | colspan = 2 |
|
60 | 60 | self.__nsubplots = 2 |
|
61 | 61 | |
|
62 | 62 | self.createFigure(id = id, |
|
63 | 63 | wintitle = wintitle, |
|
64 | 64 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
65 | 65 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
66 | 66 | show=show) |
|
67 | 67 | |
|
68 | 68 | nrow, ncol = self.getSubplots() |
|
69 | 69 | |
|
70 | 70 | counter = 0 |
|
71 | 71 | for y in range(nrow): |
|
72 | 72 | for x in range(ncol): |
|
73 | 73 | |
|
74 | 74 | if counter >= self.nplots: |
|
75 | 75 | break |
|
76 | 76 | |
|
77 | 77 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
78 | 78 | |
|
79 | 79 | if showprofile: |
|
80 | 80 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
81 | 81 | |
|
82 | 82 | counter += 1 |
|
83 | 83 | |
|
84 | 84 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
85 | 85 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
86 | 86 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
87 | 87 | server=None, folder=None, username=None, password=None, |
|
88 | 88 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
89 |
xaxis=" |
|
|
89 | xaxis="frequency"): | |
|
90 | 90 | |
|
91 | 91 | """ |
|
92 | 92 | |
|
93 | 93 | Input: |
|
94 | 94 | dataOut : |
|
95 | 95 | id : |
|
96 | 96 | wintitle : |
|
97 | 97 | channelList : |
|
98 | 98 | showProfile : |
|
99 | 99 | xmin : None, |
|
100 | 100 | xmax : None, |
|
101 | 101 | ymin : None, |
|
102 | 102 | ymax : None, |
|
103 | 103 | zmin : None, |
|
104 | 104 | zmax : None |
|
105 | 105 | """ |
|
106 | 106 | |
|
107 | 107 | if realtime: |
|
108 | 108 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
109 | 109 | print 'Skipping this plot function' |
|
110 | 110 | return |
|
111 | 111 | |
|
112 | 112 | if channelList == None: |
|
113 | 113 | channelIndexList = dataOut.channelIndexList |
|
114 | 114 | else: |
|
115 | 115 | channelIndexList = [] |
|
116 | 116 | for channel in channelList: |
|
117 | 117 | if channel not in dataOut.channelList: |
|
118 | 118 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel |
|
119 | 119 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
120 | 120 | |
|
121 | 121 | factor = dataOut.normFactor |
|
122 | 122 | |
|
123 | 123 | if xaxis == "frequency": |
|
124 | 124 | x = dataOut.getFreqRange(1)/1000. |
|
125 | xlabel = "Frquency (kHz)" | |
|
125 | xlabel = "Frequency (kHz)" | |
|
126 | 126 | |
|
127 | 127 | elif xaxis == "time": |
|
128 | 128 | x = dataOut.getAcfRange(1) |
|
129 | 129 | xlabel = "Time (ms)" |
|
130 | 130 | |
|
131 | 131 | else: |
|
132 | 132 | x = dataOut.getVelRange(1) |
|
133 | 133 | xlabel = "Velocity (m/s)" |
|
134 | 134 | |
|
135 | 135 | ylabel = "Range (Km)" |
|
136 | 136 | |
|
137 | 137 | y = dataOut.getHeiRange() |
|
138 | 138 | |
|
139 | 139 | z = dataOut.data_spc/factor |
|
140 | 140 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
141 | 141 | zdB = 10*numpy.log10(z) |
|
142 | 142 | |
|
143 | 143 | avg = numpy.average(z, axis=1) |
|
144 | 144 | avgdB = 10*numpy.log10(avg) |
|
145 | 145 | |
|
146 | 146 | noise = dataOut.getNoise()/factor |
|
147 | 147 | noisedB = 10*numpy.log10(noise) |
|
148 | 148 | |
|
149 | 149 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
150 | 150 | title = wintitle + " Spectra" |
|
151 | 151 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
152 | 152 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
153 | 153 | |
|
154 | 154 | if not self.isConfig: |
|
155 | 155 | |
|
156 | 156 | nplots = len(channelIndexList) |
|
157 | 157 | |
|
158 | 158 | self.setup(id=id, |
|
159 | 159 | nplots=nplots, |
|
160 | 160 | wintitle=wintitle, |
|
161 | 161 | showprofile=showprofile, |
|
162 | 162 | show=show) |
|
163 | 163 | |
|
164 | 164 | if xmin == None: xmin = numpy.nanmin(x) |
|
165 | 165 | if xmax == None: xmax = numpy.nanmax(x) |
|
166 | 166 | if ymin == None: ymin = numpy.nanmin(y) |
|
167 | 167 | if ymax == None: ymax = numpy.nanmax(y) |
|
168 | 168 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
169 | 169 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
170 | 170 | |
|
171 | 171 | self.FTP_WEI = ftp_wei |
|
172 | 172 | self.EXP_CODE = exp_code |
|
173 | 173 | self.SUB_EXP_CODE = sub_exp_code |
|
174 | 174 | self.PLOT_POS = plot_pos |
|
175 | 175 | |
|
176 | 176 | self.isConfig = True |
|
177 | 177 | |
|
178 | 178 | self.setWinTitle(title) |
|
179 | 179 | |
|
180 | 180 | for i in range(self.nplots): |
|
181 | 181 | index = channelIndexList[i] |
|
182 | 182 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
183 | 183 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
184 | 184 | if len(dataOut.beam.codeList) != 0: |
|
185 | 185 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
186 | 186 | |
|
187 | 187 | axes = self.axesList[i*self.__nsubplots] |
|
188 | 188 | axes.pcolor(x, y, zdB[index,:,:], |
|
189 | 189 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
190 | 190 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
191 | 191 | ticksize=9, cblabel='') |
|
192 | 192 | |
|
193 | 193 | if self.__showprofile: |
|
194 | 194 | axes = self.axesList[i*self.__nsubplots +1] |
|
195 | 195 | axes.pline(avgdB[index,:], y, |
|
196 | 196 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
197 | 197 | xlabel='dB', ylabel='', title='', |
|
198 | 198 | ytick_visible=False, |
|
199 | 199 | grid='x') |
|
200 | 200 | |
|
201 | 201 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
202 | 202 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
203 | 203 | |
|
204 | 204 | self.draw() |
|
205 | 205 | |
|
206 | 206 | if figfile == None: |
|
207 | 207 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
208 | 208 | name = str_datetime |
|
209 | 209 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
210 | 210 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
211 | 211 | figfile = self.getFilename(name) |
|
212 | 212 | |
|
213 | 213 | self.save(figpath=figpath, |
|
214 | 214 | figfile=figfile, |
|
215 | 215 | save=save, |
|
216 | 216 | ftp=ftp, |
|
217 | 217 | wr_period=wr_period, |
|
218 | 218 | thisDatetime=thisDatetime) |
|
219 | 219 | |
|
220 | 220 | class CrossSpectraPlot(Figure): |
|
221 | 221 | |
|
222 | 222 | isConfig = None |
|
223 | 223 | __nsubplots = None |
|
224 | 224 | |
|
225 | 225 | WIDTH = None |
|
226 | 226 | HEIGHT = None |
|
227 | 227 | WIDTHPROF = None |
|
228 | 228 | HEIGHTPROF = None |
|
229 | 229 | PREFIX = 'cspc' |
|
230 | 230 | |
|
231 | 231 | def __init__(self): |
|
232 | 232 | |
|
233 | 233 | self.isConfig = False |
|
234 | 234 | self.__nsubplots = 4 |
|
235 | 235 | self.counter_imagwr = 0 |
|
236 | 236 | self.WIDTH = 250 |
|
237 | 237 | self.HEIGHT = 250 |
|
238 | 238 | self.WIDTHPROF = 0 |
|
239 | 239 | self.HEIGHTPROF = 0 |
|
240 | 240 | |
|
241 | 241 | self.PLOT_CODE = CROSS_CODE |
|
242 | 242 | self.FTP_WEI = None |
|
243 | 243 | self.EXP_CODE = None |
|
244 | 244 | self.SUB_EXP_CODE = None |
|
245 | 245 | self.PLOT_POS = None |
|
246 | 246 | |
|
247 | 247 | def getSubplots(self): |
|
248 | 248 | |
|
249 | 249 | ncol = 4 |
|
250 | 250 | nrow = self.nplots |
|
251 | 251 | |
|
252 | 252 | return nrow, ncol |
|
253 | 253 | |
|
254 | 254 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
255 | 255 | |
|
256 | 256 | self.__showprofile = showprofile |
|
257 | 257 | self.nplots = nplots |
|
258 | 258 | |
|
259 | 259 | ncolspan = 1 |
|
260 | 260 | colspan = 1 |
|
261 | 261 | |
|
262 | 262 | self.createFigure(id = id, |
|
263 | 263 | wintitle = wintitle, |
|
264 | 264 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
265 | 265 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
266 | 266 | show=True) |
|
267 | 267 | |
|
268 | 268 | nrow, ncol = self.getSubplots() |
|
269 | 269 | |
|
270 | 270 | counter = 0 |
|
271 | 271 | for y in range(nrow): |
|
272 | 272 | for x in range(ncol): |
|
273 | 273 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
274 | 274 | |
|
275 | 275 | counter += 1 |
|
276 | 276 | |
|
277 | 277 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
278 | 278 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
279 | 279 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
280 | 280 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
281 | 281 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
282 | 282 | server=None, folder=None, username=None, password=None, |
|
283 |
ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0 |
|
|
283 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, | |
|
284 | xaxis='frequency'): | |
|
284 | 285 | |
|
285 | 286 | """ |
|
286 | 287 | |
|
287 | 288 | Input: |
|
288 | 289 | dataOut : |
|
289 | 290 | id : |
|
290 | 291 | wintitle : |
|
291 | 292 | channelList : |
|
292 | 293 | showProfile : |
|
293 | 294 | xmin : None, |
|
294 | 295 | xmax : None, |
|
295 | 296 | ymin : None, |
|
296 | 297 | ymax : None, |
|
297 | 298 | zmin : None, |
|
298 | 299 | zmax : None |
|
299 | 300 | """ |
|
300 | 301 | |
|
301 | 302 | if pairsList == None: |
|
302 | 303 | pairsIndexList = dataOut.pairsIndexList |
|
303 | 304 | else: |
|
304 | 305 | pairsIndexList = [] |
|
305 | 306 | for pair in pairsList: |
|
306 | 307 | if pair not in dataOut.pairsList: |
|
307 | 308 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
308 | 309 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
309 | 310 | |
|
310 | 311 | if not pairsIndexList: |
|
311 | 312 | return |
|
312 | 313 | |
|
313 | 314 | if len(pairsIndexList) > 4: |
|
314 | 315 | pairsIndexList = pairsIndexList[0:4] |
|
315 | 316 | |
|
316 | 317 | factor = dataOut.normFactor |
|
317 | 318 | x = dataOut.getVelRange(1) |
|
318 | 319 | y = dataOut.getHeiRange() |
|
319 | 320 | z = dataOut.data_spc[:,:,:]/factor |
|
320 | 321 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
321 | 322 | |
|
322 | 323 | noise = dataOut.noise/factor |
|
323 | 324 | |
|
324 | 325 | zdB = 10*numpy.log10(z) |
|
325 | 326 | noisedB = 10*numpy.log10(noise) |
|
326 | 327 | |
|
327 | 328 | if coh_min == None: |
|
328 | 329 | coh_min = 0.0 |
|
329 | 330 | if coh_max == None: |
|
330 | 331 | coh_max = 1.0 |
|
331 | 332 | |
|
332 | 333 | if phase_min == None: |
|
333 | 334 | phase_min = -180 |
|
334 | 335 | if phase_max == None: |
|
335 | 336 | phase_max = 180 |
|
336 | 337 | |
|
337 | 338 | #thisDatetime = dataOut.datatime |
|
338 | 339 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
339 | 340 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
340 | xlabel = "Velocity (m/s)" | |
|
341 | # xlabel = "Velocity (m/s)" | |
|
341 | 342 | ylabel = "Range (Km)" |
|
342 | 343 | |
|
344 | if xaxis == "frequency": | |
|
345 | x = dataOut.getFreqRange(1)/1000. | |
|
346 | xlabel = "Frequency (kHz)" | |
|
347 | ||
|
348 | elif xaxis == "time": | |
|
349 | x = dataOut.getAcfRange(1) | |
|
350 | xlabel = "Time (ms)" | |
|
351 | ||
|
352 | else: | |
|
353 | x = dataOut.getVelRange(1) | |
|
354 | xlabel = "Velocity (m/s)" | |
|
355 | ||
|
343 | 356 | if not self.isConfig: |
|
344 | 357 | |
|
345 | 358 | nplots = len(pairsIndexList) |
|
346 | 359 | |
|
347 | 360 | self.setup(id=id, |
|
348 | 361 | nplots=nplots, |
|
349 | 362 | wintitle=wintitle, |
|
350 | 363 | showprofile=False, |
|
351 | 364 | show=show) |
|
352 | 365 | |
|
353 | 366 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
354 | 367 | avgdB = 10*numpy.log10(avg) |
|
355 | 368 | |
|
356 | 369 | if xmin == None: xmin = numpy.nanmin(x) |
|
357 | 370 | if xmax == None: xmax = numpy.nanmax(x) |
|
358 | 371 | if ymin == None: ymin = numpy.nanmin(y) |
|
359 | 372 | if ymax == None: ymax = numpy.nanmax(y) |
|
360 | 373 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
361 | 374 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
362 | 375 | |
|
363 | 376 | self.FTP_WEI = ftp_wei |
|
364 | 377 | self.EXP_CODE = exp_code |
|
365 | 378 | self.SUB_EXP_CODE = sub_exp_code |
|
366 | 379 | self.PLOT_POS = plot_pos |
|
367 | 380 | |
|
368 | 381 | self.isConfig = True |
|
369 | 382 | |
|
370 | 383 | self.setWinTitle(title) |
|
371 | 384 | |
|
372 | 385 | for i in range(self.nplots): |
|
373 | 386 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
374 | 387 | |
|
375 | 388 | chan_index0 = dataOut.channelList.index(pair[0]) |
|
376 | 389 | chan_index1 = dataOut.channelList.index(pair[1]) |
|
377 | 390 | |
|
378 | 391 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
379 | 392 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) |
|
380 | 393 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) |
|
381 | 394 | axes0 = self.axesList[i*self.__nsubplots] |
|
382 | 395 | axes0.pcolor(x, y, zdB, |
|
383 | 396 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
384 | 397 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
385 | 398 | ticksize=9, colormap=power_cmap, cblabel='') |
|
386 | 399 | |
|
387 | 400 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) |
|
388 | 401 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) |
|
389 | 402 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
390 | 403 | axes0.pcolor(x, y, zdB, |
|
391 | 404 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
392 | 405 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
393 | 406 | ticksize=9, colormap=power_cmap, cblabel='') |
|
394 | 407 | |
|
395 | 408 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) |
|
396 | 409 | coherence = numpy.abs(coherenceComplex) |
|
397 | 410 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
398 | 411 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
399 | 412 | |
|
400 | 413 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
401 | 414 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
402 | 415 | axes0.pcolor(x, y, coherence, |
|
403 | 416 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
404 | 417 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
405 | 418 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
406 | 419 | |
|
407 | 420 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
408 | 421 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
409 | 422 | axes0.pcolor(x, y, phase, |
|
410 | 423 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
411 | 424 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
412 | 425 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
413 | 426 | |
|
414 | 427 | |
|
415 | 428 | |
|
416 | 429 | self.draw() |
|
417 | 430 | |
|
418 | 431 | self.save(figpath=figpath, |
|
419 | 432 | figfile=figfile, |
|
420 | 433 | save=save, |
|
421 | 434 | ftp=ftp, |
|
422 | 435 | wr_period=wr_period, |
|
423 | 436 | thisDatetime=thisDatetime) |
|
424 | 437 | |
|
425 | 438 | |
|
426 | 439 | class RTIPlot(Figure): |
|
427 | 440 | |
|
428 | 441 | __isConfig = None |
|
429 | 442 | __nsubplots = None |
|
430 | 443 | |
|
431 | 444 | WIDTHPROF = None |
|
432 | 445 | HEIGHTPROF = None |
|
433 | 446 | PREFIX = 'rti' |
|
434 | 447 | |
|
435 | 448 | def __init__(self): |
|
436 | 449 | |
|
437 | 450 | self.timerange = None |
|
438 | 451 | self.isConfig = False |
|
439 | 452 | self.__nsubplots = 1 |
|
440 | 453 | |
|
441 | 454 | self.WIDTH = 800 |
|
442 | 455 | self.HEIGHT = 180 |
|
443 | 456 | self.WIDTHPROF = 120 |
|
444 | 457 | self.HEIGHTPROF = 0 |
|
445 | 458 | self.counter_imagwr = 0 |
|
446 | 459 | |
|
447 | 460 | self.PLOT_CODE = RTI_CODE |
|
448 | 461 | |
|
449 | 462 | self.FTP_WEI = None |
|
450 | 463 | self.EXP_CODE = None |
|
451 | 464 | self.SUB_EXP_CODE = None |
|
452 | 465 | self.PLOT_POS = None |
|
453 | 466 | self.tmin = None |
|
454 | 467 | self.tmax = None |
|
455 | 468 | |
|
456 | 469 | self.xmin = None |
|
457 | 470 | self.xmax = None |
|
458 | 471 | |
|
459 | 472 | self.figfile = None |
|
460 | 473 | |
|
461 | 474 | def getSubplots(self): |
|
462 | 475 | |
|
463 | 476 | ncol = 1 |
|
464 | 477 | nrow = self.nplots |
|
465 | 478 | |
|
466 | 479 | return nrow, ncol |
|
467 | 480 | |
|
468 | 481 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
469 | 482 | |
|
470 | 483 | self.__showprofile = showprofile |
|
471 | 484 | self.nplots = nplots |
|
472 | 485 | |
|
473 | 486 | ncolspan = 1 |
|
474 | 487 | colspan = 1 |
|
475 | 488 | if showprofile: |
|
476 | 489 | ncolspan = 7 |
|
477 | 490 | colspan = 6 |
|
478 | 491 | self.__nsubplots = 2 |
|
479 | 492 | |
|
480 | 493 | self.createFigure(id = id, |
|
481 | 494 | wintitle = wintitle, |
|
482 | 495 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
483 | 496 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
484 | 497 | show=show) |
|
485 | 498 | |
|
486 | 499 | nrow, ncol = self.getSubplots() |
|
487 | 500 | |
|
488 | 501 | counter = 0 |
|
489 | 502 | for y in range(nrow): |
|
490 | 503 | for x in range(ncol): |
|
491 | 504 | |
|
492 | 505 | if counter >= self.nplots: |
|
493 | 506 | break |
|
494 | 507 | |
|
495 | 508 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
496 | 509 | |
|
497 | 510 | if showprofile: |
|
498 | 511 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
499 | 512 | |
|
500 | 513 | counter += 1 |
|
501 | 514 | |
|
502 | 515 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
503 | 516 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
504 | 517 | timerange=None, |
|
505 | 518 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
506 | 519 | server=None, folder=None, username=None, password=None, |
|
507 | 520 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
508 | 521 | |
|
509 | 522 | """ |
|
510 | 523 | |
|
511 | 524 | Input: |
|
512 | 525 | dataOut : |
|
513 | 526 | id : |
|
514 | 527 | wintitle : |
|
515 | 528 | channelList : |
|
516 | 529 | showProfile : |
|
517 | 530 | xmin : None, |
|
518 | 531 | xmax : None, |
|
519 | 532 | ymin : None, |
|
520 | 533 | ymax : None, |
|
521 | 534 | zmin : None, |
|
522 | 535 | zmax : None |
|
523 | 536 | """ |
|
524 | 537 | |
|
525 | 538 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
526 | 539 | return |
|
527 | 540 | |
|
528 | 541 | if channelList == None: |
|
529 | 542 | channelIndexList = dataOut.channelIndexList |
|
530 | 543 | else: |
|
531 | 544 | channelIndexList = [] |
|
532 | 545 | for channel in channelList: |
|
533 | 546 | if channel not in dataOut.channelList: |
|
534 | 547 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
535 | 548 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
536 | 549 | |
|
537 | 550 | factor = dataOut.normFactor |
|
538 | 551 | x = dataOut.getTimeRange() |
|
539 | 552 | y = dataOut.getHeiRange() |
|
540 | 553 | |
|
541 | 554 | z = dataOut.data_spc/factor |
|
542 | 555 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
543 | 556 | avg = numpy.average(z, axis=1) |
|
544 | 557 | |
|
545 | 558 | avgdB = 10.*numpy.log10(avg) |
|
546 | 559 | |
|
547 | 560 | thisDatetime = dataOut.datatime |
|
548 | 561 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
549 | 562 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
550 | 563 | xlabel = "" |
|
551 | 564 | ylabel = "Range (Km)" |
|
552 | 565 | |
|
553 | 566 | update_figfile = False |
|
554 | 567 | |
|
555 | 568 | if dataOut.ltctime >= self.xmax: |
|
556 | 569 | self.counter_imagwr = wr_period |
|
557 | 570 | self.isConfig = False |
|
558 | 571 | update_figfile = True |
|
559 | 572 | |
|
560 | 573 | if not self.isConfig: |
|
561 | 574 | |
|
562 | 575 | nplots = len(channelIndexList) |
|
563 | 576 | |
|
564 | 577 | self.setup(id=id, |
|
565 | 578 | nplots=nplots, |
|
566 | 579 | wintitle=wintitle, |
|
567 | 580 | showprofile=showprofile, |
|
568 | 581 | show=show) |
|
569 | 582 | |
|
570 | 583 | if timerange != None: |
|
571 | 584 | self.timerange = timerange |
|
572 | 585 | |
|
573 | 586 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
574 | 587 | |
|
575 | 588 | noise = dataOut.noise/factor |
|
576 | 589 | noisedB = 10*numpy.log10(noise) |
|
577 | 590 | |
|
578 | 591 | if ymin == None: ymin = numpy.nanmin(y) |
|
579 | 592 | if ymax == None: ymax = numpy.nanmax(y) |
|
580 | 593 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
581 | 594 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
582 | 595 | |
|
583 | 596 | self.FTP_WEI = ftp_wei |
|
584 | 597 | self.EXP_CODE = exp_code |
|
585 | 598 | self.SUB_EXP_CODE = sub_exp_code |
|
586 | 599 | self.PLOT_POS = plot_pos |
|
587 | 600 | |
|
588 | 601 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
589 | 602 | self.isConfig = True |
|
590 | 603 | self.figfile = figfile |
|
591 | 604 | update_figfile = True |
|
592 | 605 | |
|
593 | 606 | self.setWinTitle(title) |
|
594 | 607 | |
|
595 | 608 | for i in range(self.nplots): |
|
596 | 609 | index = channelIndexList[i] |
|
597 | 610 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
598 | 611 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
599 | 612 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
600 | 613 | axes = self.axesList[i*self.__nsubplots] |
|
601 | 614 | zdB = avgdB[index].reshape((1,-1)) |
|
602 | 615 | axes.pcolorbuffer(x, y, zdB, |
|
603 | 616 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
604 | 617 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
605 | 618 | ticksize=9, cblabel='', cbsize="1%") |
|
606 | 619 | |
|
607 | 620 | if self.__showprofile: |
|
608 | 621 | axes = self.axesList[i*self.__nsubplots +1] |
|
609 | 622 | axes.pline(avgdB[index], y, |
|
610 | 623 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
611 | 624 | xlabel='dB', ylabel='', title='', |
|
612 | 625 | ytick_visible=False, |
|
613 | 626 | grid='x') |
|
614 | 627 | |
|
615 | 628 | self.draw() |
|
616 | 629 | |
|
617 | 630 | self.save(figpath=figpath, |
|
618 | 631 | figfile=figfile, |
|
619 | 632 | save=save, |
|
620 | 633 | ftp=ftp, |
|
621 | 634 | wr_period=wr_period, |
|
622 | 635 | thisDatetime=thisDatetime, |
|
623 | 636 | update_figfile=update_figfile) |
|
624 | 637 | |
|
625 | 638 | class CoherenceMap(Figure): |
|
626 | 639 | isConfig = None |
|
627 | 640 | __nsubplots = None |
|
628 | 641 | |
|
629 | 642 | WIDTHPROF = None |
|
630 | 643 | HEIGHTPROF = None |
|
631 | 644 | PREFIX = 'cmap' |
|
632 | 645 | |
|
633 | 646 | def __init__(self): |
|
634 | 647 | self.timerange = 2*60*60 |
|
635 | 648 | self.isConfig = False |
|
636 | 649 | self.__nsubplots = 1 |
|
637 | 650 | |
|
638 | 651 | self.WIDTH = 800 |
|
639 | 652 | self.HEIGHT = 180 |
|
640 | 653 | self.WIDTHPROF = 120 |
|
641 | 654 | self.HEIGHTPROF = 0 |
|
642 | 655 | self.counter_imagwr = 0 |
|
643 | 656 | |
|
644 | 657 | self.PLOT_CODE = COH_CODE |
|
645 | 658 | |
|
646 | 659 | self.FTP_WEI = None |
|
647 | 660 | self.EXP_CODE = None |
|
648 | 661 | self.SUB_EXP_CODE = None |
|
649 | 662 | self.PLOT_POS = None |
|
650 | 663 | self.counter_imagwr = 0 |
|
651 | 664 | |
|
652 | 665 | self.xmin = None |
|
653 | 666 | self.xmax = None |
|
654 | 667 | |
|
655 | 668 | def getSubplots(self): |
|
656 | 669 | ncol = 1 |
|
657 | 670 | nrow = self.nplots*2 |
|
658 | 671 | |
|
659 | 672 | return nrow, ncol |
|
660 | 673 | |
|
661 | 674 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
662 | 675 | self.__showprofile = showprofile |
|
663 | 676 | self.nplots = nplots |
|
664 | 677 | |
|
665 | 678 | ncolspan = 1 |
|
666 | 679 | colspan = 1 |
|
667 | 680 | if showprofile: |
|
668 | 681 | ncolspan = 7 |
|
669 | 682 | colspan = 6 |
|
670 | 683 | self.__nsubplots = 2 |
|
671 | 684 | |
|
672 | 685 | self.createFigure(id = id, |
|
673 | 686 | wintitle = wintitle, |
|
674 | 687 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
675 | 688 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
676 | 689 | show=True) |
|
677 | 690 | |
|
678 | 691 | nrow, ncol = self.getSubplots() |
|
679 | 692 | |
|
680 | 693 | for y in range(nrow): |
|
681 | 694 | for x in range(ncol): |
|
682 | 695 | |
|
683 | 696 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
684 | 697 | |
|
685 | 698 | if showprofile: |
|
686 | 699 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
687 | 700 | |
|
688 | 701 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
689 | 702 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
690 | 703 | timerange=None, phase_min=None, phase_max=None, |
|
691 | 704 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
692 | 705 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
693 | 706 | server=None, folder=None, username=None, password=None, |
|
694 | 707 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
695 | 708 | |
|
696 | 709 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
697 | 710 | return |
|
698 | 711 | |
|
699 | 712 | if pairsList == None: |
|
700 | 713 | pairsIndexList = dataOut.pairsIndexList |
|
701 | 714 | else: |
|
702 | 715 | pairsIndexList = [] |
|
703 | 716 | for pair in pairsList: |
|
704 | 717 | if pair not in dataOut.pairsList: |
|
705 | 718 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
706 | 719 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
707 | 720 | |
|
708 | 721 | if pairsIndexList == []: |
|
709 | 722 | return |
|
710 | 723 | |
|
711 | 724 | if len(pairsIndexList) > 4: |
|
712 | 725 | pairsIndexList = pairsIndexList[0:4] |
|
713 | 726 | |
|
714 | 727 | if phase_min == None: |
|
715 | 728 | phase_min = -180 |
|
716 | 729 | if phase_max == None: |
|
717 | 730 | phase_max = 180 |
|
718 | 731 | |
|
719 | 732 | x = dataOut.getTimeRange() |
|
720 | 733 | y = dataOut.getHeiRange() |
|
721 | 734 | |
|
722 | 735 | thisDatetime = dataOut.datatime |
|
723 | 736 | |
|
724 | 737 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
725 | 738 | xlabel = "" |
|
726 | 739 | ylabel = "Range (Km)" |
|
727 | 740 | update_figfile = False |
|
728 | 741 | |
|
729 | 742 | if not self.isConfig: |
|
730 | 743 | nplots = len(pairsIndexList) |
|
731 | 744 | self.setup(id=id, |
|
732 | 745 | nplots=nplots, |
|
733 | 746 | wintitle=wintitle, |
|
734 | 747 | showprofile=showprofile, |
|
735 | 748 | show=show) |
|
736 | 749 | |
|
737 | 750 | if timerange != None: |
|
738 | 751 | self.timerange = timerange |
|
739 | 752 | |
|
740 | 753 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
741 | 754 | |
|
742 | 755 | if ymin == None: ymin = numpy.nanmin(y) |
|
743 | 756 | if ymax == None: ymax = numpy.nanmax(y) |
|
744 | 757 | if zmin == None: zmin = 0. |
|
745 | 758 | if zmax == None: zmax = 1. |
|
746 | 759 | |
|
747 | 760 | self.FTP_WEI = ftp_wei |
|
748 | 761 | self.EXP_CODE = exp_code |
|
749 | 762 | self.SUB_EXP_CODE = sub_exp_code |
|
750 | 763 | self.PLOT_POS = plot_pos |
|
751 | 764 | |
|
752 | 765 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
753 | 766 | |
|
754 | 767 | self.isConfig = True |
|
755 | 768 | update_figfile = True |
|
756 | 769 | |
|
757 | 770 | self.setWinTitle(title) |
|
758 | 771 | |
|
759 | 772 | for i in range(self.nplots): |
|
760 | 773 | |
|
761 | 774 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
762 | 775 | |
|
763 | 776 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
764 | 777 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
765 | 778 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
766 | 779 | |
|
767 | 780 | |
|
768 | 781 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
769 | 782 | coherence = numpy.abs(avgcoherenceComplex) |
|
770 | 783 | |
|
771 | 784 | z = coherence.reshape((1,-1)) |
|
772 | 785 | |
|
773 | 786 | counter = 0 |
|
774 | 787 | |
|
775 | 788 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
776 | 789 | axes = self.axesList[i*self.__nsubplots*2] |
|
777 | 790 | axes.pcolorbuffer(x, y, z, |
|
778 | 791 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
779 | 792 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
780 | 793 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
781 | 794 | |
|
782 | 795 | if self.__showprofile: |
|
783 | 796 | counter += 1 |
|
784 | 797 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
785 | 798 | axes.pline(coherence, y, |
|
786 | 799 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
787 | 800 | xlabel='', ylabel='', title='', ticksize=7, |
|
788 | 801 | ytick_visible=False, nxticks=5, |
|
789 | 802 | grid='x') |
|
790 | 803 | |
|
791 | 804 | counter += 1 |
|
792 | 805 | |
|
793 | 806 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
794 | 807 | |
|
795 | 808 | z = phase.reshape((1,-1)) |
|
796 | 809 | |
|
797 | 810 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
798 | 811 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
799 | 812 | axes.pcolorbuffer(x, y, z, |
|
800 | 813 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
801 | 814 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
802 | 815 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
803 | 816 | |
|
804 | 817 | if self.__showprofile: |
|
805 | 818 | counter += 1 |
|
806 | 819 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
807 | 820 | axes.pline(phase, y, |
|
808 | 821 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
809 | 822 | xlabel='', ylabel='', title='', ticksize=7, |
|
810 | 823 | ytick_visible=False, nxticks=4, |
|
811 | 824 | grid='x') |
|
812 | 825 | |
|
813 | 826 | self.draw() |
|
814 | 827 | |
|
815 | 828 | if dataOut.ltctime >= self.xmax: |
|
816 | 829 | self.counter_imagwr = wr_period |
|
817 | 830 | self.isConfig = False |
|
818 | 831 | update_figfile = True |
|
819 | 832 | |
|
820 | 833 | self.save(figpath=figpath, |
|
821 | 834 | figfile=figfile, |
|
822 | 835 | save=save, |
|
823 | 836 | ftp=ftp, |
|
824 | 837 | wr_period=wr_period, |
|
825 | 838 | thisDatetime=thisDatetime, |
|
826 | 839 | update_figfile=update_figfile) |
|
827 | 840 | |
|
828 | 841 | class PowerProfilePlot(Figure): |
|
829 | 842 | |
|
830 | 843 | isConfig = None |
|
831 | 844 | __nsubplots = None |
|
832 | 845 | |
|
833 | 846 | WIDTHPROF = None |
|
834 | 847 | HEIGHTPROF = None |
|
835 | 848 | PREFIX = 'spcprofile' |
|
836 | 849 | |
|
837 | 850 | def __init__(self): |
|
838 | 851 | self.isConfig = False |
|
839 | 852 | self.__nsubplots = 1 |
|
840 | 853 | |
|
841 | 854 | self.PLOT_CODE = POWER_CODE |
|
842 | 855 | |
|
843 | 856 | self.WIDTH = 300 |
|
844 | 857 | self.HEIGHT = 500 |
|
845 | 858 | self.counter_imagwr = 0 |
|
846 | 859 | |
|
847 | 860 | def getSubplots(self): |
|
848 | 861 | ncol = 1 |
|
849 | 862 | nrow = 1 |
|
850 | 863 | |
|
851 | 864 | return nrow, ncol |
|
852 | 865 | |
|
853 | 866 | def setup(self, id, nplots, wintitle, show): |
|
854 | 867 | |
|
855 | 868 | self.nplots = nplots |
|
856 | 869 | |
|
857 | 870 | ncolspan = 1 |
|
858 | 871 | colspan = 1 |
|
859 | 872 | |
|
860 | 873 | self.createFigure(id = id, |
|
861 | 874 | wintitle = wintitle, |
|
862 | 875 | widthplot = self.WIDTH, |
|
863 | 876 | heightplot = self.HEIGHT, |
|
864 | 877 | show=show) |
|
865 | 878 | |
|
866 | 879 | nrow, ncol = self.getSubplots() |
|
867 | 880 | |
|
868 | 881 | counter = 0 |
|
869 | 882 | for y in range(nrow): |
|
870 | 883 | for x in range(ncol): |
|
871 | 884 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
872 | 885 | |
|
873 | 886 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
874 | 887 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
875 | 888 | save=False, figpath='./', figfile=None, show=True, |
|
876 | 889 | ftp=False, wr_period=1, server=None, |
|
877 | 890 | folder=None, username=None, password=None): |
|
878 | 891 | |
|
879 | 892 | |
|
880 | 893 | if channelList == None: |
|
881 | 894 | channelIndexList = dataOut.channelIndexList |
|
882 | 895 | channelList = dataOut.channelList |
|
883 | 896 | else: |
|
884 | 897 | channelIndexList = [] |
|
885 | 898 | for channel in channelList: |
|
886 | 899 | if channel not in dataOut.channelList: |
|
887 | 900 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
888 | 901 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
889 | 902 | |
|
890 | 903 | factor = dataOut.normFactor |
|
891 | 904 | |
|
892 | 905 | y = dataOut.getHeiRange() |
|
893 | 906 | |
|
894 | 907 | #for voltage |
|
895 | 908 | if dataOut.type == 'Voltage': |
|
896 | 909 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
897 | 910 | x = x.real |
|
898 | 911 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
899 | 912 | |
|
900 | 913 | #for spectra |
|
901 | 914 | if dataOut.type == 'Spectra': |
|
902 | 915 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
903 | 916 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
904 | 917 | x = numpy.average(x, axis=1) |
|
905 | 918 | |
|
906 | 919 | |
|
907 | 920 | xdB = 10*numpy.log10(x) |
|
908 | 921 | |
|
909 | 922 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
910 | 923 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
911 | 924 | xlabel = "dB" |
|
912 | 925 | ylabel = "Range (Km)" |
|
913 | 926 | |
|
914 | 927 | if not self.isConfig: |
|
915 | 928 | |
|
916 | 929 | nplots = 1 |
|
917 | 930 | |
|
918 | 931 | self.setup(id=id, |
|
919 | 932 | nplots=nplots, |
|
920 | 933 | wintitle=wintitle, |
|
921 | 934 | show=show) |
|
922 | 935 | |
|
923 | 936 | if ymin == None: ymin = numpy.nanmin(y) |
|
924 | 937 | if ymax == None: ymax = numpy.nanmax(y) |
|
925 | 938 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
926 | 939 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
927 | 940 | |
|
928 | 941 | self.isConfig = True |
|
929 | 942 | |
|
930 | 943 | self.setWinTitle(title) |
|
931 | 944 | |
|
932 | 945 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
933 | 946 | axes = self.axesList[0] |
|
934 | 947 | |
|
935 | 948 | legendlabels = ["channel %d"%x for x in channelList] |
|
936 | 949 | axes.pmultiline(xdB, y, |
|
937 | 950 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
938 | 951 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
939 | 952 | ytick_visible=True, nxticks=5, |
|
940 | 953 | grid='x') |
|
941 | 954 | |
|
942 | 955 | self.draw() |
|
943 | 956 | |
|
944 | 957 | self.save(figpath=figpath, |
|
945 | 958 | figfile=figfile, |
|
946 | 959 | save=save, |
|
947 | 960 | ftp=ftp, |
|
948 | 961 | wr_period=wr_period, |
|
949 | 962 | thisDatetime=thisDatetime) |
|
950 | 963 | |
|
951 | 964 | class SpectraCutPlot(Figure): |
|
952 | 965 | |
|
953 | 966 | isConfig = None |
|
954 | 967 | __nsubplots = None |
|
955 | 968 | |
|
956 | 969 | WIDTHPROF = None |
|
957 | 970 | HEIGHTPROF = None |
|
958 | 971 | PREFIX = 'spc_cut' |
|
959 | 972 | |
|
960 | 973 | def __init__(self): |
|
961 | 974 | self.isConfig = False |
|
962 | 975 | self.__nsubplots = 1 |
|
963 | 976 | |
|
964 | 977 | self.PLOT_CODE = POWER_CODE |
|
965 | 978 | |
|
966 | 979 | self.WIDTH = 700 |
|
967 | 980 | self.HEIGHT = 500 |
|
968 | 981 | self.counter_imagwr = 0 |
|
969 | 982 | |
|
970 | 983 | def getSubplots(self): |
|
971 | 984 | ncol = 1 |
|
972 | 985 | nrow = 1 |
|
973 | 986 | |
|
974 | 987 | return nrow, ncol |
|
975 | 988 | |
|
976 | 989 | def setup(self, id, nplots, wintitle, show): |
|
977 | 990 | |
|
978 | 991 | self.nplots = nplots |
|
979 | 992 | |
|
980 | 993 | ncolspan = 1 |
|
981 | 994 | colspan = 1 |
|
982 | 995 | |
|
983 | 996 | self.createFigure(id = id, |
|
984 | 997 | wintitle = wintitle, |
|
985 | 998 | widthplot = self.WIDTH, |
|
986 | 999 | heightplot = self.HEIGHT, |
|
987 | 1000 | show=show) |
|
988 | 1001 | |
|
989 | 1002 | nrow, ncol = self.getSubplots() |
|
990 | 1003 | |
|
991 | 1004 | counter = 0 |
|
992 | 1005 | for y in range(nrow): |
|
993 | 1006 | for x in range(ncol): |
|
994 | 1007 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
995 | 1008 | |
|
996 | 1009 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
997 | 1010 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
998 | 1011 | save=False, figpath='./', figfile=None, show=True, |
|
999 | 1012 | ftp=False, wr_period=1, server=None, |
|
1000 | 1013 | folder=None, username=None, password=None, |
|
1001 |
xaxis=" |
|
|
1014 | xaxis="frequency"): | |
|
1002 | 1015 | |
|
1003 | 1016 | |
|
1004 | 1017 | if channelList == None: |
|
1005 | 1018 | channelIndexList = dataOut.channelIndexList |
|
1006 | 1019 | channelList = dataOut.channelList |
|
1007 | 1020 | else: |
|
1008 | 1021 | channelIndexList = [] |
|
1009 | 1022 | for channel in channelList: |
|
1010 | 1023 | if channel not in dataOut.channelList: |
|
1011 | 1024 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1012 | 1025 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1013 | 1026 | |
|
1014 | 1027 | factor = dataOut.normFactor |
|
1015 | 1028 | |
|
1016 | 1029 | y = dataOut.getHeiRange() |
|
1017 | 1030 | |
|
1018 | 1031 | z = dataOut.data_spc/factor |
|
1019 | 1032 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1020 | 1033 | |
|
1021 | 1034 | hei_index = numpy.arange(25)*3 + 20 |
|
1022 | 1035 | |
|
1023 | 1036 | if xaxis == "frequency": |
|
1024 | 1037 | x = dataOut.getFreqRange()/1000. |
|
1025 | 1038 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1026 | 1039 | xlabel = "Frequency (kHz)" |
|
1027 | 1040 | ylabel = "Power (dB)" |
|
1028 | 1041 | |
|
1029 | 1042 | elif xaxis == "time": |
|
1030 | 1043 | x = dataOut.getAcfRange() |
|
1031 | 1044 | zdB = z[0,:,hei_index] |
|
1032 | 1045 | xlabel = "Time (ms)" |
|
1033 | 1046 | ylabel = "ACF" |
|
1034 | 1047 | |
|
1035 | 1048 | else: |
|
1036 | 1049 | x = dataOut.getVelRange() |
|
1037 | 1050 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1038 | 1051 | xlabel = "Velocity (m/s)" |
|
1039 | 1052 | ylabel = "Power (dB)" |
|
1040 | 1053 | |
|
1041 | 1054 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1042 | 1055 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1043 | 1056 | |
|
1044 | 1057 | if not self.isConfig: |
|
1045 | 1058 | |
|
1046 | 1059 | nplots = 1 |
|
1047 | 1060 | |
|
1048 | 1061 | self.setup(id=id, |
|
1049 | 1062 | nplots=nplots, |
|
1050 | 1063 | wintitle=wintitle, |
|
1051 | 1064 | show=show) |
|
1052 | 1065 | |
|
1053 | 1066 | if xmin == None: xmin = numpy.nanmin(x)*0.9 |
|
1054 | 1067 | if xmax == None: xmax = numpy.nanmax(x)*1.1 |
|
1055 | 1068 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1056 | 1069 | if ymax == None: ymax = numpy.nanmax(zdB) |
|
1057 | 1070 | |
|
1058 | 1071 | self.isConfig = True |
|
1059 | 1072 | |
|
1060 | 1073 | self.setWinTitle(title) |
|
1061 | 1074 | |
|
1062 | 1075 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1063 | 1076 | axes = self.axesList[0] |
|
1064 | 1077 | |
|
1065 | 1078 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] |
|
1066 | 1079 | |
|
1067 | 1080 | axes.pmultilineyaxis( x, zdB, |
|
1068 | 1081 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1069 | 1082 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1070 | 1083 | ytick_visible=True, nxticks=5, |
|
1071 | 1084 | grid='x') |
|
1072 | 1085 | |
|
1073 | 1086 | self.draw() |
|
1074 | 1087 | |
|
1075 | 1088 | self.save(figpath=figpath, |
|
1076 | 1089 | figfile=figfile, |
|
1077 | 1090 | save=save, |
|
1078 | 1091 | ftp=ftp, |
|
1079 | 1092 | wr_period=wr_period, |
|
1080 | 1093 | thisDatetime=thisDatetime) |
|
1081 | 1094 | |
|
1082 | 1095 | class Noise(Figure): |
|
1083 | 1096 | |
|
1084 | 1097 | isConfig = None |
|
1085 | 1098 | __nsubplots = None |
|
1086 | 1099 | |
|
1087 | 1100 | PREFIX = 'noise' |
|
1088 | 1101 | |
|
1089 | 1102 | def __init__(self): |
|
1090 | 1103 | |
|
1091 | 1104 | self.timerange = 24*60*60 |
|
1092 | 1105 | self.isConfig = False |
|
1093 | 1106 | self.__nsubplots = 1 |
|
1094 | 1107 | self.counter_imagwr = 0 |
|
1095 | 1108 | self.WIDTH = 800 |
|
1096 | 1109 | self.HEIGHT = 400 |
|
1097 | 1110 | self.WIDTHPROF = 120 |
|
1098 | 1111 | self.HEIGHTPROF = 0 |
|
1099 | 1112 | self.xdata = None |
|
1100 | 1113 | self.ydata = None |
|
1101 | 1114 | |
|
1102 | 1115 | self.PLOT_CODE = NOISE_CODE |
|
1103 | 1116 | |
|
1104 | 1117 | self.FTP_WEI = None |
|
1105 | 1118 | self.EXP_CODE = None |
|
1106 | 1119 | self.SUB_EXP_CODE = None |
|
1107 | 1120 | self.PLOT_POS = None |
|
1108 | 1121 | self.figfile = None |
|
1109 | 1122 | |
|
1110 | 1123 | self.xmin = None |
|
1111 | 1124 | self.xmax = None |
|
1112 | 1125 | |
|
1113 | 1126 | def getSubplots(self): |
|
1114 | 1127 | |
|
1115 | 1128 | ncol = 1 |
|
1116 | 1129 | nrow = 1 |
|
1117 | 1130 | |
|
1118 | 1131 | return nrow, ncol |
|
1119 | 1132 | |
|
1120 | 1133 | def openfile(self, filename): |
|
1121 | 1134 | dirname = os.path.dirname(filename) |
|
1122 | 1135 | |
|
1123 | 1136 | if not os.path.exists(dirname): |
|
1124 | 1137 | os.mkdir(dirname) |
|
1125 | 1138 | |
|
1126 | 1139 | f = open(filename,'w+') |
|
1127 | 1140 | f.write('\n\n') |
|
1128 | 1141 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1129 | 1142 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1130 | 1143 | f.close() |
|
1131 | 1144 | |
|
1132 | 1145 | def save_data(self, filename_phase, data, data_datetime): |
|
1133 | 1146 | |
|
1134 | 1147 | f=open(filename_phase,'a') |
|
1135 | 1148 | |
|
1136 | 1149 | timetuple_data = data_datetime.timetuple() |
|
1137 | 1150 | day = str(timetuple_data.tm_mday) |
|
1138 | 1151 | month = str(timetuple_data.tm_mon) |
|
1139 | 1152 | year = str(timetuple_data.tm_year) |
|
1140 | 1153 | hour = str(timetuple_data.tm_hour) |
|
1141 | 1154 | minute = str(timetuple_data.tm_min) |
|
1142 | 1155 | second = str(timetuple_data.tm_sec) |
|
1143 | 1156 | |
|
1144 | 1157 | data_msg = '' |
|
1145 | 1158 | for i in range(len(data)): |
|
1146 | 1159 | data_msg += str(data[i]) + ' ' |
|
1147 | 1160 | |
|
1148 | 1161 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1149 | 1162 | f.close() |
|
1150 | 1163 | |
|
1151 | 1164 | |
|
1152 | 1165 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1153 | 1166 | |
|
1154 | 1167 | self.__showprofile = showprofile |
|
1155 | 1168 | self.nplots = nplots |
|
1156 | 1169 | |
|
1157 | 1170 | ncolspan = 7 |
|
1158 | 1171 | colspan = 6 |
|
1159 | 1172 | self.__nsubplots = 2 |
|
1160 | 1173 | |
|
1161 | 1174 | self.createFigure(id = id, |
|
1162 | 1175 | wintitle = wintitle, |
|
1163 | 1176 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1164 | 1177 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1165 | 1178 | show=show) |
|
1166 | 1179 | |
|
1167 | 1180 | nrow, ncol = self.getSubplots() |
|
1168 | 1181 | |
|
1169 | 1182 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1170 | 1183 | |
|
1171 | 1184 | |
|
1172 | 1185 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1173 | 1186 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1174 | 1187 | timerange=None, |
|
1175 | 1188 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1176 | 1189 | server=None, folder=None, username=None, password=None, |
|
1177 | 1190 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1178 | 1191 | |
|
1179 | 1192 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1180 | 1193 | return |
|
1181 | 1194 | |
|
1182 | 1195 | if channelList == None: |
|
1183 | 1196 | channelIndexList = dataOut.channelIndexList |
|
1184 | 1197 | channelList = dataOut.channelList |
|
1185 | 1198 | else: |
|
1186 | 1199 | channelIndexList = [] |
|
1187 | 1200 | for channel in channelList: |
|
1188 | 1201 | if channel not in dataOut.channelList: |
|
1189 | 1202 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1190 | 1203 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1191 | 1204 | |
|
1192 | 1205 | x = dataOut.getTimeRange() |
|
1193 | 1206 | #y = dataOut.getHeiRange() |
|
1194 | 1207 | factor = dataOut.normFactor |
|
1195 | 1208 | noise = dataOut.noise[channelIndexList]/factor |
|
1196 | 1209 | noisedB = 10*numpy.log10(noise) |
|
1197 | 1210 | |
|
1198 | 1211 | thisDatetime = dataOut.datatime |
|
1199 | 1212 | |
|
1200 | 1213 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1201 | 1214 | xlabel = "" |
|
1202 | 1215 | ylabel = "Intensity (dB)" |
|
1203 | 1216 | update_figfile = False |
|
1204 | 1217 | |
|
1205 | 1218 | if not self.isConfig: |
|
1206 | 1219 | |
|
1207 | 1220 | nplots = 1 |
|
1208 | 1221 | |
|
1209 | 1222 | self.setup(id=id, |
|
1210 | 1223 | nplots=nplots, |
|
1211 | 1224 | wintitle=wintitle, |
|
1212 | 1225 | showprofile=showprofile, |
|
1213 | 1226 | show=show) |
|
1214 | 1227 | |
|
1215 | 1228 | if timerange != None: |
|
1216 | 1229 | self.timerange = timerange |
|
1217 | 1230 | |
|
1218 | 1231 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1219 | 1232 | |
|
1220 | 1233 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1221 | 1234 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1222 | 1235 | |
|
1223 | 1236 | self.FTP_WEI = ftp_wei |
|
1224 | 1237 | self.EXP_CODE = exp_code |
|
1225 | 1238 | self.SUB_EXP_CODE = sub_exp_code |
|
1226 | 1239 | self.PLOT_POS = plot_pos |
|
1227 | 1240 | |
|
1228 | 1241 | |
|
1229 | 1242 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1230 | 1243 | self.isConfig = True |
|
1231 | 1244 | self.figfile = figfile |
|
1232 | 1245 | self.xdata = numpy.array([]) |
|
1233 | 1246 | self.ydata = numpy.array([]) |
|
1234 | 1247 | |
|
1235 | 1248 | update_figfile = True |
|
1236 | 1249 | |
|
1237 | 1250 | #open file beacon phase |
|
1238 | 1251 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1239 | 1252 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1240 | 1253 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1241 | 1254 | |
|
1242 | 1255 | self.setWinTitle(title) |
|
1243 | 1256 | |
|
1244 | 1257 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1245 | 1258 | |
|
1246 | 1259 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1247 | 1260 | axes = self.axesList[0] |
|
1248 | 1261 | |
|
1249 | 1262 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1250 | 1263 | |
|
1251 | 1264 | if len(self.ydata)==0: |
|
1252 | 1265 | self.ydata = noisedB.reshape(-1,1) |
|
1253 | 1266 | else: |
|
1254 | 1267 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1255 | 1268 | |
|
1256 | 1269 | |
|
1257 | 1270 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1258 | 1271 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1259 | 1272 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1260 | 1273 | XAxisAsTime=True, grid='both' |
|
1261 | 1274 | ) |
|
1262 | 1275 | |
|
1263 | 1276 | self.draw() |
|
1264 | 1277 | |
|
1265 | 1278 | if dataOut.ltctime >= self.xmax: |
|
1266 | 1279 | self.counter_imagwr = wr_period |
|
1267 | 1280 | self.isConfig = False |
|
1268 | 1281 | update_figfile = True |
|
1269 | 1282 | |
|
1270 | 1283 | self.save(figpath=figpath, |
|
1271 | 1284 | figfile=figfile, |
|
1272 | 1285 | save=save, |
|
1273 | 1286 | ftp=ftp, |
|
1274 | 1287 | wr_period=wr_period, |
|
1275 | 1288 | thisDatetime=thisDatetime, |
|
1276 | 1289 | update_figfile=update_figfile) |
|
1277 | 1290 | |
|
1278 | 1291 | #store data beacon phase |
|
1279 | 1292 | if save: |
|
1280 | 1293 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1281 | 1294 | |
|
1282 | 1295 | class BeaconPhase(Figure): |
|
1283 | 1296 | |
|
1284 | 1297 | __isConfig = None |
|
1285 | 1298 | __nsubplots = None |
|
1286 | 1299 | |
|
1287 | 1300 | PREFIX = 'beacon_phase' |
|
1288 | 1301 | |
|
1289 | 1302 | def __init__(self): |
|
1290 | 1303 | |
|
1291 | 1304 | self.timerange = 24*60*60 |
|
1292 | 1305 | self.isConfig = False |
|
1293 | 1306 | self.__nsubplots = 1 |
|
1294 | 1307 | self.counter_imagwr = 0 |
|
1295 | 1308 | self.WIDTH = 800 |
|
1296 | 1309 | self.HEIGHT = 400 |
|
1297 | 1310 | self.WIDTHPROF = 120 |
|
1298 | 1311 | self.HEIGHTPROF = 0 |
|
1299 | 1312 | self.xdata = None |
|
1300 | 1313 | self.ydata = None |
|
1301 | 1314 | |
|
1302 | 1315 | self.PLOT_CODE = BEACON_CODE |
|
1303 | 1316 | |
|
1304 | 1317 | self.FTP_WEI = None |
|
1305 | 1318 | self.EXP_CODE = None |
|
1306 | 1319 | self.SUB_EXP_CODE = None |
|
1307 | 1320 | self.PLOT_POS = None |
|
1308 | 1321 | |
|
1309 | 1322 | self.filename_phase = None |
|
1310 | 1323 | |
|
1311 | 1324 | self.figfile = None |
|
1312 | 1325 | |
|
1313 | 1326 | self.xmin = None |
|
1314 | 1327 | self.xmax = None |
|
1315 | 1328 | |
|
1316 | 1329 | def getSubplots(self): |
|
1317 | 1330 | |
|
1318 | 1331 | ncol = 1 |
|
1319 | 1332 | nrow = 1 |
|
1320 | 1333 | |
|
1321 | 1334 | return nrow, ncol |
|
1322 | 1335 | |
|
1323 | 1336 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1324 | 1337 | |
|
1325 | 1338 | self.__showprofile = showprofile |
|
1326 | 1339 | self.nplots = nplots |
|
1327 | 1340 | |
|
1328 | 1341 | ncolspan = 7 |
|
1329 | 1342 | colspan = 6 |
|
1330 | 1343 | self.__nsubplots = 2 |
|
1331 | 1344 | |
|
1332 | 1345 | self.createFigure(id = id, |
|
1333 | 1346 | wintitle = wintitle, |
|
1334 | 1347 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1335 | 1348 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1336 | 1349 | show=show) |
|
1337 | 1350 | |
|
1338 | 1351 | nrow, ncol = self.getSubplots() |
|
1339 | 1352 | |
|
1340 | 1353 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1341 | 1354 | |
|
1342 | 1355 | def save_phase(self, filename_phase): |
|
1343 | 1356 | f = open(filename_phase,'w+') |
|
1344 | 1357 | f.write('\n\n') |
|
1345 | 1358 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1346 | 1359 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1347 | 1360 | f.close() |
|
1348 | 1361 | |
|
1349 | 1362 | def save_data(self, filename_phase, data, data_datetime): |
|
1350 | 1363 | f=open(filename_phase,'a') |
|
1351 | 1364 | timetuple_data = data_datetime.timetuple() |
|
1352 | 1365 | day = str(timetuple_data.tm_mday) |
|
1353 | 1366 | month = str(timetuple_data.tm_mon) |
|
1354 | 1367 | year = str(timetuple_data.tm_year) |
|
1355 | 1368 | hour = str(timetuple_data.tm_hour) |
|
1356 | 1369 | minute = str(timetuple_data.tm_min) |
|
1357 | 1370 | second = str(timetuple_data.tm_sec) |
|
1358 | 1371 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1359 | 1372 | f.close() |
|
1360 | 1373 | |
|
1361 | 1374 | |
|
1362 | 1375 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1363 | 1376 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1364 | 1377 | timerange=None, |
|
1365 | 1378 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1366 | 1379 | server=None, folder=None, username=None, password=None, |
|
1367 | 1380 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1368 | 1381 | |
|
1369 | 1382 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1370 | 1383 | return |
|
1371 | 1384 | |
|
1372 | 1385 | if pairsList == None: |
|
1373 | 1386 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1374 | 1387 | else: |
|
1375 | 1388 | pairsIndexList = [] |
|
1376 | 1389 | for pair in pairsList: |
|
1377 | 1390 | if pair not in dataOut.pairsList: |
|
1378 | 1391 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1379 | 1392 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1380 | 1393 | |
|
1381 | 1394 | if pairsIndexList == []: |
|
1382 | 1395 | return |
|
1383 | 1396 | |
|
1384 | 1397 | # if len(pairsIndexList) > 4: |
|
1385 | 1398 | # pairsIndexList = pairsIndexList[0:4] |
|
1386 | 1399 | |
|
1387 | 1400 | hmin_index = None |
|
1388 | 1401 | hmax_index = None |
|
1389 | 1402 | |
|
1390 | 1403 | if hmin != None and hmax != None: |
|
1391 | 1404 | indexes = numpy.arange(dataOut.nHeights) |
|
1392 | 1405 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1393 | 1406 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1394 | 1407 | |
|
1395 | 1408 | if hmin_list.any(): |
|
1396 | 1409 | hmin_index = hmin_list[0] |
|
1397 | 1410 | |
|
1398 | 1411 | if hmax_list.any(): |
|
1399 | 1412 | hmax_index = hmax_list[-1]+1 |
|
1400 | 1413 | |
|
1401 | 1414 | x = dataOut.getTimeRange() |
|
1402 | 1415 | #y = dataOut.getHeiRange() |
|
1403 | 1416 | |
|
1404 | 1417 | |
|
1405 | 1418 | thisDatetime = dataOut.datatime |
|
1406 | 1419 | |
|
1407 | 1420 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1408 | 1421 | xlabel = "Local Time" |
|
1409 | 1422 | ylabel = "Phase (degrees)" |
|
1410 | 1423 | |
|
1411 | 1424 | update_figfile = False |
|
1412 | 1425 | |
|
1413 | 1426 | nplots = len(pairsIndexList) |
|
1414 | 1427 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1415 | 1428 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1416 | 1429 | for i in range(nplots): |
|
1417 | 1430 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1418 | 1431 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1419 | 1432 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1420 | 1433 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1421 | 1434 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1422 | 1435 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1423 | 1436 | |
|
1424 | 1437 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1425 | 1438 | #print phase[dataOut.beacon_heiIndexList] |
|
1426 | 1439 | |
|
1427 | 1440 | if dataOut.beacon_heiIndexList: |
|
1428 | 1441 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1429 | 1442 | else: |
|
1430 | 1443 | phase_beacon[i] = numpy.average(phase) |
|
1431 | 1444 | |
|
1432 | 1445 | if not self.isConfig: |
|
1433 | 1446 | |
|
1434 | 1447 | nplots = len(pairsIndexList) |
|
1435 | 1448 | |
|
1436 | 1449 | self.setup(id=id, |
|
1437 | 1450 | nplots=nplots, |
|
1438 | 1451 | wintitle=wintitle, |
|
1439 | 1452 | showprofile=showprofile, |
|
1440 | 1453 | show=show) |
|
1441 | 1454 | |
|
1442 | 1455 | if timerange != None: |
|
1443 | 1456 | self.timerange = timerange |
|
1444 | 1457 | |
|
1445 | 1458 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1446 | 1459 | |
|
1447 | 1460 | if ymin == None: ymin = 0 |
|
1448 | 1461 | if ymax == None: ymax = 360 |
|
1449 | 1462 | |
|
1450 | 1463 | self.FTP_WEI = ftp_wei |
|
1451 | 1464 | self.EXP_CODE = exp_code |
|
1452 | 1465 | self.SUB_EXP_CODE = sub_exp_code |
|
1453 | 1466 | self.PLOT_POS = plot_pos |
|
1454 | 1467 | |
|
1455 | 1468 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1456 | 1469 | self.isConfig = True |
|
1457 | 1470 | self.figfile = figfile |
|
1458 | 1471 | self.xdata = numpy.array([]) |
|
1459 | 1472 | self.ydata = numpy.array([]) |
|
1460 | 1473 | |
|
1461 | 1474 | update_figfile = True |
|
1462 | 1475 | |
|
1463 | 1476 | #open file beacon phase |
|
1464 | 1477 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1465 | 1478 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1466 | 1479 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1467 | 1480 | #self.save_phase(self.filename_phase) |
|
1468 | 1481 | |
|
1469 | 1482 | |
|
1470 | 1483 | #store data beacon phase |
|
1471 | 1484 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1472 | 1485 | |
|
1473 | 1486 | self.setWinTitle(title) |
|
1474 | 1487 | |
|
1475 | 1488 | |
|
1476 | 1489 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1477 | 1490 | |
|
1478 | 1491 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1479 | 1492 | |
|
1480 | 1493 | axes = self.axesList[0] |
|
1481 | 1494 | |
|
1482 | 1495 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1483 | 1496 | |
|
1484 | 1497 | if len(self.ydata)==0: |
|
1485 | 1498 | self.ydata = phase_beacon.reshape(-1,1) |
|
1486 | 1499 | else: |
|
1487 | 1500 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1488 | 1501 | |
|
1489 | 1502 | |
|
1490 | 1503 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1491 | 1504 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1492 | 1505 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1493 | 1506 | XAxisAsTime=True, grid='both' |
|
1494 | 1507 | ) |
|
1495 | 1508 | |
|
1496 | 1509 | self.draw() |
|
1497 | 1510 | |
|
1498 | 1511 | if dataOut.ltctime >= self.xmax: |
|
1499 | 1512 | self.counter_imagwr = wr_period |
|
1500 | 1513 | self.isConfig = False |
|
1501 | 1514 | update_figfile = True |
|
1502 | 1515 | |
|
1503 | 1516 | self.save(figpath=figpath, |
|
1504 | 1517 | figfile=figfile, |
|
1505 | 1518 | save=save, |
|
1506 | 1519 | ftp=ftp, |
|
1507 | 1520 | wr_period=wr_period, |
|
1508 | 1521 | thisDatetime=thisDatetime, |
|
1509 | 1522 | update_figfile=update_figfile) |
General Comments 0
You need to be logged in to leave comments.
Login now