##// END OF EJS Templates
Modificacion en la clase ScopeFigure
Daniel Valdez -
r142:08780f3f4e12
parent child
Show More
@@ -1,529 +1,520
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 from schainPlot import *
5 5
6 6 class SpcFigure(Figure):
7 7 overplot = 0
8 8 xw = 800
9 9 yw = 650
10 10 showprofile = False
11 11
12 12 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
13 13 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
14 14
15 15 self.showprofile = showprofile
16 16
17 17 def getSubplots(self):
18 18 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
19 19 nrows = int(self.nframes*1./ncolumns + 0.9)
20 20
21 21 return nrows, ncolumns
22 22
23 23 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
24 24
25 25 if xmin == None: xmin = numpy.min(x)
26 26 if xmax == None: xmax = numpy.max(x)
27 27 if ymin == None: ymin = numpy.min(y)
28 28 if ymax == None: ymax = numpy.max(y)
29 29 if minvalue == None: minvalue = 20.
30 30 if maxvalue == None: maxvalue = 90.
31 31
32 32 self.xmin = xmin
33 33 self.xmax = xmax
34 34 self.minrange = ymin
35 35 self.maxrange = ymax
36 36 self.ymin = ymin
37 37 self.ymax = ymax
38 38 self.minvalue = minvalue
39 39 self.maxvalue = maxvalue
40 40
41 41
42 42 def changeXRange(self, *args):
43 43 pass
44 44
45 45 def createFrames(self):
46 46 for frame in range(self.nframes):
47 47 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
48 48 self.frameObjList.append(frameObj)
49 49
50 50 class SpcFrame(Frame):
51 51 def __init__(self,drvObj,idframe,colorbar,showprofile):
52 52 self.drvObj = drvObj
53 53 self.idframe = idframe
54 54 self.nplots = 1
55 55
56 56 if showprofile:
57 57 self.nplots += 1
58 58
59 59 self.colorbar = colorbar
60 60 self.showprofile = showprofile
61 61 self.createPlots()
62 62
63 63 def createPlots(self):
64 64 plotObjList = []
65 65 idplot = 0
66 66 xi, yi, xw, yw = self.getScreenPos(idplot)
67 67 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
68 68 plotObjList.append(plotObj)
69 69
70 70 if self.showprofile:
71 71 idplot = 1
72 72 xi, yi, xw, yw = self.getScreenPos(idplot)
73 73 type = "pwbox"
74 74 title = ""
75 75 xlabel = "dB"
76 76 ylabel = ""
77 77 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
78 78 plotObjList.append(plotObj)
79 79
80 80 self.plotObjList = plotObjList
81 81
82 82 def getScreenPosMainPlot(self):
83 83 xi = 0.15
84 84
85 85 if self.showprofile:
86 86 xw = 0.65
87 87
88 88 else:
89 89 xw = 0.75
90 90
91 91 if self.colorbar:
92 92 xw = xw - 0.06
93 93
94 94 yi = 0.20; yw = 0.75
95 95
96 96 return xi, yi, xw, yw
97 97
98 98 def getScreenPosGraph1(self):
99 99 if self.colorbar:
100 100 xi = 0.65 + 0.08
101 101 else:
102 102 xi = 0.75 + 0.05
103 103
104 104 xw = xi + 0.2
105 105
106 106 yi = 0.2; yw = 0.75
107 107
108 108 return xi, yi, xw, yw
109 109
110 110 def plot(self,x, y, data):
111 111 plotObj = self.plotObjList[0]
112 112 plotObj.plot(x,y,data)
113 113
114 114 if self.showprofile:
115 115 plotObj = self.plotObjList[1]
116 116 plotObj.plot(data,y)
117 117
118 118 class SpcPlot(Plot):
119 119
120 120 getGrid = True
121 121
122 122 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
123 123 self.drvObj = drvObj
124 124 self.idframe = idframe
125 125 self.idplot = idplot
126 126 self.xi = xi
127 127 self.yi = yi
128 128 self.xw = xw
129 129 self.yw = yw
130 130 self.colorbar = colorbar
131 131
132 132 if self.colorbar:
133 133 cbxi = xw + 0.03
134 134 cbxw = cbxi + 0.03
135 135 cbyi = yi
136 136 cbyw = yw
137 137 self.cbxpos = [cbxi,cbxw]
138 138 self.cbypos = [cbyi,cbyw]
139 139
140 140 self.xpos = [self.xi,self.xw]
141 141 self.ypos = [self.yi,self.yw]
142 142 self.xaxisastime = False
143 143 self.timefmt = None
144 144 self.xopt = "bcnst"
145 145 self.yopt = "bcnstv"
146 146
147 147 self.szchar = 0.8
148 148 self.strforchannel = "Channel %d"%self.idframe
149 149 self.xlabel = "m/s"
150 150 self.ylabel = "Range (Km)"
151 151
152 152 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
153 153 self.xmin = xmin
154 154 self.xmax = xmax
155 155 self.ymin = ymin
156 156 self.ymax = ymax
157 157 self.minvalue = minvalue
158 158 self.maxvalue = maxvalue
159 159 self.colorbar = args[2]
160 160 self.title = "%s - %s"%(self.strforchannel,args[3])
161 161
162 162
163 163
164 164 def plot(self, x, y, data):
165 165 z = data
166 166 deltax = None
167 167 deltay = None
168 168 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
169 169 self.getGrid = False
170 170
171 171
172 172 class RTIFigure(Figure):
173 173 overplot = 1
174 174 xw = 700
175 175 yw = 650
176 176 showprofile = False
177 177 starttime = None
178 178 endtime = None
179 179 minrange = None
180 180 maxrange = None
181 181 minvalue = None
182 182 maxvalue = None
183 183 xrangestepinsecs = None
184 184
185 185
186 186 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
187 187 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
188 188
189 189 self.showprofile = showprofile
190 190
191 191 def getSubplots(self):
192 192 nrows = self.nframes
193 193 ncolumns = 1
194 194 return nrows, ncolumns
195 195
196 196 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep):
197 197
198 198 self.starttime = xmin
199 199 self.endtime = xmax
200 200
201 201 cdatetime = datetime.datetime.utcfromtimestamp(x)
202 202
203 203 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
204 204 if ((xrangestep == 0) or (xrangestep == None)):
205 205 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
206 206 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
207 207 npoints = 1000.
208 208 if xrangestep == 1:
209 209 maxdatetime = mindatetime + datetime.timedelta(hours=1)
210 210 self.xrangestepinsecs = 60*60.
211 211 npoints = 500.
212 212 if xrangestep == 2:
213 213 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
214 214 self.xrangestepinsecs = 60.
215 215 npoints = 250.
216 216 if xrangestep == 3:
217 217 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
218 218 self.xrangestepinsecs = 1.
219 219 npoints = 125.
220 220
221 221 xmin = time.mktime(mindatetime.timetuple())
222 222 xmax = time.mktime(maxdatetime.timetuple())
223 223
224 224 deltax = (xmax-xmin) / npoints
225 225
226 226
227 227 if ymin == None: ymin = numpy.min(y)
228 228 if ymax == None: ymax = numpy.max(y)
229 229
230 230 if minvalue == None: minvalue = 0.
231 231 if maxvalue == None: maxvalue = 50.
232 232
233 233 self.xmin = xmin
234 234 self.xmax = xmax
235 235 self.minrange = ymin
236 236 self.maxrange = ymax
237 237 self.ymin = ymin
238 238 self.ymax = ymax
239 239 self.minvalue = minvalue
240 240 self.maxvalue = maxvalue
241 241 self.xrangestep = xrangestep
242 242 self.deltax = deltax
243 243
244 244 def changeXRange(self,x):
245 245
246 246 cdatetime = datetime.datetime.utcfromtimestamp(x)
247 247
248 248 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
249 249 if self.xrangestep == 1:
250 250 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
251 251
252 252 if self.xrangestep == 2:
253 253 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
254 254
255 255 if self.xrangestep == 3:
256 256 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
257 257
258 258 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
259 259 self.xmax = self.xmin + self.xrangestepinsecs
260 260
261 261 self.figuretitle = "%s %s : %s"%(self.figuretitle,
262 262 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
263 263 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
264 264 return 1
265 265
266 266 return 0
267 267
268 268 def createFrames(self):
269 269 for frame in range(self.nframes):
270 270 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
271 271 self.frameObjList.append(frameObj)
272 272
273 273 class RTIFrame(Frame):
274 274 def __init__(self,drvObj,idframe,colorbar,showprofile):
275 275 self.drvObj = drvObj
276 276 self.idframe = idframe
277 277 self.nplots = 1
278 278
279 279 if showprofile:
280 280 self.nplots += 1
281 281
282 282 self.colorbar = colorbar
283 283 self.showprofile = showprofile
284 284 self.createPlots()
285 285
286 286 def createPlots(self):
287 287 plotObjList = []
288 288
289 289 idplot = 0
290 290 xi, yi, xw, yw = self.getScreenPos(idplot)
291 291
292 292 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
293 293 plotObjList.append(plotObj)
294 294
295 295 if self.showprofile:
296 296 idplot = 1
297 297 xi, yi, xw, yw = self.getScreenPos(idplot)
298 298 type = "pwbox"
299 299 title = ""
300 300 xlabel = "dB"
301 301 ylabel = ""
302 302 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
303 303 plotObjList.append(plotObj)
304 304
305 305 self.plotObjList = plotObjList
306 306
307 307 def getScreenPosMainPlot(self):
308 308 xi = 0.07
309 309 if self.showprofile:
310 310 xw = 0.65
311 311 else:
312 312 xw = 0.9
313 313
314 314 if self.colorbar:
315 315 xw = xw - 0.06
316 316
317 317 yi = 0.20; yw = 0.75
318 318
319 319 return xi, yi, xw, yw
320 320
321 321 def getScreenPosGraph1(self):
322 322 if self.colorbar:
323 323 xi = 0.65 + 0.08
324 324 else:
325 325 xi = 0.9 + 0.05
326 326
327 327 xw = xi + 0.2
328 328
329 329 yi = 0.2; yw = 0.75
330 330
331 331 return xi, yi, xw, yw
332 332
333 333 def plot(self, currenttime, range, data):
334 334 plotObj = self.plotObjList[0]
335 335 plotObj.plot(currenttime,range,data)
336 336
337 337 if self.showprofile:
338 338 plotObj = self.plotObjList[1]
339 339 plotObj.plot(data,range)
340 340
341 341
342 342 class RTIPlot(Plot):
343 343 deltax = None
344 344 deltay = None
345 345 xrange = [None,None]
346 346 xminpos = None
347 347 xmaxpos = None
348 348 xg = None
349 349 yg = None
350 350
351 351 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
352 352 self.drvObj = drvObj
353 353 self.idframe = idframe
354 354 self.idplot = idplot
355 355 self.xi = xi
356 356 self.yi = yi
357 357 self.xw = xw
358 358 self.yw = yw
359 359 self.colorbar = colorbar
360 360
361 361 if self.colorbar:
362 362 cbxi = xw + 0.03
363 363 cbxw = cbxi + 0.03
364 364 cbyi = yi
365 365 cbyw = yw
366 366 self.cbxpos = [cbxi,cbxw]
367 367 self.cbypos = [cbyi,cbyw]
368 368
369 369 self.xpos = [self.xi,self.xw]
370 370 self.ypos = [self.yi,self.yw]
371 371 self.xaxisastime = True
372 372 self.timefmt = "%H:%M"
373 373 self.xopt = "bcnstd"
374 374 self.yopt = "bcnstv"
375 375
376 376 self.szchar = 1.0
377 377 self.title = "Channel %d"%self.idframe
378 378 self.xlabel = "Local Time"
379 379 self.ylabel = "Range (Km)"
380 380
381 381
382 382 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
383 383 self.xmin = xmin
384 384 self.xmax = xmax
385 385 self.ymin = ymin
386 386 self.ymax = ymax
387 387 self.minvalue = minvalue
388 388 self.maxvalue = maxvalue
389 389 self.deltax = deltax
390 390 self.deltay = deltay
391 391 self.colorbar = colorbar
392 392
393 393 def plot(self, currenttime, range, data):
394 394
395 395 if self.xmaxpos == None:
396 396 self.xmaxpos = currenttime
397 397
398 398 if currenttime >= self.xmaxpos:
399 399
400 400 self.xminpos = currenttime
401 401 self.xmaxpos = currenttime + self.deltax
402 402 x = [currenttime]
403 403 y = range
404 404 z = numpy.reshape(data, (1,-1))
405 405 getGrid = True
406 406
407 407 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
408 408
409 409
410 410 class ScopeFigure(Figure):
411 411 overplot = 0
412 412 xw = 700
413 413 yw = 650
414 414 colorbar = None
415 415
416 416 def __init__(self,idfigure,nframes,wintitle,driver):
417 417 colormap = None
418 418 colorbar = False
419 419
420 self.idfigure = idfigure
421 self.nframes = nframes
422 self.wintitle = wintitle
423
424 self.colormap = colormap
425 self.colorbar = colorbar
426 self.driver = driver
427 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar)
428 self.drvObj.driver.setFigure()
429
430 # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args)
420 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
421
431 422
432 423 def getSubplots(self):
433 424 nrows = self.nframes
434 425 ncolumns = 1
435 426 return nrows, ncolumns
436 427
437 428 def createFrames(self):
438 429 for frame in range(self.nframes):
439 430 frameObj = ScopeFrame(self.drvObj,frame + 1)
440 431 self.frameObjList.append(frameObj)
441 432
442 433
443 434 class ScopeFrame(Frame):
444 435 # plotObjList = []
445 436 xlabel = ""
446 437 ylabel = ""
447 438 title = ""
448 439 def __init__(self,drvObj,idframe):
449 440 self.drvObj = drvObj
450 441 self.idframe = idframe
451 442 self.nplots = 1 #nplots/frame
452 443 self.createPlots()
453 444 # Frame.__init__(self, drvObj, idframe)
454 445
455 446 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
456 447 xi = 0.07; xw = 0.9
457 448 yi = 0.20; yw = 0.75
458 449 return xi,yi,xw,yw
459 450
460 451 def createPlots(self):
461 452 plotObjList = []
462 453 for idplot in range(self.nplots):
463 454 xi, yi, xw, yw = self.getScreenPos(idplot)
464 455 type = "scopebox"
465 456 title = "Channel %d"%self.idframe
466 457 xlabel = "range (Km)"
467 458 ylabel = "intensity"
468 459 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
469 460 plotObjList.append(plotObj)
470 461 self.plotObjList = plotObjList
471 462 # self.plotObjList.append(plotObj)
472 463
473 464 def plot(self, x, y, z=None):
474 465 for plotObj in self.plotObjList:
475 466 plotObj.plot(x, y)
476 467
477 468
478 469 class Plot1D(Plot):
479 470 # type, title, xlabel, ylabel
480 471 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
481 472 self.drvObj = drvObj
482 473 self.idframe = idframe
483 474 self.idplot = idplot
484 475 self.xi = xi
485 476 self.yi = yi
486 477 self.xw = xw
487 478 self.yw = yw
488 479 self.xpos = [self.xi,self.xw]
489 480 self.ypos = [self.yi,self.yw]
490 481 self.xaxisastime = False
491 482 self.timefmt = None
492 483 self.xopt = "bcnst"
493 484 self.yopt = "bcnstv"
494 485 self.szchar = 1.0
495 486 self.type = type
496 487 self.title = title
497 488 self.xlabel = xlabel
498 489 self.ylabel = ylabel
499 490
500 491
501 492
502 493 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
503 494 if self.type == "pwbox":
504 495 self.xmin = minvalue
505 496 self.xmax = maxvalue
506 497 self.ymin = ymin
507 498 self.ymax = ymax
508 499 self.minvalue = minvalue
509 500 self.maxvalue = maxvalue
510 501
511 502 else:
512 503 self.xmin = xmin
513 504 self.xmax = xmax
514 505 self.ymin = ymin
515 506 self.ymax = ymax
516 507 self.minvalue = minvalue
517 508 self.maxvalue = maxvalue
518 509
519 510 self.colorbar = False
520 511
521 512 def plot(self,x,y):
522 513 if y.dtype == "complex128":
523 514 color="blue"
524 515 self.plotBasicLine(x, y.real, color)
525 516 color="red"
526 517 self.plotBasicLine(x, y.imag, color)
527 518 else:
528 519 color="blue"
529 520 self.plotBasicLine(x, y, color)
General Comments 0
You need to be logged in to leave comments. Login now