def plot(self): """Plot RSL histogram.""" if self.__cmap == None: self.setcolourmap() self.area2d = None self.area1d = None y = 0.0 if self.plot_key: PyGMT.colourkey(self, self.__cmap.name, pos=[self.size[0] / 8.0, 0.0], size=[3.0 * self.size[0] / 4.0, 0.5]) y = 2.0 if self.plot_2dhist and self.__plot_1dhist: self.area2d = PyGMT.AutoXY(self, pos=[0.0, y], size=[3.0 * self.size[0] / 4.0, self.size[1] - y]) self.area1d = PyGMT.AutoXY( self, pos=[3.0 * self.size[0] / 4.0, y], size=[self.size[0] / 4.0, self.size[1] - y] ) else: if self.plot_2dhist: self.area2d = PyGMT.AutoXY(self, pos=[0.0, y], size=[self.size[0], self.size[1] - y]) if self.plot_1dhist: self.area1d = PyGMT.AutoXY(self, pos=[0.0, y], size=[self.size[0], self.size[1] - y]) if self.plot_2dhist: self.area2d.axis = "WSen" self.area2d.xlabel = "time [ka]" self.area2d.ylabel = "residuals [m]" self.area2d.image(self.__rsldata, self.__cmap.name) if self.plot_1dhist: counts = numpy.sum(self.__rsldata.data, 0) dx = (self.__rsldata.y_minmax[1] - self.__rsldata.y_minmax[0]) / (len(counts) - 1) bins = numpy.arange(self.__rsldata.y_minmax[0], self.__rsldata.y_minmax[1] + dx, dx) if self.plot_2dhist: self.area1d.steps("-W1", counts, bins) self.area1d.ur[0] = PyGMT.round_up(self.area1d.ur[0]) self.area1d.xlabel = "count" self.area1d.axis = "wSen" else: self.area1d.steps("-W1", bins, counts) self.area1d.ur[1] = PyGMT.round_up(self.area1d.ur[1]) self.area1d.xlabel = "residuals [m]" self.area1d.ylabel = "count" self.area1d.axis = "WSen"
def plot(self): """Plot RSL histogram.""" if self.__cmap==None: self.setcolourmap() self.area2d = None self.area1d = None y = 0. if self.plot_key: PyGMT.colourkey(self,self.__cmap.name,pos=[self.size[0]/8.,0.],size=[3.*self.size[0]/4.,.5]) y = 2. if self.plot_2dhist and self.__plot_1dhist: self.area2d = PyGMT.AutoXY(self,pos=[0.,y],size=[3.*self.size[0]/4.,self.size[1]-y]) self.area1d = PyGMT.AutoXY(self,pos=[3.*self.size[0]/4.,y],size=[self.size[0]/4.,self.size[1]-y]) else: if self.plot_2dhist: self.area2d = PyGMT.AutoXY(self,pos=[0.,y],size=[self.size[0],self.size[1]-y]) if self.plot_1dhist: self.area1d = PyGMT.AutoXY(self,pos=[0.,y],size=[self.size[0],self.size[1]-y]) if self.plot_2dhist: self.area2d.axis='WSen' self.area2d.xlabel = 'time [ka]' self.area2d.ylabel = 'residuals [m]' self.area2d.image(self.__rsldata,self.__cmap.name) if self.plot_1dhist: counts = Numeric.sum(self.__rsldata.data,0) dx = (self.__rsldata.y_minmax[1]-self.__rsldata.y_minmax[0])/(len(counts)-1) bins = Numeric.arange(self.__rsldata.y_minmax[0],self.__rsldata.y_minmax[1]+dx,dx) if self.plot_2dhist: self.area1d.steps('-W1',counts,bins) self.area1d.ur[0] = PyGMT.round_up(self.area1d.ur[0]) self.area1d.xlabel = 'count' self.area1d.axis='wSen' else: self.area1d.steps('-W1',bins,counts) self.area1d.ur[1] = PyGMT.round_up(self.area1d.ur[1]) self.area1d.xlabel = 'residuals [m]' self.area1d.ylabel = 'count' self.area1d.axis='WSen'
ctitle = "residency" for i in range(0,numplots): if i%(numx*numy)==0: # need to open a new plot file if plot!=None: plot.close() if numpages>0: p=p+1 plot = opts.plot(number=p) else: p=0 plot = opts.plot() bigarea = PyGMT.AreaXY(plot,size=opts.papersize) if opts.options.dolegend: PyGMT.colourkey(bigarea,colourmap,args='-L',title=ctitle,pos=[0,opts.papersize[1]-(numy-1)*(sizey+deltay)-1.]) if opts.options.profname!=None: infile = opts.cfprofile(i) else: infile = opts.cffile(i) deltat = opts.options.deltat*infile.timescale time = opts.times(infile) time_start = infile.timeslice(infile.time(time)-0.5*deltat) time_end = infile.timeslice(infile.time(time)+0.5*deltat) try: bvel = infile.getvar('bvel_tavg') except:
def plothist(self,var,level=0,clip=None): """Plot a colourmap of the difference histogram. var: name of variable to be plotted level: horizontal slice clip: only display data where clip>0. """ fill = -1000000. v1 = self.cffile1.getvar(var) v2 = self.cffile2.getvar(var) if clip in ['topg','thk','usurf'] : cv1 = self.cffile1.getvar(clip) cv2 = self.cffile2.getvar(clip) else: cv1 = None cv2 = None self.ylabel = '%s [%s]'%(v1.long_name,v1.units) # find min and max differences maxv = -1000000. minv = 1000000. for t in range(0,self.t1[1]-self.t1[0]): diff = v1.get2Dfield(self.t1[0]+t,level=level) - v2.get2Dfield(self.t1[0]+t,level=level) if cv1 != None: cvar = cv1.get2Dfield(self.t1[0]+t,level=level) + cv2.get2Dfield(self.t1[0]+t,level=level) maxv = max(maxv, max(numpy.ravel( numpy.where(cvar > 0. , diff, -1000000.)))) minv = min(minv, min(numpy.ravel( numpy.where(cvar > 0. , diff, 1000000.)))) else: maxv = max(maxv, max(numpy.ravel(diff))) minv = min(minv, min(numpy.ravel(diff))) # get data hist_grid = numpy.zeros([self.t1[1]-self.t1[0],self.bins],'d') for t in range(0,self.t1[1]-self.t1[0]): diff = v1.get2Dfield(self.t1[0]+t,level=level) - v2.get2Dfield(self.t1[0]+t,level=level) if cv1 != None: cvar = cv1.get2Dfield(self.t1[0]+t,level=level) + cv2.get2Dfield(self.t1[0]+t,level=level) count = sum(numpy.where(cvar > 0. , 1., 0.).flat) diff = numpy.where(cvar > 0. , diff, -1000000.) else: count = diff.flat.shape[0] hist = Scientific.Statistics.Histogram.Histogram(numpy.ravel(diff),self.bins,[minv,maxv]) if count>0: hist_grid[t,:] = hist.array[:,1]/count # creating grid grid = PyGMT.Grid() grid.x_minmax = [self.cffile1.time(self.t1[0]),self.cffile1.time(self.t1[1])] grid.y_minmax = [minv,maxv] grid.data = numpy.where(hist_grid>0.,hist_grid,-10) # creating a colourmap min_h = PyGMT.round_down(min(numpy.ravel(hist_grid))) max_h = PyGMT.round_up(max(numpy.ravel(hist_grid))) self.colourmap = tempfile.NamedTemporaryFile(suffix='.cpt') PyGMT.command('makecpt','-Crainbow -Z -T%f/%f/%f > %s'%(min_h,max_h,(max_h-min_h)/10.,self.colourmap.name)) self.colourmap.seek(0,2) self.colourmap.write('B 255 255 255') self.colourmap.flush() # plotting image PyGMT.AutoXY.image(self,grid,self.colourmap.name) # and a colourkey cm = PyGMT.colourkey(self,self.colourmap.name,pos=[self.size[0]+0.5,0],size=[.75,self.size[1]])
area.axis='wESN' area.image(btmp,time,clip = 'thk',level=-1) area.coordsystem() area.profile(args='-W5/0/0/0') for i in range(0,len(spots)): area.plotsymbol([spots_loc[i][0]],[spots_loc[i][1]],size='0.3',symbol='a',args='-G%s'%PyCF.CFcolours[i]) area.text(spots_loc[i],'%s'%Labels[i],'12 0 0 MC',comargs='-D0/0.4') area.stamp(btmp.long_name) # plot some stats area = PyGMT.AreaXY(bigarea,pos=[2*(mapheight+deltay)+0.3,ypos],size=[mapheight+0.5,mapheight]) area.text([0.,mapheight],'Ice thickness at divide: %.2fm'%thk.getSpotIJ(divide,time=time),'12 0 0 TL',comargs='-N') area.text([0.,mapheight-.5],'Basal temp at divide: %.2fC'%btmp.getSpotIJ(divide,time=time,level=-1),'12 0 0 TL',comargs='-N') area.text([0.,mapheight-1.],'Basal temp at midpnt: %.2fC'%btmp.getSpotIJ(midpoint,time=time,level=-1),'12 0 0 TL',comargs='-N') # plot colour keys PyGMT.colourkey(area,thk.colourmap.cptfile,title=thk.long_name,pos=[0,3],size=[mapheight+0.5,0.4]) PyGMT.colourkey(area,btmp.colourmap.cptfile,title=btmp.long_name,pos=[0,1],size=[mapheight+0.5,0.4]) # plot profiles thk_prof = infile.getprofile('thk') horiz_prof = infile.getprofile('uvel_avg') btmp_prof = infile.getprofile('temp') btmp_prof.pmt=opts.options.pmt ypos = ypos-3*ProfileHeight-2. area = PyCF.CFProfileMArea(bigarea,pos=[2.,ypos],size=[Width-3.,ProfileHeight]) area.newprof(horiz_prof,time) area.newprof(btmp_prof,time,level=-1) area.newprof(btmp_prof,time) area.finalise(expandy=True) area.coordsystem()
profile = opts.profs(infile) try: t0 = opts.times(infile,0) t1 = opts.times(infile,1) except: t0=0 t1=infile.numt-1 if opts.options.level == None: level = 0 else: level = opts.options.level plot = opts.plot() plot.defaults['LABEL_FONT_SIZE']='12p' plot.defaults['ANNOT_FONT_SIZE']='10p' area = PyCF.CFProfileAreaTS(plot,profile,time=[t0,t1],clip=opts.options.clip,level=level) if opts.options.profvar != None: area.plot_profs(opts.options.profvar) if opts.options.epoch != None: epoch = PyCF.CFEpoch(opts.options.epoch) area.plot_epoch(epoch) area.coordsystem() if opts.options.dolegend: PyGMT.colourkey(areats,profile.colourmap.cptfile,title=profile.long_name,args='-L',pos=[(opts.papersize[0]-10.)/2.,-2.8]) plot.close()
pass if parser.profile!=None: area.profile(args='-W5/0/0/0') area.axis='wesn' area.coordsystem() area.printinfo(time) else: plot = opts.plot() area = PyCF.CFArea(plot,infile,pos=[0.,3.],size=sizex-deltax) if opts.options.land: area.land(time) area.image(var,time,clip = opts.options.clip,level=level,mono=opts.options.mono) if var.name=="vel": area.velocity_field(time,level=level) area.coastline() try: thk = infile.getvar('thk') area.contour(thk,[0.1],'-W2/0/0/0',time) except: pass if var.name == 'is' or var.name == 'thk': area.contour(var,[500,1000,2500,3000],'-W1/255/255/255',time) if parser.profile!=None: area.profile(args='-W5/0/0/0') area.coordsystem() area.printinfo(time) if opts.options.dolegend: PyGMT.colourkey(area,var.colourmap.cptfile,title=var.long_name,pos=[0,-2]) plot.close()
import PyGMT,PyCF,Numeric,sys # creating option parser parser = PyCF.CFOptParser() parser.width=15. parser.profile() parser.time() parser.plot() opts = PyCF.CFOptions(parser,-2) plot = opts.plot() plot.defaults['LABEL_FONT_SIZE']='12p' plot.defaults['ANOT_FONT_SIZE']='10p' bigarea = PyGMT.AreaXY(plot,size=opts.papersize) area = PyCF.CFProfileMArea(bigarea,pos=[0,1.5],size=[opts.options.width,opts.options.width/5.]) for i in range(0,opts.nfiles): infile = opts.cfprofile(i) profile = opts.profs(infile) time = opts.times(infile,0) prof_area = area.newprof(profile,time) prof_area.ur=[prof_area.ur[0],4000.] prof_area.printinfo(time) area.finalise(expandy=True) area.coordsystem() PyGMT.colourkey(bigarea,profile.colourmap.cptfile,title=profile.long_name, pos=[(opts.options.width-10)/2,-2.25],size=[10,0.5],args='-L') plot.close()
if __name__ == '__main__': parser = PyCF.CFOptParser() parser.width = 12.5 parser.time() parser.plot() opts = PyCF.CFOptions(parser,2) infile = opts.cffile() time = opts.times(infile) exact = infile.getvar('thke') diff = infile.getvar('thk').getGMTgrid(time) diff.data = Numeric.transpose(infile.file.variables['thk'][time,:,:] - infile.file.variables['thke'][time,:,:]) plot = opts.plot() plot.defaults['LABEL_FONT_SIZE']='12p' plot.defaults['ANOT_FONT_SIZE']='10p' bigarea = PyGMT.AreaXY(plot,size=[30,30]) area = PyCF.CFArea(bigarea,infile,pos=[0.,3.],size=opts.options.width) area.raw_image(infile,time,diff,'../data/error.cpt') area.contour(exact,[0.01],'-W2/0/0/0',time) area.coordsystem() PyGMT.colourkey(area,'../data/error.cpt',title='H@-num@--H@-exact@-',pos=[0.,-1.75],size=[opts.options.width,.75],args='-L') bigarea.text([opts.options.width/2.,opts.options.width+4.],"Experiment %s"%infile.title,textargs='20 0 0 CM') plot.close()