##// END OF EJS Templates
Update plots modules
Juan C. Espinoza -
r1308:fe4d0955eff6
parent child
Show More
@@ -152,7 +152,7 class OperationConf(ConfBase):
152
152
153 className = eval(self.name)
153 className = eval(self.name)
154
154
155 if 'Plot' in self.name or 'Writer' in self.name or 'Send' in self.name:
155 if 'Plot' in self.name or 'Writer' in self.name or 'Send' in self.name or 'print' in self.name:
156 kwargs = self.getKwargs()
156 kwargs = self.getKwargs()
157 opObj = className(self.id, self.id, self.project_id, self.err_queue, **kwargs)
157 opObj = className(self.id, self.id, self.project_id, self.err_queue, **kwargs)
158 opObj.start()
158 opObj.start()
@@ -1122,13 +1122,14 class PlotterData(object):
1122 self.localtime = False
1122 self.localtime = False
1123 self.data = {}
1123 self.data = {}
1124 self.meta = {}
1124 self.meta = {}
1125 self.__times = []
1126 self.__heights = []
1125 self.__heights = []
1127
1126
1128 if 'snr' in code:
1127 if 'snr' in code:
1129 self.plottypes = ['snr']
1128 self.plottypes = ['snr']
1130 elif code == 'spc':
1129 elif code == 'spc':
1131 self.plottypes = ['spc', 'noise', 'rti']
1130 self.plottypes = ['spc', 'noise', 'rti']
1131 elif code == 'cspc':
1132 self.plottypes = ['cspc', 'spc', 'noise', 'rti']
1132 elif code == 'rti':
1133 elif code == 'rti':
1133 self.plottypes = ['noise', 'rti']
1134 self.plottypes = ['noise', 'rti']
1134 else:
1135 else:
@@ -1143,17 +1144,17 class PlotterData(object):
1143
1144
1144 def __str__(self):
1145 def __str__(self):
1145 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1146 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1146 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1147 return 'Data[{}][{}]'.format(';'.join(dum), len(self.times))
1147
1148
1148 def __len__(self):
1149 def __len__(self):
1149 return len(self.__times)
1150 return len(self.data[self.key])
1150
1151
1151 def __getitem__(self, key):
1152 def __getitem__(self, key):
1152
1153
1153 if key not in self.data:
1154 if key not in self.data:
1154 raise KeyError(log.error('Missing key: {}'.format(key)))
1155 raise KeyError(log.error('Missing key: {}'.format(key)))
1155 if 'spc' in key or not self.buffering:
1156 if 'spc' in key or not self.buffering:
1156 ret = self.data[key]
1157 ret = self.data[key][self.tm]
1157 elif 'scope' in key:
1158 elif 'scope' in key:
1158 ret = numpy.array(self.data[key][float(self.tm)])
1159 ret = numpy.array(self.data[key][float(self.tm)])
1159 else:
1160 else:
@@ -1171,8 +1172,8 class PlotterData(object):
1171 '''
1172 '''
1172 self.type = ''
1173 self.type = ''
1173 self.ready = False
1174 self.ready = False
1175 del self.data
1174 self.data = {}
1176 self.data = {}
1175 self.__times = []
1176 self.__heights = []
1177 self.__heights = []
1177 self.__all_heights = set()
1178 self.__all_heights = set()
1178 for plot in self.plottypes:
1179 for plot in self.plottypes:
@@ -1198,15 +1199,14 class PlotterData(object):
1198 if len(self.data[key]):
1199 if len(self.data[key]):
1199 if 'spc' in key or not self.buffering:
1200 if 'spc' in key or not self.buffering:
1200 return self.data[key].shape
1201 return self.data[key].shape
1201 return self.data[key][self.__times[0]].shape
1202 return self.data[key][self.times[0]].shape
1202 return (0,)
1203 return (0,)
1203
1204
1204 def update(self, dataOut, tm):
1205 def update(self, dataOut, tm):
1205 '''
1206 '''
1206 Update data object with new dataOut
1207 Update data object with new dataOut
1207 '''
1208 '''
1208 if tm in self.__times:
1209
1209 return
1210 self.profileIndex = dataOut.profileIndex
1210 self.profileIndex = dataOut.profileIndex
1211 self.tm = tm
1211 self.tm = tm
1212 self.type = dataOut.type
1212 self.type = dataOut.type
@@ -1223,16 +1223,14 class PlotterData(object):
1223 if True in ['spc' in ptype for ptype in self.plottypes]:
1223 if True in ['spc' in ptype for ptype in self.plottypes]:
1224 self.xrange = (dataOut.getFreqRange(1)/1000.,
1224 self.xrange = (dataOut.getFreqRange(1)/1000.,
1225 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1225 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1226 self.factor = dataOut.normFactor
1227 self.__heights.append(dataOut.heightList)
1226 self.__heights.append(dataOut.heightList)
1228 self.__all_heights.update(dataOut.heightList)
1227 self.__all_heights.update(dataOut.heightList)
1229 self.__times.append(tm)
1228
1230 for plot in self.plottypes:
1229 for plot in self.plottypes:
1231 if plot in ('spc', 'spc_moments', 'spc_cut'):
1230 if plot in ('spc', 'spc_moments', 'spc_cut'):
1232 z = dataOut.data_spc/dataOut.normFactor
1231 z = dataOut.data_spc/dataOut.normFactor
1233 buffer = 10*numpy.log10(z)
1232 buffer = 10*numpy.log10(z)
1234 if plot == 'cspc':
1233 if plot == 'cspc':
1235 z = dataOut.data_spc/dataOut.normFactor
1236 buffer = (dataOut.data_spc, dataOut.data_cspc)
1234 buffer = (dataOut.data_spc, dataOut.data_cspc)
1237 if plot == 'noise':
1235 if plot == 'noise':
1238 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1236 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
@@ -1270,18 +1268,17 class PlotterData(object):
1270 self.nProfiles = dataOut.nProfiles
1268 self.nProfiles = dataOut.nProfiles
1271
1269
1272 if plot == 'spc':
1270 if plot == 'spc':
1273 self.data['spc'] = buffer
1271 self.data['spc'][tm] = buffer
1274 elif plot == 'cspc':
1272 elif plot == 'cspc':
1275 self.data['spc'] = buffer[0]
1273 self.data['cspc'][tm] = buffer
1276 self.data['cspc'] = buffer[1]
1277 elif plot == 'spc_moments':
1274 elif plot == 'spc_moments':
1278 self.data['spc'] = buffer
1275 self.data['spc'][tm] = buffer
1279 self.data['moments'][tm] = dataOut.moments
1276 self.data['moments'][tm] = dataOut.moments
1280 else:
1277 else:
1281 if self.buffering:
1278 if self.buffering:
1282 self.data[plot][tm] = buffer
1279 self.data[plot][tm] = buffer
1283 else:
1280 else:
1284 self.data[plot] = buffer
1281 self.data[plot][tm] = buffer
1285
1282
1286 if dataOut.channelList is None:
1283 if dataOut.channelList is None:
1287 self.channels = range(buffer.shape[0])
1284 self.channels = range(buffer.shape[0])
@@ -1302,7 +1299,7 class PlotterData(object):
1302 for key in self.data:
1299 for key in self.data:
1303 shape = self.shape(key)[:-1] + H.shape
1300 shape = self.shape(key)[:-1] + H.shape
1304 for tm, obj in list(self.data[key].items()):
1301 for tm, obj in list(self.data[key].items()):
1305 h = self.__heights[self.__times.index(tm)]
1302 h = self.__heights[self.times.index(tm)]
1306 if H.size == h.size:
1303 if H.size == h.size:
1307 continue
1304 continue
1308 index = numpy.where(numpy.in1d(H, h))[0]
1305 index = numpy.where(numpy.in1d(H, h))[0]
@@ -1313,19 +1310,18 class PlotterData(object):
1313 dummy[index] = obj
1310 dummy[index] = obj
1314 self.data[key][tm] = dummy
1311 self.data[key][tm] = dummy
1315
1312
1316 self.__heights = [H for tm in self.__times]
1313 self.__heights = [H for tm in self.times]
1317
1314
1318 def jsonify(self, plot_name, plot_type, decimate=False):
1315 def jsonify(self, tm, plot_name, plot_type, decimate=False):
1319 '''
1316 '''
1320 Convert data to json
1317 Convert data to json
1321 '''
1318 '''
1322
1319
1323 tm = self.times[-1]
1324 dy = int(self.heights.size/self.MAXNUMY) + 1
1320 dy = int(self.heights.size/self.MAXNUMY) + 1
1325 if self.key in ('spc', 'cspc') or not self.buffering:
1321 if self.key in ('spc', 'cspc'):
1326 dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1
1322 dx = int(self.data[self.key][tm].shape[1]/self.MAXNUMX) + 1
1327 data = self.roundFloats(
1323 data = self.roundFloats(
1328 self.data[self.key][::, ::dx, ::dy].tolist())
1324 self.data[self.key][tm][::, ::dx, ::dy].tolist())
1329 else:
1325 else:
1330 if self.key is 'noise':
1326 if self.key is 'noise':
1331 data = [[x] for x in self.roundFloats(self.data[self.key][tm].tolist())]
1327 data = [[x] for x in self.roundFloats(self.data[self.key][tm].tolist())]
@@ -1358,8 +1354,9 class PlotterData(object):
1358 Return the list of times of the current data
1354 Return the list of times of the current data
1359 '''
1355 '''
1360
1356
1361 ret = numpy.array(self.__times)
1357 ret = numpy.array([*self.data[self.key]])
1362 ret.sort()
1358 if self:
1359 ret.sort()
1363 return ret
1360 return ret
1364
1361
1365 @property
1362 @property
@@ -202,7 +202,7 class Plot(Operation):
202 self.zlimits = kwargs.get('zlimits', None)
202 self.zlimits = kwargs.get('zlimits', None)
203 self.xmin = kwargs.get('xmin', None)
203 self.xmin = kwargs.get('xmin', None)
204 self.xmax = kwargs.get('xmax', None)
204 self.xmax = kwargs.get('xmax', None)
205 self.xrange = kwargs.get('xrange', 24)
205 self.xrange = kwargs.get('xrange', 12)
206 self.xscale = kwargs.get('xscale', None)
206 self.xscale = kwargs.get('xscale', None)
207 self.ymin = kwargs.get('ymin', None)
207 self.ymin = kwargs.get('ymin', None)
208 self.ymax = kwargs.get('ymax', None)
208 self.ymax = kwargs.get('ymax', None)
@@ -228,6 +228,7 class Plot(Operation):
228 self.exp_code = kwargs.get('exp_code', None)
228 self.exp_code = kwargs.get('exp_code', None)
229 self.plot_server = kwargs.get('plot_server', False)
229 self.plot_server = kwargs.get('plot_server', False)
230 self.sender_period = kwargs.get('sender_period', 60)
230 self.sender_period = kwargs.get('sender_period', 60)
231 self.tag = kwargs.get('tag', '')
231 self.height_index = kwargs.get('height_index', None)
232 self.height_index = kwargs.get('height_index', None)
232 self.__throttle_plot = apply_throttle(self.throttle)
233 self.__throttle_plot = apply_throttle(self.throttle)
233 self.data = PlotterData(
234 self.data = PlotterData(
@@ -572,19 +573,29 class Plot(Operation):
572
573
573 self.sender_time = self.data.tm
574 self.sender_time = self.data.tm
574
575
575 attrs = ['titles', 'zmin', 'zmax', 'colormap']
576 attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax']
576 for attr in attrs:
577 for attr in attrs:
577 value = getattr(self, attr)
578 value = getattr(self, attr)
578 if value is not None:
579 if value:
579 self.data.meta[attr] = getattr(self, attr)
580 if isinstance(value, (numpy.float32, numpy.float64)):
581 value = round(float(value), 2)
582 self.data.meta[attr] = value
583 if self.colormap == 'jet':
584 self.data.meta['colormap'] = 'Jet'
585 elif 'RdBu' in self.colormap:
586 self.data.meta['colormap'] = 'RdBu'
587 else:
588 self.data.meta['colormap'] = 'Viridis'
580 self.data.meta['interval'] = int(interval)
589 self.data.meta['interval'] = int(interval)
581 msg = self.data.jsonify(self.plot_name, self.plot_type)
590 # msg = self.data.jsonify(self.data.tm, self.plot_name, self.plot_type)
582 self.sender_queue.put(msg)
591 self.sender_queue.put(self.data.tm)
583
592
584 while True:
593 while True:
585 if self.sender_queue.empty():
594 if self.sender_queue.empty():
586 break
595 break
587 self.socket.send_string(self.sender_queue.get())
596 tm = self.sender_queue.get()
597 msg = self.data.jsonify(tm, self.plot_name, self.plot_type)
598 self.socket.send_string(msg)
588 socks = dict(self.poll.poll(5000))
599 socks = dict(self.poll.poll(5000))
589 if socks.get(self.socket) == zmq.POLLIN:
600 if socks.get(self.socket) == zmq.POLLIN:
590 reply = self.socket.recv_string()
601 reply = self.socket.recv_string()
@@ -598,7 +609,7 class Plot(Operation):
598 else:
609 else:
599 log.warning(
610 log.warning(
600 "No response from server, retrying...", self.name)
611 "No response from server, retrying...", self.name)
601 self.sender_queue.put(msg)
612 self.sender_queue.put(self.data.tm)
602 self.socket.setsockopt(zmq.LINGER, 0)
613 self.socket.setsockopt(zmq.LINGER, 0)
603 self.socket.close()
614 self.socket.close()
604 self.poll.unregister(self.socket)
615 self.poll.unregister(self.socket)
@@ -647,16 +658,16 class Plot(Operation):
647 if self.localtime:
658 if self.localtime:
648 t -= time.timezone
659 t -= time.timezone
649
660
650 if 'buffer' in self.plot_type:
661 if self.xmin is None:
651 if self.xmin is None:
662 self.tmin = t
652 self.tmin = t
663 if 'buffer' in self.plot_type:
653 self.xmin = self.getDateTime(t).hour
664 self.xmin = self.getDateTime(t).hour
654 else:
665 else:
655 self.tmin = (
666 self.tmin = (
656 self.getDateTime(t).replace(
667 self.getDateTime(t).replace(
657 hour=int(self.xmin),
668 hour=int(self.xmin),
658 minute=0,
669 minute=0,
659 second=0) - self.getDateTime(0)).total_seconds()
670 second=0) - self.getDateTime(0)).total_seconds()
660
671
661 self.data.setup()
672 self.data.setup()
662 self.isConfig = True
673 self.isConfig = True
@@ -674,12 +685,13 class Plot(Operation):
674 if dataOut.useLocalTime and not self.localtime:
685 if dataOut.useLocalTime and not self.localtime:
675 tm += time.timezone
686 tm += time.timezone
676
687
677 if self.xaxis is 'time' and self.data and (tm - self.tmin) >= self.xrange*60*60:
688 if self.data and (tm - self.tmin) >= self.xrange*60*60:
678 self.save_counter = self.save_period
689 self.save_counter = self.save_period
679 self.__plot()
690 self.__plot()
680 self.xmin += self.xrange
691 if 'time' in self.xaxis:
681 if self.xmin >= 24:
692 self.xmin += self.xrange
682 self.xmin -= 24
693 if self.xmin >= 24:
694 self.xmin -= 24
683 self.tmin += self.xrange*60*60
695 self.tmin += self.xrange*60*60
684 self.data.setup()
696 self.data.setup()
685 self.clear_figures()
697 self.clear_figures()
@@ -126,39 +126,38 class CrossSpectraPlot(Plot):
126
126
127 y = self.data.heights
127 y = self.data.heights
128 self.y = y
128 self.y = y
129 spc = self.data['spc']
129 nspc = self.data['spc']
130 cspc = self.data['cspc']
130 spc = self.data['cspc'][0]
131 cspc = self.data['cspc'][1]
131
132
132 for n in range(self.nrows):
133 for n in range(self.nrows):
133 noise = self.data['noise'][n][-1]
134 noise = self.data['noise'][:,-1]
134 pair = self.data.pairs[n]
135 pair = self.data.pairs[n]
135 ax = self.axes[4 * n]
136 ax = self.axes[4 * n]
136 spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor)
137 if ax.firsttime:
137 if ax.firsttime:
138 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
138 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
139 self.xmin = self.xmin if self.xmin else -self.xmax
139 self.xmin = self.xmin if self.xmin else -self.xmax
140 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
140 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
141 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
141 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
142 ax.plt = ax.pcolormesh(x , y , spc0.T,
142 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
143 vmin=self.zmin,
143 vmin=self.zmin,
144 vmax=self.zmax,
144 vmax=self.zmax,
145 cmap=plt.get_cmap(self.colormap)
145 cmap=plt.get_cmap(self.colormap)
146 )
146 )
147 else:
147 else:
148 ax.plt.set_array(spc0.T.ravel())
148 ax.plt.set_array(nspc[pair[0]].T.ravel())
149 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise))
149 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
150
150
151 ax = self.axes[4 * n + 1]
151 ax = self.axes[4 * n + 1]
152 spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor)
153 if ax.firsttime:
152 if ax.firsttime:
154 ax.plt = ax.pcolormesh(x , y, spc1.T,
153 ax.plt = ax.pcolormesh(x , y, nspc[pair[1]].T,
155 vmin=self.zmin,
154 vmin=self.zmin,
156 vmax=self.zmax,
155 vmax=self.zmax,
157 cmap=plt.get_cmap(self.colormap)
156 cmap=plt.get_cmap(self.colormap)
158 )
157 )
159 else:
158 else:
160 ax.plt.set_array(spc1.T.ravel())
159 ax.plt.set_array(nspc[pair[1]].T.ravel())
161 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise))
160 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
162
161
163 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
162 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
164 coh = numpy.abs(out)
163 coh = numpy.abs(out)
@@ -300,6 +299,7 class NoisePlot(Plot):
300 self.nrows = 1
299 self.nrows = 1
301 self.nplots = 1
300 self.nplots = 1
302 self.ylabel = 'Intensity [dB]'
301 self.ylabel = 'Intensity [dB]'
302 self.xlabel = 'Time'
303 self.titles = ['Noise']
303 self.titles = ['Noise']
304 self.colorbar = False
304 self.colorbar = False
305
305
@@ -20,4 +20,5 from .bltrIO_spectra import *
20 from .jroIO_mira35c import *
20 from .jroIO_mira35c import *
21 from .julIO_param import *
21 from .julIO_param import *
22
22
23 from .pxIO_param import * No newline at end of file
23 from .pxIO_param import *
24 from .jroIO_simulator import * No newline at end of file
@@ -14,7 +14,7 import time
14 import datetime
14 import datetime
15 import zmq
15 import zmq
16
16
17 from schainpy.model.proc.jroproc_base import Operation
17 from schainpy.model.proc.jroproc_base import Operation, MPDecorator
18 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
18 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
19 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
19 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
20 from schainpy.utils import log
20 from schainpy.utils import log
@@ -1555,6 +1555,7 class JRODataWriter(Reader):
1555 self.putData()
1555 self.putData()
1556 return self.dataOut
1556 return self.dataOut
1557
1557
1558 @MPDecorator
1558 class printInfo(Operation):
1559 class printInfo(Operation):
1559
1560
1560 def __init__(self):
1561 def __init__(self):
@@ -1564,7 +1565,7 class printInfo(Operation):
1564
1565
1565 def run(self, dataOut, headers = ['systemHeaderObj', 'radarControllerHeaderObj', 'processingHeaderObj']):
1566 def run(self, dataOut, headers = ['systemHeaderObj', 'radarControllerHeaderObj', 'processingHeaderObj']):
1566 if self.__printInfo == False:
1567 if self.__printInfo == False:
1567 return dataOut
1568 return
1568
1569
1569 for header in headers:
1570 for header in headers:
1570 if hasattr(dataOut, header):
1571 if hasattr(dataOut, header):
@@ -1577,4 +1578,3 class printInfo(Operation):
1577 log.warning('Header {} Not found in object'.format(header))
1578 log.warning('Header {} Not found in object'.format(header))
1578
1579
1579 self.__printInfo = False
1580 self.__printInfo = False
1580 return dataOut No newline at end of file
@@ -377,6 +377,23 class setAttribute(Operation):
377 return dataOut
377 return dataOut
378
378
379
379
380 @MPDecorator
381 class printAttribute(Operation):
382 '''
383 Print an arbitrary attribute of dataOut
384 '''
385
386 def __init__(self):
387
388 Operation.__init__(self)
389
390 def run(self, dataOut, attributes):
391
392 for attr in attributes:
393 if hasattr(dataOut, attr):
394 log.log(getattr(dataOut, attr), attr)
395
396
380 class interpolateHeights(Operation):
397 class interpolateHeights(Operation):
381
398
382 def run(self, dataOut, topLim, botLim):
399 def run(self, dataOut, topLim, botLim):
General Comments 0
You need to be logged in to leave comments. Login now