diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index fd9bf6b..e519dc4 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -1143,11 +1143,13 @@ class PlotterData(object): return len(self.__times) def __getitem__(self, key): - + if key not in self.data: raise KeyError(log.error('Missing key: {}'.format(key))) if 'spc' in key or not self.buffering: ret = self.data[key] + elif 'scope' in key: + ret = numpy.array(self.data[key][float(self.tm)]) else: ret = numpy.array([self.data[key][x] for x in self.times]) if ret.ndim > 1: @@ -1196,7 +1198,8 @@ class PlotterData(object): if tm in self.__times: return - + self.profileIndex = dataOut.profileIndex + self.tm = tm self.type = dataOut.type self.parameters = getattr(dataOut, 'parameters', []) if hasattr(dataOut, 'pairsList'): @@ -1243,7 +1246,11 @@ class PlotterData(object): buffer = dataOut.data_output if plot == 'param': buffer = dataOut.data_param - + if plot == 'scope': + buffer = dataOut.data + self.flagDataAsBlock = dataOut.flagDataAsBlock + self.nProfiles = dataOut.nProfiles + if plot == 'spc': self.data[plot] = buffer elif plot == 'cspc': diff --git a/schainpy/model/graphics/jroplot_base.py b/schainpy/model/graphics/jroplot_base.py index c7b4904..6e35c7d 100644 --- a/schainpy/model/graphics/jroplot_base.py +++ b/schainpy/model/graphics/jroplot_base.py @@ -345,6 +345,7 @@ class Plot(Operation): self.channels = kwargs.get('channels', None) self.titles = kwargs.get('titles', []) self.polar = False + self.type = kwargs.get('type', 'iq') self.grid = kwargs.get('grid', False) self.pause = kwargs.get('pause', False) self.save_labels = kwargs.get('save_labels', None) @@ -611,17 +612,18 @@ class Plot(Operation): xmax += time.timezone else: xmax = self.xmax - + ymin = self.ymin if self.ymin else numpy.nanmin(self.y) ymax = self.ymax if self.ymax else numpy.nanmax(self.y) - Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) - i = 1 if numpy.where( - abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] - ystep = Y[i] / 10. - + Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000]) + #i = 1 if numpy.where( + # abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] + #ystep = Y[i] / 10. + ystep = round(ymax,-1)//5 if self.xaxis is not 'time': X = numpy.array([0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, - 200, 500, 1000, 2000, 5000])/2. + 200, 500, 1000, 2000, 5000, 10000, 20000, 50000])/2. + i = 1 if numpy.where( abs(xmax-xmin) <= X)[0][0] < 0 else numpy.where(abs(xmax-xmin) <= X)[0][0] xstep = X[i] / 5. diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index 4db813a..691f12a 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -613,4 +613,136 @@ class PolarMapPlot(Plot): self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] self.titles = ['{} {}'.format( self.data.parameters[x], title) for x in self.channels] - \ No newline at end of file + +class ScopePlot(Plot): + + ''' + Plot for Scope + ''' + + CODE = 'scope' + + def setup(self): + + self.xaxis = 'Range (Km)' + self.ncols = 1 + self.nrows = 1 + self.nplots = 1 + self.ylabel = 'Intensity [dB]' + self.titles = ['Scope'] + self.colorbar = False + colspan = 3 + rowspan = 1 + + def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): + + yreal = y[channelIndexList,:].real + yimag = y[channelIndexList,:].imag + title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) + self.xlabel = "Range (Km)" + self.ylabel = "Intensity - IQ" + + self.y = yreal + self.x = x + self.xmin = min(x) + self.xmax = max(x) + + + self.titles[0] = title + + for i,ax in enumerate(self.axes): + title = "Channel %d" %(i) + if ax.firsttime: + ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] + ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] + else: + #pass + ax.plt_r.set_data(x, yreal[i,:]) + ax.plt_i.set_data(x, yimag[i,:]) + + def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): + y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) + yreal = y.real + self.y = yreal + title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) + self.xlabel = "Range (Km)" + self.ylabel = "Intensity" + self.xmin = min(x) + self.xmax = max(x) + + + self.titles[0] = title + + for i,ax in enumerate(self.axes): + title = "Channel %d" %(i) + + ychannel = yreal[i,:] + + if ax.firsttime: + ax.plt_r = ax.plot(x, ychannel)[0] + else: + #pass + ax.plt_r.set_data(x, ychannel) + + + def plot(self): + + if self.channels: + channels = self.channels + else: + channels = self.data.channels + + + + thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) + + scope = self.data['scope'] + + + if self.data.flagDataAsBlock: + + for i in range(self.data.nProfiles): + + wintitle1 = " [Profile = %d] " %i + + if self.type == "power": + self.plot_power(self.data.heights, + scope[:,i,:], + channels, + thisDatetime, + wintitle1 + ) + + if self.type == "iq": + self.plot_iq(self.data.heights, + scope[:,i,:], + channels, + thisDatetime, + wintitle1 + ) + + + + + + else: + wintitle = " [Profile = %d] " %self.data.profileIndex + + if self.type == "power": + self.plot_power(self.data.heights, + scope, + channels, + thisDatetime, + wintitle + ) + + if self.type == "iq": + self.plot_iq(self.data.heights, + scope, + channels, + thisDatetime, + wintitle + ) + + + \ No newline at end of file