From ff577b5ae5e0887b51e288b70e2c9f10e8f0c9e7 2017-03-14 21:54:04 From: Juan C. Valdez Date: 2017-03-14 21:54:04 Subject: [PATCH] RTI & SNR in new plotter operation --- diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index b043b1f..3191d1d 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -17,6 +17,7 @@ d1970 = datetime.datetime(1970,1,1) class PlotData(Operation): + __code = 'Figure' __MAXNUMX = 80 __MAXNUMY = 80 __missing = 1E30 @@ -30,11 +31,12 @@ class PlotData(Operation): self.dataOut = None self.isConfig = False self.figure = None + self.width = 6 + self.height = 4 def setup(self, dataOut, **kwargs): self.first = True - self.plottype = kwargs.pop('plottype', 'rti') self.localtime = kwargs.pop('localtime', True) self.show = kwargs.pop('show', True) self.save = kwargs.pop('save', False) @@ -45,7 +47,7 @@ class PlotData(Operation): self.data = [{} for __ in dataOut.channelList] self.axes = [] self.colormap = kwargs.get('colormap', 'jet') - self.title = kwargs.get('wintitle', self.plottype.upper()) + self.title = kwargs.get('wintitle', '') self.xaxis = kwargs.get('xaxis', None) self.zmin = kwargs.get('zmin', None) self.zmax = kwargs.get('zmax', None) @@ -60,27 +62,23 @@ class PlotData(Operation): self.xmin = (dtmin-d1970).total_seconds() self.xmax = (dtmax-d1970).total_seconds() - if self.plottype in ('rti',): - self.ncols = 1 - self.nrows = dataOut.nChannels - self.width = 8 - self.height = 2.2*self.nrows - self.ylabel = 'Range [Km]' - self.y = dataOut.getHeiRange() - - self.ymin = kwargs.get('ymin', min(self.y)) - self.ymax = kwargs.get('ymax', max(self.y)) + self.ymin = kwargs.get('ymin', None) + self.ymax = kwargs.get('ymax', None) if self.figure is None: self.figure = plt.figure() else: self.figure.clf() + self.setup_fig() + for n in range(dataOut.nChannels): ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) ax.firsttime = True self.axes.append(ax) + self.setup_fig() + self.figure.set_size_inches (self.width, self.height) def fill_gaps(self, x_buffer, y_buffer, z_buffer): @@ -94,24 +92,116 @@ class PlotData(Operation): index = np.where(deltas > 5*x_median) if len(index[0]) != 0: - z_buffer[index[0],::] = self.__missing + z_buffer[::,index[0],::] = self.__missing z_buffer = np.ma.masked_inside(z_buffer, 0.99*self.__missing, 1.01*self.__missing) return x_buffer, y_buffer, z_buffer + def decimate(self): + + dx = int(len(self.x)/self.__MAXNUMX) + 1 + dy = int(len(self.y)/self.__MAXNUMY) + 1 + + x = self.x[::dx] + y = self.y[::dy] + z = self.z[::, ::dx, ::dy] + + return x, y, z + + def _plot(self): + + self.plot() + + self.figure.suptitle(self.title+self.__code) + + if self.save: + figname = os.path.join(self.save, '{}_{}.png'.format(self.__code, + self.plot_dt.strftime('%y%m%d_%H%M%S'))) + print 'Saving figure: {}'.format(figname) + self.figure.savefig(figname) + + self.figure.canvas.draw() + if self.show: + self.figure.show() + if self.pause: + raw_input('Press to continue') + + + def update(self): + + pass + + def run(self, dataOut, **kwargs): + + self.dataOut = dataOut + + if not self.isConfig: + self.setup(dataOut, **kwargs) + self.isConfig = True + + self.nblock += 1 + self.update() + + if dataOut.ltctime>=self.xmax: + self._plot() + self.isConfig = False + + def close(self): + if self.dataOut: + self._plot() + + +class PlotSpectraData(PlotData): + + __code = 'Spectra' + + def setup_fig(self): + pass + + def update(self): + + for ch in self.dataOut.channelList: + self.data[ch] = self.dataOut.data_spc[ch] + def plot(self): + pass + + +class PlotRTIData(PlotData): + + __code = 'RTI' + + def setup_fig(self): + + self.ncols = 1 + self.nrows = self.dataOut.nChannels + self.width = 8 + self.height = 2.2*self.nrows + self.ylabel = 'Range [Km]' + + def update(self): + + self.time.append(self.dataOut.ltctime) + + for ch in self.dataOut.channelList: + self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] + + def plot(self): + + self.plot_dt = datetime.datetime.utcfromtimestamp(self.time[-2]) - dt = datetime.datetime.utcfromtimestamp(self.time[-2]) + self.time.sort() + self.x = self.time + self.y = self.dataOut.getHeiRange() + self.z = [] - if self.plottype=='rti': - self.time.sort() - for ch in self.dataOut.channelList: - self.z.append([self.data[ch][t] for t in self.time]) - self.x = np.array(self.time) - self.z = np.array(self.z) - self.plot_rti() + for ch in self.dataOut.channelList: + self.z.append([self.data[ch][t] for t in self.time]) + + self.x = np.array(self.x) + self.z = np.array(self.z) for n, ax in enumerate(self.axes): @@ -122,33 +212,25 @@ class PlotData(Operation): ax.yaxis.set_major_locator(LinearLocator(4)) ax.set_ylabel(self.ylabel) - ax.set_ylim(self.ymin, self.ymax) + ax.set_xlim(self.xmin, self.xmax) - ax.set_title('Channel {} {}'.format( - self.dataOut.channelList[n], - dt.strftime('%y/%m/%d %H:%M:%S'), - size=6)) + ax.set_title('Channel {} {}'.format(self.dataOut.channelList[n], + self.plot_dt.strftime('%y/%m/%d %H:%M:%S')), + size=8) - if self.save: - figname = os.path.join(self.save, 'rti_{}.png'.format(dt.strftime('%y%m%d_%H%M%S'))) - print 'Saving figure: {}'.format(figname) - self.figure.savefig(figname) - - self.figure.canvas.draw() - if self.show: - self.figure.show() - if self.pause: - raw_input('Press to continue') - - def plot_rti(self): + self.decimate() for n, ax in enumerate(self.axes): - x, y, z = self.fill_gaps(self.x, self.y, self.z[n]) + + x, y, z = self.fill_gaps(*self.decimate()) + if ax.firsttime: + ymin = self.ymin if self.ymin else np.nanmin(self.y) + ymax = self.ymax if self.ymax else np.nanmax(self.y) zmin = self.zmin if self.zmin else np.nanmin(self.z) zmax = self.zmax if self.zmax else np.nanmax(self.z) - plot = ax.pcolormesh(x, y, z.T, + plot = ax.pcolormesh(x, y, z[n].T, vmin=zmin, vmax=zmax, cmap=plt.get_cmap(self.colormap) @@ -157,40 +239,21 @@ class PlotData(Operation): cax = divider.new_horizontal(size='3%', pad=0.05) self.figure.add_axes(cax) plt.colorbar(plot, cax) + ax.set_ylim(self.ymin, self.ymax) ax.firsttime = False else: - plot = ax.pcolormesh(x, y, z.T, - vmin=zmin, - vmax=zmax, - cmap=plt.get_cmap(self.colormap) - ) + plot = ax.pcolormesh(x, y, z[n].T) - self.figure.suptitle(self.title) self.figure.subplots_adjust(wspace=None, hspace=0.5) + +class PlotSNRData(PlotRTIData): + + __code = 'SNR' + def update(self): - - self.nblock += 1 + self.time.append(self.dataOut.ltctime) - if self.plottype=='rti': - for ch in self.dataOut.channelList: - self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] - - def run(self, dataOut, **kwargs): - - self.dataOut = dataOut - - if not self.isConfig: - self.setup(dataOut, **kwargs) - self.isConfig = True - - self.update() - - if dataOut.ltctime>=self.xmax: - self.plot() - self.isConfig = False - - def close(self): - self.plot() - \ No newline at end of file + for ch in self.dataOut.channelList: + self.data[ch][self.dataOut.ltctime] = 10*np.log10(self.dataOut.data_SNR[ch]) \ No newline at end of file