def setcolourmap(self,vmin=None,vmax=None): """Set colourmap for residual plot. vmin: minimum value vmax: maximum value""" if vmin==None: v0 = 1 else: v0 = vmin if vmax==None: v1 = max(Numeric.ravel((self.__rsldata.data))) else: v1 = vmax self.__cmap = tempfile.NamedTemporaryFile(suffix='cpt') PyGMT.command('makecpt','-Ccool -T%f/%f/%f -Z > %s'%(v0,v1,(v1-v0),self.__cmap.name)) self.__cmap.seek(0,2) self.__cmap.write('B 255 255 255\n') self.__cmap.flush()
def setcolourmap(self,vmin=None,vmax=None): """Set colourmap for residual plot. vmin: minimum value vmax: maximum value""" if vmin==None: v0 = 1 else: v0 = vmin if vmax==None: v1 = max(Numeric.ravel((self.__rsldata.data))) else: v1 = vmax self.__cmap = '.__auto.cpt' PyGMT.command('makecpt','-Ccool -T%f/%f/%f -Z > %s'%(v0,v1,(v1-v0),self.__cmap)) cpt = open(self.__cmap,'a') cpt.write('B 255 255 255\n') cpt.close()
plot=None numx = int((opts.papersize[0])/(sizex)) numy = int((opts.papersize[1])/(sizey)) numpages = int(float(numplots-0.1)/float(numx*numy)) p=-1 if opts.options.velocity: bvel = infile.getvar('bvel') colourmap = PyCF.CFcolourmap(bvel).cptfile ctitle = "average velocity [m/a]" else: # create a colour map v0 = 0.1 v1 = 1. cmapfile = tempfile.NamedTemporaryFile(suffix='.cpt') PyGMT.command('makecpt','-Cjet -T%f/%f/%f > %s'%(v0,v1,(v1-v0)/10.,cmapfile.name)) cmapfile.seek(0,2) cmapfile.write('B 255 255 255\n') cmapfile.flush() colourmap = cmapfile.name 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:
proj4 = PyCF.getCFProj(proj) proj4.setOrigin(origin[0],origin[1]) proj.false_easting = proj4.params['x_0'] proj.false_northing = proj4.params['y_0'] if upper != None: u = proj4.proj4(upper) num = [int(u[0]/delta[0])+1,int(u[1]/delta[1])+1] # projecting topography proj_gmt='-J%s/1:1 -R%s -A -D%f/%f'%( proj4.getGMTprojection(), proj4.getGMTregion([0.,0.],[delta[0]*num[0],delta[1]*num[1]]), delta[0],delta[1]) projfile = tempfile.NamedTemporaryFile(suffix='.bin') PyGMT.command('grdproject','%s -G%s=1 %s'%(inname,projfile.name,proj_gmt)) projtopo = PyGMT.read_grid(projfile.file) projfile.close() (numx,numy) = projtopo.data.shape # creating output netCDF file cffile = PyCF.CFcreatefile(outname) # global attributes if title is not None: cffile.title = title if institution is not None: cffile.institution = institution if source is not None: cffile.source = source
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]])
def __get_cptfile(self): if self.__cptf != None: v0 = PyGMT.round_down(min(Numeric.ravel(self.var.var))) v1 = PyGMT.round_up(max(Numeric.ravel(self.var.var))) PyGMT.command('makecpt','-Crainbow -T%f/%f/%f > %s'%(v0,v1,(v1-v0)/10.,self.__cptfile)) return self.__cptfile
sys.exit(1) proj4 = PyCF.getCFProj(proj) proj4.setOrigin(origin[0],origin[1]) proj.false_easting = proj4.params['x_0'] proj.false_northing = proj4.params['y_0'] if upper != None: u = proj4.proj4(upper) num = [int(u[0]/delta[0])+1,int(u[1]/delta[1])+1] # projecting topography proj_gmt='-J%s/1:1 -R%s -A -D%f/%f'%( proj4.getGMTprojection(), proj4.getGMTregion([0.,0.],[delta[0]*num[0],delta[1]*num[1]]), delta[0],delta[1]) PyGMT.command('grdproject','%s -G.__temp=1 %s'%(inname,proj_gmt)) projfile = open('.__temp') projtopo = PyGMT.read_grid(projfile) projfile.close() os.remove('.__temp') (numx,numy) = projtopo.data.shape # creating output netCDF file cffile = PyCF.CFcreatefile(outname) # global attributes if title is not None: cffile.title = title if institution is not None: cffile.institution = institution
def __get_cptfile(self): if self.__cptfile == '.__auto.cpt': v0 = min(Numeric.ravel(self.var.var)) v1 = max(Numeric.ravel(self.var.var)) PyGMT.command('makecpt','-Crainbow -T%f/%f/%f > .__auto.cpt'%(v0,v1,(v1-v0)/10.)) return self.__cptfile
# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # PyGMT is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with PyGMT; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import PyGMT,string print dir(PyGMT) l= PyGMT.command('gmtdefaults','-L') for i in string.split(l,'\n'): print i l = PyGMT.command('mapproject','-R7.000000/49.000000/60.182301/71.915405r -JB33.500000/60.500000/52.833332/68.166664/10',20*'20 50\n') print len(l) print l[0:40] defaults = PyGMT.Defaults() print defaults.GetCurrentKeys() defaults['X_ORIGIN'] = '0.c' print defaults del defaults['X_ORIGIN'] defaults['X_ORIGIN'] = '0.c' defaults['Y_ORIGIN'] = '0.c'
plot=None numx = int((opts.papersize[0])/(sizex)) numy = int((opts.papersize[1])/(sizey)) numpages = int(float(numplots-0.1)/float(numx*numy)) p=-1 if opts.options.velocity: bvel = infile.getvar('bvel') colourmap = PyCF.CFcolourmap(bvel).cptfile ctitle = "average velocity [m/a]" else: # create a colour map v0 = 0.1 v1 = 1. PyGMT.command('makecpt','-Cjet -T%f/%f/%f > .__auto.cpt'%(v0,v1,(v1-v0)/10.)) cpt = open('.__auto.cpt','a') cpt.write('B 255 255 255\n') cpt.close() colourmap = '.__auto.cpt' 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: