From 15feaa6e0b57533588eba80899b3760d40952baf 2018-10-01 16:09:06 From: Juan C. Espinoza Date: 2018-10-01 16:09:06 Subject: [PATCH] Fix SpectralMoments Plot --- diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 4e4fa19..3194b28 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -1163,9 +1163,11 @@ class PlotterData(object): for plot in self.plottypes: if 'snr' in plot: plot = 'snr' + elif 'spc_moments' == plot: + plot = 'moments' self.data[plot] = {} - if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data: + if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: self.data['noise'] = {} if 'noise' not in self.plottypes: self.plottypes.append('noise') @@ -1199,7 +1201,7 @@ class PlotterData(object): self.channels = dataOut.channelList self.interval = dataOut.getTimeInterval() self.localtime = dataOut.useLocalTime - if 'spc' in self.plottypes or 'cspc' in self.plottypes: + if 'spc' in self.plottypes or 'cspc' in self.plottypes or 'spc_moments' in self.plottypes: self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) self.factor = dataOut.normFactor @@ -1208,7 +1210,7 @@ class PlotterData(object): self.__times.append(tm) for plot in self.plottypes: - if plot == 'spc': + if plot in ('spc', 'spc_moments'): z = dataOut.data_spc/dataOut.normFactor buffer = 10*numpy.log10(z) if plot == 'cspc': @@ -1246,6 +1248,9 @@ class PlotterData(object): elif plot == 'cspc': self.data['spc'] = buffer[0] self.data['cspc'] = buffer[1] + elif plot == 'spc_moments': + self.data['spc'] = buffer + self.data['moments'][tm] = dataOut.moments else: if self.buffering: self.data[plot][tm] = buffer diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index 691f12a..ef4c80a 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -66,7 +66,7 @@ class SpectraPlot(Plot): x = self.data.xrange[2] self.xlabel = "Velocity (m/s)" - if self.CODE == 'spc_mean': + if self.CODE == 'spc_moments': x = self.data.xrange[2] self.xlabel = "Velocity (m/s)" @@ -78,8 +78,8 @@ class SpectraPlot(Plot): for n, ax in enumerate(self.axes): noise = self.data['noise'][n][-1] - if self.CODE == 'spc_mean': - mean = self.data['mean'][n][-1] + if self.CODE == 'spc_moments': + mean = self.data['moments'][n, :, 1, :][-1] if ax.firsttime: self.xmax = self.xmax if self.xmax else numpy.nanmax(x) self.xmin = self.xmin if self.xmin else -self.xmax @@ -96,16 +96,15 @@ class SpectraPlot(Plot): self.data['rti'][n][-1], y)[0] ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, color="k", linestyle="dashed", lw=1)[0] - if self.CODE == 'spc_mean': + if self.CODE == 'spc_moments': ax.plt_mean = ax.plot(mean, y, color='k')[0] else: ax.plt.set_array(z[n].T.ravel()) if self.showprofile: ax.plt_profile.set_data(self.data['rti'][n][-1], y) ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) - if self.CODE == 'spc_mean': + if self.CODE == 'spc_moments': ax.plt_mean.set_data(mean, y) - self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) @@ -206,11 +205,11 @@ class CrossSpectraPlot(Plot): self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) -class SpectraMeanPlot(SpectraPlot): +class SpectralMomentsPlot(SpectraPlot): ''' - Plot for Spectra and Mean + Plot for Spectral Moments ''' - CODE = 'spc_mean' + CODE = 'spc_moments' colormap = 'jro' diff --git a/schainpy/model/graphics/jroplot_parameters.py b/schainpy/model/graphics/jroplot_parameters.py index cd9fa92..b0dab65 100644 --- a/schainpy/model/graphics/jroplot_parameters.py +++ b/schainpy/model/graphics/jroplot_parameters.py @@ -290,10 +290,10 @@ class SpcParamPlot_(Figure): raise ValueError("Channel %d is not in dataOut.channelList" %channel) channelIndexList.append(dataOut.channelList.index(channel)) -# if normFactor is None: -# factor = dataOut.normFactor -# else: -# factor = normFactor + # if normFactor is None: + # factor = dataOut.normFactor + # else: + # factor = normFactor if xaxis == "frequency": x = dataOut.spcparam_range[0] xlabel = "Frequency (kHz)" @@ -594,8 +594,8 @@ class SkyMapPlot_(Figure): self.isConfig = False self.__nsubplots = 1 -# self.WIDTH = 280 -# self.HEIGHT = 250 + # self.WIDTH = 280 + # self.HEIGHT = 250 self.WIDTH = 600 self.HEIGHT = 600 self.WIDTHPROF = 120 @@ -828,11 +828,11 @@ class WindProfilerPlot_(Figure): if dataOut.flagNoData: return dataOut -# if timerange is not None: -# self.timerange = timerange -# -# tmin = None -# tmax = None + # if timerange is not None: + # self.timerange = timerange + # + # tmin = None + # tmax = None x = dataOut.getTimeRange1(dataOut.paramInterval) y = dataOut.heightList @@ -1082,7 +1082,7 @@ class ParametersPlot_(Figure): z[ind] = numpy.nan thisDatetime = dataOut.datatime -# thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) + # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (km)" @@ -1129,24 +1129,24 @@ class ParametersPlot_(Figure): self.setWinTitle(title) -# for i in range(self.nchan): -# index = channelIndexList[i] -# title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) -# axes = self.axesList[i*self.plotFact] -# z1 = z[i,:].reshape((1,-1)) -# axes.pcolorbuffer(x, y, z1, -# xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, -# xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, -# ticksize=9, cblabel='', cbsize="1%",colormap=colormap) -# -# if showSNR: -# title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) -# axes = self.axesList[i*self.plotFact + 1] -# SNRdB1 = SNRdB[i,:].reshape((1,-1)) -# axes.pcolorbuffer(x, y, SNRdB1, -# xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, -# xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, -# ticksize=9, cblabel='', cbsize="1%",colormap='jet') + # for i in range(self.nchan): + # index = channelIndexList[i] + # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) + # axes = self.axesList[i*self.plotFact] + # z1 = z[i,:].reshape((1,-1)) + # axes.pcolorbuffer(x, y, z1, + # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, + # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, + # ticksize=9, cblabel='', cbsize="1%",colormap=colormap) + # + # if showSNR: + # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) + # axes = self.axesList[i*self.plotFact + 1] + # SNRdB1 = SNRdB[i,:].reshape((1,-1)) + # axes.pcolorbuffer(x, y, SNRdB1, + # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, + # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, + # ticksize=9, cblabel='', cbsize="1%",colormap='jet') i=0 index = channelIndexList[i] @@ -1587,11 +1587,11 @@ class SpectralFittingPlot_(Figure): for f in range(nGroups): groupChann = groupArray[f,:] p = dataOut.data_param[f,:,heightindex] -# p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) + # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) spcFitLine[groupChann,:] = fitLineAux -# spcFitLine = spcFitLine/factor + # spcFitLine = spcFitLine/factor z = z[listChannels,:] spcFitLine = spcFitLine[listChannels,:] @@ -1623,7 +1623,7 @@ class SpectralFittingPlot_(Figure): self.setWinTitle(title) for i in range(self.nplots): -# title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) + # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) axes = self.axesList[i*self.__nsubplots] if fit == False: @@ -1747,7 +1747,7 @@ class EWDriftsPlot_(Figure): tmax = None x = dataOut.getTimeRange1(dataOut.outputInterval) -# y = dataOut.heightList + # y = dataOut.heightList y = dataOut.heightList z = dataOut.data_output @@ -1774,7 +1774,7 @@ class EWDriftsPlot_(Figure): showprofile = False -# thisDatetime = dataOut.datatime + # thisDatetime = dataOut.datatime thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) title = wintitle + " EW Drifts" xlabel = "" diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index 1f6e1f3..c3a39fe 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -228,6 +228,7 @@ class SpectraPlot_(Figure): return dataOut + @MPDecorator class CrossSpectraPlot_(Figure): @@ -358,7 +359,7 @@ class CrossSpectraPlot_(Figure): #thisDatetime = dataOut.datatime thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) -# xlabel = "Velocity (m/s)" + # xlabel = "Velocity (m/s)" ylabel = "Range (Km)" if xaxis == "frequency": @@ -428,7 +429,7 @@ class CrossSpectraPlot_(Figure): coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] ) coherence = numpy.abs(coherenceComplex) -# phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi + # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) @@ -1461,8 +1462,8 @@ class BeaconPhase_(Figure): if pairsIndexList == []: return -# if len(pairsIndexList) > 4: -# pairsIndexList = pairsIndexList[0:4] + # if len(pairsIndexList) > 4: + # pairsIndexList = pairsIndexList[0:4] hmin_index = None hmax_index = None diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 2be2ad3..c195258 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -2,37 +2,7 @@ import os import sys import datetime import numpy -import matplotlib - -if 'BACKEND' in os.environ: - matplotlib.use(os.environ['BACKEND']) -elif 'linux' in sys.platform: - matplotlib.use("TkAgg") -elif 'darwin' in sys.platform: - matplotlib.use('TkAgg') -else: - from schainpy.utils import log - log.warning('Using default Backend="Agg"', 'INFO') - matplotlib.use('Agg') -# Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' -import matplotlib.pyplot - -from mpl_toolkits.axes_grid1 import make_axes_locatable -from matplotlib.ticker import FuncFormatter, LinearLocator - -########################################### -# Actualizacion de las funciones del driver -########################################### - -# create jro colormap - -jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] -blu_values = matplotlib.pyplot.get_cmap( - "seismic_r", 20)(numpy.arange(20))[10:15] -ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( - "jro", numpy.vstack((blu_values, jet_values))) -matplotlib.pyplot.register_cmap(cmap=ncmap) - +from .jroplot_base import matplotlib, make_axes_locatable, FuncFormatter, LinearLocator def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80): diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index 0b9fcdc..6a07805 100755 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -1197,8 +1197,8 @@ class SpectralMoments(Operation): self.dataOut.noise : Noise level per channel Affected: - self.dataOut.moments : Parameters per channel - self.dataOut.data_SNR : SNR per channel + self.dataOut.moments : Parameters per channel + self.dataOut.data_SNR : SNR per channel '''