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