diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index df9a125..e17c9a9 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -11,85 +11,85 @@ from figure import Figure, isRealtime, isTimeInHourRange from plotting_codes import * class SpectraPlot(Figure): - + isConfig = None __nsubplots = None - + WIDTHPROF = None HEIGHTPROF = None PREFIX = 'spc' - + def __init__(self): - + self.isConfig = False self.__nsubplots = 1 - + self.WIDTH = 250 self.HEIGHT = 250 self.WIDTHPROF = 120 self.HEIGHTPROF = 0 self.counter_imagwr = 0 - + self.PLOT_CODE = SPEC_CODE - + self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None - + self.__xfilter_ena = False self.__yfilter_ena = False - + def getSubplots(self): - + ncol = int(numpy.sqrt(self.nplots)+0.9) nrow = int(self.nplots*1./ncol + 0.9) - + return nrow, ncol - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): - + self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 1 colspan = 1 if showprofile: ncolspan = 3 colspan = 2 self.__nsubplots = 2 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH + self.WIDTHPROF, heightplot = self.HEIGHT + self.HEIGHTPROF, show=show) - + nrow, ncol = self.getSubplots() - + counter = 0 for y in range(nrow): for x in range(ncol): - + if counter >= self.nplots: break - + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + if showprofile: self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) - + counter += 1 - + def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, - xaxis="frequency"): - + xaxis="frequency", colormap='jet'): + """ - + Input: dataOut : id : @@ -103,12 +103,12 @@ class SpectraPlot(Figure): zmin : None, zmax : None """ - + if realtime: if not(isRealtime(utcdatatime = dataOut.utctime)): print 'Skipping this plot function' return - + if channelList == None: channelIndexList = dataOut.channelIndexList else: @@ -117,66 +117,66 @@ class SpectraPlot(Figure): if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" %channel channelIndexList.append(dataOut.channelList.index(channel)) - + factor = dataOut.normFactor - + if xaxis == "frequency": x = dataOut.getFreqRange(1)/1000. xlabel = "Frequency (kHz)" - + elif xaxis == "time": x = dataOut.getAcfRange(1) xlabel = "Time (ms)" - + else: x = dataOut.getVelRange(1) xlabel = "Velocity (m/s)" - + ylabel = "Range (Km)" - + y = dataOut.getHeiRange() - + z = dataOut.data_spc/factor - z = numpy.where(numpy.isfinite(z), z, numpy.NAN) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) zdB = 10*numpy.log10(z) avg = numpy.average(z, axis=1) avgdB = 10*numpy.log10(avg) - + noise = dataOut.getNoise()/factor noisedB = 10*numpy.log10(noise) - + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) - title = wintitle + " Spectra" + title = wintitle + " Spectra" if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) - + if not self.isConfig: - + nplots = len(channelIndexList) - + self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=showprofile, show=show) - + if xmin == None: xmin = numpy.nanmin(x) if xmax == None: xmax = numpy.nanmax(x) if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - + self.isConfig = True - + self.setWinTitle(title) - + for i in range(self.nplots): index = channelIndexList[i] str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) @@ -187,9 +187,9 @@ class SpectraPlot(Figure): axes = self.axesList[i*self.__nsubplots] axes.pcolor(x, y, zdB[index,:,:], xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, - xlabel=xlabel, ylabel=ylabel, title=title, + xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, ticksize=9, cblabel='') - + if self.__showprofile: axes = self.axesList[i*self.__nsubplots +1] axes.pline(avgdB[index,:], y, @@ -197,19 +197,19 @@ class SpectraPlot(Figure): xlabel='dB', ylabel='', title='', ytick_visible=False, grid='x') - + noiseline = numpy.repeat(noisedB[index], len(y)) axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) - + self.draw() - + if figfile == None: str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") name = str_datetime if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): - name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) + name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) figfile = self.getFilename(name) - + self.save(figpath=figpath, figfile=figfile, save=save, @@ -218,18 +218,18 @@ class SpectraPlot(Figure): thisDatetime=thisDatetime) class CrossSpectraPlot(Figure): - + isConfig = None __nsubplots = None - + WIDTH = None HEIGHT = None WIDTHPROF = None HEIGHTPROF = None PREFIX = 'cspc' - + def __init__(self): - + self.isConfig = False self.__nsubplots = 4 self.counter_imagwr = 0 @@ -237,44 +237,44 @@ class CrossSpectraPlot(Figure): self.HEIGHT = 250 self.WIDTHPROF = 0 self.HEIGHTPROF = 0 - + self.PLOT_CODE = CROSS_CODE self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None - + def getSubplots(self): - + ncol = 4 nrow = self.nplots - + return nrow, ncol - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): - + self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 1 colspan = 1 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH + self.WIDTHPROF, heightplot = self.HEIGHT + self.HEIGHTPROF, show=True) - + nrow, ncol = self.getSubplots() - + counter = 0 for y in range(nrow): - for x in range(ncol): + for x in range(ncol): self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + counter += 1 - - def run(self, dataOut, id, wintitle="", pairsList=None, + + def run(self, dataOut, id, wintitle="", pairsList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, coh_min=None, coh_max=None, phase_min=None, phase_max=None, save=False, figpath='./', figfile=None, ftp=False, wr_period=1, @@ -282,9 +282,9 @@ class CrossSpectraPlot(Figure): server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, xaxis='frequency'): - + """ - + Input: dataOut : id : @@ -298,7 +298,7 @@ class CrossSpectraPlot(Figure): zmin : None, zmax : None """ - + if pairsList == None: pairsIndexList = dataOut.pairsIndexList else: @@ -307,87 +307,87 @@ class CrossSpectraPlot(Figure): if pair not in dataOut.pairsList: raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) - + if not pairsIndexList: return - + if len(pairsIndexList) > 4: pairsIndexList = pairsIndexList[0:4] - + factor = dataOut.normFactor x = dataOut.getVelRange(1) y = dataOut.getHeiRange() z = dataOut.data_spc[:,:,:]/factor z = numpy.where(numpy.isfinite(z), z, numpy.NAN) - + noise = dataOut.noise/factor - + zdB = 10*numpy.log10(z) noisedB = 10*numpy.log10(noise) - + if coh_min == None: coh_min = 0.0 if coh_max == None: coh_max = 1.0 - + if phase_min == None: phase_min = -180 if phase_max == None: phase_max = 180 - + #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)" ylabel = "Range (Km)" - + if xaxis == "frequency": x = dataOut.getFreqRange(1)/1000. xlabel = "Frequency (kHz)" - + elif xaxis == "time": x = dataOut.getAcfRange(1) xlabel = "Time (ms)" - + else: x = dataOut.getVelRange(1) xlabel = "Velocity (m/s)" - + if not self.isConfig: - + nplots = len(pairsIndexList) - + self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=False, show=show) - + avg = numpy.abs(numpy.average(z, axis=1)) avgdB = 10*numpy.log10(avg) - + if xmin == None: xmin = numpy.nanmin(x) if xmax == None: xmax = numpy.nanmax(x) if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - + self.isConfig = True - + self.setWinTitle(title) - + for i in range(self.nplots): pair = dataOut.pairsList[pairsIndexList[i]] - + chan_index0 = dataOut.channelList.index(pair[0]) chan_index1 = dataOut.channelList.index(pair[1]) - + str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) @@ -396,7 +396,7 @@ class CrossSpectraPlot(Figure): xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, xlabel=xlabel, ylabel=ylabel, title=title, ticksize=9, colormap=power_cmap, cblabel='') - + title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) axes0 = self.axesList[i*self.__nsubplots+1] @@ -409,14 +409,14 @@ class CrossSpectraPlot(Figure): coherence = numpy.abs(coherenceComplex) # 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]) axes0 = self.axesList[i*self.__nsubplots+2] axes0.pcolor(x, y, coherence, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, xlabel=xlabel, ylabel=ylabel, title=title, ticksize=9, colormap=coherence_cmap, cblabel='') - + title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) axes0 = self.axesList[i*self.__nsubplots+3] axes0.pcolor(x, y, phase, @@ -425,102 +425,102 @@ class CrossSpectraPlot(Figure): ticksize=9, colormap=phase_cmap, cblabel='') - + self.draw() - + self.save(figpath=figpath, figfile=figfile, save=save, ftp=ftp, wr_period=wr_period, - thisDatetime=thisDatetime) + thisDatetime=thisDatetime) class RTIPlot(Figure): - + __isConfig = None __nsubplots = None - + WIDTHPROF = None HEIGHTPROF = None PREFIX = 'rti' - + def __init__(self): - + self.timerange = None self.isConfig = False self.__nsubplots = 1 - + self.WIDTH = 800 self.HEIGHT = 180 self.WIDTHPROF = 120 self.HEIGHTPROF = 0 self.counter_imagwr = 0 - + self.PLOT_CODE = RTI_CODE - + self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None - self.tmin = None + self.tmin = None self.tmax = None - + self.xmin = None self.xmax = None - + self.figfile = None - + def getSubplots(self): - + ncol = 1 nrow = self.nplots - + return nrow, ncol - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): - + self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 1 colspan = 1 if showprofile: ncolspan = 7 colspan = 6 self.__nsubplots = 2 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH + self.WIDTHPROF, heightplot = self.HEIGHT + self.HEIGHTPROF, show=show) - + nrow, ncol = self.getSubplots() - + counter = 0 for y in range(nrow): for x in range(ncol): - + if counter >= self.nplots: break - + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + if showprofile: self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) - + counter += 1 - + def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, - timerange=None, + timerange=None, colormap='jet', save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): - + """ - + Input: dataOut : id : @@ -534,10 +534,10 @@ class RTIPlot(Figure): zmin : None, zmax : None """ - + if not isTimeInHourRange(dataOut.datatime, xmin, xmax): return - + if channelList == None: channelIndexList = dataOut.channelIndexList else: @@ -546,70 +546,70 @@ class RTIPlot(Figure): if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - + if hasattr(dataOut, 'normFactor'): factor = dataOut.normFactor else: factor = 1 - + # factor = dataOut.normFactor x = dataOut.getTimeRange() y = dataOut.getHeiRange() - + # z = dataOut.data_spc/factor -# z = numpy.where(numpy.isfinite(z), z, numpy.NAN) +# z = numpy.where(numpy.isfinite(z), z, numpy.NAN) # avg = numpy.average(z, axis=1) # avgdB = 10.*numpy.log10(avg) avgdB = dataOut.getPower() - + thisDatetime = dataOut.datatime # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (Km)" - + update_figfile = False - + if dataOut.ltctime >= self.xmax: self.counter_imagwr = wr_period self.isConfig = False update_figfile = True - + if not self.isConfig: - + nplots = len(channelIndexList) - + self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=showprofile, show=show) - + if timerange != None: self.timerange = timerange - + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) - + noise = dataOut.noise/factor noisedB = 10*numpy.log10(noise) - + if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") self.isConfig = True self.figfile = figfile update_figfile = True - + self.setWinTitle(title) - + for i in range(self.nplots): index = channelIndexList[i] title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) @@ -620,8 +620,8 @@ class RTIPlot(Figure): axes.pcolorbuffer(x, y, zdB, 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%") - + ticksize=9, cblabel='', cbsize="1%", colormap=colormap) + if self.__showprofile: axes = self.axesList[i*self.__nsubplots +1] axes.pline(avgdB[index], y, @@ -629,9 +629,9 @@ class RTIPlot(Figure): xlabel='dB', ylabel='', title='', ytick_visible=False, grid='x') - + self.draw() - + self.save(figpath=figpath, figfile=figfile, save=save, @@ -643,7 +643,7 @@ class RTIPlot(Figure): class CoherenceMap(Figure): isConfig = None __nsubplots = None - + WIDTHPROF = None HEIGHTPROF = None PREFIX = 'cmap' @@ -652,57 +652,57 @@ class CoherenceMap(Figure): self.timerange = 2*60*60 self.isConfig = False self.__nsubplots = 1 - + self.WIDTH = 800 self.HEIGHT = 180 self.WIDTHPROF = 120 self.HEIGHTPROF = 0 self.counter_imagwr = 0 - + self.PLOT_CODE = COH_CODE - + self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None self.counter_imagwr = 0 - + self.xmin = None self.xmax = None - + def getSubplots(self): ncol = 1 nrow = self.nplots*2 - + return nrow, ncol - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 1 colspan = 1 if showprofile: ncolspan = 7 colspan = 6 self.__nsubplots = 2 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH + self.WIDTHPROF, heightplot = self.HEIGHT + self.HEIGHTPROF, show=True) - + nrow, ncol = self.getSubplots() - + for y in range(nrow): for x in range(ncol): - + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + if showprofile: self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) - + def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, phase_min=None, phase_max=None, @@ -710,10 +710,10 @@ class CoherenceMap(Figure): coherence_cmap='jet', phase_cmap='RdBu_r', show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): - + if not isTimeInHourRange(dataOut.datatime, xmin, xmax): return - + if pairsList == None: pairsIndexList = dataOut.pairsIndexList else: @@ -722,81 +722,81 @@ class CoherenceMap(Figure): if pair not in dataOut.pairsList: raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) - + if pairsIndexList == []: return - + if len(pairsIndexList) > 4: pairsIndexList = pairsIndexList[0:4] - + if phase_min == None: phase_min = -180 if phase_max == None: phase_max = 180 - + x = dataOut.getTimeRange() y = dataOut.getHeiRange() - + thisDatetime = dataOut.datatime - + title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (Km)" update_figfile = False - - if not self.isConfig: + + if not self.isConfig: nplots = len(pairsIndexList) self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=showprofile, show=show) - + if timerange != None: self.timerange = timerange - + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) - + if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if zmin == None: zmin = 0. if zmax == None: zmax = 1. - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") - + self.isConfig = True update_figfile = True - + self.setWinTitle(title) - + for i in range(self.nplots): - + pair = dataOut.pairsList[pairsIndexList[i]] - + ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) - - + + avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) coherence = numpy.abs(avgcoherenceComplex) - + z = coherence.reshape((1,-1)) counter = 0 - + title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) axes = self.axesList[i*self.__nsubplots*2] axes.pcolorbuffer(x, y, z, 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='', colormap=coherence_cmap, cbsize="1%") - + if self.__showprofile: counter += 1 axes = self.axesList[i*self.__nsubplots*2 + counter] @@ -805,20 +805,20 @@ class CoherenceMap(Figure): xlabel='', ylabel='', title='', ticksize=7, ytick_visible=False, nxticks=5, grid='x') - + counter += 1 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi z = phase.reshape((1,-1)) - + title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) axes = self.axesList[i*self.__nsubplots*2 + counter] axes.pcolorbuffer(x, y, z, xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") - + if self.__showprofile: counter += 1 axes = self.axesList[i*self.__nsubplots*2 + counter] @@ -827,14 +827,14 @@ class CoherenceMap(Figure): xlabel='', ylabel='', title='', ticksize=7, ytick_visible=False, nxticks=4, grid='x') - + self.draw() - + if dataOut.ltctime >= self.xmax: self.counter_imagwr = wr_period self.isConfig = False update_figfile = True - + self.save(figpath=figpath, figfile=figfile, save=save, @@ -844,57 +844,57 @@ class CoherenceMap(Figure): update_figfile=update_figfile) class PowerProfilePlot(Figure): - + isConfig = None __nsubplots = None - + WIDTHPROF = None HEIGHTPROF = None PREFIX = 'spcprofile' - + def __init__(self): self.isConfig = False self.__nsubplots = 1 - + self.PLOT_CODE = POWER_CODE - + self.WIDTH = 300 self.HEIGHT = 500 self.counter_imagwr = 0 - + def getSubplots(self): ncol = 1 nrow = 1 - + return nrow, ncol - + def setup(self, id, nplots, wintitle, show): - + self.nplots = nplots - + ncolspan = 1 colspan = 1 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH, heightplot = self.HEIGHT, show=show) - + nrow, ncol = self.getSubplots() - + counter = 0 for y in range(nrow): - for x in range(ncol): + for x in range(ncol): self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + def run(self, dataOut, id, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None): - - + + if channelList == None: channelIndexList = dataOut.channelIndexList channelList = dataOut.channelList @@ -904,61 +904,61 @@ class PowerProfilePlot(Figure): if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - + factor = dataOut.normFactor - + y = dataOut.getHeiRange() - + #for voltage if dataOut.type == 'Voltage': x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) x = x.real x = numpy.where(numpy.isfinite(x), x, numpy.NAN) - + #for spectra if dataOut.type == 'Spectra': x = dataOut.data_spc[channelIndexList,:,:]/factor - x = numpy.where(numpy.isfinite(x), x, numpy.NAN) + x = numpy.where(numpy.isfinite(x), x, numpy.NAN) x = numpy.average(x, axis=1) - - + + xdB = 10*numpy.log10(x) - + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "dB" ylabel = "Range (Km)" - + if not self.isConfig: - + nplots = 1 - + self.setup(id=id, nplots=nplots, wintitle=wintitle, show=show) - + if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if xmin == None: xmin = numpy.nanmin(xdB)*0.9 if xmax == None: xmax = numpy.nanmax(xdB)*1.1 - + self.isConfig = True - + self.setWinTitle(title) - + title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) axes = self.axesList[0] - + legendlabels = ["channel %d"%x for x in channelList] axes.pmultiline(xdB, y, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, ytick_visible=True, nxticks=5, grid='x') - + self.draw() - + self.save(figpath=figpath, figfile=figfile, save=save, @@ -967,58 +967,58 @@ class PowerProfilePlot(Figure): thisDatetime=thisDatetime) class SpectraCutPlot(Figure): - + isConfig = None __nsubplots = None - + WIDTHPROF = None HEIGHTPROF = None PREFIX = 'spc_cut' - + def __init__(self): self.isConfig = False self.__nsubplots = 1 - + self.PLOT_CODE = POWER_CODE - + self.WIDTH = 700 self.HEIGHT = 500 self.counter_imagwr = 0 - + def getSubplots(self): ncol = 1 nrow = 1 - + return nrow, ncol - + def setup(self, id, nplots, wintitle, show): - + self.nplots = nplots - + ncolspan = 1 colspan = 1 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH, heightplot = self.HEIGHT, show=show) - + nrow, ncol = self.getSubplots() - + counter = 0 for y in range(nrow): - for x in range(ncol): + for x in range(ncol): self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) - + def run(self, dataOut, id, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, xaxis="frequency"): - - + + if channelList == None: channelIndexList = dataOut.channelIndexList channelList = dataOut.channelList @@ -1028,84 +1028,84 @@ class SpectraCutPlot(Figure): if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - + factor = dataOut.normFactor - + y = dataOut.getHeiRange() - + z = dataOut.data_spc/factor - z = numpy.where(numpy.isfinite(z), z, numpy.NAN) - + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) + hei_index = numpy.arange(25)*3 + 20 - + if xaxis == "frequency": x = dataOut.getFreqRange()/1000. zdB = 10*numpy.log10(z[0,:,hei_index]) xlabel = "Frequency (kHz)" ylabel = "Power (dB)" - + elif xaxis == "time": x = dataOut.getAcfRange() zdB = z[0,:,hei_index] xlabel = "Time (ms)" ylabel = "ACF" - + else: x = dataOut.getVelRange() zdB = 10*numpy.log10(z[0,:,hei_index]) xlabel = "Velocity (m/s)" ylabel = "Power (dB)" - + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) - + if not self.isConfig: - + nplots = 1 - + self.setup(id=id, nplots=nplots, wintitle=wintitle, show=show) - + if xmin == None: xmin = numpy.nanmin(x)*0.9 if xmax == None: xmax = numpy.nanmax(x)*1.1 if ymin == None: ymin = numpy.nanmin(zdB) if ymax == None: ymax = numpy.nanmax(zdB) - + self.isConfig = True - + self.setWinTitle(title) - + title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) axes = self.axesList[0] - + legendlabels = ["Range = %dKm" %y[i] for i in hei_index] - + axes.pmultilineyaxis( x, zdB, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, ytick_visible=True, nxticks=5, grid='x') - + self.draw() - + self.save(figpath=figpath, figfile=figfile, save=save, ftp=ftp, wr_period=wr_period, thisDatetime=thisDatetime) - + class Noise(Figure): - + isConfig = None __nsubplots = None PREFIX = 'noise' - + def __init__(self): - + self.timerange = 24*60*60 self.isConfig = False self.__nsubplots = 1 @@ -1116,41 +1116,41 @@ class Noise(Figure): self.HEIGHTPROF = 0 self.xdata = None self.ydata = None - + self.PLOT_CODE = NOISE_CODE - + self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None self.figfile = None - + self.xmin = None self.xmax = None - + def getSubplots(self): - + ncol = 1 nrow = 1 - + return nrow, ncol - + def openfile(self, filename): dirname = os.path.dirname(filename) - + if not os.path.exists(dirname): os.mkdir(dirname) - - f = open(filename,'w+') + + f = open(filename,'w+') f.write('\n\n') f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') - f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) + f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) f.close() def save_data(self, filename_phase, data, data_datetime): - + f=open(filename_phase,'a') - + timetuple_data = data_datetime.timetuple() day = str(timetuple_data.tm_mday) month = str(timetuple_data.tm_mon) @@ -1158,45 +1158,45 @@ class Noise(Figure): hour = str(timetuple_data.tm_hour) minute = str(timetuple_data.tm_min) second = str(timetuple_data.tm_sec) - + data_msg = '' for i in range(len(data)): data_msg += str(data[i]) + ' ' - + f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') f.close() - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): - + self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 7 colspan = 6 self.__nsubplots = 2 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH+self.WIDTHPROF, heightplot = self.HEIGHT+self.HEIGHTPROF, show=show) - + nrow, ncol = self.getSubplots() - + self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) - - + + def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, timerange=None, save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): - + if not isTimeInHourRange(dataOut.datatime, xmin, xmax): return - + if channelList == None: channelIndexList = dataOut.channelIndexList channelList = dataOut.channelList @@ -1206,85 +1206,85 @@ class Noise(Figure): if channel not in dataOut.channelList: raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - + x = dataOut.getTimeRange() #y = dataOut.getHeiRange() factor = dataOut.normFactor noise = dataOut.noise[channelIndexList]/factor noisedB = 10*numpy.log10(noise) - + thisDatetime = dataOut.datatime - + title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Intensity (dB)" update_figfile = False - + if not self.isConfig: - + nplots = 1 - + self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=showprofile, show=show) - + if timerange != None: self.timerange = timerange - + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) - + if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - - + + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") self.isConfig = True self.figfile = figfile self.xdata = numpy.array([]) self.ydata = numpy.array([]) - + update_figfile = True - + #open file beacon phase path = '%s%03d' %(self.PREFIX, self.id) noise_file = os.path.join(path,'%s.txt'%self.name) self.filename_noise = os.path.join(figpath,noise_file) self.setWinTitle(title) - + title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) - + legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] axes = self.axesList[0] - + self.xdata = numpy.hstack((self.xdata, x[0:1])) - + if len(self.ydata)==0: self.ydata = noisedB.reshape(-1,1) else: self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) - - + + axes.pmultilineyaxis(x=self.xdata, y=self.ydata, xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", XAxisAsTime=True, grid='both' ) - + self.draw() - + if dataOut.ltctime >= self.xmax: self.counter_imagwr = wr_period self.isConfig = False update_figfile = True - + self.save(figpath=figpath, figfile=figfile, save=save, @@ -1292,20 +1292,20 @@ class Noise(Figure): wr_period=wr_period, thisDatetime=thisDatetime, update_figfile=update_figfile) - + #store data beacon phase if save: self.save_data(self.filename_noise, noisedB, thisDatetime) - + class BeaconPhase(Figure): - + __isConfig = None __nsubplots = None PREFIX = 'beacon_phase' - + def __init__(self): - + self.timerange = 24*60*60 self.isConfig = False self.__nsubplots = 1 @@ -1316,52 +1316,52 @@ class BeaconPhase(Figure): self.HEIGHTPROF = 0 self.xdata = None self.ydata = None - + self.PLOT_CODE = BEACON_CODE - + self.FTP_WEI = None self.EXP_CODE = None self.SUB_EXP_CODE = None self.PLOT_POS = None - + self.filename_phase = None - + self.figfile = None - + self.xmin = None self.xmax = None - + def getSubplots(self): - + ncol = 1 nrow = 1 - + return nrow, ncol - + def setup(self, id, nplots, wintitle, showprofile=True, show=True): - + self.__showprofile = showprofile self.nplots = nplots - + ncolspan = 7 colspan = 6 self.__nsubplots = 2 - + self.createFigure(id = id, wintitle = wintitle, widthplot = self.WIDTH+self.WIDTHPROF, heightplot = self.HEIGHT+self.HEIGHTPROF, show=show) - + nrow, ncol = self.getSubplots() - + self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) def save_phase(self, filename_phase): - f = open(filename_phase,'w+') + f = open(filename_phase,'w+') f.write('\n\n') f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') - f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) + f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) f.close() def save_data(self, filename_phase, data, data_datetime): @@ -1383,10 +1383,10 @@ class BeaconPhase(Figure): save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): - + if not isTimeInHourRange(dataOut.datatime, xmin, xmax): return - + if pairsList == None: pairsIndexList = dataOut.pairsIndexList[:10] else: @@ -1395,39 +1395,39 @@ class BeaconPhase(Figure): if pair not in dataOut.pairsList: raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) - + if pairsIndexList == []: return - + # if len(pairsIndexList) > 4: # pairsIndexList = pairsIndexList[0:4] hmin_index = None hmax_index = None - + if hmin != None and hmax != None: indexes = numpy.arange(dataOut.nHeights) hmin_list = indexes[dataOut.heightList >= hmin] hmax_list = indexes[dataOut.heightList <= hmax] - + if hmin_list.any(): hmin_index = hmin_list[0] - + if hmax_list.any(): hmax_index = hmax_list[-1]+1 - + x = dataOut.getTimeRange() #y = dataOut.getHeiRange() - + thisDatetime = dataOut.datatime - + title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "Local Time" ylabel = "Phase (degrees)" - + update_figfile = False - + nplots = len(pairsIndexList) #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) phase_beacon = numpy.zeros(len(pairsIndexList)) @@ -1438,86 +1438,86 @@ class BeaconPhase(Figure): powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi - + #print "Phase %d%d" %(pair[0], pair[1]) #print phase[dataOut.beacon_heiIndexList] - + if dataOut.beacon_heiIndexList: phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) else: phase_beacon[i] = numpy.average(phase) - + if not self.isConfig: - + nplots = len(pairsIndexList) - + self.setup(id=id, nplots=nplots, wintitle=wintitle, showprofile=showprofile, show=show) - + if timerange != None: self.timerange = timerange - + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) - + if ymin == None: ymin = 0 if ymax == None: ymax = 360 - + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code self.PLOT_POS = plot_pos - + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") self.isConfig = True self.figfile = figfile self.xdata = numpy.array([]) self.ydata = numpy.array([]) - + update_figfile = True - + #open file beacon phase path = '%s%03d' %(self.PREFIX, self.id) beacon_file = os.path.join(path,'%s.txt'%self.name) self.filename_phase = os.path.join(figpath,beacon_file) #self.save_phase(self.filename_phase) - - + + #store data beacon phase #self.save_data(self.filename_phase, phase_beacon, thisDatetime) - + self.setWinTitle(title) - - + + title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) - + legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] - + axes = self.axesList[0] - + self.xdata = numpy.hstack((self.xdata, x[0:1])) - + if len(self.ydata)==0: self.ydata = phase_beacon.reshape(-1,1) else: self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) - - + + axes.pmultilineyaxis(x=self.xdata, y=self.ydata, xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", XAxisAsTime=True, grid='both' ) - + self.draw() - + if dataOut.ltctime >= self.xmax: self.counter_imagwr = wr_period self.isConfig = False update_figfile = True - + self.save(figpath=figpath, figfile=figfile, save=save, diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 2bd70fa..6749ec4 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -5,7 +5,7 @@ import matplotlib if 'linux' in sys.platform: matplotlib.use("TKAgg") - + if 'darwin' in sys.platform: matplotlib.use('TKAgg') #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' @@ -18,35 +18,40 @@ from matplotlib.ticker import FuncFormatter, LinearLocator #Actualizacion de las funciones del driver ########################################### +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) + def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80): - + matplotlib.pyplot.ioff() - + fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi)) fig.canvas.manager.set_window_title(wintitle) # fig.canvas.manager.resize(width, height) matplotlib.pyplot.ion() - + if show: matplotlib.pyplot.show() - + return fig def closeFigure(show=False, fig=None): - + # matplotlib.pyplot.ioff() # matplotlib.pyplot.pause(0) - + if show: matplotlib.pyplot.show() - + if fig != None: matplotlib.pyplot.close(fig) # matplotlib.pyplot.pause(0) # matplotlib.pyplot.ion() return - + matplotlib.pyplot.close("all") # matplotlib.pyplot.pause(0) # matplotlib.pyplot.ion() @@ -54,25 +59,25 @@ def closeFigure(show=False, fig=None): return def saveFigure(fig, filename): - + # matplotlib.pyplot.ioff() fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) # matplotlib.pyplot.ion() def clearFigure(fig): - + fig.clf() - + def setWinTitle(fig, title): - + fig.canvas.manager.set_window_title(title) def setTitle(fig, title): - + fig.suptitle(title) def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): - + matplotlib.pyplot.ioff() matplotlib.pyplot.figure(fig.number) axes = matplotlib.pyplot.subplot2grid((nrow, ncol), @@ -80,12 +85,12 @@ def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): colspan=colspan, rowspan=rowspan, polar=polar) - + matplotlib.pyplot.ion() return axes def setAxesText(ax, text): - + ax.annotate(text, xy = (.1, .99), xycoords = 'figure fraction', @@ -94,29 +99,29 @@ def setAxesText(ax, text): fontsize = 10) def printLabels(ax, xlabel, ylabel, title): - + ax.set_xlabel(xlabel, size=11) ax.set_ylabel(ylabel, size=11) ax.set_title(title, size=8) - + def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', ticksize=9, xtick_visible=True, ytick_visible=True, nxticks=4, nyticks=10, grid=None,color='blue'): - + """ - + Input: grid : None, 'both', 'x', 'y' """ - + matplotlib.pyplot.ioff() - + ax.set_xlim([xmin,xmax]) ax.set_ylim([ymin,ymax]) - + printLabels(ax, xlabel, ylabel, title) - + ###################################################### if (xmax-xmin)<=1: xtickspos = numpy.linspace(xmin,xmax,nxticks) @@ -126,55 +131,55 @@ def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='' xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) ax.set_xticks(xtickspos) - + for tick in ax.get_xticklabels(): tick.set_visible(xtick_visible) - + for tick in ax.xaxis.get_major_ticks(): - tick.label.set_fontsize(ticksize) - + tick.label.set_fontsize(ticksize) + ###################################################### for tick in ax.get_yticklabels(): tick.set_visible(ytick_visible) - + for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(ticksize) - + ax.plot(x, y, color=color) iplot = ax.lines[-1] - + ###################################################### if '0.' in matplotlib.__version__[0:2]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if '1.0.' in matplotlib.__version__[0:4]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if grid != None: ax.grid(b=True, which='major', axis=grid) - + matplotlib.pyplot.tight_layout() - + matplotlib.pyplot.ion() - + return iplot def set_linedata(ax, x, y, idline): - + ax.lines[idline].set_data(x,y) - + def pline(iplot, x, y, xlabel='', ylabel='', title=''): - + ax = iplot.get_axes() - + printLabels(ax, xlabel, ylabel, title) - + set_linedata(ax, x, y, idline=0) def addpline(ax, x, y, color, linestyle, lw): - + ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) @@ -182,215 +187,224 @@ def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, colormap='jet',cblabel='', cbsize="5%", XAxisAsTime=False): - + matplotlib.pyplot.ioff() - + divider = make_axes_locatable(ax) ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) fig = ax.get_figure() fig.add_axes(ax_cb) - + ax.set_xlim([xmin,xmax]) ax.set_ylim([ymin,ymax]) - + printLabels(ax, xlabel, ylabel, title) - - imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) + + z = numpy.ma.masked_invalid(z) + cmap=matplotlib.pyplot.get_cmap(colormap) + cmap.set_bad('white',1.) + imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap) cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) cb.set_label(cblabel) - + # for tl in ax_cb.get_yticklabels(): # tl.set_visible(True) - + for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(ticksize) - + for tick in ax.xaxis.get_major_ticks(): - tick.label.set_fontsize(ticksize) - + tick.label.set_fontsize(ticksize) + for tick in cb.ax.get_yticklabels(): tick.set_fontsize(ticksize) - + ax_cb.yaxis.tick_right() - + if '0.' in matplotlib.__version__[0:2]: print "The matplotlib version has to be updated to 1.1 or newer" return imesh - + if '1.0.' in matplotlib.__version__[0:4]: print "The matplotlib version has to be updated to 1.1 or newer" return imesh - + matplotlib.pyplot.tight_layout() - + if XAxisAsTime: - + func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) ax.xaxis.set_major_formatter(FuncFormatter(func)) ax.xaxis.set_major_locator(LinearLocator(7)) - + matplotlib.pyplot.ion() return imesh def pcolor(imesh, z, xlabel='', ylabel='', title=''): - + z = z.T ax = imesh.get_axes() printLabels(ax, xlabel, ylabel, title) imesh.set_array(z.ravel()) def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): - + printLabels(ax, xlabel, ylabel, title) - + ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) - + def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): - + printLabels(ax, xlabel, ylabel, title) - + ax.collections.remove(ax.collections[0]) + + z = numpy.ma.masked_invalid(z) - ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) + cmap=matplotlib.pyplot.get_cmap(colormap) + cmap.set_bad('white',1.) + + + ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap) def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, ticksize=9, xtick_visible=True, ytick_visible=True, nxticks=4, nyticks=10, grid=None): - + """ - + Input: grid : None, 'both', 'x', 'y' """ - + matplotlib.pyplot.ioff() - + lines = ax.plot(x.T, y) leg = ax.legend(lines, legendlabels, loc='upper right') leg.get_frame().set_alpha(0.5) ax.set_xlim([xmin,xmax]) - ax.set_ylim([ymin,ymax]) + ax.set_ylim([ymin,ymax]) printLabels(ax, xlabel, ylabel, title) - + xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) ax.set_xticks(xtickspos) - + for tick in ax.get_xticklabels(): tick.set_visible(xtick_visible) - + for tick in ax.xaxis.get_major_ticks(): - tick.label.set_fontsize(ticksize) - + tick.label.set_fontsize(ticksize) + for tick in ax.get_yticklabels(): tick.set_visible(ytick_visible) - + for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(ticksize) - + iplot = ax.lines[-1] - + if '0.' in matplotlib.__version__[0:2]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if '1.0.' in matplotlib.__version__[0:4]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if grid != None: ax.grid(b=True, which='major', axis=grid) - + matplotlib.pyplot.tight_layout() - + matplotlib.pyplot.ion() - + return iplot def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): - + ax = iplot.get_axes() - + printLabels(ax, xlabel, ylabel, title) - + for i in range(len(ax.lines)): line = ax.lines[i] line.set_data(x[i,:],y) def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, ticksize=9, xtick_visible=True, ytick_visible=True, - nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", + nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", grid=None, XAxisAsTime=False): - + """ - + Input: grid : None, 'both', 'x', 'y' """ - + matplotlib.pyplot.ioff() - + # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) lines = ax.plot(x, y.T) # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) - + leg = ax.legend(lines, legendlabels, loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) - + for label in leg.get_texts(): label.set_fontsize(9) - + ax.set_xlim([xmin,xmax]) - ax.set_ylim([ymin,ymax]) + ax.set_ylim([ymin,ymax]) printLabels(ax, xlabel, ylabel, title) - + # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) # ax.set_xticks(xtickspos) - + for tick in ax.get_xticklabels(): tick.set_visible(xtick_visible) - + for tick in ax.xaxis.get_major_ticks(): - tick.label.set_fontsize(ticksize) - + tick.label.set_fontsize(ticksize) + for tick in ax.get_yticklabels(): tick.set_visible(ytick_visible) - + for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(ticksize) - + iplot = ax.lines[-1] - + if '0.' in matplotlib.__version__[0:2]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if '1.0.' in matplotlib.__version__[0:4]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if grid != None: ax.grid(b=True, which='major', axis=grid) - + matplotlib.pyplot.tight_layout() - + if XAxisAsTime: - + func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) ax.xaxis.set_major_formatter(FuncFormatter(func)) ax.xaxis.set_major_locator(LinearLocator(7)) - + matplotlib.pyplot.ion() - + return iplot def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): - + ax = iplot.get_axes() - + printLabels(ax, xlabel, ylabel, title) - + for i in range(len(ax.lines)): line = ax.lines[i] line.set_data(x,y[i,:]) @@ -399,9 +413,9 @@ def createPolar(ax, x, y, xlabel='', ylabel='', title='', ticksize = 9, colormap='jet',cblabel='', cbsize="5%", XAxisAsTime=False): - + matplotlib.pyplot.ioff() - + ax.plot(x,y,'bo', markersize=5) # ax.set_rmax(90) ax.set_ylim(0,90) @@ -412,42 +426,41 @@ def createPolar(ax, x, y, ax.yaxis.labelpad = 230 printLabels(ax, xlabel, ylabel, title) iplot = ax.lines[-1] - + if '0.' in matplotlib.__version__[0:2]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + if '1.0.' in matplotlib.__version__[0:4]: print "The matplotlib version has to be updated to 1.1 or newer" return iplot - + # if grid != None: # ax.grid(b=True, which='major', axis=grid) - + matplotlib.pyplot.tight_layout() - + matplotlib.pyplot.ion() - - + + return iplot def polar(iplot, x, y, xlabel='', ylabel='', title=''): - + ax = iplot.get_axes() - + # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') printLabels(ax, xlabel, ylabel, title) - + set_linedata(ax, x, y, idline=0) - + def draw(fig): - + if type(fig) == 'int': raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" - + fig.canvas.draw() def pause(interval=0.000001): - + matplotlib.pyplot.pause(interval) - \ No newline at end of file