From 2ee3e6bd4db054253859e41c1aa8569853686289 2018-08-29 13:45:43 From: George Yong Date: 2018-08-29 13:45:43 Subject: [PATCH] Fix bug in CrossSpectraPlot --- diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 2fc4394..fd9bf6b 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -1112,7 +1112,7 @@ class PlotterData(object): MAXNUMY = 100 def __init__(self, code, throttle_value, exp_code, buffering=True): - + self.throttle = throttle_value self.exp_code = exp_code self.buffering = buffering @@ -1173,11 +1173,11 @@ class PlotterData(object): plot = 'snr' self.data[plot] = {} - if 'spc' in self.data or 'rti' in self.data: + if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data: self.data['noise'] = {} if 'noise' not in self.plottypes: self.plottypes.append('noise') - + def shape(self, key): ''' Get the shape of the one-element data for the given key @@ -1193,10 +1193,10 @@ class PlotterData(object): ''' Update data object with new dataOut ''' - + if tm in self.__times: return - + self.type = dataOut.type self.parameters = getattr(dataOut, 'parameters', []) if hasattr(dataOut, 'pairsList'): @@ -1209,16 +1209,18 @@ class PlotterData(object): if 'spc' in self.plottypes or 'cspc' in self.plottypes: self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) + self.factor = dataOut.normFactor self.__heights.append(dataOut.heightList) self.__all_heights.update(dataOut.heightList) self.__times.append(tm) - + for plot in self.plottypes: if plot == 'spc': z = dataOut.data_spc/dataOut.normFactor buffer = 10*numpy.log10(z) if plot == 'cspc': - buffer = dataOut.data_cspc + z = dataOut.data_spc/dataOut.normFactor + buffer = (dataOut.data_spc, dataOut.data_cspc) if plot == 'noise': buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) if plot == 'rti': @@ -1242,8 +1244,11 @@ class PlotterData(object): if plot == 'param': buffer = dataOut.data_param - if 'spc' in plot: + if plot == 'spc': self.data[plot] = buffer + elif plot == 'cspc': + self.data['spc'] = buffer[0] + self.data['cspc'] = buffer[1] else: if self.buffering: self.data[plot][tm] = buffer diff --git a/schainpy/model/graphics/jroplot_base.py b/schainpy/model/graphics/jroplot_base.py index c4bd457..c7b4904 100644 --- a/schainpy/model/graphics/jroplot_base.py +++ b/schainpy/model/graphics/jroplot_base.py @@ -672,7 +672,7 @@ class Plot(Operation): ax.set_title('{} {} {}'.format( self.titles[n], self.getDateTime(self.data.max_time).strftime( - '%Y-%m-%dT%H:%M:%S'), + '%H:%M:%S'), self.time_label), size=8) else: diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index e85be46..4db813a 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -112,6 +112,7 @@ class SpectraPlot(Plot): class CrossSpectraPlot(Plot): CODE = 'cspc' + colormap = 'jet' zmin_coh = None zmax_coh = None zmin_phase = None @@ -138,7 +139,7 @@ class CrossSpectraPlot(Plot): else: x = self.data.xrange[2] self.xlabel = "Velocity (m/s)" - + self.titles = [] y = self.data.heights @@ -150,32 +151,33 @@ class CrossSpectraPlot(Plot): noise = self.data['noise'][n][-1] pair = self.data.pairs[n] ax = self.axes[4 * n] - ax3 = self.axes[4 * n + 3] - if ax.firsttime: - self.xmax = self.xmax if self.xmax else numpy.nanmax(x) - self.xmin = self.xmin if self.xmin else -self.xmax - self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) - self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) - ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, + spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor) + if ax.firsttime: + self.xmax = self.xmax if self.xmax else numpy.nanmax(x) + self.xmin = self.xmin if self.xmin else -self.xmax + self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) + self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) + ax.plt = ax.pcolormesh(x , y , spc0.T, vmin=self.zmin, vmax=self.zmax, cmap=plt.get_cmap(self.colormap) - ) - else: - ax.plt.set_array(spc[pair[0]].T.ravel()) - self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) + ) + else: + ax.plt.set_array(spc0.T.ravel()) + self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise)) ax = self.axes[4 * n + 1] + spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor) if ax.firsttime: - ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, + ax.plt = ax.pcolormesh(x , y, spc1.T, vmin=self.zmin, vmax=self.zmax, cmap=plt.get_cmap(self.colormap) ) - else: - ax.plt.set_array(spc[pair[1]].T.ravel()) - self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) - + else: + ax.plt.set_array(spc1.T.ravel()) + self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise)) + out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) coh = numpy.abs(out) phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi @@ -191,13 +193,13 @@ class CrossSpectraPlot(Plot): ax.plt.set_array(coh.T.ravel()) self.titles.append( 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) - + ax = self.axes[4 * n + 3] if ax.firsttime: ax.plt = ax.pcolormesh(x, y, phase.T, vmin=-180, vmax=180, - cmap=plt.get_cmap(self.colormap_phase) + cmap=plt.get_cmap(self.colormap_phase) ) else: ax.plt.set_array(phase.T.ravel()) @@ -611,3 +613,4 @@ 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 diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index ec29edd..18b9f67 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -190,9 +190,8 @@ def MPDecorator(BaseClass): self.sender = None self.receiver = None self.name = BaseClass.__name__ - if 'plot' in self.name.lower(): - if not self.name.endswith('_'): - self.name = '{}{}'.format(self.CODE.upper(), 'Plot') + if 'plot' in self.name.lower() and not self.name.endswith('_'): + self.name = '{}{}'.format(self.CODE.upper(), 'Plot') self.start_time = time.time() if len(self.args) is 3: @@ -294,7 +293,7 @@ def MPDecorator(BaseClass): op(**kwargs) elif optype == 'other' and not self.dataOut.flagNoData: self.dataOut = op.run(self.dataOut, **kwargs) - elif optype == 'external': + elif optype == 'external' and not self.dataOut.flagNoData: if not self.dataOut.flagNoData or self.dataOut.error: self.publish(self.dataOut, opId)