##// END OF EJS Templates
Nueva clase de ploteo SNRPlot
Daniel Valdez -
r469:b302bf20d2ac
parent child
Show More
@@ -212,6 +212,226 class CrossSpectraPlot(Figure):
212 212
213 213 self.counter_imagwr = 0
214 214
215 class SNRPlot(Figure):
216
217 __isConfig = None
218 __nsubplots = None
219
220 WIDTHPROF = None
221 HEIGHTPROF = None
222 PREFIX = 'snr'
223
224 def __init__(self):
225
226 self.timerange = 2*60*60
227 self.__isConfig = False
228 self.__nsubplots = 1
229
230 self.WIDTH = 800
231 self.HEIGHT = 150
232 self.WIDTHPROF = 120
233 self.HEIGHTPROF = 0
234 self.counter_imagwr = 0
235
236 self.PLOT_CODE = 0
237 self.FTP_WEI = None
238 self.EXP_CODE = None
239 self.SUB_EXP_CODE = None
240 self.PLOT_POS = None
241
242 def getSubplots(self):
243
244 ncol = 1
245 nrow = self.nplots
246
247 return nrow, ncol
248
249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
250
251 self.__showprofile = showprofile
252 self.nplots = nplots
253
254 ncolspan = 1
255 colspan = 1
256 if showprofile:
257 ncolspan = 7
258 colspan = 6
259 self.__nsubplots = 2
260
261 self.createFigure(id = id,
262 wintitle = wintitle,
263 widthplot = self.WIDTH + self.WIDTHPROF,
264 heightplot = self.HEIGHT + self.HEIGHTPROF,
265 show=show)
266
267 nrow, ncol = self.getSubplots()
268
269 counter = 0
270 for y in range(nrow):
271 for x in range(ncol):
272
273 if counter >= self.nplots:
274 break
275
276 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
277
278 if showprofile:
279 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
280
281 counter += 1
282
283 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
284 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
285 timerange=None,
286 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
287 server=None, folder=None, username=None, password=None,
288 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
289
290 """
291
292 Input:
293 dataOut :
294 id :
295 wintitle :
296 channelList :
297 showProfile :
298 xmin : None,
299 xmax : None,
300 ymin : None,
301 ymax : None,
302 zmin : None,
303 zmax : None
304 """
305
306 if channelList == None:
307 channelIndexList = dataOut.channelIndexList
308 else:
309 channelIndexList = []
310 for channel in channelList:
311 if channel not in dataOut.channelList:
312 raise ValueError, "Channel %d is not in dataOut.channelList"
313 channelIndexList.append(dataOut.channelList.index(channel))
314
315 if timerange != None:
316 self.timerange = timerange
317
318 tmin = None
319 tmax = None
320 factor = dataOut.normFactor
321 x = dataOut.getTimeRange()
322 y = dataOut.getHeiRange()
323
324 z = dataOut.data_spc[channelIndexList,:,:]/factor
325 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 avg = numpy.average(z, axis=1)
327
328 avgdB = 10.*numpy.log10(avg)
329
330 noise = dataOut.getNoise()/factor
331 noisedB = 10.*numpy.log10(noise)
332
333 SNR = numpy.transpose(numpy.divide(avg.T,noise))
334
335 SNR_dB = 10.*numpy.log10(SNR)
336
337 #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB))
338
339 # thisDatetime = dataOut.datatime
340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
341 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
342 xlabel = ""
343 ylabel = "Range (Km)"
344
345 if not self.__isConfig:
346
347 nplots = len(channelIndexList)
348
349 self.setup(id=id,
350 nplots=nplots,
351 wintitle=wintitle,
352 showprofile=showprofile,
353 show=show)
354
355 tmin, tmax = self.getTimeLim(x, xmin, xmax)
356 if ymin == None: ymin = numpy.nanmin(y)
357 if ymax == None: ymax = numpy.nanmax(y)
358 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
359 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
360
361 self.FTP_WEI = ftp_wei
362 self.EXP_CODE = exp_code
363 self.SUB_EXP_CODE = sub_exp_code
364 self.PLOT_POS = plot_pos
365
366 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
367 self.__isConfig = True
368
369
370 self.setWinTitle(title)
371
372 for i in range(self.nplots):
373 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
374 axes = self.axesList[i*self.__nsubplots]
375 zdB = SNR_dB[i].reshape((1,-1))
376 axes.pcolorbuffer(x, y, zdB,
377 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
378 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
379 ticksize=9, cblabel='', cbsize="1%")
380
381 # if self.__showprofile:
382 # axes = self.axesList[i*self.__nsubplots +1]
383 # axes.pline(avgdB[i], y,
384 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
385 # xlabel='dB', ylabel='', title='',
386 # ytick_visible=False,
387 # grid='x')
388 #
389 self.draw()
390
391 if lastone:
392 if dataOut.blocknow >= dataOut.last_block:
393 if figfile == None:
394 figfile = self.getFilename(name = self.name)
395 self.saveFigure(figpath, figfile)
396
397 if (save and not(lastone)):
398
399 self.counter_imagwr += 1
400 if (self.counter_imagwr==wr_period):
401 if figfile == None:
402 figfile = self.getFilename(name = self.name)
403 self.saveFigure(figpath, figfile)
404
405 if ftp:
406 #provisionalmente envia archivos en el formato de la web en tiempo real
407 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
408 path = '%s%03d' %(self.PREFIX, self.id)
409 ftp_file = os.path.join(path,'ftp','%s.png'%name)
410 self.saveFigure(figpath, ftp_file)
411 ftp_filename = os.path.join(figpath,ftp_file)
412 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
413 self.counter_imagwr = 0
414
415 self.counter_imagwr = 0
416
417 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
418
419 self.__isConfig = False
420
421 if lastone:
422 if figfile == None:
423 figfile = self.getFilename(name = self.name)
424 self.saveFigure(figpath, figfile)
425
426 if ftp:
427 #provisionalmente envia archivos en el formato de la web en tiempo real
428 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
429 path = '%s%03d' %(self.PREFIX, self.id)
430 ftp_file = os.path.join(path,'ftp','%s.png'%name)
431 self.saveFigure(figpath, ftp_file)
432 ftp_filename = os.path.join(figpath,ftp_file)
433 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
434
215 435
216 436 class RTIPlot(Figure):
217 437
General Comments 0
You need to be logged in to leave comments. Login now