Changeset 1279 for trunk/UTIL
- Timestamp:
- Jun 2, 2014, 11:03:13 PM (10 years ago)
- Location:
- trunk/UTIL/PYTHON/planetoplot_v2
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot_v2/pp.py
r1084 r1279 51 51 parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help="multiplicative factor on field") 52 52 parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help="additive factor on field") 53 parser.add_option('-o','--output',action='store',dest='filename',type="string",default= "myplot",help="name of output files")53 parser.add_option('-o','--output',action='store',dest='filename',type="string",default=None,help="name of output files") 54 54 parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files") 55 55 parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,\ … … 68 68 parser.add_option('-H','--trans',action='store',dest='trans',type="float",default=1.0,help="float for transparency (0=transp,1=opaque)") 69 69 parser.add_option('-Z','--logy',action='store_true',dest='logy',default=False,help="set log for vertical axis") 70 parser.add_option('-O','--save',action='store',dest='out',type="string",default= "gui",help="save mode: 'gui' 'png' 'pdf' 'eps' 'svg' 'ps'")70 parser.add_option('-O','--save',action='store',dest='out',type="string",default=None,help="save mode: 'gui' 'png' 'pdf' 'eps' 'svg' 'ps'") 71 71 parser.add_option('-V','--void',action='store_true',dest='void',default=False,help="no colorbar, no title, no labels") 72 72 parser.add_option('-U','--units',action='append',dest='units',type="string",default=None,help="units for the field") … … 89 89 # -- 2D plot 90 90 parser.add_option('-C','--colorbar',action='append',dest='colorbar',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png") 91 parser.add_option('-P','--proj',action=' append',dest='proj',type="string",default=None,help="[2D] map projection: 'cyl' 'npstere' 'spstere' 'ortho' 'moll' 'robin' 'lcc' 'laea' 'merc' 'noproj'")91 parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help="[2D] map projection: 'cyl' 'npstere' 'spstere' 'ortho' 'moll' 'robin' 'lcc' 'laea' 'merc'") 92 92 parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='[2D] predefined map background (cf. set_back.txt)') 93 93 parser.add_option('-A','--area',action='append',dest='area',type="string",default=None,help='[2D] predefined region of mapping (cf. set_area.txt)') … … 154 154 user.folder = opt.folder 155 155 user.out = opt.out 156 # if noproj is given for proj, no map mode 157 if opt.proj is not None: 158 if 'noproj' in opt.proj: 159 user.noproj = True 160 # if user wants to give a name, we drop the indication of date 161 if opt.filename != "myplot": 162 user.includedate = False 156 user.proj = opt.proj 163 157 # define plot 164 158 user.defineplot() … … 174 168 command = "" 175 169 for arg in sys.argv: command = command + arg + ' ' 176 try: 170 if opt.filename is not None: 171 try: 177 172 f = open(opt.folder+'/'+opt.filename+'.sh', 'w') 178 173 f.write(command) 179 except IOError:174 except IOError: 180 175 print "!! WARNING !! pp.py command not saved. Probably do not have permission to write here." -
trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
r1219 r1279 168 168 verbose=False,\ 169 169 quiet=False,\ 170 noproj=False,\171 170 superpose=False,\ 172 171 plotin=None,\ 173 172 forcedimplot=-1,\ 174 out= "gui",\175 filename= "myplot",\173 out=None,\ 174 filename=None,\ 176 175 folder="./",\ 177 includedate= True,\176 includedate=False,\ 178 177 res=150.,\ 179 178 xlabel=None,ylabel=None,\ … … 233 232 self.verbose = verbose 234 233 self.quiet = quiet 235 self.noproj = noproj236 234 self.plotin = plotin 237 235 self.superpose = superpose … … 272 270 def printstatus(self): 273 271 if not self.quiet: 274 if self.filename == "THIS_IS_A_CLONE": 275 pass 276 else: 277 print "**** PPCLASS. Done step: " + self.status 272 print "**** PPCLASS. Done step: " + self.status 278 273 279 274 # print attributes … … 303 298 self.kind3d = other.kind3d 304 299 self.verbose = other.verbose 305 self. noproj = other.noproj300 self.quiet = other.quiet 306 301 self.plotin = other.plotin 307 302 self.superpose = other.superpose … … 376 371 setattr(the_clone,k,v) 377 372 the_clone.verbose = False 378 the_clone. filename = "THIS_IS_A_CLONE"# trick to avoid additional outputs373 the_clone.quiet = True # trick to avoid additional outputs 379 374 the_clone.define() 380 375 for i in range(self.nfin): … … 390 385 setattr(obj,k,v) 391 386 the_clone.status = "retrieved" 392 the_clone. filename = self.filename387 the_clone.quiet = self.quiet 393 388 return the_clone 394 389 … … 886 881 # specific 2d plot stuff 887 882 if dp == 2: 883 plobj.proj = self.proj 884 plobj.svx = self.svx 885 plobj.svy = self.svy 888 886 # -- light grey background for missing values 889 887 if type(plobj.f).__name__ in 'MaskedArray': plobj.axisbg = '0.75' 890 888 # -- define if it is a map or a plot 891 889 plobj.mapmode = ( obj.method_x+obj.method_y == "freefree" \ 892 and "grid points" not in obj.name_x \ 893 and not self.noproj ) 890 and "grid points" not in obj.name_x ) 894 891 # possible user-defined plot settings shared by all plots 895 892 if self.div is not None: plobj.div = self.div … … 919 916 # -- 2D specific 920 917 elif dp == 2: 921 if self.proj is not None and not self.noproj: plobj.proj = self.proj922 918 if self.vmin is not None: plobj.vmin = self.vmin 923 919 if self.vmax is not None: plobj.vmax = self.vmax 924 920 if self.trans is not None: plobj.trans = self.trans 925 921 if self.back is not None: plobj.back = self.back 926 plobj.svx = self.svx927 plobj.svy = self.svy928 922 # finally append plot object 929 923 self.p.append(plobj) … … 1014 1008 self.customplot = self.p[0].f.ndim == 2 \ 1015 1009 and self.p[0].mapmode == True \ 1016 and self.p[0].proj not in ["ortho" ]1010 and self.p[0].proj not in ["ortho","robin"] 1017 1011 if self.customplot: 1018 1012 margin = 0.07 … … 1026 1020 self.howmanyplots = self.plotin.howmanyplots 1027 1021 self.customplot = self.plotin.customplot 1022 self.filename = self.plotin.filename 1028 1023 # LOOP on all subplots 1029 1024 # NB: cannot use 'for pl in self.p' if self.plotin not None … … 1087 1082 mpl.close() 1088 1083 # SAVE A PICKLE FILE WITH THE self.p ARRAY OF OBJECTS 1089 if self.verbose: print "**** Saving session in "+self.filename + ".ppobj" 1090 savfile = self.folder + "/" + self.filename + ".ppobj" 1091 try: 1092 filehandler = open(savfile, 'w') 1093 pickle.dump(self.p, filehandler) 1094 except IOError: 1095 if self.verbose: print "!! WARNING !! Saved object file not written. Probably do not have permission to write here." 1084 if self.filename is not None: 1085 if self.verbose: print "**** Saving session in "+self.filename + ".ppobj" 1086 savfile = self.folder + "/" + self.filename + ".ppobj" 1087 try: 1088 filehandler = open(savfile, 'w') 1089 pickle.dump(self.p, filehandler) 1090 except IOError: 1091 if self.verbose: print "!! WARNING !! Saved object file not written. Probably do not have permission to write here." 1096 1092 return self 1097 1093 … … 1235 1231 try: self.p[iii].legend = opt.legend[0] 1236 1232 except: pass 1237 ### 1238 try: self.p[iii].proj = opt.proj[iii] 1239 except: 1240 try: self.p[iii].proj = opt.proj[0] 1241 except: pass 1242 ### 1233 #### 1243 1234 try: self.p[iii].back = opt.back[iii] 1244 1235 except: -
trunk/UTIL/PYTHON/planetoplot_v2/ppcompute.py
r1219 r1279 123 123 mm = mean(field,axis=axis) 124 124 # include back the reduced dim 125 if field.ndim == 4: mm = np.tile(mm,(field.shape[axis],1,1,1)) 126 elif field.ndim == 3: mm = np.tile(mm,(field.shape[axis],1,1)) 127 elif field.ndim == 2: mm = np.tile(mm,(field.shape[axis],1)) 128 # array has right shape but not in good order: fix this. 129 mm = np.reshape(mm,field.shape) 125 if field.ndim == 4: 126 if axis == 0: mm = mm[np.newaxis,:,:,:] 127 elif axis == 1: mm = mm[:,np.newaxis,:,:] 128 elif axis == 2: mm = mm[:,:,np.newaxis,:] 129 elif axis == 3: mm = mm[:,:,:,np.newaxis] 130 else: 131 print "not supported. yet!" 132 exit() 133 # repeat the calculated mean on this dimension 134 mm = np.repeat(mm,field.shape[axis],axis=axis) 130 135 # compute perturbations 131 136 field = field - mm … … 314 319 return time 315 320 321 ######################### 322 #### FLOW DIAGNOSTIC #### 323 ######################### 324 325 def divort(u,v,lon,lat,rad): 326 #################### 327 # compute divergence and vorticity 328 # div,vorti = divort(u,v,lon,lat,rad) 329 #################### 330 # u: zonal wind 331 # v: meridional wind 332 # lon: longitude 333 # lat: latitude 334 # rad: radius of the planet 335 #################### 336 337 # compute gradients -- with normalized coordinates 338 du_y,du_x = np.gradient(u) 339 dv_y,dv_x = np.gradient(v) 340 341 # convert to radian 342 la = lon*np.pi/180. 343 ph = lat*np.pi/180. 344 345 # ensure 2D arrays for lon,lat 346 if lon.ndim == 1 and lat.ndim == 1: 347 [lar,phr] = np.meshgrid(la,ph) 348 elif lon.ndim == 2 and lat.ndim == 2: 349 lar,phr = la,ph 350 else: 351 print "ppcompute. there is a problem with lat/lon rank. stop." 352 exit() 353 354 # compute normalized gradients for lat/lon grid 355 dump,dla_x = np.gradient(lar) 356 dph_y,dump = np.gradient(phr) 357 358 # compute cartesian differential coordinates 359 dx = dla_x*rad*np.cos(phr) 360 dy = dph_y*rad 361 362 # eventually compute cartesian derivatives 363 du_dx = du_x / dx 364 du_dy = du_y / dy 365 dv_dx = dv_x / dx 366 dv_dy = dv_y / dy 367 368 # vorticity 369 vorti = dv_dx - du_dy 370 div = du_dx + dv_dy 371 372 return div,vorti 373 374 -
trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py
r1211 r1279 299 299 return 300 300 301 # a necessary addition for people used to matplotlib 302 def show(): 303 mpl.show() 304 301 305 # a generic function to show (GUI) or save a plot (PNG,EPS,PDF,...) 302 306 # ------------------------------- 303 def save(mode="gui",filename="plot",folder="./",includedate=True,res=150,custom=False): 304 if mode != "nothing": 307 def save(mode=None,filename=None,folder="./",includedate=False,res=150,custom=False): 308 # no filename or no mode set --> graphical user interface 309 if filename is None or mode is None: 310 show() 311 # otherwise --> an image is saved 312 else: 305 313 # a few settings 306 314 possiblesave = ['eps','ps','svg','png','jpg','pdf'] 307 315 # now the main instructions 308 if mode == "gui": 309 mpl.show() 310 elif mode in possiblesave: 316 if mode in possiblesave: 311 317 ## name of plot 312 318 name = folder+'/'+filename … … 327 333 print "!! ERROR !! File format not supported. Supported: ",possiblesave 328 334 329 # a necessary addition for people used to matplotlib 330 def show(): 331 mpl.show() 335 332 336 333 337 ################################## … … 554 558 ax.xaxis.set_major_locator(MaxNLocator(self.nxticks)) 555 559 else: 556 print "!! WARNING. in logx mode, ticks are set automatically." 560 # in logx mode, ticks are set automatically 561 pass 557 562 if not self.logy: 558 563 ax.yaxis.set_major_locator(MaxNLocator(self.nyticks)) 559 564 else: 560 print "!! WARNING. in logy mode, ticks are set automatically." 565 # in logy mode, ticks are set automatically 566 pass 561 567 ## specific modulo labels 562 568 if self.modx is not None: … … 568 574 self.make() 569 575 mpl.show() 576 # makesave = make + save 577 # ------------------------------- 578 def makesave(self,mode="png",filename="plot",includedate=False,res=150): 579 self.make() 580 save(mode=mode,filename=filename,includedate=includedate,res=res) 581 close() 582 570 583 571 584 ################################ … … 648 661 ### PRE-SETTINGS 649 662 ############################################################################################ 663 # if no projection is set, set mapmode to False 664 if self.proj is None: 665 self.mapmode = False 650 666 # set dummy xy axis if not defined 651 667 if self.x is None: … … 727 743 ax.xaxis.set_major_locator(MaxNLocator(self.nxticks)) 728 744 else: 729 print "!! WARNING. in logx mode, ticks are set automatically." 745 pass 746 #print "!! WARNING. in logx mode, ticks are set automatically." 730 747 if not self.logy: 731 748 ax.yaxis.set_major_locator(MaxNLocator(self.nyticks)) 732 749 else: 733 print "!! WARNING. in logy mode, ticks are set automatically." 750 pass 751 #print "!! WARNING. in logy mode, ticks are set automatically." 734 752 ## specific modulo labels 735 753 if self.modx is not None: … … 774 792 if self.proj == "cyl": 775 793 format = '%.0f' 794 partab = np.r_[-90.,-60.,-30.,0.,30.,60.,90.] 776 795 # ... global projections 777 796 elif self.proj in ["ortho","moll","robin"]: … … 782 801 if self.proj in ["robin"]: steplon = 90. 783 802 mertab = np.r_[-360.:360.:steplon] 784 partab = np.r_[-90.:90.+steplat:steplat] 803 #partab = np.r_[-90.:90.+steplat:steplat] 804 partab = np.r_[-90.,-30.,0.,30.,90.] 785 805 if self.proj == "ortho": 786 806 merlab = [0,0,0,0] ; parlab = [0,0,0,0] … … 847 867 # contour field. first line contour then shaded contour. 848 868 if self.c is not None: 869 #zelevelsc = np.arange(900.,1100.,5.) 849 870 objC2 = m.contour(x, y, what_I_contour, \ 850 871 zelevelsc, colors = ccol, linewidths = cline) 851 872 #mpl.clabel(objC2, inline=1, fontsize=10,manual=True,fmt='-%2.0f$^{\circ}$C',colors='r') 873 #mpl.clabel(objC2, inline=0, fontsize=8, fmt='%.0f',colors='r', inline_spacing=0) 852 874 m.contourf(x, y, what_I_plot, zelevels, cmap = palette, alpha = self.trans, antialiased=True) 853 875 ############################################################################################ … … 856 878 if self.trans > 0. and self.showcb: 857 879 ## draw colorbar. settings are different with projections. or if not mapmode. 858 if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 ; lu = 0.5 880 #if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 ; lu = 0.5 881 if not self.mapmode: orientation=zeorientation ; frac = 0.15 ; pad = 0.04 ; lu = 0.5 859 882 elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.08 ; pad = 0.03 ; lu = 1.0 883 elif self.proj in ['robin']: orientation="horizontal" ; frac = 0.07 ; pad = 0.1 ; lu = 1.0 860 884 elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03 ; lu = 0.5 861 885 else: orientation = zeorientation ; frac = zefrac ; pad = 0.03 ; lu = 0.5 … … 932 956 self.make() 933 957 mpl.show() 958 959 # makesave = make + save 960 # ------------------------------- 961 def makesave(self,mode="png",filename="plot",includedate=False,res=150): 962 self.make() 963 save(mode=mode,filename=filename,includedate=includedate,res=res) 964 close() 965
Note: See TracChangeset
for help on using the changeset viewer.