@@ -1103,8 +1103,9 class PlotterData(object): | |||||
1103 | MAXNUMX = 100 |
|
1103 | MAXNUMX = 100 | |
1104 | MAXNUMY = 100 |
|
1104 | MAXNUMY = 100 | |
1105 |
|
1105 | |||
1106 | def __init__(self, code, throttle_value, exp_code, buffering=True): |
|
1106 | def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False): | |
1107 |
|
1107 | |||
|
1108 | self.key = code | |||
1108 | self.throttle = throttle_value |
|
1109 | self.throttle = throttle_value | |
1109 | self.exp_code = exp_code |
|
1110 | self.exp_code = exp_code | |
1110 | self.buffering = buffering |
|
1111 | self.buffering = buffering | |
@@ -1123,7 +1124,10 class PlotterData(object): | |||||
1123 | self.plottypes = ['noise', 'rti'] |
|
1124 | self.plottypes = ['noise', 'rti'] | |
1124 | else: |
|
1125 | else: | |
1125 | self.plottypes = [code] |
|
1126 | self.plottypes = [code] | |
1126 |
|
1127 | |||
|
1128 | if 'snr' not in self.plottypes and snr: | |||
|
1129 | self.plottypes.append('snr') | |||
|
1130 | ||||
1127 | for plot in self.plottypes: |
|
1131 | for plot in self.plottypes: | |
1128 | self.data[plot] = {} |
|
1132 | self.data[plot] = {} | |
1129 |
|
1133 | |||
@@ -1199,10 +1203,8 class PlotterData(object): | |||||
1199 | self.tm = tm |
|
1203 | self.tm = tm | |
1200 | self.type = dataOut.type |
|
1204 | self.type = dataOut.type | |
1201 | self.parameters = getattr(dataOut, 'parameters', []) |
|
1205 | self.parameters = getattr(dataOut, 'parameters', []) | |
1202 | if hasattr(dataOut, 'pairsList'): |
|
|||
1203 | self.pairs = dataOut.pairsList |
|
|||
1204 | if hasattr(dataOut, 'meta'): |
|
1206 | if hasattr(dataOut, 'meta'): | |
1205 |
self.meta |
|
1207 | self.meta.update(dataOut.meta) | |
1206 | self.channels = dataOut.channelList |
|
1208 | self.channels = dataOut.channelList | |
1207 | self.interval = dataOut.getTimeInterval() |
|
1209 | self.interval = dataOut.getTimeInterval() | |
1208 | self.localtime = dataOut.useLocalTime |
|
1210 | self.localtime = dataOut.useLocalTime | |
@@ -1285,40 +1287,40 class PlotterData(object): | |||||
1285 |
|
1287 | |||
1286 | self.__heights = [H for tm in self.__times] |
|
1288 | self.__heights = [H for tm in self.__times] | |
1287 |
|
1289 | |||
1288 | def jsonify(self, decimate=False): |
|
1290 | def jsonify(self, plot_name, plot_type, decimate=False): | |
1289 | ''' |
|
1291 | ''' | |
1290 | Convert data to json |
|
1292 | Convert data to json | |
1291 | ''' |
|
1293 | ''' | |
1292 |
|
1294 | |||
1293 | data = {} |
|
|||
1294 | tm = self.times[-1] |
|
1295 | tm = self.times[-1] | |
1295 | dy = int(self.heights.size/self.MAXNUMY) + 1 |
|
1296 | dy = int(self.heights.size/self.MAXNUMY) + 1 | |
1296 | for key in self.data: |
|
1297 | if self.key in ('spc', 'cspc') or not self.buffering: | |
1297 | if key in ('spc', 'cspc') or not self.buffering: |
|
1298 | dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1 | |
1298 | dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1 |
|
1299 | data = self.roundFloats( | |
1299 | data[key] = self.roundFloats( |
|
1300 | self.data[self.key][::, ::dx, ::dy].tolist()) | |
1300 | self.data[key][::, ::dx, ::dy].tolist()) |
|
|||
1301 | else: |
|
|||
1302 | data[key] = self.roundFloats(self.data[key][tm].tolist()) |
|
|||
1303 |
|
||||
1304 | ret = {'data': data} |
|
|||
1305 | ret['exp_code'] = self.exp_code |
|
|||
1306 | ret['time'] = float(tm) |
|
|||
1307 | ret['interval'] = float(self.interval) |
|
|||
1308 | ret['localtime'] = self.localtime |
|
|||
1309 | ret['yrange'] = self.roundFloats(self.heights[::dy].tolist()) |
|
|||
1310 | if 'spc' in self.data or 'cspc' in self.data: |
|
|||
1311 | ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
|||
1312 | else: |
|
1301 | else: | |
1313 | ret['xrange'] = [] |
|
1302 | data = self.roundFloats(self.data[self.key][tm].tolist()) | |
1314 |
if |
|
1303 | if self.key is 'noise': | |
1315 | ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs] |
|
1304 | data = [[x] for x in data] | |
|
1305 | ||||
|
1306 | meta = {} | |||
|
1307 | ret = { | |||
|
1308 | 'plot': plot_name, | |||
|
1309 | 'code': self.exp_code, | |||
|
1310 | 'time': float(tm), | |||
|
1311 | 'data': data, | |||
|
1312 | } | |||
|
1313 | meta['type'] = plot_type | |||
|
1314 | meta['interval'] = float(self.interval) | |||
|
1315 | meta['localtime'] = self.localtime | |||
|
1316 | meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) | |||
|
1317 | if 'spc' in self.data or 'cspc' in self.data: | |||
|
1318 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) | |||
1316 | else: |
|
1319 | else: | |
1317 |
|
|
1320 | meta['xrange'] = [] | |
1318 |
|
||||
1319 | for key, value in list(self.meta.items()): |
|
|||
1320 | ret[key] = value |
|
|||
1321 |
|
1321 | |||
|
1322 | meta.update(self.meta) | |||
|
1323 | ret['metadata'] = meta | |||
1322 | return json.dumps(ret) |
|
1324 | return json.dumps(ret) | |
1323 |
|
1325 | |||
1324 | @property |
|
1326 | @property |
@@ -162,6 +162,7 class Plot(Operation): | |||||
162 | self.isPlotConfig = False |
|
162 | self.isPlotConfig = False | |
163 | self.save_counter = 1 |
|
163 | self.save_counter = 1 | |
164 | self.sender_counter = 1 |
|
164 | self.sender_counter = 1 | |
|
165 | self.data = None | |||
165 |
|
166 | |||
166 | def __fmtTime(self, x, pos): |
|
167 | def __fmtTime(self, x, pos): | |
167 | ''' |
|
168 | ''' | |
@@ -226,7 +227,7 class Plot(Operation): | |||||
226 | self.sender_period = kwargs.get('sender_period', 2) |
|
227 | self.sender_period = kwargs.get('sender_period', 2) | |
227 | self.__throttle_plot = apply_throttle(self.throttle) |
|
228 | self.__throttle_plot = apply_throttle(self.throttle) | |
228 | self.data = PlotterData( |
|
229 | self.data = PlotterData( | |
229 | self.CODE, self.throttle, self.exp_code, self.buffering) |
|
230 | self.CODE, self.throttle, self.exp_code, self.buffering, snr=self.showSNR) | |
230 |
|
231 | |||
231 | if self.plot_server: |
|
232 | if self.plot_server: | |
232 | if not self.plot_server.startswith('tcp://'): |
|
233 | if not self.plot_server.startswith('tcp://'): | |
@@ -235,6 +236,8 class Plot(Operation): | |||||
235 | 'Sending to server: {}'.format(self.plot_server), |
|
236 | 'Sending to server: {}'.format(self.plot_server), | |
236 | self.name |
|
237 | self.name | |
237 | ) |
|
238 | ) | |
|
239 | if 'plot_name' in kwargs: | |||
|
240 | self.plot_name = kwargs['plot_name'] | |||
238 |
|
241 | |||
239 | def __setup_plot(self): |
|
242 | def __setup_plot(self): | |
240 | ''' |
|
243 | ''' | |
@@ -243,11 +246,7 class Plot(Operation): | |||||
243 |
|
246 | |||
244 | self.setup() |
|
247 | self.setup() | |
245 |
|
248 | |||
246 | self.time_label = 'LT' if self.localtime else 'UTC' |
|
249 | self.time_label = 'LT' if self.localtime else 'UTC' | |
247 | if self.data.localtime: |
|
|||
248 | self.getDateTime = datetime.datetime.fromtimestamp |
|
|||
249 | else: |
|
|||
250 | self.getDateTime = datetime.datetime.utcfromtimestamp |
|
|||
251 |
|
250 | |||
252 | if self.width is None: |
|
251 | if self.width is None: | |
253 | self.width = 8 |
|
252 | self.width = 8 | |
@@ -306,15 +305,13 class Plot(Operation): | |||||
306 | cmap = plt.get_cmap(self.colormap) |
|
305 | cmap = plt.get_cmap(self.colormap) | |
307 | cmap.set_bad(self.bgcolor, 1.) |
|
306 | cmap.set_bad(self.bgcolor, 1.) | |
308 | self.cmaps.append(cmap) |
|
307 | self.cmaps.append(cmap) | |
309 |
|
308 | |||
310 | for fig in self.figures: |
|
309 | for fig in self.figures: | |
311 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) |
|
310 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
312 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) |
|
311 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
313 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) |
|
312 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
314 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) |
|
313 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
315 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) |
|
314 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
316 | if self.show: |
|
|||
317 | fig.show() |
|
|||
318 |
|
315 | |||
319 | def OnKeyPress(self, event): |
|
316 | def OnKeyPress(self, event): | |
320 | ''' |
|
317 | ''' | |
@@ -463,7 +460,6 class Plot(Operation): | |||||
463 | datetime.datetime(1970, 1, 1)).total_seconds() |
|
460 | datetime.datetime(1970, 1, 1)).total_seconds() | |
464 | if self.data.localtime: |
|
461 | if self.data.localtime: | |
465 | xmin += time.timezone |
|
462 | xmin += time.timezone | |
466 | self.tmin = xmin |
|
|||
467 | else: |
|
463 | else: | |
468 | xmin = self.xmin |
|
464 | xmin = self.xmin | |
469 |
|
465 | |||
@@ -563,7 +559,7 class Plot(Operation): | |||||
563 | ax.set_title('{} {} {}'.format( |
|
559 | ax.set_title('{} {} {}'.format( | |
564 | self.titles[n], |
|
560 | self.titles[n], | |
565 | self.getDateTime(self.data.max_time).strftime( |
|
561 | self.getDateTime(self.data.max_time).strftime( | |
566 | '%H:%M:%S'), |
|
562 | '%Y-%m-%d %H:%M:%S'), | |
567 | self.time_label), |
|
563 | self.time_label), | |
568 | size=8) |
|
564 | size=8) | |
569 | else: |
|
565 | else: | |
@@ -608,6 +604,9 class Plot(Operation): | |||||
608 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
604 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
609 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) |
|
605 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) | |
610 | fig.canvas.draw() |
|
606 | fig.canvas.draw() | |
|
607 | if self.show: | |||
|
608 | fig.show() | |||
|
609 | figpause(0.1) | |||
611 |
|
610 | |||
612 | if self.save: |
|
611 | if self.save: | |
613 | self.save_figure(n) |
|
612 | self.save_figure(n) | |
@@ -675,10 +674,10 class Plot(Operation): | |||||
675 | self.sender_counter += 1 |
|
674 | self.sender_counter += 1 | |
676 |
|
675 | |||
677 | self.sender_counter = 1 |
|
676 | self.sender_counter = 1 | |
678 |
|
677 | self.data.meta['titles'] = self.titles | ||
679 | retries = 2 |
|
678 | retries = 2 | |
680 | while True: |
|
679 | while True: | |
681 | self.socket.send_string(self.data.jsonify()) |
|
680 | self.socket.send_string(self.data.jsonify(self.plot_name, self.plot_type)) | |
682 | socks = dict(self.poll.poll(5000)) |
|
681 | socks = dict(self.poll.poll(5000)) | |
683 | if socks.get(self.socket) == zmq.POLLIN: |
|
682 | if socks.get(self.socket) == zmq.POLLIN: | |
684 | reply = self.socket.recv_string() |
|
683 | reply = self.socket.recv_string() | |
@@ -730,14 +729,35 class Plot(Operation): | |||||
730 | raise NotImplementedError |
|
729 | raise NotImplementedError | |
731 |
|
730 | |||
732 | def run(self, dataOut, **kwargs): |
|
731 | def run(self, dataOut, **kwargs): | |
733 |
|
732 | ''' | ||
734 | if dataOut.error: |
|
733 | Main plotting routine | |
735 | coerce = True |
|
734 | ''' | |
736 | else: |
|
|||
737 | coerce = False |
|
|||
738 |
|
735 | |||
739 | if self.isConfig is False: |
|
736 | if self.isConfig is False: | |
740 | self.__setup(**kwargs) |
|
737 | self.__setup(**kwargs) | |
|
738 | if dataOut.type == 'Parameters': | |||
|
739 | t = dataOut.utctimeInit | |||
|
740 | else: | |||
|
741 | t = dataOut.utctime | |||
|
742 | ||||
|
743 | if dataOut.useLocalTime: | |||
|
744 | self.getDateTime = datetime.datetime.fromtimestamp | |||
|
745 | if not self.localtime: | |||
|
746 | t += time.timezone | |||
|
747 | else: | |||
|
748 | self.getDateTime = datetime.datetime.utcfromtimestamp | |||
|
749 | if self.localtime: | |||
|
750 | t -= time.timezone | |||
|
751 | ||||
|
752 | if self.xmin is None: | |||
|
753 | self.tmin = t | |||
|
754 | else: | |||
|
755 | self.tmin = ( | |||
|
756 | self.getDateTime(t).replace( | |||
|
757 | hour=self.xmin, | |||
|
758 | minute=0, | |||
|
759 | second=0) - self.getDateTime(0)).total_seconds() | |||
|
760 | ||||
741 | self.data.setup() |
|
761 | self.data.setup() | |
742 | self.isConfig = True |
|
762 | self.isConfig = True | |
743 | if self.plot_server: |
|
763 | if self.plot_server: | |
@@ -751,16 +771,19 class Plot(Operation): | |||||
751 | tm = dataOut.utctimeInit |
|
771 | tm = dataOut.utctimeInit | |
752 | else: |
|
772 | else: | |
753 | tm = dataOut.utctime |
|
773 | tm = dataOut.utctime | |
754 |
|
||||
755 | if dataOut.useLocalTime: |
|
|||
756 | if not self.localtime: |
|
|||
757 | tm += time.timezone |
|
|||
758 | else: |
|
|||
759 | if self.localtime: |
|
|||
760 | tm -= time.timezone |
|
|||
761 |
|
774 | |||
762 | if self.xaxis is 'time' and self.data and (tm - self.tmin) >= self.xrange*60*60: |
|
775 | if not dataOut.useLocalTime and self.localtime: | |
|
776 | tm -= time.timezone | |||
|
777 | if dataOut.useLocalTime and not self.localtime: | |||
|
778 | tm += time.timezone | |||
|
779 | ||||
|
780 | if self.xaxis is 'time' and self.data and (tm - self.tmin) >= self.xrange*60*60: | |||
|
781 | self.save_counter = self.save_period | |||
763 | self.__plot() |
|
782 | self.__plot() | |
|
783 | self.xmin += self.xrange | |||
|
784 | if self.xmin >= 24: | |||
|
785 | self.xmin -= 24 | |||
|
786 | self.tmin += self.xrange*60*60 | |||
764 | self.data.setup() |
|
787 | self.data.setup() | |
765 | self.clear_figures() |
|
788 | self.clear_figures() | |
766 |
|
789 | |||
@@ -773,12 +796,13 class Plot(Operation): | |||||
773 | if self.realtime: |
|
796 | if self.realtime: | |
774 | self.__plot() |
|
797 | self.__plot() | |
775 | else: |
|
798 | else: | |
776 |
self.__throttle_plot(self.__plot |
|
799 | self.__throttle_plot(self.__plot)#, coerce=coerce) | |
777 |
|
||||
778 | figpause(0.001) |
|
|||
779 |
|
800 | |||
780 | def close(self): |
|
801 | def close(self): | |
781 |
|
802 | |||
|
803 | if self.data: | |||
|
804 | self.save_counter = self.save_period | |||
|
805 | self.__plot() | |||
782 | if self.data and self.pause: |
|
806 | if self.data and self.pause: | |
783 | figpause(10) |
|
807 | figpause(10) | |
784 |
|
808 |
@@ -42,6 +42,8 class SpectraPlot(Plot): | |||||
42 |
|
42 | |||
43 | CODE = 'spc' |
|
43 | CODE = 'spc' | |
44 | colormap = 'jro' |
|
44 | colormap = 'jro' | |
|
45 | plot_name = 'Spectra' | |||
|
46 | plot_type = 'pcolor' | |||
45 |
|
47 | |||
46 | def setup(self): |
|
48 | def setup(self): | |
47 | self.nplots = len(self.data.channels) |
|
49 | self.nplots = len(self.data.channels) | |
@@ -112,6 +114,8 class CrossSpectraPlot(Plot): | |||||
112 |
|
114 | |||
113 | CODE = 'cspc' |
|
115 | CODE = 'cspc' | |
114 | colormap = 'jet' |
|
116 | colormap = 'jet' | |
|
117 | plot_name = 'CrossSpectra' | |||
|
118 | plot_type = 'pcolor' | |||
115 | zmin_coh = None |
|
119 | zmin_coh = None | |
116 | zmax_coh = None |
|
120 | zmax_coh = None | |
117 | zmin_phase = None |
|
121 | zmin_phase = None | |
@@ -211,6 +215,8 class SpectralMomentsPlot(SpectraPlot): | |||||
211 | ''' |
|
215 | ''' | |
212 | CODE = 'spc_moments' |
|
216 | CODE = 'spc_moments' | |
213 | colormap = 'jro' |
|
217 | colormap = 'jro' | |
|
218 | plot_name = 'SpectralMoments' | |||
|
219 | plot_type = 'pcolor' | |||
214 |
|
220 | |||
215 |
|
221 | |||
216 | class RTIPlot(Plot): |
|
222 | class RTIPlot(Plot): | |
@@ -220,6 +226,8 class RTIPlot(Plot): | |||||
220 |
|
226 | |||
221 | CODE = 'rti' |
|
227 | CODE = 'rti' | |
222 | colormap = 'jro' |
|
228 | colormap = 'jro' | |
|
229 | plot_name = 'RTI' | |||
|
230 | plot_type = 'pcolorbuffer' | |||
223 |
|
231 | |||
224 | def setup(self): |
|
232 | def setup(self): | |
225 | self.xaxis = 'time' |
|
233 | self.xaxis = 'time' | |
@@ -275,6 +283,7 class CoherencePlot(RTIPlot): | |||||
275 | ''' |
|
283 | ''' | |
276 |
|
284 | |||
277 | CODE = 'coh' |
|
285 | CODE = 'coh' | |
|
286 | plot_name = 'Coherence' | |||
278 |
|
287 | |||
279 | def setup(self): |
|
288 | def setup(self): | |
280 | self.xaxis = 'time' |
|
289 | self.xaxis = 'time' | |
@@ -299,6 +308,7 class PhasePlot(CoherencePlot): | |||||
299 |
|
308 | |||
300 | CODE = 'phase' |
|
309 | CODE = 'phase' | |
301 | colormap = 'seismic' |
|
310 | colormap = 'seismic' | |
|
311 | plot_name = 'Phase' | |||
302 |
|
312 | |||
303 |
|
313 | |||
304 | class NoisePlot(Plot): |
|
314 | class NoisePlot(Plot): | |
@@ -307,6 +317,9 class NoisePlot(Plot): | |||||
307 | ''' |
|
317 | ''' | |
308 |
|
318 | |||
309 | CODE = 'noise' |
|
319 | CODE = 'noise' | |
|
320 | plot_name = 'Noise' | |||
|
321 | plot_type = 'scatterbuffer' | |||
|
322 | ||||
310 |
|
323 | |||
311 | def setup(self): |
|
324 | def setup(self): | |
312 | self.xaxis = 'time' |
|
325 | self.xaxis = 'time' | |
@@ -345,6 +358,7 class SnrPlot(RTIPlot): | |||||
345 |
|
358 | |||
346 | CODE = 'snr' |
|
359 | CODE = 'snr' | |
347 | colormap = 'jet' |
|
360 | colormap = 'jet' | |
|
361 | plot_name = 'SNR' | |||
348 |
|
362 | |||
349 |
|
363 | |||
350 | class DopplerPlot(RTIPlot): |
|
364 | class DopplerPlot(RTIPlot): | |
@@ -354,6 +368,7 class DopplerPlot(RTIPlot): | |||||
354 |
|
368 | |||
355 | CODE = 'dop' |
|
369 | CODE = 'dop' | |
356 | colormap = 'jet' |
|
370 | colormap = 'jet' | |
|
371 | plot_name = 'Doppler' | |||
357 |
|
372 | |||
358 |
|
373 | |||
359 | class SkyMapPlot(Plot): |
|
374 | class SkyMapPlot(Plot): | |
@@ -411,6 +426,7 class ParametersPlot(RTIPlot): | |||||
411 |
|
426 | |||
412 | CODE = 'param' |
|
427 | CODE = 'param' | |
413 | colormap = 'seismic' |
|
428 | colormap = 'seismic' | |
|
429 | plot_name = 'Parameters' | |||
414 |
|
430 | |||
415 | def setup(self): |
|
431 | def setup(self): | |
416 | self.xaxis = 'time' |
|
432 | self.xaxis = 'time' | |
@@ -480,6 +496,7 class OutputPlot(ParametersPlot): | |||||
480 |
|
496 | |||
481 | CODE = 'output' |
|
497 | CODE = 'output' | |
482 | colormap = 'seismic' |
|
498 | colormap = 'seismic' | |
|
499 | plot_name = 'Output' | |||
483 |
|
500 | |||
484 |
|
501 | |||
485 | class PolarMapPlot(Plot): |
|
502 | class PolarMapPlot(Plot): | |
@@ -621,6 +638,8 class ScopePlot(Plot): | |||||
621 | ''' |
|
638 | ''' | |
622 |
|
639 | |||
623 | CODE = 'scope' |
|
640 | CODE = 'scope' | |
|
641 | plot_name = 'Scope' | |||
|
642 | plot_type = 'scatter' | |||
624 |
|
643 | |||
625 | def setup(self): |
|
644 | def setup(self): | |
626 |
|
645 | |||
@@ -720,11 +739,6 class ScopePlot(Plot): | |||||
720 | thisDatetime, |
|
739 | thisDatetime, | |
721 | wintitle1 |
|
740 | wintitle1 | |
722 | ) |
|
741 | ) | |
723 |
|
||||
724 |
|
||||
725 |
|
||||
726 |
|
||||
727 |
|
||||
728 | else: |
|
742 | else: | |
729 | wintitle = " [Profile = %d] " %self.data.profileIndex |
|
743 | wintitle = " [Profile = %d] " %self.data.profileIndex | |
730 |
|
744 | |||
@@ -743,6 +757,3 class ScopePlot(Plot): | |||||
743 | thisDatetime, |
|
757 | thisDatetime, | |
744 | wintitle |
|
758 | wintitle | |
745 | ) |
|
759 | ) | |
746 |
|
||||
747 |
|
||||
748 | No newline at end of file |
|
@@ -86,7 +86,8 DATA_STRUCTURE = numpy.dtype([ | |||||
86 | @MPDecorator |
|
86 | @MPDecorator | |
87 | class BLTRParamReader(JRODataReader, ProcessingUnit): |
|
87 | class BLTRParamReader(JRODataReader, ProcessingUnit): | |
88 | ''' |
|
88 | ''' | |
89 |
Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR |
|
89 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR | |
|
90 | from *.sswma files | |||
90 | ''' |
|
91 | ''' | |
91 |
|
92 | |||
92 | ext = '.sswma' |
|
93 | ext = '.sswma' | |
@@ -118,6 +119,9 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
118 | self.endTime = endTime |
|
119 | self.endTime = endTime | |
119 | self.status_value = status_value |
|
120 | self.status_value = status_value | |
120 | self.datatime = datetime.datetime(1900,1,1) |
|
121 | self.datatime = datetime.datetime(1900,1,1) | |
|
122 | self.delay = kwargs.get('delay', 10) | |||
|
123 | self.online = kwargs.get('online', False) | |||
|
124 | self.nTries = kwargs.get('nTries', 3) | |||
121 |
|
125 | |||
122 | if self.path is None: |
|
126 | if self.path is None: | |
123 | raise ValueError("The path is not valid") |
|
127 | raise ValueError("The path is not valid") | |
@@ -125,7 +129,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
125 | if ext is None: |
|
129 | if ext is None: | |
126 | ext = self.ext |
|
130 | ext = self.ext | |
127 |
|
131 | |||
128 | self.search_files(self.path, startDate, endDate, ext) |
|
132 | self.fileList = self.search_files(self.path, startDate, endDate, ext) | |
129 | self.timezone = timezone |
|
133 | self.timezone = timezone | |
130 | self.fileIndex = 0 |
|
134 | self.fileIndex = 0 | |
131 |
|
135 | |||
@@ -135,6 +139,29 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
135 |
|
139 | |||
136 | self.setNextFile() |
|
140 | self.setNextFile() | |
137 |
|
141 | |||
|
142 | def search_last_file(self): | |||
|
143 | ''' | |||
|
144 | Get last file and add it to the list | |||
|
145 | ''' | |||
|
146 | ||||
|
147 | for n in range(self.nTries+1): | |||
|
148 | if n>0: | |||
|
149 | log.warning( | |||
|
150 | "Waiting %0.2f seconds for the next file, try %03d ..." % (self.delay, n+1), | |||
|
151 | self.name | |||
|
152 | ) | |||
|
153 | time.sleep(self.delay) | |||
|
154 | file_list = os.listdir(self.path) | |||
|
155 | file_list.sort() | |||
|
156 | if file_list: | |||
|
157 | if self.filename: | |||
|
158 | if file_list[-1] not in self.filename: | |||
|
159 | return file_list[-1] | |||
|
160 | else: | |||
|
161 | continue | |||
|
162 | return file_list[-1] | |||
|
163 | return 0 | |||
|
164 | ||||
138 | def search_files(self, path, startDate, endDate, ext): |
|
165 | def search_files(self, path, startDate, endDate, ext): | |
139 | ''' |
|
166 | ''' | |
140 | Searching for BLTR rawdata file in path |
|
167 | Searching for BLTR rawdata file in path | |
@@ -152,9 +179,6 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
152 | fileList0 = glob.glob1(path, "*%s" % ext) |
|
179 | fileList0 = glob.glob1(path, "*%s" % ext) | |
153 | fileList0.sort() |
|
180 | fileList0.sort() | |
154 |
|
181 | |||
155 | self.fileList = [] |
|
|||
156 | self.dateFileList = [] |
|
|||
157 |
|
||||
158 | for thisFile in fileList0: |
|
182 | for thisFile in fileList0: | |
159 | year = thisFile[-14:-10] |
|
183 | year = thisFile[-14:-10] | |
160 | if not isNumber(year): |
|
184 | if not isNumber(year): | |
@@ -174,28 +198,32 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
174 | if (startDate > dateFile) or (endDate < dateFile): |
|
198 | if (startDate > dateFile) or (endDate < dateFile): | |
175 | continue |
|
199 | continue | |
176 |
|
200 | |||
177 |
|
|
201 | yield thisFile | |
178 | self.dateFileList.append(dateFile) |
|
|||
179 |
|
202 | |||
180 | return |
|
203 | return | |
181 |
|
204 | |||
182 | def setNextFile(self): |
|
205 | def setNextFile(self): | |
183 |
|
206 | |||
184 |
|
|
207 | if self.online: | |
185 |
|
208 | filename = self.search_last_file() | ||
186 | if file_id == len(self.fileList): |
|
209 | if not filename: | |
187 | self.flagNoMoreFiles = 1 |
|
210 | self.flagNoMoreFiles = 1 | |
188 | return 0 |
|
211 | return 0 | |
189 |
|
212 | else: | ||
190 | log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader') |
|
213 | try: | |
191 |
filename = |
|
214 | filename = next(self.fileList) | |
|
215 | except StopIteration: | |||
|
216 | self.flagNoMoreFiles = 1 | |||
|
217 | return 0 | |||
|
218 | ||||
|
219 | log.success('Opening {}'.format(filename), 'BLTRParamReader') | |||
192 |
|
220 | |||
193 | dirname, name = os.path.split(filename) |
|
221 | dirname, name = os.path.split(filename) | |
194 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya |
|
222 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya | |
195 | self.siteFile = name.split('.')[0] |
|
223 | self.siteFile = filename.split('.')[0] | |
196 | if self.filename is not None: |
|
224 | if self.filename is not None: | |
197 | self.fp.close() |
|
225 | self.fp.close() | |
198 | self.filename = filename |
|
226 | self.filename = os.path.join(self.path, filename) | |
199 | self.fp = open(self.filename, 'rb') |
|
227 | self.fp = open(self.filename, 'rb') | |
200 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
228 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) | |
201 | self.nrecords = self.header_file['nrec'][0] |
|
229 | self.nrecords = self.header_file['nrec'][0] | |
@@ -203,18 +231,27 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
203 | self.counter_records = 0 |
|
231 | self.counter_records = 0 | |
204 | self.flagIsNewFile = 0 |
|
232 | self.flagIsNewFile = 0 | |
205 | self.fileIndex += 1 |
|
233 | self.fileIndex += 1 | |
|
234 | time.sleep(2) | |||
206 |
|
235 | |||
207 | return 1 |
|
236 | return 1 | |
208 |
|
237 | |||
209 | def readNextBlock(self): |
|
238 | def readNextBlock(self): | |
210 |
|
239 | |||
211 | while True: |
|
240 | while True: | |
212 | if self.counter_records == self.nrecords: |
|
241 | if not self.online and self.counter_records == self.nrecords: | |
213 | self.flagIsNewFile = 1 |
|
242 | self.flagIsNewFile = 1 | |
214 | if not self.setNextFile(): |
|
243 | if not self.setNextFile(): | |
215 | return 0 |
|
244 | return 0 | |
216 |
|
245 | |||
217 | self.readBlock() |
|
246 | try: | |
|
247 | pointer = self.fp.tell() | |||
|
248 | self.readBlock() | |||
|
249 | except: | |||
|
250 | if self.online and self.waitDataBlock(pointer, 38512) == 1: | |||
|
251 | continue | |||
|
252 | else: | |||
|
253 | if not self.setNextFile(): | |||
|
254 | return 0 | |||
218 |
|
255 | |||
219 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
256 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ | |
220 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
257 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
@@ -227,9 +264,9 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
227 | continue |
|
264 | continue | |
228 | break |
|
265 | break | |
229 |
|
266 | |||
230 |
log.log('Reading Record No. {} |
|
267 | log.log('Reading Record No. {} -> {}'.format( | |
231 | self.counter_records, |
|
268 | self.counter_records, | |
232 | self.nrecords, |
|
269 | # self.nrecords, | |
233 | self.datatime.ctime()), 'BLTRParamReader') |
|
270 | self.datatime.ctime()), 'BLTRParamReader') | |
234 |
|
271 | |||
235 | return 1 |
|
272 | return 1 | |
@@ -288,10 +325,12 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
288 |
|
325 | |||
289 | def readData(self): |
|
326 | def readData(self): | |
290 | ''' |
|
327 | ''' | |
291 |
Reading and filtering data block record of BLTR rawdata file, |
|
328 | Reading and filtering data block record of BLTR rawdata file, | |
|
329 | filtering is according to status_value. | |||
292 |
|
330 | |||
293 | Input: |
|
331 | Input: | |
294 |
status_value - Array data is set to NAN for values that are not |
|
332 | status_value - Array data is set to NAN for values that are not | |
|
333 | equal to status_value | |||
295 |
|
334 | |||
296 | ''' |
|
335 | ''' | |
297 | self.nchannels = int(self.nchannels) |
|
336 | self.nchannels = int(self.nchannels) | |
@@ -357,10 +396,11 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
357 | if self.flagNoMoreFiles: |
|
396 | if self.flagNoMoreFiles: | |
358 | self.dataOut.flagNoData = True |
|
397 | self.dataOut.flagNoData = True | |
359 | self.dataOut.error = 'No More files to read' |
|
398 | self.dataOut.error = 'No More files to read' | |
|
399 | return | |||
360 |
|
400 | |||
361 | if not self.readNextBlock(): |
|
401 | if not self.readNextBlock(): | |
362 | self.dataOut.flagNoData = True |
|
402 | self.dataOut.flagNoData = True | |
363 | return 0 |
|
403 | self.dataOut.error = 'Time for wait new file reach!!!' | |
364 |
|
404 | |||
365 | self.set_output() |
|
405 | self.set_output() | |
366 |
|
406 |
@@ -946,11 +946,13 class JRODataReader(JRODataIO): | |||||
946 |
|
946 | |||
947 | return 0 |
|
947 | return 0 | |
948 |
|
948 | |||
949 | def waitDataBlock(self, pointer_location): |
|
949 | def waitDataBlock(self, pointer_location, blocksize=None): | |
950 |
|
950 | |||
951 | currentPointer = pointer_location |
|
951 | currentPointer = pointer_location | |
952 |
|
952 | if blocksize is None: | ||
953 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize |
|
953 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize | |
|
954 | else: | |||
|
955 | neededSize = blocksize | |||
954 |
|
956 | |||
955 | for nTries in range(self.nTries): |
|
957 | for nTries in range(self.nTries): | |
956 | self.fp.close() |
|
958 | self.fp.close() | |
@@ -963,7 +965,10 class JRODataReader(JRODataIO): | |||||
963 | if (currentSize >= neededSize): |
|
965 | if (currentSize >= neededSize): | |
964 | return 1 |
|
966 | return 1 | |
965 |
|
967 | |||
966 | print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)) |
|
968 | log.warning( | |
|
969 | "Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1), | |||
|
970 | self.name | |||
|
971 | ) | |||
967 | sleep(self.delay) |
|
972 | sleep(self.delay) | |
968 |
|
973 | |||
969 | return 0 |
|
974 | return 0 |
@@ -189,6 +189,7 def MPDecorator(BaseClass): | |||||
189 | self.kwargs = kwargs |
|
189 | self.kwargs = kwargs | |
190 | self.sender = None |
|
190 | self.sender = None | |
191 | self.receiver = None |
|
191 | self.receiver = None | |
|
192 | self.i = 0 | |||
192 | self.name = BaseClass.__name__ |
|
193 | self.name = BaseClass.__name__ | |
193 | if 'plot' in self.name.lower() and not self.name.endswith('_'): |
|
194 | if 'plot' in self.name.lower() and not self.name.endswith('_'): | |
194 | self.name = '{}{}'.format(self.CODE.upper(), 'Plot') |
|
195 | self.name = '{}{}'.format(self.CODE.upper(), 'Plot') | |
@@ -204,6 +205,9 def MPDecorator(BaseClass): | |||||
204 | self.inputId = args[0] |
|
205 | self.inputId = args[0] | |
205 | self.project_id = args[1] |
|
206 | self.project_id = args[1] | |
206 | self.typeProc = "Operation" |
|
207 | self.typeProc = "Operation" | |
|
208 | ||||
|
209 | def fix_publish(self,valor,multiple1): | |||
|
210 | return True if valor%multiple1 ==0 else False | |||
207 |
|
211 | |||
208 | def subscribe(self): |
|
212 | def subscribe(self): | |
209 | ''' |
|
213 | ''' | |
@@ -221,8 +225,11 def MPDecorator(BaseClass): | |||||
221 | ''' |
|
225 | ''' | |
222 | This function waits for objects and deserialize using pickle |
|
226 | This function waits for objects and deserialize using pickle | |
223 | ''' |
|
227 | ''' | |
224 |
|
228 | try: | ||
225 | data = pickle.loads(self.receiver.recv_multipart()[1]) |
|
229 | data = pickle.loads(self.receiver.recv_multipart()[1]) | |
|
230 | except zmq.ZMQError as e: | |||
|
231 | if e.errno == zmq.ETERM: | |||
|
232 | print (e.errno) | |||
226 |
|
233 | |||
227 | return data |
|
234 | return data | |
228 |
|
235 | |||
@@ -240,7 +247,14 def MPDecorator(BaseClass): | |||||
240 | def publish(self, data, id): |
|
247 | def publish(self, data, id): | |
241 | ''' |
|
248 | ''' | |
242 | This function publish an object, to a specific topic. |
|
249 | This function publish an object, to a specific topic. | |
|
250 | The fix method only affect inputId None which is Read Unit | |||
|
251 | Use value between 64 80, you should notice a little retard in processing | |||
243 | ''' |
|
252 | ''' | |
|
253 | if self.inputId is None: | |||
|
254 | self.i+=1 | |||
|
255 | if self.fix_publish(self.i,80) == True:# value n | |||
|
256 | time.sleep(0.01) | |||
|
257 | ||||
244 | self.sender.send_multipart([str(id).encode(), pickle.dumps(data)]) |
|
258 | self.sender.send_multipart([str(id).encode(), pickle.dumps(data)]) | |
245 |
|
259 | |||
246 | def runReader(self): |
|
260 | def runReader(self): |
General Comments 0
You need to be logged in to leave comments.
Login now