diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 3f66067..5a3bb3e 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -1105,6 +1105,7 @@ class PlotterData(object): def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False): + self.key = code self.throttle = throttle_value self.exp_code = exp_code self.buffering = buffering @@ -1202,10 +1203,8 @@ class PlotterData(object): self.tm = tm self.type = dataOut.type self.parameters = getattr(dataOut, 'parameters', []) - if hasattr(dataOut, 'pairsList'): - self.pairs = dataOut.pairsList if hasattr(dataOut, 'meta'): - self.meta = dataOut.meta + self.meta.update(dataOut.meta) self.channels = dataOut.channelList self.interval = dataOut.getTimeInterval() self.localtime = dataOut.useLocalTime @@ -1288,40 +1287,40 @@ class PlotterData(object): self.__heights = [H for tm in self.__times] - def jsonify(self, decimate=False): + def jsonify(self, plot_name, plot_type, decimate=False): ''' Convert data to json ''' - data = {} tm = self.times[-1] dy = int(self.heights.size/self.MAXNUMY) + 1 - for key in self.data: - if key in ('spc', 'cspc') or not self.buffering: - dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1 - data[key] = self.roundFloats( - self.data[key][::, ::dx, ::dy].tolist()) - else: - data[key] = self.roundFloats(self.data[key][tm].tolist()) - - ret = {'data': data} - ret['exp_code'] = self.exp_code - ret['time'] = float(tm) - ret['interval'] = float(self.interval) - ret['localtime'] = self.localtime - ret['yrange'] = self.roundFloats(self.heights[::dy].tolist()) - if 'spc' in self.data or 'cspc' in self.data: - ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) + if self.key in ('spc', 'cspc') or not self.buffering: + dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1 + data = self.roundFloats( + self.data[self.key][::, ::dx, ::dy].tolist()) else: - ret['xrange'] = [] - if hasattr(self, 'pairs'): - ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs] + data = self.roundFloats(self.data[self.key][tm].tolist()) + if self.key is 'noise': + data = [[x] for x in data] + + meta = {} + ret = { + 'plot': plot_name, + 'code': self.exp_code, + 'time': float(tm), + 'data': data, + } + meta['type'] = plot_type + meta['interval'] = float(self.interval) + meta['localtime'] = self.localtime + meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) + if 'spc' in self.data or 'cspc' in self.data: + meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) else: - ret['pairs'] = [] - - for key, value in list(self.meta.items()): - ret[key] = value + meta['xrange'] = [] + meta.update(self.meta) + ret['metadata'] = meta return json.dumps(ret) @property diff --git a/schainpy/model/graphics/jroplot_base.py b/schainpy/model/graphics/jroplot_base.py index 6c1b8c0..ec57ba2 100644 --- a/schainpy/model/graphics/jroplot_base.py +++ b/schainpy/model/graphics/jroplot_base.py @@ -236,6 +236,8 @@ class Plot(Operation): 'Sending to server: {}'.format(self.plot_server), self.name ) + if 'plot_name' in kwargs: + self.plot_name = kwargs['plot_name'] def __setup_plot(self): ''' @@ -672,10 +674,10 @@ class Plot(Operation): self.sender_counter += 1 self.sender_counter = 1 - + self.data.meta['titles'] = self.titles retries = 2 while True: - self.socket.send_string(self.data.jsonify()) + self.socket.send_string(self.data.jsonify(self.plot_name, self.plot_type)) socks = dict(self.poll.poll(5000)) if socks.get(self.socket) == zmq.POLLIN: reply = self.socket.recv_string() diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index f2ac422..688db09 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -42,6 +42,8 @@ class SpectraPlot(Plot): CODE = 'spc' colormap = 'jro' + plot_name = 'Spectra' + plot_type = 'pcolor' def setup(self): self.nplots = len(self.data.channels) @@ -112,6 +114,8 @@ class CrossSpectraPlot(Plot): CODE = 'cspc' colormap = 'jet' + plot_name = 'CrossSpectra' + plot_type = 'pcolor' zmin_coh = None zmax_coh = None zmin_phase = None @@ -211,6 +215,8 @@ class SpectralMomentsPlot(SpectraPlot): ''' CODE = 'spc_moments' colormap = 'jro' + plot_name = 'SpectralMoments' + plot_type = 'pcolor' class RTIPlot(Plot): @@ -220,6 +226,8 @@ class RTIPlot(Plot): CODE = 'rti' colormap = 'jro' + plot_name = 'RTI' + plot_type = 'pcolorbuffer' def setup(self): self.xaxis = 'time' @@ -275,6 +283,7 @@ class CoherencePlot(RTIPlot): ''' CODE = 'coh' + plot_name = 'Coherence' def setup(self): self.xaxis = 'time' @@ -299,6 +308,7 @@ class PhasePlot(CoherencePlot): CODE = 'phase' colormap = 'seismic' + plot_name = 'Phase' class NoisePlot(Plot): @@ -307,6 +317,9 @@ class NoisePlot(Plot): ''' CODE = 'noise' + plot_name = 'Noise' + plot_type = 'scatterbuffer' + def setup(self): self.xaxis = 'time' @@ -345,6 +358,7 @@ class SnrPlot(RTIPlot): CODE = 'snr' colormap = 'jet' + plot_name = 'SNR' class DopplerPlot(RTIPlot): @@ -354,6 +368,7 @@ class DopplerPlot(RTIPlot): CODE = 'dop' colormap = 'jet' + plot_name = 'Doppler' class SkyMapPlot(Plot): @@ -411,6 +426,7 @@ class ParametersPlot(RTIPlot): CODE = 'param' colormap = 'seismic' + plot_name = 'Parameters' def setup(self): self.xaxis = 'time' @@ -480,6 +496,7 @@ class OutputPlot(ParametersPlot): CODE = 'output' colormap = 'seismic' + plot_name = 'Output' class PolarMapPlot(Plot): @@ -621,6 +638,8 @@ class ScopePlot(Plot): ''' CODE = 'scope' + plot_name = 'Scope' + plot_type = 'scatter' def setup(self): @@ -720,11 +739,6 @@ class ScopePlot(Plot): thisDatetime, wintitle1 ) - - - - - else: wintitle = " [Profile = %d] " %self.data.profileIndex @@ -743,6 +757,3 @@ class ScopePlot(Plot): thisDatetime, wintitle ) - - - \ No newline at end of file