##// END OF EJS Templates
Update and fix plot modules #TODO: correlation & spectraheis
Juan C. Espinoza -
r1285:7f395116f8a5
parent child
Show More
@@ -9,6 +9,7 import numpy
9 import datetime
9 import datetime
10 import json
10 import json
11
11
12 import schainpy.admin
12 from schainpy.utils import log
13 from schainpy.utils import log
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
14 from .jroheaderIO import SystemHeader, RadarControllerHeader
14
15
@@ -142,6 +143,10 class GenericData(object):
142
143
143 return self.flagNoData
144 return self.flagNoData
144
145
146 def isReady(self):
147
148 return not self.flagNoData
149
145
150
146 class JROData(GenericData):
151 class JROData(GenericData):
147
152
@@ -526,7 +531,7 class Spectra(JROData):
526 def getFreqRangeTimeResponse(self, extrapoints=0):
531 def getFreqRangeTimeResponse(self, extrapoints=0):
527
532
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
533 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
529 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
534 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2
530
535
531 return freqrange
536 return freqrange
532
537
@@ -1110,6 +1115,7 class PlotterData(object):
1110 self.exp_code = exp_code
1115 self.exp_code = exp_code
1111 self.buffering = buffering
1116 self.buffering = buffering
1112 self.ready = False
1117 self.ready = False
1118 self.flagNoData = False
1113 self.localtime = False
1119 self.localtime = False
1114 self.data = {}
1120 self.data = {}
1115 self.meta = {}
1121 self.meta = {}
@@ -1207,10 +1213,12 class PlotterData(object):
1207 if hasattr(dataOut, 'meta'):
1213 if hasattr(dataOut, 'meta'):
1208 self.meta.update(dataOut.meta)
1214 self.meta.update(dataOut.meta)
1209
1215
1210 self.pairs = dataOut.pairsList
1216 if hasattr(dataOut, 'pairsList'):
1217 self.pairs = dataOut.pairsList
1218
1211 self.interval = dataOut.getTimeInterval()
1219 self.interval = dataOut.getTimeInterval()
1212 self.localtime = dataOut.useLocalTime
1220 self.localtime = dataOut.useLocalTime
1213 if 'spc' in self.plottypes or 'cspc' in self.plottypes or 'spc_moments' in self.plottypes:
1221 if True in ['spc' in ptype for ptype in self.plottypes]:
1214 self.xrange = (dataOut.getFreqRange(1)/1000.,
1222 self.xrange = (dataOut.getFreqRange(1)/1000.,
1215 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1223 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1216 self.factor = dataOut.normFactor
1224 self.factor = dataOut.normFactor
@@ -1219,7 +1227,7 class PlotterData(object):
1219 self.__times.append(tm)
1227 self.__times.append(tm)
1220
1228
1221 for plot in self.plottypes:
1229 for plot in self.plottypes:
1222 if plot in ('spc', 'spc_moments'):
1230 if plot in ('spc', 'spc_moments', 'spc_cut'):
1223 z = dataOut.data_spc/dataOut.normFactor
1231 z = dataOut.data_spc/dataOut.normFactor
1224 buffer = 10*numpy.log10(z)
1232 buffer = 10*numpy.log10(z)
1225 if plot == 'cspc':
1233 if plot == 'cspc':
@@ -1227,7 +1235,7 class PlotterData(object):
1227 buffer = (dataOut.data_spc, dataOut.data_cspc)
1235 buffer = (dataOut.data_spc, dataOut.data_cspc)
1228 if plot == 'noise':
1236 if plot == 'noise':
1229 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1237 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1230 if plot == 'rti':
1238 if plot in ('rti', 'spcprofile'):
1231 buffer = dataOut.getPower()
1239 buffer = dataOut.getPower()
1232 if plot == 'snr_db':
1240 if plot == 'snr_db':
1233 buffer = dataOut.data_SNR
1241 buffer = dataOut.data_SNR
@@ -1271,6 +1279,10 class PlotterData(object):
1271 else:
1279 else:
1272 self.channels = dataOut.channelList
1280 self.channels = dataOut.channelList
1273
1281
1282 if buffer is None:
1283 self.flagNoData = True
1284 raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key))
1285
1274 def normalize_heights(self):
1286 def normalize_heights(self):
1275 '''
1287 '''
1276 Ensure same-dimension of the data for different heighList
1288 Ensure same-dimension of the data for different heighList
@@ -3,4 +3,3 from .jroplot_spectra import *
3 from .jroplot_heispectra import *
3 from .jroplot_heispectra import *
4 from .jroplot_correlation import *
4 from .jroplot_correlation import *
5 from .jroplot_parameters import *
5 from .jroplot_parameters import *
6 from .jroplot_data import *
@@ -148,12 +148,11 class Plot(Operation):
148 CODE = 'Figure'
148 CODE = 'Figure'
149 colormap = 'jet'
149 colormap = 'jet'
150 bgcolor = 'white'
150 bgcolor = 'white'
151 buffering = True
151 __missing = 1E30
152 __missing = 1E30
152
153
153 __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax',
154 __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title',
154 'zlimits', 'xlabel', 'ylabel', 'xaxis', 'cb_label', 'title',
155 'showprofile']
155 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure',
156 'showprofile', 'decimation', 'pause']
157
156
158 def __init__(self):
157 def __init__(self):
159
158
@@ -163,6 +162,8 class Plot(Operation):
163 self.save_counter = 1
162 self.save_counter = 1
164 self.sender_counter = 1
163 self.sender_counter = 1
165 self.data = None
164 self.data = None
165 self.firsttime = True
166 self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2}
166
167
167 def __fmtTime(self, x, pos):
168 def __fmtTime(self, x, pos):
168 '''
169 '''
@@ -221,11 +222,11 class Plot(Operation):
221 self.pause = kwargs.get('pause', False)
222 self.pause = kwargs.get('pause', False)
222 self.save_code = kwargs.get('save_code', None)
223 self.save_code = kwargs.get('save_code', None)
223 self.realtime = kwargs.get('realtime', True)
224 self.realtime = kwargs.get('realtime', True)
224 self.buffering = kwargs.get('buffering', True)
225 self.throttle = kwargs.get('throttle', 0)
225 self.throttle = kwargs.get('throttle', 0)
226 self.exp_code = kwargs.get('exp_code', None)
226 self.exp_code = kwargs.get('exp_code', None)
227 self.plot_server = kwargs.get('plot_server', False)
227 self.plot_server = kwargs.get('plot_server', False)
228 self.sender_period = kwargs.get('sender_period', 1)
228 self.sender_period = kwargs.get('sender_period', 1)
229 self.height_index = kwargs.get('height_index', None)
229 self.__throttle_plot = apply_throttle(self.throttle)
230 self.__throttle_plot = apply_throttle(self.throttle)
230 self.data = PlotterData(
231 self.data = PlotterData(
231 self.CODE, self.throttle, self.exp_code, self.buffering, snr=self.showSNR)
232 self.CODE, self.throttle, self.exp_code, self.buffering, snr=self.showSNR)
@@ -305,106 +306,7 class Plot(Operation):
305 else:
306 else:
306 cmap = plt.get_cmap(self.colormap)
307 cmap = plt.get_cmap(self.colormap)
307 cmap.set_bad(self.bgcolor, 1.)
308 cmap.set_bad(self.bgcolor, 1.)
308 self.cmaps.append(cmap)
309 self.cmaps.append(cmap)
309
310 for fig in self.figures:
311 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
312 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
313 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
314 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
315 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
316
317 def OnKeyPress(self, event):
318 '''
319 Event for pressing keys (up, down) change colormap
320 '''
321 ax = event.inaxes
322 if ax in self.axes:
323 if event.key == 'down':
324 ax.index += 1
325 elif event.key == 'up':
326 ax.index -= 1
327 if ax.index < 0:
328 ax.index = len(CMAPS) - 1
329 elif ax.index == len(CMAPS):
330 ax.index = 0
331 cmap = CMAPS[ax.index]
332 ax.cbar.set_cmap(cmap)
333 ax.cbar.draw_all()
334 ax.plt.set_cmap(cmap)
335 ax.cbar.patch.figure.canvas.draw()
336 self.colormap = cmap.name
337
338 def OnBtnScroll(self, event):
339 '''
340 Event for scrolling, scale figure
341 '''
342 cb_ax = event.inaxes
343 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
344 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
345 pt = ax.cbar.ax.bbox.get_points()[:, 1]
346 nrm = ax.cbar.norm
347 vmin, vmax, p0, p1, pS = (
348 nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
349 scale = 2 if event.step == 1 else 0.5
350 point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0)
351 ax.cbar.norm.vmin = point - scale * (point - vmin)
352 ax.cbar.norm.vmax = point - scale * (point - vmax)
353 ax.plt.set_norm(ax.cbar.norm)
354 ax.cbar.draw_all()
355 ax.cbar.patch.figure.canvas.draw()
356
357 def onBtnPress(self, event):
358 '''
359 Event for mouse button press
360 '''
361 cb_ax = event.inaxes
362 if cb_ax is None:
363 return
364
365 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
366 cb_ax.press = event.x, event.y
367 else:
368 cb_ax.press = None
369
370 def onMotion(self, event):
371 '''
372 Event for move inside colorbar
373 '''
374 cb_ax = event.inaxes
375 if cb_ax is None:
376 return
377 if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]:
378 return
379 if cb_ax.press is None:
380 return
381
382 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
383 xprev, yprev = cb_ax.press
384 dx = event.x - xprev
385 dy = event.y - yprev
386 cb_ax.press = event.x, event.y
387 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
388 perc = 0.03
389
390 if event.button == 1:
391 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
392 ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy)
393 elif event.button == 3:
394 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
395 ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy)
396
397 ax.cbar.draw_all()
398 ax.plt.set_norm(ax.cbar.norm)
399 ax.cbar.patch.figure.canvas.draw()
400
401 def onBtnRelease(self, event):
402 '''
403 Event for mouse button release
404 '''
405 cb_ax = event.inaxes
406 if cb_ax is not None:
407 cb_ax.press = None
408
310
409 def __add_axes(self, ax, size='30%', pad='8%'):
311 def __add_axes(self, ax, size='30%', pad='8%'):
410 '''
312 '''
@@ -567,12 +469,17 class Plot(Operation):
567 ax.set_yticks(numpy.arange(0, 90, 20))
469 ax.set_yticks(numpy.arange(0, 90, 20))
568 ax.yaxis.labelpad = 40
470 ax.yaxis.labelpad = 40
569
471
472 if self.firsttime:
473 for n, fig in enumerate(self.figures):
474 fig.subplots_adjust(**self.plots_adjust)
475 self.firsttime = False
476
570 def clear_figures(self):
477 def clear_figures(self):
571 '''
478 '''
572 Reset axes for redraw plots
479 Reset axes for redraw plots
573 '''
480 '''
574
481
575 for ax in self.axes:
482 for ax in self.axes+self.pf_axes+self.cb_axes:
576 ax.clear()
483 ax.clear()
577 ax.firsttime = True
484 ax.firsttime = True
578 if ax.cbar:
485 if ax.cbar:
@@ -583,29 +490,22 class Plot(Operation):
583 Main function to plot, format and save figures
490 Main function to plot, format and save figures
584 '''
491 '''
585
492
586 try:
493 self.plot()
587 self.plot()
494 self.format()
588 self.format()
495
589 except Exception as e:
590 log.warning('{} Plot could not be updated... check data'.format(
591 self.CODE), self.name)
592 log.error(str(e), '')
593 return
594
595 for n, fig in enumerate(self.figures):
496 for n, fig in enumerate(self.figures):
596 if self.nrows == 0 or self.nplots == 0:
497 if self.nrows == 0 or self.nplots == 0:
597 log.warning('No data', self.name)
498 log.warning('No data', self.name)
598 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
499 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
599 fig.canvas.manager.set_window_title(self.CODE)
500 fig.canvas.manager.set_window_title(self.CODE)
600 continue
501 continue
601
502
602 fig.tight_layout()
603 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
503 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
604 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
504 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
605 fig.canvas.draw()
505 fig.canvas.draw()
606 if self.show:
506 if self.show:
607 fig.show()
507 fig.show()
608 # figpause(0.1)
508 figpause(0.01)
609
509
610 if self.save:
510 if self.save:
611 self.save_figure(n)
511 self.save_figure(n)
@@ -727,7 +627,7 class Plot(Operation):
727 '''
627 '''
728 Main plotting routine
628 Main plotting routine
729 '''
629 '''
730
630
731 if self.isConfig is False:
631 if self.isConfig is False:
732 self.__setup(**kwargs)
632 self.__setup(**kwargs)
733
633
@@ -792,9 +692,9 class Plot(Operation):
792
692
793 def close(self):
693 def close(self):
794
694
795 if self.data:
695 if not self.data.flagNoData:
796 self.save_counter = self.save_period
696 self.save_counter = self.save_period
797 self.__plot()
697 self.__plot()
798 if self.data and self.pause:
698 if not self.data.flagNoData and self.pause:
799 figpause(10)
699 figpause(10)
800
700
@@ -2,10 +2,10 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5 from schainpy.model import *
5 from schainpy.model.graphics.jroplot_base import Plot
6 from .figure import Figure, isRealtime
7
6
8 class CorrelationPlot_(Figure):
7
8 class CorrelationPlot(Plot):
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
@@ -7,13 +7,10 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from .figure import Figure, isRealtime
10 from schainpy.model.graphics.jroplot_base import Plot
11 from .plotting_codes import *
12 from schainpy.model.proc.jroproc_base import MPDecorator
13
11
14
12
15 @MPDecorator
13 class SpectraHeisScope(Plot):
16 class SpectraHeisScope_(Figure):
17
14
18
15
19 isConfig = None
16 isConfig = None
@@ -25,7 +22,7 class SpectraHeisScope_(Figure):
25
22
26 def __init__(self):#, **kwargs):
23 def __init__(self):#, **kwargs):
27
24
28 Figure.__init__(self)#, **kwargs)
25 Plot.__init__(self)#, **kwargs)
29 self.isConfig = False
26 self.isConfig = False
30 self.__nsubplots = 1
27 self.__nsubplots = 1
31
28
@@ -181,8 +178,8 class SpectraHeisScope_(Figure):
181
178
182 return dataOut
179 return dataOut
183
180
184 @MPDecorator
181
185 class RTIfromSpectraHeis_(Figure):
182 class RTIfromSpectraHeis(Plot):
186
183
187 isConfig = None
184 isConfig = None
188 __nsubplots = None
185 __nsubplots = None
@@ -190,7 +187,7 class RTIfromSpectraHeis_(Figure):
190 PREFIX = 'rtinoise'
187 PREFIX = 'rtinoise'
191
188
192 def __init__(self):#, **kwargs):
189 def __init__(self):#, **kwargs):
193 Figure.__init__(self)#, **kwargs)
190 Plot.__init__(self)#, **kwargs)
194 self.timerange = 24*60*60
191 self.timerange = 24*60*60
195 self.isConfig = False
192 self.isConfig = False
196 self.__nsubplots = 1
193 self.__nsubplots = 1
This diff has been collapsed as it changes many lines, (2633 lines changed) Show them Hide them
@@ -1,2394 +1,341
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
5 from .figure import Figure, isRealtime, isTimeInHourRange
6 from .plotting_codes import *
7 from schainpy.model.proc.jroproc_base import MPDecorator
8 from schainpy.utils import log
9
10 class ParamLine_(Figure):
11
12 isConfig = None
13
14 def __init__(self):
15
16 self.isConfig = False
17 self.WIDTH = 300
18 self.HEIGHT = 200
19 self.counter_imagwr = 0
20
21 def getSubplots(self):
22
23 nrow = self.nplots
24 ncol = 3
25 return nrow, ncol
26
27 def setup(self, id, nplots, wintitle, show):
28
29 self.nplots = nplots
30
31 self.createFigure(id=id,
32 wintitle=wintitle,
33 show=show)
34
35 nrow,ncol = self.getSubplots()
36 colspan = 3
37 rowspan = 1
38
39 for i in range(nplots):
40 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
41
42 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
43 yreal = y[channelIndexList,:].real
44 yimag = y[channelIndexList,:].imag
45
46 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
47 xlabel = "Range (Km)"
48 ylabel = "Intensity - IQ"
49
50 if not self.isConfig:
51 nplots = len(channelIndexList)
52
53 self.setup(id=id,
54 nplots=nplots,
55 wintitle='',
56 show=show)
57
58 if xmin == None: xmin = numpy.nanmin(x)
59 if xmax == None: xmax = numpy.nanmax(x)
60 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
61 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
62
63 self.isConfig = True
64
65 self.setWinTitle(title)
66
67 for i in range(len(self.axesList)):
68 title = "Channel %d" %(i)
69 axes = self.axesList[i]
70
71 axes.pline(x, yreal[i,:],
72 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
73 xlabel=xlabel, ylabel=ylabel, title=title)
74
75 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
76
77 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
78 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
79 yreal = y.real
80
81 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
82 xlabel = "Range (Km)"
83 ylabel = "Intensity"
84
85 if not self.isConfig:
86 nplots = len(channelIndexList)
87
88 self.setup(id=id,
89 nplots=nplots,
90 wintitle='',
91 show=show)
92
93 if xmin == None: xmin = numpy.nanmin(x)
94 if xmax == None: xmax = numpy.nanmax(x)
95 if ymin == None: ymin = numpy.nanmin(yreal)
96 if ymax == None: ymax = numpy.nanmax(yreal)
97
98 self.isConfig = True
99
100 self.setWinTitle(title)
101
102 for i in range(len(self.axesList)):
103 title = "Channel %d" %(i)
104 axes = self.axesList[i]
105 ychannel = yreal[i,:]
106 axes.pline(x, ychannel,
107 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
108 xlabel=xlabel, ylabel=ylabel, title=title)
109
110
111 def run(self, dataOut, id, wintitle="", channelList=None,
112 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
113 figpath='./', figfile=None, show=True, wr_period=1,
114 ftp=False, server=None, folder=None, username=None, password=None):
115
116 """
117
118 Input:
119 dataOut :
120 id :
121 wintitle :
122 channelList :
123 xmin : None,
124 xmax : None,
125 ymin : None,
126 ymax : None,
127 """
128
129 if channelList == None:
130 channelIndexList = dataOut.channelIndexList
131 else:
132 channelIndexList = []
133 for channel in channelList:
134 if channel not in dataOut.channelList:
135 raise ValueError("Channel %d is not in dataOut.channelList" % channel)
136 channelIndexList.append(dataOut.channelList.index(channel))
137
138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
139
140 y = dataOut.RR
141
142 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
143 xlabel = "Range (Km)"
144 ylabel = "Intensity"
145
146 if not self.isConfig:
147 nplots = len(channelIndexList)
148
149 self.setup(id=id,
150 nplots=nplots,
151 wintitle='',
152 show=show)
153
154 if xmin == None: xmin = numpy.nanmin(x)
155 if xmax == None: xmax = numpy.nanmax(x)
156 if ymin == None: ymin = numpy.nanmin(y)
157 if ymax == None: ymax = numpy.nanmax(y)
158
159 self.isConfig = True
160
161 self.setWinTitle(title)
162
163 for i in range(len(self.axesList)):
164 title = "Channel %d" %(i)
165 axes = self.axesList[i]
166 ychannel = y[i,:]
167 axes.pline(x, ychannel,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
169 xlabel=xlabel, ylabel=ylabel, title=title)
170
171
172 self.draw()
173
174 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
175 figfile = self.getFilename(name = str_datetime)
176
177 self.save(figpath=figpath,
178 figfile=figfile,
179 save=save,
180 ftp=ftp,
181 wr_period=wr_period,
182 thisDatetime=thisDatetime)
183
184
185
186 class SpcParamPlot_(Figure):
187
188 isConfig = None
189 __nsubplots = None
190
191 WIDTHPROF = None
192 HEIGHTPROF = None
193 PREFIX = 'SpcParam'
194
195 def __init__(self, **kwargs):
196 Figure.__init__(self, **kwargs)
197 self.isConfig = False
198 self.__nsubplots = 1
199
200 self.WIDTH = 250
201 self.HEIGHT = 250
202 self.WIDTHPROF = 120
203 self.HEIGHTPROF = 0
204 self.counter_imagwr = 0
205
206 self.PLOT_CODE = SPEC_CODE
207
208 self.FTP_WEI = None
209 self.EXP_CODE = None
210 self.SUB_EXP_CODE = None
211 self.PLOT_POS = None
212
213 self.__xfilter_ena = False
214 self.__yfilter_ena = False
215
216 def getSubplots(self):
217
218 ncol = int(numpy.sqrt(self.nplots)+0.9)
219 nrow = int(self.nplots*1./ncol + 0.9)
220
221 return nrow, ncol
222
223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
224
225 self.__showprofile = showprofile
226 self.nplots = nplots
227
228 ncolspan = 1
229 colspan = 1
230 if showprofile:
231 ncolspan = 3
232 colspan = 2
233 self.__nsubplots = 2
234
235 self.createFigure(id = id,
236 wintitle = wintitle,
237 widthplot = self.WIDTH + self.WIDTHPROF,
238 heightplot = self.HEIGHT + self.HEIGHTPROF,
239 show=show)
240
241 nrow, ncol = self.getSubplots()
242
243 counter = 0
244 for y in range(nrow):
245 for x in range(ncol):
246
247 if counter >= self.nplots:
248 break
249
250 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
251
252 if showprofile:
253 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
254
255 counter += 1
256
257 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
258 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
259 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
260 server=None, folder=None, username=None, password=None,
261 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
262 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
263
264 """
265
266 Input:
267 dataOut :
268 id :
269 wintitle :
270 channelList :
271 showProfile :
272 xmin : None,
273 xmax : None,
274 ymin : None,
275 ymax : None,
276 zmin : None,
277 zmax : None
278 """
279 if realtime:
280 if not(isRealtime(utcdatatime = dataOut.utctime)):
281 print('Skipping this plot function')
282 return
283
284 if channelList == None:
285 channelIndexList = dataOut.channelIndexList
286 else:
287 channelIndexList = []
288 for channel in channelList:
289 if channel not in dataOut.channelList:
290 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
291 channelIndexList.append(dataOut.channelList.index(channel))
292
293 # if normFactor is None:
294 # factor = dataOut.normFactor
295 # else:
296 # factor = normFactor
297 if xaxis == "frequency":
298 x = dataOut.spcparam_range[0]
299 xlabel = "Frequency (kHz)"
300
301 elif xaxis == "time":
302 x = dataOut.spcparam_range[1]
303 xlabel = "Time (ms)"
304
305 else:
306 x = dataOut.spcparam_range[2]
307 xlabel = "Velocity (m/s)"
308
309 ylabel = "Range (km)"
310
311 y = dataOut.getHeiRange()
312
313 z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor
314 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
315 zdB = 10*numpy.log10(z)
316
317 avg = numpy.average(z, axis=1)
318 avgdB = 10*numpy.log10(avg)
319
320 noise = dataOut.spc_noise
321 noisedB = 10*numpy.log10(noise)
322
323 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
324 title = wintitle + " Spectra"
325 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
326 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
327
328 if not self.isConfig:
329
4
330 nplots = len(channelIndexList)
5 from schainpy.model.graphics.jroplot_base import Plot, plt
331
6 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot
332 self.setup(id=id,
7 from schainpy.utils import log
333 nplots=nplots,
334 wintitle=wintitle,
335 showprofile=showprofile,
336 show=show)
337
338 if xmin == None: xmin = numpy.nanmin(x)
339 if xmax == None: xmax = numpy.nanmax(x)
340 if ymin == None: ymin = numpy.nanmin(y)
341 if ymax == None: ymax = numpy.nanmax(y)
342 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
343 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
344
345 self.FTP_WEI = ftp_wei
346 self.EXP_CODE = exp_code
347 self.SUB_EXP_CODE = sub_exp_code
348 self.PLOT_POS = plot_pos
349
350 self.isConfig = True
351
352 self.setWinTitle(title)
353
354 for i in range(self.nplots):
355 index = channelIndexList[i]
356 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
357 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
358 if len(dataOut.beam.codeList) != 0:
359 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)
360
8
361 axes = self.axesList[i*self.__nsubplots]
9 EARTH_RADIUS = 6.3710e3
362 axes.pcolor(x, y, zdB[index,:,:],
363 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
364 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
365 ticksize=9, cblabel='')
366
10
367 if self.__showprofile:
368 axes = self.axesList[i*self.__nsubplots +1]
369 axes.pline(avgdB[index,:], y,
370 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
371 xlabel='dB', ylabel='', title='',
372 ytick_visible=False,
373 grid='x')
374
11
375 noiseline = numpy.repeat(noisedB[index], len(y))
12 def ll2xy(lat1, lon1, lat2, lon2):
376 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
377
13
378 self.draw()
14 p = 0.017453292519943295
379
15 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
380 if figfile == None:
16 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
381 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
17 r = 12742 * numpy.arcsin(numpy.sqrt(a))
382 name = str_datetime
18 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
383 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
19 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
384 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
20 theta = -theta + numpy.pi/2
385 figfile = self.getFilename(name)
21 return r*numpy.cos(theta), r*numpy.sin(theta)
386
387 self.save(figpath=figpath,
388 figfile=figfile,
389 save=save,
390 ftp=ftp,
391 wr_period=wr_period,
392 thisDatetime=thisDatetime)
393
394
395
396 class MomentsPlot_(Figure):
397
22
398 isConfig = None
399 __nsubplots = None
400
23
401 WIDTHPROF = None
24 def km2deg(km):
402 HEIGHTPROF = None
25 '''
403 PREFIX = 'prm'
26 Convert distance in km to degrees
404 def __init__(self):
27 '''
405 Figure.__init__(self)
406 self.isConfig = False
407 self.__nsubplots = 1
408
28
409 self.WIDTH = 280
29 return numpy.rad2deg(km/EARTH_RADIUS)
410 self.HEIGHT = 250
411 self.WIDTHPROF = 120
412 self.HEIGHTPROF = 0
413 self.counter_imagwr = 0
414
415 self.PLOT_CODE = MOMENTS_CODE
416
30
417 self.FTP_WEI = None
418 self.EXP_CODE = None
419 self.SUB_EXP_CODE = None
420 self.PLOT_POS = None
421
422 def getSubplots(self):
423
424 ncol = int(numpy.sqrt(self.nplots)+0.9)
425 nrow = int(self.nplots*1./ncol + 0.9)
426
427 return nrow, ncol
428
429 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
430
431 self.__showprofile = showprofile
432 self.nplots = nplots
433
434 ncolspan = 1
435 colspan = 1
436 if showprofile:
437 ncolspan = 3
438 colspan = 2
439 self.__nsubplots = 2
440
441 self.createFigure(id = id,
442 wintitle = wintitle,
443 widthplot = self.WIDTH + self.WIDTHPROF,
444 heightplot = self.HEIGHT + self.HEIGHTPROF,
445 show=show)
446
447 nrow, ncol = self.getSubplots()
448
31
449 counter = 0
450 for y in range(nrow):
451 for x in range(ncol):
452
453 if counter >= self.nplots:
454 break
455
456 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
457
458 if showprofile:
459 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
460
32
461 counter += 1
33 class SpectralMomentsPlot(SpectraPlot):
462
34 '''
463 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
35 Plot for Spectral Moments
464 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
36 '''
465 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
37 CODE = 'spc_moments'
466 server=None, folder=None, username=None, password=None,
38 colormap = 'jet'
467 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
39 plot_name = 'SpectralMoments'
40 plot_type = 'pcolor'
468
41
469 """
470
42
471 Input:
43 class SnrPlot(RTIPlot):
472 dataOut :
44 '''
473 id :
45 Plot for SNR Data
474 wintitle :
46 '''
475 channelList :
476 showProfile :
477 xmin : None,
478 xmax : None,
479 ymin : None,
480 ymax : None,
481 zmin : None,
482 zmax : None
483 """
484
47
485 if dataOut.flagNoData:
48 CODE = 'snr'
486 return None
49 colormap = 'jet'
50 plot_name = 'SNR'
487
51
488 if realtime:
489 if not(isRealtime(utcdatatime = dataOut.utctime)):
490 print('Skipping this plot function')
491 return
492
52
493 if channelList == None:
53 class DopplerPlot(RTIPlot):
494 channelIndexList = dataOut.channelIndexList
54 '''
495 else:
55 Plot for DOPPLER Data (1st moment)
496 channelIndexList = []
56 '''
497 for channel in channelList:
498 if channel not in dataOut.channelList:
499 raise ValueError("Channel %d is not in dataOut.channelList")
500 channelIndexList.append(dataOut.channelList.index(channel))
501
502 factor = dataOut.normFactor
503 x = dataOut.abscissaList
504 y = dataOut.heightList
505
506 z = dataOut.data_pre[channelIndexList,:,:]/factor
507 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
508 avg = numpy.average(z, axis=1)
509 noise = dataOut.noise/factor
510
511 zdB = 10*numpy.log10(z)
512 avgdB = 10*numpy.log10(avg)
513 noisedB = 10*numpy.log10(noise)
514
515 #thisDatetime = dataOut.datatime
516 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
517 title = wintitle + " Parameters"
518 xlabel = "Velocity (m/s)"
519 ylabel = "Range (Km)"
520
521 update_figfile = False
522
523 if not self.isConfig:
524
525 nplots = len(channelIndexList)
526
57
527 self.setup(id=id,
58 CODE = 'dop'
528 nplots=nplots,
59 colormap = 'jet'
529 wintitle=wintitle,
60 plot_name = 'DopplerShift'
530 showprofile=showprofile,
531 show=show)
532
533 if xmin == None: xmin = numpy.nanmin(x)
534 if xmax == None: xmax = numpy.nanmax(x)
535 if ymin == None: ymin = numpy.nanmin(y)
536 if ymax == None: ymax = numpy.nanmax(y)
537 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
538 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
539
540 self.FTP_WEI = ftp_wei
541 self.EXP_CODE = exp_code
542 self.SUB_EXP_CODE = sub_exp_code
543 self.PLOT_POS = plot_pos
544
545 self.isConfig = True
546 update_figfile = True
547
548 self.setWinTitle(title)
549
550 for i in range(self.nplots):
551 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
552 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
553 axes = self.axesList[i*self.__nsubplots]
554 axes.pcolor(x, y, zdB[i,:,:],
555 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
556 xlabel=xlabel, ylabel=ylabel, title=title,
557 ticksize=9, cblabel='')
558 #Mean Line
559 mean = dataOut.data_param[i, 1, :]
560 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
561
562 if self.__showprofile:
563 axes = self.axesList[i*self.__nsubplots +1]
564 axes.pline(avgdB[i], y,
565 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
566 xlabel='dB', ylabel='', title='',
567 ytick_visible=False,
568 grid='x')
569
570 noiseline = numpy.repeat(noisedB[i], len(y))
571 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
572
573 self.draw()
574
575 self.save(figpath=figpath,
576 figfile=figfile,
577 save=save,
578 ftp=ftp,
579 wr_period=wr_period,
580 thisDatetime=thisDatetime)
581
582
583 class SkyMapPlot_(Figure):
584
585 __isConfig = None
586 __nsubplots = None
587
588 WIDTHPROF = None
589 HEIGHTPROF = None
590 PREFIX = 'mmap'
591
592 def __init__(self, **kwargs):
593 Figure.__init__(self, **kwargs)
594 self.isConfig = False
595 self.__nsubplots = 1
596
597 # self.WIDTH = 280
598 # self.HEIGHT = 250
599 self.WIDTH = 600
600 self.HEIGHT = 600
601 self.WIDTHPROF = 120
602 self.HEIGHTPROF = 0
603 self.counter_imagwr = 0
604
605 self.PLOT_CODE = MSKYMAP_CODE
606
607 self.FTP_WEI = None
608 self.EXP_CODE = None
609 self.SUB_EXP_CODE = None
610 self.PLOT_POS = None
611
612 def getSubplots(self):
613
614 ncol = int(numpy.sqrt(self.nplots)+0.9)
615 nrow = int(self.nplots*1./ncol + 0.9)
616
617 return nrow, ncol
618
619 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
620
621 self.__showprofile = showprofile
622 self.nplots = nplots
623
624 ncolspan = 1
625 colspan = 1
626
627 self.createFigure(id = id,
628 wintitle = wintitle,
629 widthplot = self.WIDTH, #+ self.WIDTHPROF,
630 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
631 show=show)
632
633 nrow, ncol = 1,1
634 counter = 0
635 x = 0
636 y = 0
637 self.addAxes(1, 1, 0, 0, 1, 1, True)
638
639 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
640 tmin=0, tmax=24, timerange=None,
641 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
642 server=None, folder=None, username=None, password=None,
643 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
644
645 """
646
647 Input:
648 dataOut :
649 id :
650 wintitle :
651 channelList :
652 showProfile :
653 xmin : None,
654 xmax : None,
655 ymin : None,
656 ymax : None,
657 zmin : None,
658 zmax : None
659 """
660
661 arrayParameters = dataOut.data_param
662 error = arrayParameters[:,-1]
663 indValid = numpy.where(error == 0)[0]
664 finalMeteor = arrayParameters[indValid,:]
665 finalAzimuth = finalMeteor[:,3]
666 finalZenith = finalMeteor[:,4]
667
61
668 x = finalAzimuth*numpy.pi/180
669 y = finalZenith
670 x1 = [dataOut.ltctime, dataOut.ltctime]
671
62
672 #thisDatetime = dataOut.datatime
63 class PowerPlot(RTIPlot):
673 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
64 '''
674 title = wintitle + " Parameters"
65 Plot for Power Data (0 moment)
675 xlabel = "Zonal Zenith Angle (deg) "
66 '''
676 ylabel = "Meridional Zenith Angle (deg)"
677 update_figfile = False
678
67
679 if not self.isConfig:
68 CODE = 'pow'
69 colormap = 'jet'
70 plot_name = 'TotalPower'
680
71
681 nplots = 1
682
72
683 self.setup(id=id,
73 class SpectralWidthPlot(RTIPlot):
684 nplots=nplots,
74 '''
685 wintitle=wintitle,
75 Plot for Spectral Width Data (2nd moment)
686 showprofile=showprofile,
76 '''
687 show=show)
688
77
689 if self.xmin is None and self.xmax is None:
78 CODE = 'width'
690 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
79 colormap = 'jet'
80 plot_name = 'SpectralWidth'
691
81
692 if timerange != None:
693 self.timerange = timerange
694 else:
695 self.timerange = self.xmax - self.xmin
696
82
697 self.FTP_WEI = ftp_wei
83 class SkyMapPlot(Plot):
698 self.EXP_CODE = exp_code
84 '''
699 self.SUB_EXP_CODE = sub_exp_code
85 Plot for meteors detection data
700 self.PLOT_POS = plot_pos
86 '''
701 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
702 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
703 self.isConfig = True
704 update_figfile = True
705
87
706 self.setWinTitle(title)
88 CODE = 'param'
707
89
708 i = 0
90 def setup(self):
709 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
710
91
711 axes = self.axesList[i*self.__nsubplots]
92 self.ncols = 1
712 nevents = axes.x_buffer.shape[0] + x.shape[0]
93 self.nrows = 1
713 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
94 self.width = 7.2
714 axes.polar(x, y,
95 self.height = 7.2
715 title=title, xlabel=xlabel, ylabel=ylabel,
96 self.nplots = 1
716 ticksize=9, cblabel='')
97 self.xlabel = 'Zonal Zenith Angle (deg)'
98 self.ylabel = 'Meridional Zenith Angle (deg)'
99 self.polar = True
100 self.ymin = -180
101 self.ymax = 180
102 self.colorbar = False
717
103
718 self.draw()
104 def plot(self):
719
720 self.save(figpath=figpath,
721 figfile=figfile,
722 save=save,
723 ftp=ftp,
724 wr_period=wr_period,
725 thisDatetime=thisDatetime,
726 update_figfile=update_figfile)
727
728 if dataOut.ltctime >= self.xmax:
729 self.isConfigmagwr = wr_period
730 self.isConfig = False
731 update_figfile = True
732 axes.__firsttime = True
733 self.xmin += self.timerange
734 self.xmax += self.timerange
735
736
737
738 @MPDecorator
739 class WindProfilerPlot_(Figure):
740
741 __isConfig = None
742 __nsubplots = None
743
744 WIDTHPROF = None
745 HEIGHTPROF = None
746 PREFIX = 'wind'
747
748 def __init__(self):
749 Figure.__init__(self)
750 self.timerange = None
751 self.isConfig = False
752 self.__nsubplots = 1
753
754 self.WIDTH = 800
755 self.HEIGHT = 300
756 self.WIDTHPROF = 120
757 self.HEIGHTPROF = 0
758 self.counter_imagwr = 0
759
760 self.PLOT_CODE = WIND_CODE
761
762 self.FTP_WEI = None
763 self.EXP_CODE = None
764 self.SUB_EXP_CODE = None
765 self.PLOT_POS = None
766 self.tmin = None
767 self.tmax = None
768
769 self.xmin = None
770 self.xmax = None
771
772 self.figfile = None
773
774 def getSubplots(self):
775
776 ncol = 1
777 nrow = self.nplots
778
779 return nrow, ncol
780
781 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
782
783 self.__showprofile = showprofile
784 self.nplots = nplots
785
786 ncolspan = 1
787 colspan = 1
788
789 self.createFigure(id = id,
790 wintitle = wintitle,
791 widthplot = self.WIDTH + self.WIDTHPROF,
792 heightplot = self.HEIGHT + self.HEIGHTPROF,
793 show=show)
794
795 nrow, ncol = self.getSubplots()
796
797 counter = 0
798 for y in range(nrow):
799 if counter >= self.nplots:
800 break
801
802 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
803 counter += 1
804
805 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
806 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
807 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
808 timerange=None, SNRthresh = None,
809 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
810 server=None, folder=None, username=None, password=None,
811 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
812 """
813
814 Input:
815 dataOut :
816 id :
817 wintitle :
818 channelList :
819 showProfile :
820 xmin : None,
821 xmax : None,
822 ymin : None,
823 ymax : None,
824 zmin : None,
825 zmax : None
826 """
827
828 if dataOut.flagNoData:
829 return dataOut
830
831 # if timerange is not None:
832 # self.timerange = timerange
833 #
834 # tmin = None
835 # tmax = None
836
837 x = dataOut.getTimeRange1(dataOut.paramInterval)
838 y = dataOut.heightList
839 z = dataOut.data_output.copy()
840 nplots = z.shape[0] #Number of wind dimensions estimated
841 nplotsw = nplots
842
843
844 #If there is a SNR function defined
845 if dataOut.data_SNR is not None:
846 nplots += 1
847 SNR = dataOut.data_SNR[0]
848 SNRavg = SNR#numpy.average(SNR, axis=0)
849
850 SNRdB = 10*numpy.log10(SNR)
851 SNRavgdB = 10*numpy.log10(SNRavg)
852
853 if SNRthresh == None:
854 SNRthresh = -5.0
855 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
856
857 for i in range(nplotsw):
858 z[i,ind] = numpy.nan
859
860 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
861 #thisDatetime = datetime.datetime.now()
862 title = wintitle + "Wind"
863 xlabel = ""
864 ylabel = "Height (km)"
865 update_figfile = False
866
867 if not self.isConfig:
868
869 self.setup(id=id,
870 nplots=nplots,
871 wintitle=wintitle,
872 showprofile=showprofile,
873 show=show)
874
875 if timerange is not None:
876 self.timerange = timerange
877
878 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
879
880 if ymin == None: ymin = numpy.nanmin(y)
881 if ymax == None: ymax = numpy.nanmax(y)
882
883 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
884 #if numpy.isnan(zmax): zmax = 50
885 if zmin == None: zmin = -zmax
886
887 if nplotsw == 3:
888 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
889 if zmin_ver == None: zmin_ver = -zmax_ver
890
891 if dataOut.data_SNR is not None:
892 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
893 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
894
895
896 self.FTP_WEI = ftp_wei
897 self.EXP_CODE = exp_code
898 self.SUB_EXP_CODE = sub_exp_code
899 self.PLOT_POS = plot_pos
900
901 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
902 self.isConfig = True
903 self.figfile = figfile
904 update_figfile = True
905
906 self.setWinTitle(title)
907
908 if ((self.xmax - x[1]) < (x[1]-x[0])):
909 x[1] = self.xmax
910
911 strWind = ['Zonal', 'Meridional', 'Vertical']
912 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
913 zmaxVector = [zmax, zmax, zmax_ver]
914 zminVector = [zmin, zmin, zmin_ver]
915 windFactor = [1,1,100]
916
917 for i in range(nplotsw):
918
919 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
920 axes = self.axesList[i*self.__nsubplots]
921
922 z1 = z[i,:].reshape((1,-1))*windFactor[i]
923
924 axes.pcolorbuffer(x, y, z1,
925 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
926 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
927 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
928
105
929 if dataOut.data_SNR is not None:
106 arrayParameters = numpy.concatenate(self.data['param'])
930 i += 1
107 error = arrayParameters[:, -1]
931 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
108 indValid = numpy.where(error == 0)[0]
932 axes = self.axesList[i*self.__nsubplots]
109 finalMeteor = arrayParameters[indValid, :]
933 SNRavgdB = SNRavgdB.reshape((1,-1))
110 finalAzimuth = finalMeteor[:, 3]
934 axes.pcolorbuffer(x, y, SNRavgdB,
111 finalZenith = finalMeteor[:, 4]
935 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
936 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
937 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
938
112
939 self.draw()
113 x = finalAzimuth * numpy.pi / 180
114 y = finalZenith
940
115
941 self.save(figpath=figpath,
116 ax = self.axes[0]
942 figfile=figfile,
943 save=save,
944 ftp=ftp,
945 wr_period=wr_period,
946 thisDatetime=thisDatetime,
947 update_figfile=update_figfile)
948
117
949 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
118 if ax.firsttime:
950 self.counter_imagwr = wr_period
119 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
951 self.isConfig = False
952 update_figfile = True
953
954 return dataOut
955
956 @MPDecorator
957 class ParametersPlot_(Figure):
958
959 __isConfig = None
960 __nsubplots = None
961
962 WIDTHPROF = None
963 HEIGHTPROF = None
964 PREFIX = 'param'
965
966 nplots = None
967 nchan = None
968
969 def __init__(self):#, **kwargs):
970 Figure.__init__(self)#, **kwargs)
971 self.timerange = None
972 self.isConfig = False
973 self.__nsubplots = 1
974
975 self.WIDTH = 300
976 self.HEIGHT = 550
977 self.WIDTHPROF = 120
978 self.HEIGHTPROF = 0
979 self.counter_imagwr = 0
980
981 self.PLOT_CODE = RTI_CODE
982
983 self.FTP_WEI = None
984 self.EXP_CODE = None
985 self.SUB_EXP_CODE = None
986 self.PLOT_POS = None
987 self.tmin = None
988 self.tmax = None
989
990 self.xmin = None
991 self.xmax = None
992
993 self.figfile = None
994
995 def getSubplots(self):
996
997 ncol = 1
998 nrow = self.nplots
999
1000 return nrow, ncol
1001
1002 def setup(self, id, nplots, wintitle, show=True):
1003
1004 self.nplots = nplots
1005
1006 ncolspan = 1
1007 colspan = 1
1008
1009 self.createFigure(id = id,
1010 wintitle = wintitle,
1011 widthplot = self.WIDTH + self.WIDTHPROF,
1012 heightplot = self.HEIGHT + self.HEIGHTPROF,
1013 show=show)
1014
1015 nrow, ncol = self.getSubplots()
1016
1017 counter = 0
1018 for y in range(nrow):
1019 for x in range(ncol):
1020
1021 if counter >= self.nplots:
1022 break
1023
1024 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1025
1026 counter += 1
1027
1028 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
1029 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
1030 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
1031 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1032 server=None, folder=None, username=None, password=None,
1033 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
1034 """
1035
1036 Input:
1037 dataOut :
1038 id :
1039 wintitle :
1040 channelList :
1041 showProfile :
1042 xmin : None,
1043 xmax : None,
1044 ymin : None,
1045 ymax : None,
1046 zmin : None,
1047 zmax : None
1048 """
1049 if dataOut.flagNoData:
1050 return dataOut
1051
1052
1053 if HEIGHT is not None:
1054 self.HEIGHT = HEIGHT
1055
1056
1057 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1058 return
1059
1060 if channelList == None:
1061 channelIndexList = list(range(dataOut.data_param.shape[0]))
1062 else:
120 else:
1063 channelIndexList = []
121 ax.plot.set_data(x, y)
1064 for channel in channelList:
122
1065 if channel not in dataOut.channelList:
123 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
1066 raise ValueError("Channel %d is not in dataOut.channelList")
124 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
1067 channelIndexList.append(dataOut.channelList.index(channel))
125 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
1068
126 dt2,
1069 x = dataOut.getTimeRange1(dataOut.paramInterval)
127 len(x))
1070 y = dataOut.getHeiRange()
128 self.titles[0] = title
1071
129
1072 if dataOut.data_param.ndim == 3:
130
1073 z = dataOut.data_param[channelIndexList,paramIndex,:]
131 class ParametersPlot(RTIPlot):
132 '''
133 Plot for data_param object
134 '''
135
136 CODE = 'param'
137 colormap = 'seismic'
138 plot_name = 'Parameters'
139
140 def setup(self):
141 self.xaxis = 'time'
142 self.ncols = 1
143 self.nrows = self.data.shape(self.CODE)[0]
144 self.nplots = self.nrows
145 if self.showSNR:
146 self.nrows += 1
147 self.nplots += 1
148
149 self.ylabel = 'Height [km]'
150 if not self.titles:
151 self.titles = self.data.parameters \
152 if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)]
153 if self.showSNR:
154 self.titles.append('SNR')
155
156 def plot(self):
157 self.data.normalize_heights()
158 self.x = self.data.times
159 self.y = self.data.heights
160 if self.showSNR:
161 self.z = numpy.concatenate(
162 (self.data[self.CODE], self.data['snr'])
163 )
1074 else:
164 else:
1075 z = dataOut.data_param[channelIndexList,:]
165 self.z = self.data[self.CODE]
1076
1077 if showSNR:
1078 #SNR data
1079 SNRarray = dataOut.data_SNR[channelIndexList,:]
1080 SNRdB = 10*numpy.log10(SNRarray)
1081 ind = numpy.where(SNRdB < SNRthresh)
1082 z[ind] = numpy.nan
1083
1084 thisDatetime = dataOut.datatime
1085 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1086 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1087 xlabel = ""
1088 ylabel = "Range (km)"
1089
1090 update_figfile = False
1091
1092 if not self.isConfig:
1093
1094 nchan = len(channelIndexList)
1095 self.nchan = nchan
1096 self.plotFact = 1
1097 nplots = nchan
1098
1099 if showSNR:
1100 nplots = nchan*2
1101 self.plotFact = 2
1102 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1103 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1104
1105 self.setup(id=id,
1106 nplots=nplots,
1107 wintitle=wintitle,
1108 show=show)
1109
1110 if timerange != None:
1111 self.timerange = timerange
1112
1113 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1114
1115 if ymin == None: ymin = numpy.nanmin(y)
1116 if ymax == None: ymax = numpy.nanmax(y)
1117 if zmin == None: zmin = numpy.nanmin(z)
1118 if zmax == None: zmax = numpy.nanmax(z)
1119
1120 self.FTP_WEI = ftp_wei
1121 self.EXP_CODE = exp_code
1122 self.SUB_EXP_CODE = sub_exp_code
1123 self.PLOT_POS = plot_pos
1124
1125 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1126 self.isConfig = True
1127 self.figfile = figfile
1128 update_figfile = True
1129
1130 self.setWinTitle(title)
1131
1132 # for i in range(self.nchan):
1133 # index = channelIndexList[i]
1134 # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1135 # axes = self.axesList[i*self.plotFact]
1136 # z1 = z[i,:].reshape((1,-1))
1137 # axes.pcolorbuffer(x, y, z1,
1138 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1139 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1140 # ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1141 #
1142 # if showSNR:
1143 # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1144 # axes = self.axesList[i*self.plotFact + 1]
1145 # SNRdB1 = SNRdB[i,:].reshape((1,-1))
1146 # axes.pcolorbuffer(x, y, SNRdB1,
1147 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1148 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1149 # ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1150
1151 i=0
1152 index = channelIndexList[i]
1153 title = "Factor de reflectividad Z [dBZ]"
1154 axes = self.axesList[i*self.plotFact]
1155 z1 = z[i,:].reshape((1,-1))
1156 axes.pcolorbuffer(x, y, z1,
1157 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1158 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1159 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1160
1161 if showSNR:
1162 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1163 axes = self.axesList[i*self.plotFact + 1]
1164 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1165 axes.pcolorbuffer(x, y, SNRdB1,
1166 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1167 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1168 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1169
1170 i=1
1171 index = channelIndexList[i]
1172 title = "Velocidad vertical Doppler [m/s]"
1173 axes = self.axesList[i*self.plotFact]
1174 z1 = z[i,:].reshape((1,-1))
1175 axes.pcolorbuffer(x, y, z1,
1176 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10,
1177 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1178 ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r')
1179
1180 if showSNR:
1181 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1182 axes = self.axesList[i*self.plotFact + 1]
1183 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1184 axes.pcolorbuffer(x, y, SNRdB1,
1185 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1186 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1187 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1188
1189 i=2
1190 index = channelIndexList[i]
1191 title = "Intensidad de lluvia [mm/h]"
1192 axes = self.axesList[i*self.plotFact]
1193 z1 = z[i,:].reshape((1,-1))
1194 axes.pcolorbuffer(x, y, z1,
1195 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40,
1196 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1197 ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r')
1198
1199 if showSNR:
1200 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1201 axes = self.axesList[i*self.plotFact + 1]
1202 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1203 axes.pcolorbuffer(x, y, SNRdB1,
1204 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1205 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1206 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1207
1208
1209 self.draw()
1210
1211 if dataOut.ltctime >= self.xmax:
1212 self.counter_imagwr = wr_period
1213 self.isConfig = False
1214 update_figfile = True
1215
1216 self.save(figpath=figpath,
1217 figfile=figfile,
1218 save=save,
1219 ftp=ftp,
1220 wr_period=wr_period,
1221 thisDatetime=thisDatetime,
1222 update_figfile=update_figfile)
1223
1224 return dataOut
1225 @MPDecorator
1226 class Parameters1Plot_(Figure):
1227
1228 __isConfig = None
1229 __nsubplots = None
1230
1231 WIDTHPROF = None
1232 HEIGHTPROF = None
1233 PREFIX = 'prm'
1234
1235 def __init__(self):
1236 Figure.__init__(self)
1237 self.timerange = 2*60*60
1238 self.isConfig = False
1239 self.__nsubplots = 1
1240
1241 self.WIDTH = 800
1242 self.HEIGHT = 180
1243 self.WIDTHPROF = 120
1244 self.HEIGHTPROF = 0
1245 self.counter_imagwr = 0
1246
1247 self.PLOT_CODE = PARMS_CODE
1248
1249 self.FTP_WEI = None
1250 self.EXP_CODE = None
1251 self.SUB_EXP_CODE = None
1252 self.PLOT_POS = None
1253 self.tmin = None
1254 self.tmax = None
1255
1256 self.xmin = None
1257 self.xmax = None
1258
1259 self.figfile = None
1260
1261 def getSubplots(self):
1262
1263 ncol = 1
1264 nrow = self.nplots
1265
1266 return nrow, ncol
1267
1268 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1269
1270 self.__showprofile = showprofile
1271 self.nplots = nplots
1272
1273 ncolspan = 1
1274 colspan = 1
1275
1276 self.createFigure(id = id,
1277 wintitle = wintitle,
1278 widthplot = self.WIDTH + self.WIDTHPROF,
1279 heightplot = self.HEIGHT + self.HEIGHTPROF,
1280 show=show)
1281
1282 nrow, ncol = self.getSubplots()
1283
1284 counter = 0
1285 for y in range(nrow):
1286 for x in range(ncol):
1287
1288 if counter >= self.nplots:
1289 break
1290
1291 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1292
1293 if showprofile:
1294 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1295
1296 counter += 1
1297
1298 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1299 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1300 parameterIndex = None, onlyPositive = False,
1301 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1302 DOP = True,
1303 zlabel = "", parameterName = "", parameterObject = "data_param",
1304 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1305 server=None, folder=None, username=None, password=None,
1306 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1307
166
1308 """
167 self.z = numpy.ma.masked_invalid(self.z)
1309 Input:
1310 dataOut :
1311 id :
1312 wintitle :
1313 channelList :
1314 showProfile :
1315 xmin : None,
1316 xmax : None,
1317 ymin : None,
1318 ymax : None,
1319 zmin : None,
1320 zmax : None
1321 """
1322 if dataOut.flagNoData:
1323 return dataOut
1324
1325 data_param = getattr(dataOut, parameterObject)
1326
168
1327 if channelList == None:
169 if self.decimation is None:
1328 channelIndexList = numpy.arange(data_param.shape[0])
170 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1329 else:
171 else:
1330 channelIndexList = numpy.array(channelList)
172 x, y, z = self.fill_gaps(*self.decimate())
1331
1332 nchan = len(channelIndexList) #Number of channels being plotted
1333
1334 if nchan < 1:
1335 return
1336
1337 nGraphsByChannel = 0
1338
173
1339 if SNR:
174 for n, ax in enumerate(self.axes):
1340 nGraphsByChannel += 1
1341 if DOP:
1342 nGraphsByChannel += 1
1343
175
1344 if nGraphsByChannel < 1:
176 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1345 return
177 self.z[n])
178 self.zmin = self.zmin if self.zmin is not None else numpy.min(
179 self.z[n])
1346
180
1347 nplots = nGraphsByChannel*nchan
181 if ax.firsttime:
182 if self.zlimits is not None:
183 self.zmin, self.zmax = self.zlimits[n]
1348
184
1349 if timerange is not None:
185 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
1350 self.timerange = timerange
186 vmin=self.zmin,
1351
187 vmax=self.zmax,
1352 #tmin = None
188 cmap=self.cmaps[n]
1353 #tmax = None
189 )
1354 if parameterIndex == None:
190 else:
1355 parameterIndex = 1
191 if self.zlimits is not None:
1356
192 self.zmin, self.zmax = self.zlimits[n]
1357 x = dataOut.getTimeRange1(dataOut.paramInterval)
193 ax.collections.remove(ax.collections[0])
1358 y = dataOut.heightList
194 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
1359
195 vmin=self.zmin,
1360 if dataOut.data_param.ndim == 3:
196 vmax=self.zmax,
1361 z = dataOut.data_param[channelIndexList,parameterIndex,:]
197 cmap=self.cmaps[n]
198 )
199
200
201 class OutputPlot(ParametersPlot):
202 '''
203 Plot data_output object
204 '''
205
206 CODE = 'output'
207 colormap = 'seismic'
208 plot_name = 'Output'
209
210
211 class PolarMapPlot(Plot):
212 '''
213 Plot for weather radar
214 '''
215
216 CODE = 'param'
217 colormap = 'seismic'
218
219 def setup(self):
220 self.ncols = 1
221 self.nrows = 1
222 self.width = 9
223 self.height = 8
224 self.mode = self.data.meta['mode']
225 if self.channels is not None:
226 self.nplots = len(self.channels)
227 self.nrows = len(self.channels)
1362 else:
228 else:
1363 z = dataOut.data_param[channelIndexList,:]
229 self.nplots = self.data.shape(self.CODE)[0]
1364
230 self.nrows = self.nplots
1365 if dataOut.data_SNR is not None:
231 self.channels = list(range(self.nplots))
1366 if dataOut.data_SNR.ndim == 2:
232 if self.mode == 'E':
1367 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
233 self.xlabel = 'Longitude'
234 self.ylabel = 'Latitude'
235 else:
236 self.xlabel = 'Range (km)'
237 self.ylabel = 'Height (km)'
238 self.bgcolor = 'white'
239 self.cb_labels = self.data.meta['units']
240 self.lat = self.data.meta['latitude']
241 self.lon = self.data.meta['longitude']
242 self.xmin, self.xmax = float(
243 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
244 self.ymin, self.ymax = float(
245 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
246 # self.polar = True
247
248 def plot(self):
249
250 for n, ax in enumerate(self.axes):
251 data = self.data['param'][self.channels[n]]
252
253 zeniths = numpy.linspace(
254 0, self.data.meta['max_range'], data.shape[1])
255 if self.mode == 'E':
256 azimuths = -numpy.radians(self.data.heights)+numpy.pi/2
257 r, theta = numpy.meshgrid(zeniths, azimuths)
258 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
259 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
260 x = km2deg(x) + self.lon
261 y = km2deg(y) + self.lat
1368 else:
262 else:
1369 SNRavg = dataOut.data_SNR
263 azimuths = numpy.radians(self.data.heights)
1370 SNRdB = 10*numpy.log10(SNRavg)
264 r, theta = numpy.meshgrid(zeniths, azimuths)
1371
265 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
1372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
266 self.y = zeniths
1373 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
267
1374 xlabel = ""
268 if ax.firsttime:
1375 ylabel = "Range (Km)"
269 if self.zlimits is not None:
1376
270 self.zmin, self.zmax = self.zlimits[n]
1377 if onlyPositive:
271 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1378 colormap = "jet"
272 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1379 zmin = 0
273 vmin=self.zmin,
1380 else: colormap = "RdBu_r"
274 vmax=self.zmax,
1381
275 cmap=self.cmaps[n])
1382 if not self.isConfig:
1383
1384 self.setup(id=id,
1385 nplots=nplots,
1386 wintitle=wintitle,
1387 showprofile=showprofile,
1388 show=show)
1389
1390 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1391
1392 if ymin == None: ymin = numpy.nanmin(y)
1393 if ymax == None: ymax = numpy.nanmax(y)
1394 if zmin == None: zmin = numpy.nanmin(z)
1395 if zmax == None: zmax = numpy.nanmax(z)
1396
1397 if SNR:
1398 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1399 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1400
1401 self.FTP_WEI = ftp_wei
1402 self.EXP_CODE = exp_code
1403 self.SUB_EXP_CODE = sub_exp_code
1404 self.PLOT_POS = plot_pos
1405
1406 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1407 self.isConfig = True
1408 self.figfile = figfile
1409
1410 self.setWinTitle(title)
1411
1412 if ((self.xmax - x[1]) < (x[1]-x[0])):
1413 x[1] = self.xmax
1414
1415 for i in range(nchan):
1416
1417 if (SNR and not onlySNR): j = 2*i
1418 else: j = i
1419
1420 j = nGraphsByChannel*i
1421
1422 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1423 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1424
1425 if not onlySNR:
1426 axes = self.axesList[j*self.__nsubplots]
1427 z1 = z[i,:].reshape((1,-1))
1428 axes.pcolorbuffer(x, y, z1,
1429 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1430 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1431 ticksize=9, cblabel=zlabel, cbsize="1%")
1432
1433 if DOP:
1434 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1435
1436 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1437 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1438 axes = self.axesList[j]
1439 z1 = z[i,:].reshape((1,-1))
1440 axes.pcolorbuffer(x, y, z1,
1441 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1442 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1443 ticksize=9, cblabel=zlabel, cbsize="1%")
1444
1445 if SNR:
1446 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1447 axes = self.axesList[(j)*self.__nsubplots]
1448 if not onlySNR:
1449 axes = self.axesList[(j + 1)*self.__nsubplots]
1450
1451 axes = self.axesList[(j + nGraphsByChannel-1)]
1452 z1 = SNRdB.reshape((1,-1))
1453 axes.pcolorbuffer(x, y, z1,
1454 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1455 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1456 ticksize=9, cblabel=zlabel, cbsize="1%")
1457
1458
1459
1460 self.draw()
1461
1462 if x[1] >= self.axesList[0].xmax:
1463 self.counter_imagwr = wr_period
1464 self.isConfig = False
1465 self.figfile = None
1466
1467 self.save(figpath=figpath,
1468 figfile=figfile,
1469 save=save,
1470 ftp=ftp,
1471 wr_period=wr_period,
1472 thisDatetime=thisDatetime,
1473 update_figfile=False)
1474 return dataOut
1475
1476 class SpectralFittingPlot_(Figure):
1477
1478 __isConfig = None
1479 __nsubplots = None
1480
1481 WIDTHPROF = None
1482 HEIGHTPROF = None
1483 PREFIX = 'prm'
1484
1485
1486 N = None
1487 ippSeconds = None
1488
1489 def __init__(self, **kwargs):
1490 Figure.__init__(self, **kwargs)
1491 self.isConfig = False
1492 self.__nsubplots = 1
1493
1494 self.PLOT_CODE = SPECFIT_CODE
1495
1496 self.WIDTH = 450
1497 self.HEIGHT = 250
1498 self.WIDTHPROF = 0
1499 self.HEIGHTPROF = 0
1500
1501 def getSubplots(self):
1502
1503 ncol = int(numpy.sqrt(self.nplots)+0.9)
1504 nrow = int(self.nplots*1./ncol + 0.9)
1505
1506 return nrow, ncol
1507
1508 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1509
1510 showprofile = False
1511 self.__showprofile = showprofile
1512 self.nplots = nplots
1513
1514 ncolspan = 5
1515 colspan = 4
1516 if showprofile:
1517 ncolspan = 5
1518 colspan = 4
1519 self.__nsubplots = 2
1520
1521 self.createFigure(id = id,
1522 wintitle = wintitle,
1523 widthplot = self.WIDTH + self.WIDTHPROF,
1524 heightplot = self.HEIGHT + self.HEIGHTPROF,
1525 show=show)
1526
1527 nrow, ncol = self.getSubplots()
1528
1529 counter = 0
1530 for y in range(nrow):
1531 for x in range(ncol):
1532
1533 if counter >= self.nplots:
1534 break
1535
1536 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1537
1538 if showprofile:
1539 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1540
1541 counter += 1
1542
1543 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1544 xmin=None, xmax=None, ymin=None, ymax=None,
1545 save=False, figpath='./', figfile=None, show=True):
1546
1547 """
1548
1549 Input:
1550 dataOut :
1551 id :
1552 wintitle :
1553 channelList :
1554 showProfile :
1555 xmin : None,
1556 xmax : None,
1557 zmin : None,
1558 zmax : None
1559 """
1560
1561 if cutHeight==None:
1562 h=270
1563 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1564 cutHeight = dataOut.heightList[heightindex]
1565
1566 factor = dataOut.normFactor
1567 x = dataOut.abscissaList[:-1]
1568 #y = dataOut.getHeiRange()
1569
1570 z = dataOut.data_pre[:,:,heightindex]/factor
1571 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1572 avg = numpy.average(z, axis=1)
1573 listChannels = z.shape[0]
1574
1575 #Reconstruct Function
1576 if fit==True:
1577 groupArray = dataOut.groupList
1578 listChannels = groupArray.reshape((groupArray.size))
1579 listChannels.sort()
1580 spcFitLine = numpy.zeros(z.shape)
1581 constants = dataOut.constants
1582
1583 nGroups = groupArray.shape[0]
1584 nChannels = groupArray.shape[1]
1585 nProfiles = z.shape[1]
1586
1587 for f in range(nGroups):
1588 groupChann = groupArray[f,:]
1589 p = dataOut.data_param[f,:,heightindex]
1590 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1591 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1592 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1593 spcFitLine[groupChann,:] = fitLineAux
1594 # spcFitLine = spcFitLine/factor
1595
1596 z = z[listChannels,:]
1597 spcFitLine = spcFitLine[listChannels,:]
1598 spcFitLinedB = 10*numpy.log10(spcFitLine)
1599
1600 zdB = 10*numpy.log10(z)
1601 #thisDatetime = dataOut.datatime
1602 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1603 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1604 xlabel = "Velocity (m/s)"
1605 ylabel = "Spectrum"
1606
1607 if not self.isConfig:
1608
1609 nplots = listChannels.size
1610
1611 self.setup(id=id,
1612 nplots=nplots,
1613 wintitle=wintitle,
1614 showprofile=showprofile,
1615 show=show)
1616
1617 if xmin == None: xmin = numpy.nanmin(x)
1618 if xmax == None: xmax = numpy.nanmax(x)
1619 if ymin == None: ymin = numpy.nanmin(zdB)
1620 if ymax == None: ymax = numpy.nanmax(zdB)+2
1621
1622 self.isConfig = True
1623
1624 self.setWinTitle(title)
1625 for i in range(self.nplots):
1626 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1627 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1628 axes = self.axesList[i*self.__nsubplots]
1629 if fit == False:
1630 axes.pline(x, zdB[i,:],
1631 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1632 xlabel=xlabel, ylabel=ylabel, title=title
1633 )
1634 if fit == True:
1635 fitline=spcFitLinedB[i,:]
1636 y=numpy.vstack([zdB[i,:],fitline] )
1637 legendlabels=['Data','Fitting']
1638 axes.pmultilineyaxis(x, y,
1639 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1640 xlabel=xlabel, ylabel=ylabel, title=title,
1641 legendlabels=legendlabels, marker=None,
1642 linestyle='solid', grid='both')
1643
1644 self.draw()
1645
1646 self.save(figpath=figpath,
1647 figfile=figfile,
1648 save=save,
1649 ftp=ftp,
1650 wr_period=wr_period,
1651 thisDatetime=thisDatetime)
1652
1653
1654 class EWDriftsPlot_(Figure):
1655
1656 __isConfig = None
1657 __nsubplots = None
1658
1659 WIDTHPROF = None
1660 HEIGHTPROF = None
1661 PREFIX = 'drift'
1662
1663 def __init__(self, **kwargs):
1664 Figure.__init__(self, **kwargs)
1665 self.timerange = 2*60*60
1666 self.isConfig = False
1667 self.__nsubplots = 1
1668
1669 self.WIDTH = 800
1670 self.HEIGHT = 150
1671 self.WIDTHPROF = 120
1672 self.HEIGHTPROF = 0
1673 self.counter_imagwr = 0
1674
1675 self.PLOT_CODE = EWDRIFT_CODE
1676
1677 self.FTP_WEI = None
1678 self.EXP_CODE = None
1679 self.SUB_EXP_CODE = None
1680 self.PLOT_POS = None
1681 self.tmin = None
1682 self.tmax = None
1683
1684 self.xmin = None
1685 self.xmax = None
1686
1687 self.figfile = None
1688
1689 def getSubplots(self):
1690
1691 ncol = 1
1692 nrow = self.nplots
1693
1694 return nrow, ncol
1695
1696 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1697
1698 self.__showprofile = showprofile
1699 self.nplots = nplots
1700
1701 ncolspan = 1
1702 colspan = 1
1703
1704 self.createFigure(id = id,
1705 wintitle = wintitle,
1706 widthplot = self.WIDTH + self.WIDTHPROF,
1707 heightplot = self.HEIGHT + self.HEIGHTPROF,
1708 show=show)
1709
1710 nrow, ncol = self.getSubplots()
1711
1712 counter = 0
1713 for y in range(nrow):
1714 if counter >= self.nplots:
1715 break
1716
1717 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1718 counter += 1
1719
1720 def run(self, dataOut, id, wintitle="", channelList=None,
1721 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1722 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1723 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1724 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1725 server=None, folder=None, username=None, password=None,
1726 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1727 """
1728
1729 Input:
1730 dataOut :
1731 id :
1732 wintitle :
1733 channelList :
1734 showProfile :
1735 xmin : None,
1736 xmax : None,
1737 ymin : None,
1738 ymax : None,
1739 zmin : None,
1740 zmax : None
1741 """
1742
1743 if timerange is not None:
1744 self.timerange = timerange
1745
1746 tmin = None
1747 tmax = None
1748
1749 x = dataOut.getTimeRange1(dataOut.outputInterval)
1750 # y = dataOut.heightList
1751 y = dataOut.heightList
1752
1753 z = dataOut.data_output
1754 nplots = z.shape[0] #Number of wind dimensions estimated
1755 nplotsw = nplots
1756
1757 #If there is a SNR function defined
1758 if dataOut.data_SNR is not None:
1759 nplots += 1
1760 SNR = dataOut.data_SNR
1761
1762 if SNR_1:
1763 SNR += 1
1764
1765 SNRavg = numpy.average(SNR, axis=0)
1766
1767 SNRdB = 10*numpy.log10(SNR)
1768 SNRavgdB = 10*numpy.log10(SNRavg)
1769
1770 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1771
1772 for i in range(nplotsw):
1773 z[i,ind] = numpy.nan
1774
1775
1776 showprofile = False
1777 # thisDatetime = dataOut.datatime
1778 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1779 title = wintitle + " EW Drifts"
1780 xlabel = ""
1781 ylabel = "Height (Km)"
1782
1783 if not self.isConfig:
1784
1785 self.setup(id=id,
1786 nplots=nplots,
1787 wintitle=wintitle,
1788 showprofile=showprofile,
1789 show=show)
1790
1791 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1792
1793 if ymin == None: ymin = numpy.nanmin(y)
1794 if ymax == None: ymax = numpy.nanmax(y)
1795
1796 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1797 if zminZonal == None: zminZonal = -zmaxZonal
1798 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1799 if zminVertical == None: zminVertical = -zmaxVertical
1800
1801 if dataOut.data_SNR is not None:
1802 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1803 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1804
1805 self.FTP_WEI = ftp_wei
1806 self.EXP_CODE = exp_code
1807 self.SUB_EXP_CODE = sub_exp_code
1808 self.PLOT_POS = plot_pos
1809
1810 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1811 self.isConfig = True
1812
1813
1814 self.setWinTitle(title)
1815
1816 if ((self.xmax - x[1]) < (x[1]-x[0])):
1817 x[1] = self.xmax
1818
1819 strWind = ['Zonal','Vertical']
1820 strCb = 'Velocity (m/s)'
1821 zmaxVector = [zmaxZonal, zmaxVertical]
1822 zminVector = [zminZonal, zminVertical]
1823
1824 for i in range(nplotsw):
1825
1826 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1827 axes = self.axesList[i*self.__nsubplots]
1828
1829 z1 = z[i,:].reshape((1,-1))
1830
1831 axes.pcolorbuffer(x, y, z1,
1832 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1833 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1834 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1835
1836 if dataOut.data_SNR is not None:
1837 i += 1
1838 if SNR_1:
1839 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1840 else:
276 else:
1841 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
277 if self.zlimits is not None:
1842 axes = self.axesList[i*self.__nsubplots]
278 self.zmin, self.zmax = self.zlimits[n]
1843 SNRavgdB = SNRavgdB.reshape((1,-1))
279 ax.collections.remove(ax.collections[0])
1844
280 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1845 axes.pcolorbuffer(x, y, SNRavgdB,
281 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1846 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
282 vmin=self.zmin,
1847 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
283 vmax=self.zmax,
1848 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
284 cmap=self.cmaps[n])
1849
285
1850 self.draw()
286 if self.mode == 'A':
1851
287 continue
1852 if x[1] >= self.axesList[0].xmax:
288
1853 self.counter_imagwr = wr_period
289 # plot district names
1854 self.isConfig = False
290 f = open('/data/workspace/schain_scripts/distrito.csv')
1855 self.figfile = None
291 for line in f:
1856
292 label, lon, lat = [s.strip() for s in line.split(',') if s]
1857
293 lat = float(lat)
1858
294 lon = float(lon)
1859
295 # ax.plot(lon, lat, '.b', ms=2)
1860 class PhasePlot_(Figure):
296 ax.text(lon, lat, label.decode('utf8'), ha='center',
1861
297 va='bottom', size='8', color='black')
1862 __isConfig = None
298
1863 __nsubplots = None
299 # plot limites
1864
300 limites = []
1865 PREFIX = 'mphase'
301 tmp = []
1866
302 for line in open('/data/workspace/schain_scripts/lima.csv'):
1867
303 if '#' in line:
1868 def __init__(self, **kwargs):
304 if tmp:
1869 Figure.__init__(self, **kwargs)
305 limites.append(tmp)
1870 self.timerange = 24*60*60
306 tmp = []
1871 self.isConfig = False
307 continue
1872 self.__nsubplots = 1
308 values = line.strip().split(',')
1873 self.counter_imagwr = 0
309 tmp.append((float(values[0]), float(values[1])))
1874 self.WIDTH = 600
310 for points in limites:
1875 self.HEIGHT = 300
311 ax.add_patch(
1876 self.WIDTHPROF = 120
312 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
1877 self.HEIGHTPROF = 0
313
1878 self.xdata = None
314 # plot Cuencas
1879 self.ydata = None
315 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
1880
316 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
1881 self.PLOT_CODE = MPHASE_CODE
317 values = [line.strip().split(',') for line in f]
1882
318 points = [(float(s[0]), float(s[1])) for s in values]
1883 self.FTP_WEI = None
319 ax.add_patch(Polygon(points, ec='b', fc='none'))
1884 self.EXP_CODE = None
320
1885 self.SUB_EXP_CODE = None
321 # plot grid
1886 self.PLOT_POS = None
322 for r in (15, 30, 45, 60):
1887
323 ax.add_artist(plt.Circle((self.lon, self.lat),
1888
324 km2deg(r), color='0.6', fill=False, lw=0.2))
1889 self.filename_phase = None
325 ax.text(
1890
326 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
1891 self.figfile = None
327 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
1892
328 '{}km'.format(r),
1893 def getSubplots(self):
329 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
1894
330
1895 ncol = 1
331 if self.mode == 'E':
1896 nrow = 1
332 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
1897
333 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
1898 return nrow, ncol
1899
1900 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1901
1902 self.__showprofile = showprofile
1903 self.nplots = nplots
1904
1905 ncolspan = 7
1906 colspan = 6
1907 self.__nsubplots = 2
1908
1909 self.createFigure(id = id,
1910 wintitle = wintitle,
1911 widthplot = self.WIDTH+self.WIDTHPROF,
1912 heightplot = self.HEIGHT+self.HEIGHTPROF,
1913 show=show)
1914
1915 nrow, ncol = self.getSubplots()
1916
1917 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1918
1919
1920 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1921 xmin=None, xmax=None, ymin=None, ymax=None,
1922 timerange=None,
1923 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1924 server=None, folder=None, username=None, password=None,
1925 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1926
1927
1928 tmin = None
1929 tmax = None
1930 x = dataOut.getTimeRange1(dataOut.outputInterval)
1931 y = dataOut.getHeiRange()
1932
1933
1934 #thisDatetime = dataOut.datatime
1935 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1936 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1937 xlabel = "Local Time"
1938 ylabel = "Phase"
1939
1940
1941 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1942 phase_beacon = dataOut.data_output
1943 update_figfile = False
1944
1945 if not self.isConfig:
1946
1947 self.nplots = phase_beacon.size
1948
1949 self.setup(id=id,
1950 nplots=self.nplots,
1951 wintitle=wintitle,
1952 showprofile=showprofile,
1953 show=show)
1954
1955 if timerange is not None:
1956 self.timerange = timerange
1957
1958 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1959
1960 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1961 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1962
1963 self.FTP_WEI = ftp_wei
1964 self.EXP_CODE = exp_code
1965 self.SUB_EXP_CODE = sub_exp_code
1966 self.PLOT_POS = plot_pos
1967
1968 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1969 self.isConfig = True
1970 self.figfile = figfile
1971 self.xdata = numpy.array([])
1972 self.ydata = numpy.array([])
1973
1974 #open file beacon phase
1975 path = '%s%03d' %(self.PREFIX, self.id)
1976 beacon_file = os.path.join(path,'%s.txt'%self.name)
1977 self.filename_phase = os.path.join(figpath,beacon_file)
1978 update_figfile = True
1979
1980
1981 #store data beacon phase
1982 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1983
1984 self.setWinTitle(title)
1985
1986
1987 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1988
1989 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1990
1991 axes = self.axesList[0]
1992
1993 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1994
1995 if len(self.ydata)==0:
1996 self.ydata = phase_beacon.reshape(-1,1)
1997 else:
334 else:
1998 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
335 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
1999
336 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
2000
2001 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
2002 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
2003 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
2004 XAxisAsTime=True, grid='both'
2005 )
2006
2007 self.draw()
2008
2009 self.save(figpath=figpath,
2010 figfile=figfile,
2011 save=save,
2012 ftp=ftp,
2013 wr_period=wr_period,
2014 thisDatetime=thisDatetime,
2015 update_figfile=update_figfile)
2016
2017 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
2018 self.counter_imagwr = wr_period
2019 self.isConfig = False
2020 update_figfile = True
2021
2022
2023
2024 class NSMeteorDetection1Plot_(Figure):
2025
2026 isConfig = None
2027 __nsubplots = None
2028
2029 WIDTHPROF = None
2030 HEIGHTPROF = None
2031 PREFIX = 'nsm'
2032
2033 zminList = None
2034 zmaxList = None
2035 cmapList = None
2036 titleList = None
2037 nPairs = None
2038 nChannels = None
2039 nParam = None
2040
2041 def __init__(self, **kwargs):
2042 Figure.__init__(self, **kwargs)
2043 self.isConfig = False
2044 self.__nsubplots = 1
2045
2046 self.WIDTH = 750
2047 self.HEIGHT = 250
2048 self.WIDTHPROF = 120
2049 self.HEIGHTPROF = 0
2050 self.counter_imagwr = 0
2051
2052 self.PLOT_CODE = SPEC_CODE
2053
2054 self.FTP_WEI = None
2055 self.EXP_CODE = None
2056 self.SUB_EXP_CODE = None
2057 self.PLOT_POS = None
2058
2059 self.__xfilter_ena = False
2060 self.__yfilter_ena = False
2061
2062 def getSubplots(self):
2063
2064 ncol = 3
2065 nrow = int(numpy.ceil(self.nplots/3.0))
2066
2067 return nrow, ncol
2068
2069 def setup(self, id, nplots, wintitle, show=True):
2070
2071 self.nplots = nplots
2072
2073 ncolspan = 1
2074 colspan = 1
2075
2076 self.createFigure(id = id,
2077 wintitle = wintitle,
2078 widthplot = self.WIDTH + self.WIDTHPROF,
2079 heightplot = self.HEIGHT + self.HEIGHTPROF,
2080 show=show)
2081
2082 nrow, ncol = self.getSubplots()
2083
2084 counter = 0
2085 for y in range(nrow):
2086 for x in range(ncol):
2087
2088 if counter >= self.nplots:
2089 break
2090
2091 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2092
2093 counter += 1
2094
2095 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2096 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2097 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2098 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2099 server=None, folder=None, username=None, password=None,
2100 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2101 xaxis="frequency"):
2102
2103 """
2104
2105 Input:
2106 dataOut :
2107 id :
2108 wintitle :
2109 channelList :
2110 showProfile :
2111 xmin : None,
2112 xmax : None,
2113 ymin : None,
2114 ymax : None,
2115 zmin : None,
2116 zmax : None
2117 """
2118 #SEPARAR EN DOS PLOTS
2119 nParam = dataOut.data_param.shape[1] - 3
2120
2121 utctime = dataOut.data_param[0,0]
2122 tmet = dataOut.data_param[:,1].astype(int)
2123 hmet = dataOut.data_param[:,2].astype(int)
2124
2125 x = dataOut.abscissaList
2126 y = dataOut.heightList
2127
2128 z = numpy.zeros((nParam, y.size, x.size - 1))
2129 z[:,:] = numpy.nan
2130 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
2131 z[0,:,:] = 10*numpy.log10(z[0,:,:])
2132
2133 xlabel = "Time (s)"
2134 ylabel = "Range (km)"
2135
2136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2137
2138 if not self.isConfig:
2139
2140 nplots = nParam
2141
2142 self.setup(id=id,
2143 nplots=nplots,
2144 wintitle=wintitle,
2145 show=show)
2146
2147 if xmin is None: xmin = numpy.nanmin(x)
2148 if xmax is None: xmax = numpy.nanmax(x)
2149 if ymin is None: ymin = numpy.nanmin(y)
2150 if ymax is None: ymax = numpy.nanmax(y)
2151 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2152 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2153 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2154 if vmin is None: vmin = -vmax
2155 if wmin is None: wmin = 0
2156 if wmax is None: wmax = 50
2157
2158 pairsList = dataOut.groupList
2159 self.nPairs = len(dataOut.groupList)
2160
2161 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
2162 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
2163 titleList = ["SNR","Radial Velocity","Coherence"]
2164 cmapList = ["jet","RdBu_r","jet"]
2165
337
2166 for i in range(self.nPairs):
338 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
2167 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
339 self.titles = ['{} {}'.format(
2168 titleList = titleList + [strAux1]
340 self.data.parameters[x], title) for x in self.channels]
2169 cmapList = cmapList + ["RdBu_r"]
2170
2171 self.zminList = zminList
2172 self.zmaxList = zmaxList
2173 self.cmapList = cmapList
2174 self.titleList = titleList
2175
2176 self.FTP_WEI = ftp_wei
2177 self.EXP_CODE = exp_code
2178 self.SUB_EXP_CODE = sub_exp_code
2179 self.PLOT_POS = plot_pos
2180
341
2181 self.isConfig = True
2182
2183 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2184
2185 for i in range(nParam):
2186 title = self.titleList[i] + ": " +str_datetime
2187 axes = self.axesList[i]
2188 axes.pcolor(x, y, z[i,:].T,
2189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2190 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2191 self.draw()
2192
2193 if figfile == None:
2194 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2195 name = str_datetime
2196 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2197 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2198 figfile = self.getFilename(name)
2199
2200 self.save(figpath=figpath,
2201 figfile=figfile,
2202 save=save,
2203 ftp=ftp,
2204 wr_period=wr_period,
2205 thisDatetime=thisDatetime)
2206
2207
2208 class NSMeteorDetection2Plot_(Figure):
2209
2210 isConfig = None
2211 __nsubplots = None
2212
2213 WIDTHPROF = None
2214 HEIGHTPROF = None
2215 PREFIX = 'nsm'
2216
2217 zminList = None
2218 zmaxList = None
2219 cmapList = None
2220 titleList = None
2221 nPairs = None
2222 nChannels = None
2223 nParam = None
2224
2225 def __init__(self, **kwargs):
2226 Figure.__init__(self, **kwargs)
2227 self.isConfig = False
2228 self.__nsubplots = 1
2229
2230 self.WIDTH = 750
2231 self.HEIGHT = 250
2232 self.WIDTHPROF = 120
2233 self.HEIGHTPROF = 0
2234 self.counter_imagwr = 0
2235
2236 self.PLOT_CODE = SPEC_CODE
2237
2238 self.FTP_WEI = None
2239 self.EXP_CODE = None
2240 self.SUB_EXP_CODE = None
2241 self.PLOT_POS = None
2242
2243 self.__xfilter_ena = False
2244 self.__yfilter_ena = False
2245
2246 def getSubplots(self):
2247
2248 ncol = 3
2249 nrow = int(numpy.ceil(self.nplots/3.0))
2250
2251 return nrow, ncol
2252
2253 def setup(self, id, nplots, wintitle, show=True):
2254
2255 self.nplots = nplots
2256
2257 ncolspan = 1
2258 colspan = 1
2259
2260 self.createFigure(id = id,
2261 wintitle = wintitle,
2262 widthplot = self.WIDTH + self.WIDTHPROF,
2263 heightplot = self.HEIGHT + self.HEIGHTPROF,
2264 show=show)
2265
2266 nrow, ncol = self.getSubplots()
2267
2268 counter = 0
2269 for y in range(nrow):
2270 for x in range(ncol):
2271
2272 if counter >= self.nplots:
2273 break
2274
2275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2276
2277 counter += 1
2278
2279 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2280 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2281 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2282 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2283 server=None, folder=None, username=None, password=None,
2284 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2285 xaxis="frequency"):
2286
2287 """
2288
2289 Input:
2290 dataOut :
2291 id :
2292 wintitle :
2293 channelList :
2294 showProfile :
2295 xmin : None,
2296 xmax : None,
2297 ymin : None,
2298 ymax : None,
2299 zmin : None,
2300 zmax : None
2301 """
2302 #Rebuild matrix
2303 utctime = dataOut.data_param[0,0]
2304 cmet = dataOut.data_param[:,1].astype(int)
2305 tmet = dataOut.data_param[:,2].astype(int)
2306 hmet = dataOut.data_param[:,3].astype(int)
2307
2308 nParam = 3
2309 nChan = len(dataOut.groupList)
2310 x = dataOut.abscissaList
2311 y = dataOut.heightList
2312
2313 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2314 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2315 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2316 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2317
2318 xlabel = "Time (s)"
2319 ylabel = "Range (km)"
2320
2321 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2322
2323 if not self.isConfig:
2324
2325 nplots = nParam*nChan
2326
2327 self.setup(id=id,
2328 nplots=nplots,
2329 wintitle=wintitle,
2330 show=show)
2331
2332 if xmin is None: xmin = numpy.nanmin(x)
2333 if xmax is None: xmax = numpy.nanmax(x)
2334 if ymin is None: ymin = numpy.nanmin(y)
2335 if ymax is None: ymax = numpy.nanmax(y)
2336 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2337 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2338 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2339 if vmin is None: vmin = -vmax
2340 if wmin is None: wmin = 0
2341 if wmax is None: wmax = 50
2342
2343 self.nChannels = nChan
2344
2345 zminList = []
2346 zmaxList = []
2347 titleList = []
2348 cmapList = []
2349 for i in range(self.nChannels):
2350 strAux1 = "SNR Channel "+ str(i)
2351 strAux2 = "Radial Velocity Channel "+ str(i)
2352 strAux3 = "Spectral Width Channel "+ str(i)
2353
2354 titleList = titleList + [strAux1,strAux2,strAux3]
2355 cmapList = cmapList + ["jet","RdBu_r","jet"]
2356 zminList = zminList + [SNRmin,vmin,wmin]
2357 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2358
2359 self.zminList = zminList
2360 self.zmaxList = zmaxList
2361 self.cmapList = cmapList
2362 self.titleList = titleList
2363
2364 self.FTP_WEI = ftp_wei
2365 self.EXP_CODE = exp_code
2366 self.SUB_EXP_CODE = sub_exp_code
2367 self.PLOT_POS = plot_pos
2368
2369 self.isConfig = True
2370
2371 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2372
2373 for i in range(self.nplots):
2374 title = self.titleList[i] + ": " +str_datetime
2375 axes = self.axesList[i]
2376 axes.pcolor(x, y, z[i,:].T,
2377 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2378 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2379 self.draw()
2380
2381 if figfile == None:
2382 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2383 name = str_datetime
2384 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2385 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2386 figfile = self.getFilename(name)
2387
2388 self.save(figpath=figpath,
2389 figfile=figfile,
2390 save=save,
2391 ftp=ftp,
2392 wr_period=wr_period,
2393 thisDatetime=thisDatetime)
2394 No newline at end of file
This diff has been collapsed as it changes many lines, (1688 lines changed) Show them Hide them
@@ -1,1363 +1,423
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3 Modified on May 10, 2020
3
4
4 @author: roj-idl71
5 @author: Juan C. Espinoza
5 '''
6 '''
7
6 import os
8 import os
7 import datetime
9 import datetime
8 import numpy
10 import numpy
9
11
10 from .figure import Figure, isRealtime, isTimeInHourRange
12 from schainpy.model.graphics.jroplot_base import Plot, plt
11 from .plotting_codes import *
12 from schainpy.model.proc.jroproc_base import MPDecorator
13
14 from schainpy.utils import log
15
16 @MPDecorator
17 class SpectraPlot_(Figure):
18
19 isConfig = None
20 __nsubplots = None
21
22 WIDTHPROF = None
23 HEIGHTPROF = None
24 PREFIX = 'spc'
25
26 def __init__(self):
27 Figure.__init__(self)
28 self.isConfig = False
29 self.__nsubplots = 1
30 self.WIDTH = 250
31 self.HEIGHT = 250
32 self.WIDTHPROF = 120
33 self.HEIGHTPROF = 0
34 self.counter_imagwr = 0
35
36 self.PLOT_CODE = SPEC_CODE
37
38 self.FTP_WEI = None
39 self.EXP_CODE = None
40 self.SUB_EXP_CODE = None
41 self.PLOT_POS = None
42
43 self.__xfilter_ena = False
44 self.__yfilter_ena = False
45
46 self.indice=1
47
48 def getSubplots(self):
49
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
52
53 return nrow, ncol
54
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
56
57 self.__showprofile = showprofile
58 self.nplots = nplots
59
60 ncolspan = 1
61 colspan = 1
62 if showprofile:
63 ncolspan = 3
64 colspan = 2
65 self.__nsubplots = 2
66
13
67 self.createFigure(id = id,
68 wintitle = wintitle,
69 widthplot = self.WIDTH + self.WIDTHPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
71 show=show)
72
73 nrow, ncol = self.getSubplots()
74
75 counter = 0
76 for y in range(nrow):
77 for x in range(ncol):
78
79 if counter >= self.nplots:
80 break
81
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
83
14
84 if showprofile:
15 class SpectraPlot(Plot):
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
16 '''
17 Plot for Spectra data
18 '''
86
19
87 counter += 1
20 CODE = 'spc'
21 colormap = 'jet'
22 plot_name = 'Spectra'
23 plot_type = 'pcolor'
88
24
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
25 def setup(self):
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
26 self.nplots = len(self.data.channels)
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
27 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
92 server=None, folder=None, username=None, password=None,
28 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
29 self.height = 3 * self.nrows
94 xaxis="frequency", colormap='jet', normFactor=None):
30 self.cb_label = 'dB'
95
31 if self.showprofile:
96 """
32 self.width = 4 * self.ncols
97
98 Input:
99 dataOut :
100 id :
101 wintitle :
102 channelList :
103 showProfile :
104 xmin : None,
105 xmax : None,
106 ymin : None,
107 ymax : None,
108 zmin : None,
109 zmax : None
110 """
111 if dataOut.flagNoData:
112 return dataOut
113
114 if realtime:
115 if not(isRealtime(utcdatatime = dataOut.utctime)):
116 print('Skipping this plot function')
117 return
118
119 if channelList == None:
120 channelIndexList = dataOut.channelIndexList
121 else:
33 else:
122 channelIndexList = []
34 self.width = 3.5 * self.ncols
123 for channel in channelList:
35 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
124 if channel not in dataOut.channelList:
36 self.ylabel = 'Range [km]'
125 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
37
126 channelIndexList.append(dataOut.channelList.index(channel))
38 def plot(self):
127
39 if self.xaxis == "frequency":
128 if normFactor is None:
40 x = self.data.xrange[0]
129 factor = dataOut.normFactor
41 self.xlabel = "Frequency (kHz)"
42 elif self.xaxis == "time":
43 x = self.data.xrange[1]
44 self.xlabel = "Time (ms)"
130 else:
45 else:
131 factor = normFactor
46 x = self.data.xrange[2]
132 if xaxis == "frequency":
47 self.xlabel = "Velocity (m/s)"
133 x = dataOut.getFreqRange(1)/1000.
48
134 xlabel = "Frequency (kHz)"
49 if self.CODE == 'spc_moments':
135
50 x = self.data.xrange[2]
136 elif xaxis == "time":
51 self.xlabel = "Velocity (m/s)"
137 x = dataOut.getAcfRange(1)
52
138 xlabel = "Time (ms)"
53 self.titles = []
139
54
55 y = self.data.heights
56 self.y = y
57 z = self.data['spc']
58
59 for n, ax in enumerate(self.axes):
60 noise = self.data['noise'][n][-1]
61 if self.CODE == 'spc_moments':
62 mean = self.data['moments'][n, :, 1, :][-1]
63 if ax.firsttime:
64 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
65 self.xmin = self.xmin if self.xmin else -self.xmax
66 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
67 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
68 ax.plt = ax.pcolormesh(x, y, z[n].T,
69 vmin=self.zmin,
70 vmax=self.zmax,
71 cmap=plt.get_cmap(self.colormap)
72 )
73
74 if self.showprofile:
75 ax.plt_profile = self.pf_axes[n].plot(
76 self.data['rti'][n][-1], y)[0]
77 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
78 color="k", linestyle="dashed", lw=1)[0]
79 if self.CODE == 'spc_moments':
80 ax.plt_mean = ax.plot(mean, y, color='k')[0]
81 else:
82 ax.plt.set_array(z[n].T.ravel())
83 if self.showprofile:
84 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
85 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
86 if self.CODE == 'spc_moments':
87 ax.plt_mean.set_data(mean, y)
88 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
89
90
91 class CrossSpectraPlot(Plot):
92
93 CODE = 'cspc'
94 colormap = 'jet'
95 plot_name = 'CrossSpectra'
96 plot_type = 'pcolor'
97 zmin_coh = None
98 zmax_coh = None
99 zmin_phase = None
100 zmax_phase = None
101
102 def setup(self):
103
104 self.ncols = 4
105 self.nrows = len(self.data.pairs)
106 self.nplots = self.nrows * 4
107 self.width = 3.4 * self.ncols
108 self.height = 3 * self.nrows
109 self.ylabel = 'Range [km]'
110 self.showprofile = False
111 self.plots_adjust.update({'bottom': 0.08})
112
113 def plot(self):
114
115 if self.xaxis == "frequency":
116 x = self.data.xrange[0]
117 self.xlabel = "Frequency (kHz)"
118 elif self.xaxis == "time":
119 x = self.data.xrange[1]
120 self.xlabel = "Time (ms)"
140 else:
121 else:
141 x = dataOut.getVelRange(1)
122 x = self.data.xrange[2]
142 xlabel = "Velocity (m/s)"
123 self.xlabel = "Velocity (m/s)"
143
144 ylabel = "Range (km)"
145
146 y = dataOut.getHeiRange()
147 z = dataOut.data_spc/factor
148 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
149 zdB = 10*numpy.log10(z)
150
151 avg = numpy.average(z, axis=1)
152 avgdB = 10*numpy.log10(avg)
153
154 noise = dataOut.getNoise()/factor
155 noisedB = 10*numpy.log10(noise)
156
157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
158 title = wintitle + " Spectra"
159
160 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
161 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
162
163 if not self.isConfig:
164
165 nplots = len(channelIndexList)
166
167 self.setup(id=id,
168 nplots=nplots,
169 wintitle=wintitle,
170 showprofile=showprofile,
171 show=show)
172
173 if xmin == None: xmin = numpy.nanmin(x)
174 if xmax == None: xmax = numpy.nanmax(x)
175 if ymin == None: ymin = numpy.nanmin(y)
176 if ymax == None: ymax = numpy.nanmax(y)
177 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
178 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
179
180 self.FTP_WEI = ftp_wei
181 self.EXP_CODE = exp_code
182 self.SUB_EXP_CODE = sub_exp_code
183 self.PLOT_POS = plot_pos
184
185 self.isConfig = True
186
187 self.setWinTitle(title)
188
189 for i in range(self.nplots):
190 index = channelIndexList[i]
191 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
192 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
193 if len(dataOut.beam.codeList) != 0:
194 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)
195
196 axes = self.axesList[i*self.__nsubplots]
197 axes.pcolor(x, y, zdB[index,:,:],
198 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
199 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
200 ticksize=9, cblabel='')
201
202 if self.__showprofile:
203 axes = self.axesList[i*self.__nsubplots +1]
204 axes.pline(avgdB[index,:], y,
205 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
206 xlabel='dB', ylabel='', title='',
207 ytick_visible=False,
208 grid='x')
209
210 noiseline = numpy.repeat(noisedB[index], len(y))
211 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
212
213 self.draw()
214
215 if figfile == None:
216 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
217 name = str_datetime
218 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
219 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
220 figfile = self.getFilename(name)
221
222 self.save(figpath=figpath,
223 figfile=figfile,
224 save=save,
225 ftp=ftp,
226 wr_period=wr_period,
227 thisDatetime=thisDatetime)
228
229
230 return dataOut
231
232 @MPDecorator
233 class CrossSpectraPlot_(Figure):
234
235 isConfig = None
236 __nsubplots = None
237
238 WIDTH = None
239 HEIGHT = None
240 WIDTHPROF = None
241 HEIGHTPROF = None
242 PREFIX = 'cspc'
243
244 def __init__(self):
245 Figure.__init__(self)
246 self.isConfig = False
247 self.__nsubplots = 4
248 self.counter_imagwr = 0
249 self.WIDTH = 250
250 self.HEIGHT = 250
251 self.WIDTHPROF = 0
252 self.HEIGHTPROF = 0
253
254 self.PLOT_CODE = CROSS_CODE
255 self.FTP_WEI = None
256 self.EXP_CODE = None
257 self.SUB_EXP_CODE = None
258 self.PLOT_POS = None
259
124
260 self.indice=0
125 self.titles = []
261
126
262 def getSubplots(self):
127 y = self.data.heights
263
128 self.y = y
264 ncol = 4
129 spc = self.data['spc']
265 nrow = self.nplots
130 cspc = self.data['cspc']
266
131
267 return nrow, ncol
132 for n in range(self.nrows):
268
133 noise = self.data['noise'][n][-1]
269 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
134 pair = self.data.pairs[n]
270
135 ax = self.axes[4 * n]
271 self.__showprofile = showprofile
136 spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor)
272 self.nplots = nplots
137 if ax.firsttime:
273
138 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
274 ncolspan = 1
139 self.xmin = self.xmin if self.xmin else -self.xmax
275 colspan = 1
140 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
276
141 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
277 self.createFigure(id = id,
142 ax.plt = ax.pcolormesh(x , y , spc0.T,
278 wintitle = wintitle,
143 vmin=self.zmin,
279 widthplot = self.WIDTH + self.WIDTHPROF,
144 vmax=self.zmax,
280 heightplot = self.HEIGHT + self.HEIGHTPROF,
145 cmap=plt.get_cmap(self.colormap)
281 show=True)
146 )
282
147 else:
283 nrow, ncol = self.getSubplots()
148 ax.plt.set_array(spc0.T.ravel())
284
149 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise))
285 counter = 0
150
286 for y in range(nrow):
151 ax = self.axes[4 * n + 1]
287 for x in range(ncol):
152 spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor)
288 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
153 if ax.firsttime:
289
154 ax.plt = ax.pcolormesh(x , y, spc1.T,
290 counter += 1
155 vmin=self.zmin,
291
156 vmax=self.zmax,
292 def run(self, dataOut, id, wintitle="", pairsList=None,
157 cmap=plt.get_cmap(self.colormap)
293 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
158 )
294 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
159 else:
295 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
160 ax.plt.set_array(spc1.T.ravel())
296 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
161 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise))
297 server=None, folder=None, username=None, password=None,
298 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
299 xaxis='frequency'):
300
301 """
302
303 Input:
304 dataOut :
305 id :
306 wintitle :
307 channelList :
308 showProfile :
309 xmin : None,
310 xmax : None,
311 ymin : None,
312 ymax : None,
313 zmin : None,
314 zmax : None
315 """
316
317 if dataOut.flagNoData:
318 return dataOut
319
320 if pairsList == None:
321 pairsIndexList = dataOut.pairsIndexList
322 else:
323 pairsIndexList = []
324 for pair in pairsList:
325 if pair not in dataOut.pairsList:
326 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
327 pairsIndexList.append(dataOut.pairsList.index(pair))
328
329 if not pairsIndexList:
330 return
331
332 if len(pairsIndexList) > 4:
333 pairsIndexList = pairsIndexList[0:4]
334
162
335 if normFactor is None:
163 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
336 factor = dataOut.normFactor
164 coh = numpy.abs(out)
165 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
166
167 ax = self.axes[4 * n + 2]
168 if ax.firsttime:
169 ax.plt = ax.pcolormesh(x, y, coh.T,
170 vmin=0,
171 vmax=1,
172 cmap=plt.get_cmap(self.colormap_coh)
173 )
174 else:
175 ax.plt.set_array(coh.T.ravel())
176 self.titles.append(
177 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
178
179 ax = self.axes[4 * n + 3]
180 if ax.firsttime:
181 ax.plt = ax.pcolormesh(x, y, phase.T,
182 vmin=-180,
183 vmax=180,
184 cmap=plt.get_cmap(self.colormap_phase)
185 )
186 else:
187 ax.plt.set_array(phase.T.ravel())
188 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
189
190
191 class RTIPlot(Plot):
192 '''
193 Plot for RTI data
194 '''
195
196 CODE = 'rti'
197 colormap = 'jet'
198 plot_name = 'RTI'
199 plot_type = 'pcolorbuffer'
200
201 def setup(self):
202 self.xaxis = 'time'
203 self.ncols = 1
204 self.nrows = len(self.data.channels)
205 self.nplots = len(self.data.channels)
206 self.ylabel = 'Range [km]'
207 self.xlabel = 'Time'
208 self.cb_label = 'dB'
209 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
210 self.titles = ['{} Channel {}'.format(
211 self.CODE.upper(), x) for x in range(self.nrows)]
212
213 def plot(self):
214 self.x = self.data.times
215 self.y = self.data.heights
216 self.z = self.data[self.CODE]
217 self.z = numpy.ma.masked_invalid(self.z)
218
219 if self.decimation is None:
220 x, y, z = self.fill_gaps(self.x, self.y, self.z)
337 else:
221 else:
338 factor = normFactor
222 x, y, z = self.fill_gaps(*self.decimate())
339 x = dataOut.getVelRange(1)
223
340 y = dataOut.getHeiRange()
224 for n, ax in enumerate(self.axes):
341 z = dataOut.data_spc[:,:,:]/factor
225 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
342 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
226 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
343
227 if ax.firsttime:
344 noise = dataOut.noise/factor
228 ax.plt = ax.pcolormesh(x, y, z[n].T,
345
229 vmin=self.zmin,
346 zdB = 10*numpy.log10(z)
230 vmax=self.zmax,
347 noisedB = 10*numpy.log10(noise)
231 cmap=plt.get_cmap(self.colormap)
348
232 )
349 if coh_min == None:
233 if self.showprofile:
350 coh_min = 0.0
234 ax.plot_profile = self.pf_axes[n].plot(
351 if coh_max == None:
235 self.data['rti'][n][-1], self.y)[0]
352 coh_max = 1.0
236 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
353
237 color="k", linestyle="dashed", lw=1)[0]
354 if phase_min == None:
238 else:
355 phase_min = -180
239 ax.collections.remove(ax.collections[0])
356 if phase_max == None:
240 ax.plt = ax.pcolormesh(x, y, z[n].T,
357 phase_max = 180
241 vmin=self.zmin,
358
242 vmax=self.zmax,
359 #thisDatetime = dataOut.datatime
243 cmap=plt.get_cmap(self.colormap)
360 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
244 )
361 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
245 if self.showprofile:
362 # xlabel = "Velocity (m/s)"
246 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
363 ylabel = "Range (Km)"
247 ax.plot_noise.set_data(numpy.repeat(
364
248 self.data['noise'][n][-1], len(self.y)), self.y)
365 if xaxis == "frequency":
249
366 x = dataOut.getFreqRange(1)/1000.
250
367 xlabel = "Frequency (kHz)"
251 class CoherencePlot(RTIPlot):
368
252 '''
369 elif xaxis == "time":
253 Plot for Coherence data
370 x = dataOut.getAcfRange(1)
254 '''
371 xlabel = "Time (ms)"
255
372
256 CODE = 'coh'
257 plot_name = 'Coherence'
258
259 def setup(self):
260 self.xaxis = 'time'
261 self.ncols = 1
262 self.nrows = len(self.data.pairs)
263 self.nplots = len(self.data.pairs)
264 self.ylabel = 'Range [km]'
265 self.xlabel = 'Time'
266 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
267 if self.CODE == 'coh':
268 self.cb_label = ''
269 self.titles = [
270 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
373 else:
271 else:
374 x = dataOut.getVelRange(1)
272 self.cb_label = 'Degrees'
375 xlabel = "Velocity (m/s)"
273 self.titles = [
376
274 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
377 if not self.isConfig:
378
379 nplots = len(pairsIndexList)
380
381 self.setup(id=id,
382 nplots=nplots,
383 wintitle=wintitle,
384 showprofile=False,
385 show=show)
386
387 avg = numpy.abs(numpy.average(z, axis=1))
388 avgdB = 10*numpy.log10(avg)
389
390 if xmin == None: xmin = numpy.nanmin(x)
391 if xmax == None: xmax = numpy.nanmax(x)
392 if ymin == None: ymin = numpy.nanmin(y)
393 if ymax == None: ymax = numpy.nanmax(y)
394 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
395 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
396
397 self.FTP_WEI = ftp_wei
398 self.EXP_CODE = exp_code
399 self.SUB_EXP_CODE = sub_exp_code
400 self.PLOT_POS = plot_pos
401
402 self.isConfig = True
403
404 self.setWinTitle(title)
405
406
407 for i in range(self.nplots):
408 pair = dataOut.pairsList[pairsIndexList[i]]
409
410 chan_index0 = dataOut.channelList.index(pair[0])
411 chan_index1 = dataOut.channelList.index(pair[1])
412
413 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
414 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
415 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
416 axes0 = self.axesList[i*self.__nsubplots]
417 axes0.pcolor(x, y, zdB,
418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
419 xlabel=xlabel, ylabel=ylabel, title=title,
420 ticksize=9, colormap=power_cmap, cblabel='')
421
422 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
423 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
424 axes0 = self.axesList[i*self.__nsubplots+1]
425 axes0.pcolor(x, y, zdB,
426 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
427 xlabel=xlabel, ylabel=ylabel, title=title,
428 ticksize=9, colormap=power_cmap, cblabel='')
429
430 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
431 coherence = numpy.abs(coherenceComplex)
432 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
433 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
434
435 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
436 axes0 = self.axesList[i*self.__nsubplots+2]
437 axes0.pcolor(x, y, coherence,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
439 xlabel=xlabel, ylabel=ylabel, title=title,
440 ticksize=9, colormap=coherence_cmap, cblabel='')
441
442 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
443 axes0 = self.axesList[i*self.__nsubplots+3]
444 axes0.pcolor(x, y, phase,
445 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
446 xlabel=xlabel, ylabel=ylabel, title=title,
447 ticksize=9, colormap=phase_cmap, cblabel='')
448
449 self.draw()
450
451 self.save(figpath=figpath,
452 figfile=figfile,
453 save=save,
454 ftp=ftp,
455 wr_period=wr_period,
456 thisDatetime=thisDatetime)
457
458 return dataOut
459
460 @MPDecorator
461 class RTIPlot_(Figure):
462
463 __isConfig = None
464 __nsubplots = None
465
466 WIDTHPROF = None
467 HEIGHTPROF = None
468 PREFIX = 'rti'
469
470 def __init__(self):
471
275
472 Figure.__init__(self)
473 self.timerange = None
474 self.isConfig = False
475 self.__nsubplots = 1
476
477 self.WIDTH = 800
478 self.HEIGHT = 250
479 self.WIDTHPROF = 120
480 self.HEIGHTPROF = 0
481 self.counter_imagwr = 0
482
276
483 self.PLOT_CODE = RTI_CODE
277 class PhasePlot(CoherencePlot):
278 '''
279 Plot for Phase map data
280 '''
484
281
485 self.FTP_WEI = None
282 CODE = 'phase'
486 self.EXP_CODE = None
283 colormap = 'seismic'
487 self.SUB_EXP_CODE = None
284 plot_name = 'Phase'
488 self.PLOT_POS = None
489 self.tmin = None
490 self.tmax = None
491
285
492 self.xmin = None
493 self.xmax = None
494
286
495 self.figfile = None
287 class NoisePlot(Plot):
288 '''
289 Plot for noise
290 '''
496
291
497 def getSubplots(self):
292 CODE = 'noise'
293 plot_name = 'Noise'
294 plot_type = 'scatterbuffer'
498
295
499 ncol = 1
500 nrow = self.nplots
501
296
502 return nrow, ncol
297 def setup(self):
298 self.xaxis = 'time'
299 self.ncols = 1
300 self.nrows = 1
301 self.nplots = 1
302 self.ylabel = 'Intensity [dB]'
303 self.titles = ['Noise']
304 self.colorbar = False
503
305
504 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
306 def plot(self):
505
307
506 self.__showprofile = showprofile
308 x = self.data.times
507 self.nplots = nplots
309 xmin = self.data.min_time
310 xmax = xmin + self.xrange * 60 * 60
311 Y = self.data[self.CODE]
508
312
509 ncolspan = 1
313 if self.axes[0].firsttime:
510 colspan = 1
314 for ch in self.data.channels:
511 if showprofile:
315 y = Y[ch]
512 ncolspan = 7
316 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
513 colspan = 6
317 plt.legend()
514 self.__nsubplots = 2
318 else:
319 for ch in self.data.channels:
320 y = Y[ch]
321 self.axes[0].lines[ch].set_data(x, y)
515
322
516 self.createFigure(id = id,
323 self.ymin = numpy.nanmin(Y) - 5
517 wintitle = wintitle,
324 self.ymax = numpy.nanmax(Y) + 5
518 widthplot = self.WIDTH + self.WIDTHPROF,
519 heightplot = self.HEIGHT + self.HEIGHTPROF,
520 show=show)
521
325
522 nrow, ncol = self.getSubplots()
523
326
524 counter = 0
327 class PowerProfilePlot(Plot):
525 for y in range(nrow):
526 for x in range(ncol):
527
328
528 if counter >= self.nplots:
329 CODE = 'spcprofile'
529 break
330 plot_name = 'Power Profile'
331 plot_type = 'scatter'
332 buffering = False
530
333
531 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
334 def setup(self):
532
335
533 if showprofile:
336 self.ncols = 1
534 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
337 self.nrows = 1
338 self.nplots = 1
339 self.height = 4
340 self.width = 3
341 self.ylabel = 'Range [km]'
342 self.xlabel = 'Intensity [dB]'
343 self.titles = ['Power Profile']
344 self.colorbar = False
535
345
536 counter += 1
346 def plot(self):
537
347
538 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
348 y = self.data.heights
539 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
349 self.y = y
540 timerange=None, colormap='jet',
541 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
542 server=None, folder=None, username=None, password=None,
543 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
544
545 """
546
547 Input:
548 dataOut :
549 id :
550 wintitle :
551 channelList :
552 showProfile :
553 xmin : None,
554 xmax : None,
555 ymin : None,
556 ymax : None,
557 zmin : None,
558 zmax : None
559 """
560 if dataOut.flagNoData:
561 return dataOut
562
350
563 #colormap = kwargs.get('colormap', 'jet')
351 x = self.data['spcprofile']
564 if HEIGHT is not None:
565 self.HEIGHT = HEIGHT
566
352
567 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
353 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
568 return
354 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
569
355
570 if channelList == None:
356 if self.axes[0].firsttime:
571 channelIndexList = dataOut.channelIndexList
357 for ch in self.data.channels:
358 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
359 plt.legend()
572 else:
360 else:
573 channelIndexList = []
361 for ch in self.data.channels:
574 for channel in channelList:
362 self.axes[0].lines[ch].set_data(x[ch], y)
575 if channel not in dataOut.channelList:
363
576 raise ValueError("Channel %d is not in dataOut.channelList")
364
577 channelIndexList.append(dataOut.channelList.index(channel))
365 class SpectraCutPlot(Plot):
578
366
579 if normFactor is None:
367 CODE = 'spc_cut'
580 factor = dataOut.normFactor
368 plot_name = 'Spectra Cut'
369 plot_type = 'scatter'
370 buffering = False
371
372 def setup(self):
373
374 self.nplots = len(self.data.channels)
375 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
376 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
377 self.width = 3.4 * self.ncols + 1.5
378 self.height = 3 * self.nrows
379 self.ylabel = 'Power [dB]'
380 self.colorbar = False
381 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
382
383 def plot(self):
384 if self.xaxis == "frequency":
385 x = self.data.xrange[0][1:]
386 self.xlabel = "Frequency (kHz)"
387 elif self.xaxis == "time":
388 x = self.data.xrange[1]
389 self.xlabel = "Time (ms)"
581 else:
390 else:
582 factor = normFactor
391 x = self.data.xrange[2]
583
392 self.xlabel = "Velocity (m/s)"
584 #factor = dataOut.normFactor
585 x = dataOut.getTimeRange()
586 y = dataOut.getHeiRange()
587
588 z = dataOut.data_spc/factor
589 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
590 avg = numpy.average(z, axis=1)
591 avgdB = 10.*numpy.log10(avg)
592 # avgdB = dataOut.getPower()
593
594
595 thisDatetime = dataOut.datatime
596 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
597 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
598 xlabel = ""
599 ylabel = "Range (Km)"
600
601 update_figfile = False
602
603 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
604 self.counter_imagwr = wr_period
605 self.isConfig = False
606 update_figfile = True
607
608 if not self.isConfig:
609
610 nplots = len(channelIndexList)
611
612 self.setup(id=id,
613 nplots=nplots,
614 wintitle=wintitle,
615 showprofile=showprofile,
616 show=show)
617
618 if timerange != None:
619 self.timerange = timerange
620
621 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
622
623 noise = dataOut.noise/factor
624 noisedB = 10*numpy.log10(noise)
625
626 if ymin == None: ymin = numpy.nanmin(y)
627 if ymax == None: ymax = numpy.nanmax(y)
628 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
629 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
630
631 self.FTP_WEI = ftp_wei
632 self.EXP_CODE = exp_code
633 self.SUB_EXP_CODE = sub_exp_code
634 self.PLOT_POS = plot_pos
635
636 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
637 self.isConfig = True
638 self.figfile = figfile
639 update_figfile = True
640
641 self.setWinTitle(title)
642
393
643 for i in range(self.nplots):
394 self.titles = []
644 index = channelIndexList[i]
645 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
646 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
647 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
648 axes = self.axesList[i*self.__nsubplots]
649 zdB = avgdB[index].reshape((1,-1))
650 axes.pcolorbuffer(x, y, zdB,
651 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
652 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
653 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
654
655 if self.__showprofile:
656 axes = self.axesList[i*self.__nsubplots +1]
657 axes.pline(avgdB[index], y,
658 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
659 xlabel='dB', ylabel='', title='',
660 ytick_visible=False,
661 grid='x')
662
395
663 self.draw()
396 y = self.data.heights
397 #self.y = y
398 z = self.data['spc_cut']
664
399
665 self.save(figpath=figpath,
400 if self.height_index:
666 figfile=figfile,
401 index = numpy.array(self.height_index)
667 save=save,
668 ftp=ftp,
669 wr_period=wr_period,
670 thisDatetime=thisDatetime,
671 update_figfile=update_figfile)
672 return dataOut
673
674 @MPDecorator
675 class CoherenceMap_(Figure):
676 isConfig = None
677 __nsubplots = None
678
679 WIDTHPROF = None
680 HEIGHTPROF = None
681 PREFIX = 'cmap'
682
683 def __init__(self):
684 Figure.__init__(self)
685 self.timerange = 2*60*60
686 self.isConfig = False
687 self.__nsubplots = 1
688
689 self.WIDTH = 800
690 self.HEIGHT = 180
691 self.WIDTHPROF = 120
692 self.HEIGHTPROF = 0
693 self.counter_imagwr = 0
694
695 self.PLOT_CODE = COH_CODE
696
697 self.FTP_WEI = None
698 self.EXP_CODE = None
699 self.SUB_EXP_CODE = None
700 self.PLOT_POS = None
701 self.counter_imagwr = 0
702
703 self.xmin = None
704 self.xmax = None
705
706 def getSubplots(self):
707 ncol = 1
708 nrow = self.nplots*2
709
710 return nrow, ncol
711
712 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
713 self.__showprofile = showprofile
714 self.nplots = nplots
715
716 ncolspan = 1
717 colspan = 1
718 if showprofile:
719 ncolspan = 7
720 colspan = 6
721 self.__nsubplots = 2
722
723 self.createFigure(id = id,
724 wintitle = wintitle,
725 widthplot = self.WIDTH + self.WIDTHPROF,
726 heightplot = self.HEIGHT + self.HEIGHTPROF,
727 show=True)
728
729 nrow, ncol = self.getSubplots()
730
731 for y in range(nrow):
732 for x in range(ncol):
733
734 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
735
736 if showprofile:
737 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
738
739 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
740 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
741 timerange=None, phase_min=None, phase_max=None,
742 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
743 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
744 server=None, folder=None, username=None, password=None,
745 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
746
747
748 if dataOut.flagNoData:
749 return dataOut
750
751 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
752 return
753
754 if pairsList == None:
755 pairsIndexList = dataOut.pairsIndexList
756 else:
402 else:
757 pairsIndexList = []
403 index = numpy.arange(0, len(y), int((len(y))/9))
758 for pair in pairsList:
404
759 if pair not in dataOut.pairsList:
405 for n, ax in enumerate(self.axes):
760 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
406 if ax.firsttime:
761 pairsIndexList.append(dataOut.pairsList.index(pair))
407 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
762
408 self.xmin = self.xmin if self.xmin else -self.xmax
763 if pairsIndexList == []:
409 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
764 return
410 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
765
411 ax.plt = ax.plot(x, z[n, :, index].T)
766 if len(pairsIndexList) > 4:
412 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
767 pairsIndexList = pairsIndexList[0:4]
413 self.figures[0].legend(ax.plt, labels, loc='center right')
768
414 else:
769 if phase_min == None:
415 for i, line in enumerate(ax.plt):
770 phase_min = -180
416 line.set_data(x, z[n, :, i])
771 if phase_max == None:
417 self.titles.append('CH {}'.format(n))
772 phase_max = 180
773
774 x = dataOut.getTimeRange()
775 y = dataOut.getHeiRange()
776
777 thisDatetime = dataOut.datatime
778
779 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
780 xlabel = ""
781 ylabel = "Range (Km)"
782 update_figfile = False
783
784 if not self.isConfig:
785 nplots = len(pairsIndexList)
786 self.setup(id=id,
787 nplots=nplots,
788 wintitle=wintitle,
789 showprofile=showprofile,
790 show=show)
791
792 if timerange != None:
793 self.timerange = timerange
794
795 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
796
797 if ymin == None: ymin = numpy.nanmin(y)
798 if ymax == None: ymax = numpy.nanmax(y)
799 if zmin == None: zmin = 0.
800 if zmax == None: zmax = 1.
801
802 self.FTP_WEI = ftp_wei
803 self.EXP_CODE = exp_code
804 self.SUB_EXP_CODE = sub_exp_code
805 self.PLOT_POS = plot_pos
806
807 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
808
809 self.isConfig = True
810 update_figfile = True
811
812 self.setWinTitle(title)
813
814 for i in range(self.nplots):
815
816 pair = dataOut.pairsList[pairsIndexList[i]]
817
818 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
819 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
820 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
821
822
823 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
824 coherence = numpy.abs(avgcoherenceComplex)
825
826 z = coherence.reshape((1,-1))
827
828 counter = 0
829
830 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
831 axes = self.axesList[i*self.__nsubplots*2]
832 axes.pcolorbuffer(x, y, z,
833 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
834 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
835 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
836
837 if self.__showprofile:
838 counter += 1
839 axes = self.axesList[i*self.__nsubplots*2 + counter]
840 axes.pline(coherence, y,
841 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
842 xlabel='', ylabel='', title='', ticksize=7,
843 ytick_visible=False, nxticks=5,
844 grid='x')
845
846 counter += 1
847
848 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
849
850 z = phase.reshape((1,-1))
851
852 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
853 axes = self.axesList[i*self.__nsubplots*2 + counter]
854 axes.pcolorbuffer(x, y, z,
855 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
856 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
857 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
858
859 if self.__showprofile:
860 counter += 1
861 axes = self.axesList[i*self.__nsubplots*2 + counter]
862 axes.pline(phase, y,
863 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
864 xlabel='', ylabel='', title='', ticksize=7,
865 ytick_visible=False, nxticks=4,
866 grid='x')
867
868 self.draw()
869
870 if dataOut.ltctime >= self.xmax:
871 self.counter_imagwr = wr_period
872 self.isConfig = False
873 update_figfile = True
874
875 self.save(figpath=figpath,
876 figfile=figfile,
877 save=save,
878 ftp=ftp,
879 wr_period=wr_period,
880 thisDatetime=thisDatetime,
881 update_figfile=update_figfile)
882
883 return dataOut
884
885 @MPDecorator
886 class PowerProfilePlot_(Figure):
887
888 isConfig = None
889 __nsubplots = None
890
891 WIDTHPROF = None
892 HEIGHTPROF = None
893 PREFIX = 'spcprofile'
894
895 def __init__(self):
896 Figure.__init__(self)
897 self.isConfig = False
898 self.__nsubplots = 1
899
900 self.PLOT_CODE = POWER_CODE
901
902 self.WIDTH = 300
903 self.HEIGHT = 500
904 self.counter_imagwr = 0
905
906 def getSubplots(self):
907 ncol = 1
908 nrow = 1
909
910 return nrow, ncol
911
912 def setup(self, id, nplots, wintitle, show):
913
914 self.nplots = nplots
915
916 ncolspan = 1
917 colspan = 1
918
919 self.createFigure(id = id,
920 wintitle = wintitle,
921 widthplot = self.WIDTH,
922 heightplot = self.HEIGHT,
923 show=show)
924
925 nrow, ncol = self.getSubplots()
926
927 counter = 0
928 for y in range(nrow):
929 for x in range(ncol):
930 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
931
932 def run(self, dataOut, id, wintitle="", channelList=None,
933 xmin=None, xmax=None, ymin=None, ymax=None,
934 save=False, figpath='./', figfile=None, show=True,
935 ftp=False, wr_period=1, server=None,
936 folder=None, username=None, password=None):
937
938 if dataOut.flagNoData:
939 return dataOut
940
941
942 if channelList == None:
943 channelIndexList = dataOut.channelIndexList
944 channelList = dataOut.channelList
945 else:
946 channelIndexList = []
947 for channel in channelList:
948 if channel not in dataOut.channelList:
949 raise ValueError("Channel %d is not in dataOut.channelList")
950 channelIndexList.append(dataOut.channelList.index(channel))
951
952 factor = dataOut.normFactor
953
954 y = dataOut.getHeiRange()
955
956 #for voltage
957 if dataOut.type == 'Voltage':
958 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
959 x = x.real
960 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
961
962 #for spectra
963 if dataOut.type == 'Spectra':
964 x = dataOut.data_spc[channelIndexList,:,:]/factor
965 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
966 x = numpy.average(x, axis=1)
967
968
969 xdB = 10*numpy.log10(x)
970
971 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
972 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
973 xlabel = "dB"
974 ylabel = "Range (Km)"
975
976 if not self.isConfig:
977
978 nplots = 1
979
980 self.setup(id=id,
981 nplots=nplots,
982 wintitle=wintitle,
983 show=show)
984
985 if ymin == None: ymin = numpy.nanmin(y)
986 if ymax == None: ymax = numpy.nanmax(y)
987 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
988 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
989
990 self.isConfig = True
991
992 self.setWinTitle(title)
993
994 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
995 axes = self.axesList[0]
996
997 legendlabels = ["channel %d"%x for x in channelList]
998 axes.pmultiline(xdB, y,
999 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1000 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1001 ytick_visible=True, nxticks=5,
1002 grid='x')
1003
1004 self.draw()
1005
1006 self.save(figpath=figpath,
1007 figfile=figfile,
1008 save=save,
1009 ftp=ftp,
1010 wr_period=wr_period,
1011 thisDatetime=thisDatetime)
1012
1013 return dataOut
1014
1015 @MPDecorator
1016 class SpectraCutPlot_(Figure):
1017
1018 isConfig = None
1019 __nsubplots = None
1020
1021 WIDTHPROF = None
1022 HEIGHTPROF = None
1023 PREFIX = 'spc_cut'
1024
1025 def __init__(self):
1026 Figure.__init__(self)
1027 self.isConfig = False
1028 self.__nsubplots = 1
1029
1030 self.PLOT_CODE = POWER_CODE
1031
1032 self.WIDTH = 700
1033 self.HEIGHT = 500
1034 self.counter_imagwr = 0
1035
1036 def getSubplots(self):
1037 ncol = 1
1038 nrow = 1
1039
1040 return nrow, ncol
1041
1042 def setup(self, id, nplots, wintitle, show):
1043
1044 self.nplots = nplots
1045
1046 ncolspan = 1
1047 colspan = 1
1048
1049 self.createFigure(id = id,
1050 wintitle = wintitle,
1051 widthplot = self.WIDTH,
1052 heightplot = self.HEIGHT,
1053 show=show)
1054
1055 nrow, ncol = self.getSubplots()
1056
1057 counter = 0
1058 for y in range(nrow):
1059 for x in range(ncol):
1060 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1061
1062 def run(self, dataOut, id, wintitle="", channelList=None,
1063 xmin=None, xmax=None, ymin=None, ymax=None,
1064 save=False, figpath='./', figfile=None, show=True,
1065 ftp=False, wr_period=1, server=None,
1066 folder=None, username=None, password=None,
1067 xaxis="frequency"):
1068
1069 if dataOut.flagNoData:
1070 return dataOut
1071
1072 if channelList == None:
1073 channelIndexList = dataOut.channelIndexList
1074 channelList = dataOut.channelList
1075 else:
1076 channelIndexList = []
1077 for channel in channelList:
1078 if channel not in dataOut.channelList:
1079 raise ValueError("Channel %d is not in dataOut.channelList")
1080 channelIndexList.append(dataOut.channelList.index(channel))
1081
1082 factor = dataOut.normFactor
1083
1084 y = dataOut.getHeiRange()
1085
1086 z = dataOut.data_spc/factor
1087 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1088
1089 hei_index = numpy.arange(25)*3 + 20
1090
1091 if xaxis == "frequency":
1092 x = dataOut.getFreqRange()/1000.
1093 zdB = 10*numpy.log10(z[0,:,hei_index])
1094 xlabel = "Frequency (kHz)"
1095 ylabel = "Power (dB)"
1096
1097 elif xaxis == "time":
1098 x = dataOut.getAcfRange()
1099 zdB = z[0,:,hei_index]
1100 xlabel = "Time (ms)"
1101 ylabel = "ACF"
1102
1103 else:
1104 x = dataOut.getVelRange()
1105 zdB = 10*numpy.log10(z[0,:,hei_index])
1106 xlabel = "Velocity (m/s)"
1107 ylabel = "Power (dB)"
1108
1109 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1110 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1111
1112 if not self.isConfig:
1113
1114 nplots = 1
1115
1116 self.setup(id=id,
1117 nplots=nplots,
1118 wintitle=wintitle,
1119 show=show)
1120
1121 if xmin == None: xmin = numpy.nanmin(x)*0.9
1122 if xmax == None: xmax = numpy.nanmax(x)*1.1
1123 if ymin == None: ymin = numpy.nanmin(zdB)
1124 if ymax == None: ymax = numpy.nanmax(zdB)
1125
1126 self.isConfig = True
1127
1128 self.setWinTitle(title)
1129
1130 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1131 axes = self.axesList[0]
1132
1133 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1134
1135 axes.pmultilineyaxis( x, zdB,
1136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1137 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1138 ytick_visible=True, nxticks=5,
1139 grid='x')
1140
1141 self.draw()
1142
1143 self.save(figpath=figpath,
1144 figfile=figfile,
1145 save=save,
1146 ftp=ftp,
1147 wr_period=wr_period,
1148 thisDatetime=thisDatetime)
1149
1150 return dataOut
1151
1152 @MPDecorator
1153 class Noise_(Figure):
1154
1155 isConfig = None
1156 __nsubplots = None
1157
1158 PREFIX = 'noise'
1159
1160
1161 def __init__(self):
1162 Figure.__init__(self)
1163 self.timerange = 24*60*60
1164 self.isConfig = False
1165 self.__nsubplots = 1
1166 self.counter_imagwr = 0
1167 self.WIDTH = 800
1168 self.HEIGHT = 400
1169 self.WIDTHPROF = 120
1170 self.HEIGHTPROF = 0
1171 self.xdata = None
1172 self.ydata = None
1173
1174 self.PLOT_CODE = NOISE_CODE
1175
1176 self.FTP_WEI = None
1177 self.EXP_CODE = None
1178 self.SUB_EXP_CODE = None
1179 self.PLOT_POS = None
1180 self.figfile = None
1181
1182 self.xmin = None
1183 self.xmax = None
1184
1185 def getSubplots(self):
1186
1187 ncol = 1
1188 nrow = 1
1189
1190 return nrow, ncol
1191
1192 def openfile(self, filename):
1193 dirname = os.path.dirname(filename)
1194
1195 if not os.path.exists(dirname):
1196 os.mkdir(dirname)
1197
1198 f = open(filename,'w+')
1199 f.write('\n\n')
1200 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1201 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1202 f.close()
1203
1204 def save_data(self, filename_phase, data, data_datetime):
1205
1206 f=open(filename_phase,'a')
1207
1208 timetuple_data = data_datetime.timetuple()
1209 day = str(timetuple_data.tm_mday)
1210 month = str(timetuple_data.tm_mon)
1211 year = str(timetuple_data.tm_year)
1212 hour = str(timetuple_data.tm_hour)
1213 minute = str(timetuple_data.tm_min)
1214 second = str(timetuple_data.tm_sec)
1215
1216 data_msg = ''
1217 for i in range(len(data)):
1218 data_msg += str(data[i]) + ' '
1219
1220 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1221 f.close()
1222
1223
1224 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1225
1226 self.__showprofile = showprofile
1227 self.nplots = nplots
1228
1229 ncolspan = 7
1230 colspan = 6
1231 self.__nsubplots = 2
1232
1233 self.createFigure(id = id,
1234 wintitle = wintitle,
1235 widthplot = self.WIDTH+self.WIDTHPROF,
1236 heightplot = self.HEIGHT+self.HEIGHTPROF,
1237 show=show)
1238
1239 nrow, ncol = self.getSubplots()
1240
1241 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1242
1243
1244 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1245 xmin=None, xmax=None, ymin=None, ymax=None,
1246 timerange=None,
1247 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1248 server=None, folder=None, username=None, password=None,
1249 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1250
1251 if dataOut.flagNoData:
1252 return dataOut
1253
1254 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1255 return
1256
1257 if channelList == None:
1258 channelIndexList = dataOut.channelIndexList
1259 channelList = dataOut.channelList
1260 else:
1261 channelIndexList = []
1262 for channel in channelList:
1263 if channel not in dataOut.channelList:
1264 raise ValueError("Channel %d is not in dataOut.channelList")
1265 channelIndexList.append(dataOut.channelList.index(channel))
1266
1267 x = dataOut.getTimeRange()
1268 #y = dataOut.getHeiRange()
1269 factor = dataOut.normFactor
1270 noise = dataOut.noise[channelIndexList]/factor
1271 noisedB = 10*numpy.log10(noise)
1272
1273 thisDatetime = dataOut.datatime
1274
1275 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1276 xlabel = ""
1277 ylabel = "Intensity (dB)"
1278 update_figfile = False
1279
1280 if not self.isConfig:
1281
1282 nplots = 1
1283
1284 self.setup(id=id,
1285 nplots=nplots,
1286 wintitle=wintitle,
1287 showprofile=showprofile,
1288 show=show)
1289
1290 if timerange != None:
1291 self.timerange = timerange
1292
1293 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1294
1295 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1296 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1297
1298 self.FTP_WEI = ftp_wei
1299 self.EXP_CODE = exp_code
1300 self.SUB_EXP_CODE = sub_exp_code
1301 self.PLOT_POS = plot_pos
1302
1303
1304 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1305 self.isConfig = True
1306 self.figfile = figfile
1307 self.xdata = numpy.array([])
1308 self.ydata = numpy.array([])
1309
1310 update_figfile = True
1311
1312 #open file beacon phase
1313 path = '%s%03d' %(self.PREFIX, self.id)
1314 noise_file = os.path.join(path,'%s.txt'%self.name)
1315 self.filename_noise = os.path.join(figpath,noise_file)
1316
1317 self.setWinTitle(title)
1318
1319 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1320
1321 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1322 axes = self.axesList[0]
1323
1324 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1325
1326 if len(self.ydata)==0:
1327 self.ydata = noisedB.reshape(-1,1)
1328 else:
1329 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1330
1331
1332 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1333 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1334 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1335 XAxisAsTime=True, grid='both'
1336 )
1337
1338 self.draw()
1339
1340 if dataOut.ltctime >= self.xmax:
1341 self.counter_imagwr = wr_period
1342 self.isConfig = False
1343 update_figfile = True
1344
1345 self.save(figpath=figpath,
1346 figfile=figfile,
1347 save=save,
1348 ftp=ftp,
1349 wr_period=wr_period,
1350 thisDatetime=thisDatetime,
1351 update_figfile=update_figfile)
1352
1353 #store data beacon phase
1354 if save:
1355 self.save_data(self.filename_noise, noisedB, thisDatetime)
1356
418
1357 return dataOut
1358
419
1359 @MPDecorator
420 class BeaconPhase(Plot):
1360 class BeaconPhase_(Figure):
1361
421
1362 __isConfig = None
422 __isConfig = None
1363 __nsubplots = None
423 __nsubplots = None
@@ -1365,7 +425,7 class BeaconPhase_(Figure):
1365 PREFIX = 'beacon_phase'
425 PREFIX = 'beacon_phase'
1366
426
1367 def __init__(self):
427 def __init__(self):
1368 Figure.__init__(self)
428 Plot.__init__(self)
1369 self.timerange = 24*60*60
429 self.timerange = 24*60*60
1370 self.isConfig = False
430 self.isConfig = False
1371 self.__nsubplots = 1
431 self.__nsubplots = 1
@@ -1436,6 +496,8 class BeaconPhase_(Figure):
1436 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
496 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1437 f.close()
497 f.close()
1438
498
499 def plot(self):
500 log.warning('TODO: Not yet implemented...')
1439
501
1440 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
502 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1441 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
503 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
@@ -6,227 +6,129 Created on Jul 9, 2014
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
10 from schainpy.utils import log
11 from .figure import Figure
12
9
10 from schainpy.model.graphics.jroplot_base import Plot, plt
13
11
14 @MPDecorator
12
15 class Scope_(Figure):
13 class ScopePlot(Plot):
16
14
17 isConfig = None
15 '''
18
16 Plot for Scope
19 def __init__(self):#, **kwargs): #YONG
17 '''
20 Figure.__init__(self)#, **kwargs)
18
21 self.isConfig = False
19 CODE = 'scope'
22 self.WIDTH = 300
20 plot_name = 'Scope'
23 self.HEIGHT = 200
21 plot_type = 'scatter'
24 self.counter_imagwr = 0
25
26 def getSubplots(self):
27
28 nrow = self.nplots
29 ncol = 3
30 return nrow, ncol
31
22
32 def setup(self, id, nplots, wintitle, show):
23 def setup(self):
33
24
34 self.nplots = nplots
25 self.xaxis = 'Range (Km)'
35
26 self.ncols = 1
36 self.createFigure(id=id,
27 self.nrows = 1
37 wintitle=wintitle,
28 self.nplots = 1
38 show=show)
29 self.ylabel = 'Intensity [dB]'
39
30 self.titles = ['Scope']
40 nrow,ncol = self.getSubplots()
31 self.colorbar = False
41 colspan = 3
32 self.width = 6
42 rowspan = 1
33 self.height = 4
34
35 def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle):
43
36
44 for i in range(nplots):
45 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
46
47 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
48 yreal = y[channelIndexList,:].real
37 yreal = y[channelIndexList,:].real
49 yimag = y[channelIndexList,:].imag
38 yimag = y[channelIndexList,:].imag
50
39 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
51 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
40 self.xlabel = "Range (Km)"
52 xlabel = "Range (Km)"
41 self.ylabel = "Intensity - IQ"
53 ylabel = "Intensity - IQ"
54
55 if not self.isConfig:
56 nplots = len(channelIndexList)
57
58 self.setup(id=id,
59 nplots=nplots,
60 wintitle='',
61 show=show)
62
63 if xmin == None: xmin = numpy.nanmin(x)
64 if xmax == None: xmax = numpy.nanmax(x)
65 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
66 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
67
42
68 self.isConfig = True
43 self.y = yreal
44 self.x = x
45 self.xmin = min(x)
46 self.xmax = max(x)
69
47
70 self.setWinTitle(title)
71
72 for i in range(len(self.axesList)):
73 title = "Channel %d" %(i)
74 axes = self.axesList[i]
75
48
76 axes.pline(x, yreal[i,:],
49 self.titles[0] = title
77 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
78 xlabel=xlabel, ylabel=ylabel, title=title)
79
50
80 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
51 for i,ax in enumerate(self.axes):
81
52 title = "Channel %d" %(i)
82 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
53 if ax.firsttime:
54 ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0]
55 ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0]
56 else:
57 ax.plt_r.set_data(x, yreal[i,:])
58 ax.plt_i.set_data(x, yimag[i,:])
59
60 def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle):
83 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
61 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
84 yreal = y.real
62 yreal = y.real
63 self.y = yreal
64 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
65 self.xlabel = "Range (Km)"
66 self.ylabel = "Intensity"
67 self.xmin = min(x)
68 self.xmax = max(x)
85
69
86 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
87 xlabel = "Range (Km)"
88 ylabel = "Intensity"
89
70
90 if not self.isConfig:
71 self.titles[0] = title
91 nplots = len(channelIndexList)
72
73 for i,ax in enumerate(self.axes):
74 title = "Channel %d" %(i)
92
75
93 self.setup(id=id,
76 ychannel = yreal[i,:]
94 nplots=nplots,
95 wintitle='',
96 show=show)
97
77
98 if xmin == None: xmin = numpy.nanmin(x)
78 if ax.firsttime:
99 if xmax == None: xmax = numpy.nanmax(x)
79 ax.plt_r = ax.plot(x, ychannel)[0]
100 if ymin == None: ymin = numpy.nanmin(yreal)
80 else:
101 if ymax == None: ymax = numpy.nanmax(yreal)
81 #pass
102
82 ax.plt_r.set_data(x, ychannel)
103 self.isConfig = True
104
83
105 self.setWinTitle(title)
106
107 for i in range(len(self.axesList)):
108 title = "Channel %d" %(i)
109 axes = self.axesList[i]
110 ychannel = yreal[i,:]
111 axes.pline(x, ychannel,
112 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
113 xlabel=xlabel, ylabel=ylabel, title=title)
114
84
115
85 def plot(self):
116 def run(self, dataOut, id, wintitle="", channelList=None,
117 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
118 figpath='./', figfile=None, show=True, wr_period=1,
119 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
120
121 """
122
123 Input:
124 dataOut :
125 id :
126 wintitle :
127 channelList :
128 xmin : None,
129 xmax : None,
130 ymin : None,
131 ymax : None,
132 """
133 if dataOut.flagNoData:
134 return dataOut
135
86
136 if channelList == None:
87 if self.channels:
137 channelIndexList = dataOut.channelIndexList
88 channels = self.channels
138 else:
89 else:
139 channelIndexList = []
90 channels = self.data.channels
140 for channel in channelList:
91
141 if channel not in dataOut.channelList:
92 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1])
142 raise ValueError("Channel %d is not in dataOut.channelList")
143 channelIndexList.append(dataOut.channelList.index(channel))
144
93
145 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
94 scope = self.data['scope']
146
95
147 if dataOut.flagDataAsBlock:
96 if self.data.flagDataAsBlock:
148
97
149 for i in range(dataOut.nProfiles):
98 for i in range(self.data.nProfiles):
150
99
151 wintitle1 = wintitle + " [Profile = %d] " %i
100 wintitle1 = " [Profile = %d] " %i
152
101
153 if type == "power":
102 if self.type == "power":
154 self.plot_power(dataOut.heightList,
103 self.plot_power(self.data.heights,
155 dataOut.data[:,i,:],
104 scope[:,i,:],
156 id,
105 channels,
157 channelIndexList,
106 thisDatetime,
158 thisDatetime,
107 wintitle1
159 wintitle1,
108 )
160 show,
109
161 xmin,
110 if self.type == "iq":
162 xmax,
111 self.plot_iq(self.data.heights,
163 ymin,
112 scope[:,i,:],
164 ymax)
113 channels,
165
114 thisDatetime,
166 if type == "iq":
115 wintitle1
167 self.plot_iq(dataOut.heightList,
116 )
168 dataOut.data[:,i,:],
169 id,
170 channelIndexList,
171 thisDatetime,
172 wintitle1,
173 show,
174 xmin,
175 xmax,
176 ymin,
177 ymax)
178
179 self.draw()
180
181 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
182 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
183
184 self.save(figpath=figpath,
185 figfile=figfile,
186 save=save,
187 ftp=ftp,
188 wr_period=wr_period,
189 thisDatetime=thisDatetime)
190
191 else:
117 else:
192 wintitle += " [Profile = %d] " %dataOut.profileIndex
118 wintitle = " [Profile = %d] " %self.data.profileIndex
193
119
194 if type == "power":
120 if self.type == "power":
195 self.plot_power(dataOut.heightList,
121 self.plot_power(self.data.heights,
196 dataOut.data,
122 scope,
197 id,
123 channels,
198 channelIndexList,
124 thisDatetime,
199 thisDatetime,
125 wintitle
200 wintitle,
126 )
201 show,
202 xmin,
203 xmax,
204 ymin,
205 ymax)
206
127
207 if type == "iq":
128 if self.type == "iq":
208 self.plot_iq(dataOut.heightList,
129 self.plot_iq(self.data.heights,
209 dataOut.data,
130 scope,
210 id,
131 channels,
211 channelIndexList,
132 thisDatetime,
212 thisDatetime,
133 wintitle
213 wintitle,
134 )
214 show,
215 xmin,
216 xmax,
217 ymin,
218 ymax)
219
220 self.draw()
221
222 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
223 figfile = self.getFilename(name = str_datetime)
224
225 self.save(figpath=figpath,
226 figfile=figfile,
227 save=save,
228 ftp=ftp,
229 wr_period=wr_period,
230 thisDatetime=thisDatetime)
231
232 return dataOut No newline at end of file
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (658 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (779 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now