Changeset 933 for trunk/UTIL
- Timestamp:
- Apr 19, 2013, 4:19:20 PM (12 years ago)
- Location:
- trunk/UTIL/PYTHON/planetoplot_v2
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot_v2/examples/anomaly.py
r923 r933 19 19 anomaly.filename = "anomaly" 20 20 anomaly.defineplot() 21 anomaly.p[0].title = "surface temperature anomaly in %" 21 anomaly.p[0].title = "surface temperature anomaly" 22 anomaly.p[0].units = '%' 22 23 anomaly.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/function.py
r923 r933 25 25 S.p[0].ylabel = "Surface geopotential height (km)" 26 26 S.p[0].ycoeff = 1./1000. 27 S.p[0].fmt = '%.0f' 27 28 S.filename = "function" 28 29 S.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/les_psfc.py
r923 r933 14 14 les.y = None 15 15 les.t = ["10"] 16 les.stridex = 317 les.stridey = 316 #les.stridex = 3 17 #les.stridey = 3 18 18 les.filename = "les_psfc" 19 19 les.getplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/simple.py
r923 r933 19 19 # we define the plot, then set a few personal stuff 20 20 u.defineplot() 21 u.p[0].title = "This is what we name $u$ (m s$^{-1}$)"21 u.p[0].title = "This is what we name $u$" 22 22 u.p[0].proj = "robin" 23 23 u.filename = "simple" -
trunk/UTIL/PYTHON/planetoplot_v2/examples/windspeed.py
r923 r933 9 9 u.getdefineplot(extraplot=2) # prepare 2 extraplots (do not show) 10 10 u.p[0].proj = "ortho" 11 u.p[0].title = "$u$ (m s$^{-1}$)"11 u.p[0].title = "$u$" 12 12 u.makeplot() 13 13 … … 19 19 v.defineplot() 20 20 v.p[1].proj = "ortho" 21 v.p[1].title = "$v$ (m s$^{-1}$)"21 v.p[1].title = "$v$" 22 22 v.makeplot() # plot within the previous one (do not show) 23 23 … … 27 27 wind.filename = "windspeed" 28 28 wind.defineplot() 29 wind.p[2].title = "$\sqrt{u^2+v^2}$ (m s$^{-1}$)"29 wind.p[2].title = "$\sqrt{u^2+v^2}$" 30 30 wind.p[2].proj = "ortho" 31 31 wind.makeplot() # plot within the previous one (show because complete) -
trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py
r923 r933 10 10 parser = OptionParser() 11 11 parser.add_option('-O','--out',action='store',dest='out',type="string",default="gui",help='Specify a new output format') 12 parser.add_option('-T','--title',action='store',dest='title',type="string",default=None,help='Give a new title') 12 13 parser.add_option('-K','--marker',action='store',dest='marker',type="string",default=None,help="[1D] Define a new marker") 13 14 parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='[2D] Define a new map projection') … … 28 29 for plot in yeah.p: 29 30 plot.marker = opt.marker 31 if opt.title is not None: 32 for plot in yeah.p: 33 plot.title = opt.title 30 34 yeah.makeplot() 31 35 -
trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
r932 r933 1365 1365 # waiting for more fundamental modifications. case when self.index_y is a bool array. 1366 1366 # ... be careful if no point... 1367 if type(self.index_x[0]) == np.bool_: nx = np.sum(self.index_x) ## gives the size of the True part! 1368 if type(self.index_y[0]) == np.bool_: ny = np.sum(self.index_y) ## gives the size of the True part! 1367 try: 1368 if type(self.index_x[0]) == np.bool_: nx = np.sum(self.index_x) ## gives the size of the True part! 1369 if type(self.index_y[0]) == np.bool_: ny = np.sum(self.index_y) ## gives the size of the True part! 1370 except: 1371 pass 1369 1372 # NB: ... always 4D array but possibly with "size 1" dimensions 1370 1373 # ... if one dimension is missing because 1D 2D or 3D requests, make it appear again -
trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py
r932 r933 12 12 from matplotlib.cm import get_cmap 13 13 from mpl_toolkits.basemap import Basemap 14 from matplotlib.ticker import FormatStrFormatter 14 15 # personal librairies 15 16 import ppcompute … … 79 80 # ------------------------------- 80 81 zefile = "set_var.txt" 81 vf = {} ; vc = {} ; vl = {} 82 vf = {} ; vc = {} ; vl = {} ; vu = {} 82 83 try: 83 84 f = open(whereset+zefile, 'r') … … 85 86 if "#" in line: pass 86 87 else: 87 var, format, colorb, label = line.strip().split(';')88 var, format, colorb, label, units = line.strip().split(';') 88 89 ind = var.strip() 89 90 vf[ind] = format.strip() 90 91 vc[ind] = colorb.strip() 91 92 vl[ind] = label.strip() 93 vu[ind] = units.strip() 92 94 f.close() 93 95 except IOError: … … 213 215 if vmax is None: zevmax = damean + dev 214 216 # special case: negative values with stddev while field is positive 215 if zevmin < 0. and ppcompute.min(fieldcalc) > 0.: zevmin = 0.217 if zevmin < 0. and ppcompute.min(fieldcalc) >= 0.: zevmin = 0. 216 218 # check that bounds are not too tight given the field 217 219 amin = ppcompute.min(field) … … 239 241 # ------------------------------- 240 242 def save(mode="gui",filename="plot",folder="./",includedate=True,res=150,custom=False): 241 # a few settings 242 possiblesave = ['eps','ps','svg','png','jpg','pdf'] 243 # now the main instructions 244 if mode == "gui": 245 mpl.show() 246 elif mode in possiblesave: 247 ## name of plot 248 name = folder+'/'+filename 249 if includedate: 250 for ttt in timelib.gmtime(): 251 name = name + "_" + str(ttt) 252 name = name +"."+mode 253 ## save file 254 print "**** Saving file in "+mode+" format... Please wait." 255 if not custom: 256 # ... regular plots 257 mpl.savefig(name,dpi=res,pad_inches=pad_inches_value,bbox_inches='tight') 258 else: 259 # ... mapping mode, adapted space for labels etc... 260 mpl.savefig(name,dpi=res) 261 else: 262 print "!! ERROR !! File format not supported. Supported: ",possiblesave 243 if mode != "nothing": 244 # a few settings 245 possiblesave = ['eps','ps','svg','png','jpg','pdf'] 246 # now the main instructions 247 if mode == "gui": 248 mpl.show() 249 elif mode in possiblesave: 250 ## name of plot 251 name = folder+'/'+filename 252 if includedate: 253 for ttt in timelib.gmtime(): 254 name = name + "_" + str(ttt) 255 name = name +"."+mode 256 ## save file 257 print "**** Saving file in "+mode+" format... Please wait." 258 if not custom: 259 # ... regular plots 260 mpl.savefig(name,dpi=res,pad_inches=pad_inches_value,bbox_inches='tight') 261 else: 262 # ... mapping mode, adapted space for labels etc... 263 mpl.savefig(name,dpi=res) 264 else: 265 print "!! ERROR !! File format not supported. Supported: ",possiblesave 263 266 264 267 ################################## … … 292 295 xcoeff=1.,\ 293 296 ycoeff=1.,\ 297 fmt=None,\ 298 units="",\ 294 299 title=""): 295 300 ## what could be defined by the user … … 308 313 self.xcoeff = xcoeff 309 314 self.ycoeff = ycoeff 315 self.fmt = fmt 316 self.units = units 310 317 ## other useful arguments 311 318 ## ... not used here in ppplot but need to be attached to plot object … … 325 332 if self.var.upper() in vl.keys(): 326 333 self.title = vl[self.var.upper()] 334 self.units = vu[self.var.upper()] 327 335 328 336 # make … … 383 391 self.ylabel = vl[self.var.upper()] 384 392 self.title = "" 393 self.fmt = vf[self.var.upper()] 385 394 386 395 # make … … 389 398 # get what is done in the parent class 390 399 plot.make(self) 400 if self.fmt is None: self.fmt = '%.0f' 391 401 # add specific stuff 392 402 mpl.grid(color='grey') … … 417 427 if self.label != "": 418 428 mpl.legend(loc="best",fancybox=True) 419 ## TBD: set with .div the number of ticks 429 # AXES 430 ax = mpl.gca() 431 # format labels 432 if self.swap: ax.get_xaxis().set_major_formatter(FormatStrFormatter(self.fmt)) 433 else: ax.get_yaxis().set_major_formatter(FormatStrFormatter(self.fmt)) 434 # plot limits: ensure that no curve would be outside the window 435 # x-axis 436 x1, x2 = ax.get_xbound() 437 xmin = ppcompute.min(x) 438 xmax = ppcompute.max(x) 439 if xmin < x1: x1 = xmin 440 if xmax > x2: x2 = xmax 441 ax.set_xbound(lower=x1,upper=x2) 442 # y-axis 443 y1, y2 = ax.get_ybound() 444 ymin = ppcompute.min(y) 445 ymax = ppcompute.max(y) 446 if ymin < y1: y1 = ymin 447 if ymax > y2: y2 = ymax 448 ax.set_ybound(lower=y1,upper=y2) 449 ## set with .div the number of ticks. less good than automatic. 420 450 #ticks = self.div + 1 421 #ax = mpl.gca() 422 #ax.get_xaxis().set_ticks(np.linspace(ppcompute.min(x),ppcompute.max(x),ticks/2+1)) 423 # control plot limits (TBD: be able to control those) 424 ax = mpl.gca() ; ax.set_xbound(lower=ppcompute.min(x), upper=ppcompute.max(x)) 425 451 #ax.get_xaxis().set_ticks(np.linspace(x1,x2,ticks/2+1)) 426 452 427 453 ################################ … … 451 477 addvecy=None,\ 452 478 addcontour=None,\ 453 fmt="%.2e",\454 479 blon=None,\ 455 480 blat=None,\ … … 471 496 self.colorvec = colorvec 472 497 self.addcontour = addcontour 473 self.fmt = fmt474 498 self.blon = blon ; self.blat = blat 475 499 self.area = area … … 493 517 # get what is done in the parent class... 494 518 plot.make(self) 519 if self.fmt is None: self.fmt = "%.2e" 495 520 # ... then add specific stuff 496 521 ############################################################################################ … … 624 649 if self.back in back.keys(): 625 650 print "**** info: loading a background, please wait.",self.back 626 if back not in ["coast","sea"]: m.warpimage(back[self.back],scale=0.75)627 elif back == "coast": m.drawcoastlines()628 elif back == "sea": m.drawlsmask(land_color='white',ocean_color='aqua')651 if self.back not in ["coast","sea"]: m.warpimage(back[self.back],scale=0.75) 652 elif self.back == "coast": m.drawcoastlines() 653 elif self.back == "sea": m.drawlsmask(land_color='white',ocean_color='aqua') 629 654 else: 630 655 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit() … … 641 666 if self.trans > 0.: 642 667 ## draw colorbar. settings are different with projections. or if not mapmode. 643 if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 644 elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03 645 elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03 646 else: orientation = zeorientation ; frac = zefrac ; pad = 0.03 668 if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 ; lu = 0.5 669 elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03 ; lu = 1.0 670 elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03 ; lu = 0.5 671 else: orientation = zeorientation ; frac = zefrac ; pad = 0.03 ; lu = 0.5 647 672 zelevpal = np.linspace(zevmin,zevmax,num=min([ticks/2+1,21])) 648 673 zecb = mpl.colorbar(fraction=frac,pad=pad,\ 649 674 format=self.fmt,orientation=orientation,\ 650 675 ticks=zelevpal,\ 651 extend='neither',spacing='proportional') 676 extend='neither',spacing='proportional') 652 677 if zeorientation == "horizontal": zecb.ax.set_xlabel(self.title) ; self.title = "" 678 # colorbar title --> units 679 if self.units not in ["dimless",""]: 680 zecb.ax.set_title("["+self.units+"]",fontsize=3.*mpl.rcParams['font.size']/4.,x=lu,y=1.025) 681 653 682 ############################################################################################ 654 683 ### VECTORS. must be after the colorbar. we could also leave possibility for streamlines. … … 668 697 scale=zescale*reducevec,width=widthvec ) 669 698 # make vector key. 670 keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar 699 #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar 700 keyh = 0.98 ; keyv = 1.06 671 701 #keyh = -0.03 ; keyv = 1.08 # upper left corner 672 702 p = mpl.quiverkey(q,keyh,keyv,\ -
trunk/UTIL/PYTHON/planetoplot_v2/set_back.txt
r910 r933 26 26 venus ; http://laps.noaa.gov/albers/sos/venus/venus4/venus4_rgb_cyl_www.jpg 27 27 cosmic ; http://laps.noaa.gov/albers/sos/universe/wmap/wmap_rgb_cyl_www.jpg 28 coast ; dummy 29 sea ; dummy -
trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt
r920 r933 3 3 ## var ; format ; colormap ; label 4 4 ################################## 5 T ; %.0f ; gist_heat ; Temperature (K)6 TEMP ; %0.f ; gist_heat ; Temperature (K)7 TPOT ; %.0f ; Paired ; Potential temperature (K)8 TSURF ; %.0f ; RdBu_r ; Surface temperature (K)9 TK ; %.0f ; gist_heat ; Temperature (K)10 U ; %.1f ; jet ; Zonal wind (m s$^{-1}$)11 UM ; %.1f ; jet ; Zonal wind (m s$^{-1}$)12 V ; %.1f ; jet ; Meridional wind (m s$^{-1}$)13 VM ; %.1f ; jet ; Meridional wind (m s$^{-1}$)14 W ; %.2f ; jet ; Vertical wind (m s$^{-1}$)15 WIND ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)16 UV ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)17 UVMET ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)18 PTOT ; %.0f ; jet ; Pressure (Pa)19 PSFC ; %.1f ; RdYlBu_r ; Surface pressure (Pa)20 PS ; %.1f ; RdYlBu_r ; Surface pressure (Pa)21 ANOMALY ; %.1f ; gist_ncar ; Anomaly (%)22 HGT ; %.1e ; spectral ; Topography (m)23 HGT_M ; %.1e ; spectral ; Topography (m)24 MARS_TI ; %.0f ; jet ; Thermal inertia (tiu)25 THERMAL_INERTIA ; %.0f ; jet ; Thermal inertia (tiu)26 TAU ; %.1f ; YlOrBr_r ; Opacity 27 TAU_DUST ; %.1f ; Oranges_r ; Dust opacity 28 QDUST ; %.6f ; Oranges_r ; Dust mass mixing ratio (kg/kg)29 CCNQ ; %.2e ; YlOrBr ; Cloud condensation nuclei (kg/kg)30 CCNN ; %.2e ; YlOrBr ; Cloud condensation nuclei density 31 QH2O ; %.2e ; PuBu ; Water vapor mixing ratio (kg/kg)32 MTOT ; %.1e ; spectral ; Column vapor (pr. $\mu$m)33 ICETOT ; %.1e ; YlGnBu_r ; Column ice (pr. $\mu$m)34 TAU_ICE ; %.2f ; Blues ; Ice cloud opacity 35 TAUICE ; %.2f ; Blues ; Ice cloud opacity 36 VMR_ICE ; %.1e ; Blues ; Ice volume mix. rat. 37 VMR_H2OICE ; %.0f ; PuBu ; Ice volume mix. rat. 38 VMR_H2OVAP ; %.0f ; PuBu ; Vapor volume mix. rat. 39 QSURFICE ; %.0f ; hot_r ; Surface ice 40 WATERCAPTAG ; %.0f ; Blues ; Cap grid point 41 TAUTES ; %.2f ; jet ; Opacity 42 TAUTESAP ; %.2f ; jet ; Opacity 43 USTM ; %.2f ; jet ; Friction velocity (m s$^{-1}$)44 HFX ; %.0f ; RdYlBu ; Sensible heat flux (W m$^{-2}$)45 WSTAR ; %.1f ; YlOrRd ; Turbulent convective velocity scale (m s$^{-1}$)46 CO2 ; %.2f ; YlOrBr_r ; CO$_2$ mixing ratio 47 ENFACT ; %.1.f ; jet ; Enrichment factor 48 T_NADIR_DAY ; %.0f ; RdBu_r ; Temperature (K)49 T_NADIR_NIT ; %.0f ; RdBu_r ; Temperature (K)50 TEMP_DAY ; %.0f ; gist_heat ; Temperature (K)51 TEMP_NIGHT ; %.0f ; gist_heat ; Temperature (K)52 DTEMP ; %.0f ; gist_heat ; Temperature (K)53 NTEMP ; %.0f ; gist_heat ; Temperature (K)54 DNUMBINTEMP ; %.0f ; gist_heat ; Temperature (K)55 NNUMBINTEMP ; %.0f ; gist_heat ; Temperature (K)56 OLR ; %.0f ; gist_heat ; Outgoing Longwave Radiation (W m$^{-2}$)57 ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation (W m$^{-2}$)58 ISR ; %.0f ; gist_heat ; Incoming Solar Radiation (W m$^{-2}$)59 SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ (W m$^{-2}$)5 T ; %.0f ; gist_heat ; Temperature ; K 6 TEMP ; %0.f ; gist_heat ; Temperature ; K 7 TPOT ; %.0f ; Paired ; Potential temperature ; K 8 TSURF ; %.0f ; RdBu_r ; Surface temperature ; K 9 TK ; %.0f ; gist_heat ; Temperature ; K 10 U ; %.1f ; jet ; Zonal wind ; m s$^{-1}$ 11 UM ; %.1f ; jet ; Zonal wind ; m s$^{-1}$ 12 V ; %.1f ; jet ; Meridional wind ; m s$^{-1}$ 13 VM ; %.1f ; jet ; Meridional wind ; m s$^{-1}$ 14 W ; %.2f ; jet ; Vertical wind ; m s$^{-1}$ 15 WIND ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$ 16 UV ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$ 17 UVMET ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$ 18 PTOT ; %.0f ; jet ; Pressure ; Pa 19 PSFC ; %.1f ; RdYlBu_r ; Surface pressure ; Pa 20 PS ; %.1f ; RdYlBu_r ; Surface pressure ; Pa 21 ANOMALY ; %.1f ; gist_ncar ; Anomaly ; % 22 HGT ; %.1e ; spectral ; Topography ; m 23 HGT_M ; %.1e ; spectral ; Topography ; m 24 MARS_TI ; %.0f ; jet ; Thermal inertia ; tiu 25 THERMAL_INERTIA ; %.0f ; jet ; Thermal inertia ; tiu 26 TAU ; %.1f ; YlOrBr_r ; Opacity ; dimless 27 TAU_DUST ; %.1f ; Oranges_r ; Dust opacity ; dimless 28 QDUST ; %.6f ; Oranges_r ; Dust mass mixing ratio ; kg/kg 29 CCNQ ; %.2e ; YlOrBr ; Cloud condensation nuclei ; kg/kg 30 CCNN ; %.2e ; YlOrBr ; Cloud condensation nuclei density ; dimless 31 QH2O ; %.2e ; PuBu ; Water vapor mixing ratio ; kg/kg 32 MTOT ; %.1e ; spectral ; Column vapor ; pr. $\mu$m 33 ICETOT ; %.1e ; YlGnBu_r ; Column ice ; pr. $\mu$m 34 TAU_ICE ; %.2f ; Blues ; Ice cloud opacity ; dimless 35 TAUICE ; %.2f ; Blues ; Ice cloud opacity ; dimless 36 VMR_ICE ; %.1e ; Blues ; Ice volume mix. rat. ; dimless 37 VMR_H2OICE ; %.0f ; PuBu ; Ice volume mix. rat. ; dimless 38 VMR_H2OVAP ; %.0f ; PuBu ; Vapor volume mix. rat. ; dimless 39 QSURFICE ; %.0f ; hot_r ; Surface ice ; dimless 40 WATERCAPTAG ; %.0f ; Blues ; Cap grid point ; dimless 41 TAUTES ; %.2f ; jet ; Opacity ; dimless 42 TAUTESAP ; %.2f ; jet ; Opacity ; dimless 43 USTM ; %.2f ; jet ; Friction velocity ; m s$^{-1}$ 44 HFX ; %.0f ; RdYlBu ; Sensible heat flux ; W m$^{-2}$ 45 WSTAR ; %.1f ; YlOrRd ; Turbulent convective velocity scale ; m s$^{-1}$ 46 CO2 ; %.2f ; YlOrBr_r ; CO$_2$ mixing ratio ; dimless 47 ENFACT ; %.1.f ; jet ; Enrichment factor ; dimless 48 T_NADIR_DAY ; %.0f ; RdBu_r ; Temperature ; K 49 T_NADIR_NIT ; %.0f ; RdBu_r ; Temperature ; K 50 TEMP_DAY ; %.0f ; gist_heat ; Temperature ; K 51 TEMP_NIGHT ; %.0f ; gist_heat ; Temperature ; K 52 DTEMP ; %.0f ; gist_heat ; Temperature ; K 53 NTEMP ; %.0f ; gist_heat ; Temperature ; K 54 DNUMBINTEMP ; %.0f ; gist_heat ; Temperature ; K 55 NNUMBINTEMP ; %.0f ; gist_heat ; Temperature ; K 56 OLR ; %.0f ; gist_heat ; Outgoing Longwave Radiation ; W m$^{-2}$ 57 ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation ; W m$^{-2}$ 58 ISR ; %.0f ; gist_heat ; Incoming Solar Radiation ; W m$^{-2}$ 59 SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ ; W m$^{-2}$
Note: See TracChangeset
for help on using the changeset viewer.