Changeset 241 for trunk/MESOSCALE_DEV/PLOT
- Timestamp:
- Jul 23, 2011, 1:38:02 AM (13 years ago)
- Location:
- trunk/MESOSCALE_DEV/PLOT/PYTHON
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE_DEV/PLOT/PYTHON/mylib/myplot.py
r240 r241 71 71 return output, error 72 72 73 def latinterv (area): 74 if area == "Europe": 75 wlat = [20.,80.] 76 wlon = [-50.,50.] 77 elif area == "Central_America": 78 wlat = [-10.,40.] 79 wlon = [230.,300.] 80 elif area == "Africa": 81 wlat = [-20.,50.] 82 wlon = [-50.,50.] 83 elif area == "Whole": 84 wlat = [-90.,90.] 85 wlon = [-180.,180.] 86 elif area == "Southern_Hemisphere": 87 wlat = [-90.,60.] 88 wlon = [-180.,180.] 89 elif area == "Northern_Hemisphere": 90 wlat = [-60.,90.] 91 wlon = [-180.,180.] 92 elif area == "Tharsis": 93 wlat = [-30.,60.] 94 wlon = [-170.,-10.] 95 elif area == "Whole_No_High": 96 wlat = [-60.,60.] 97 wlon = [-180.,180.] 98 elif area == "Chryse": 99 wlat = [-60.,60.] 100 wlon = [-60.,60.] 101 elif area == "North_Pole": 102 wlat = [50.,90.] 103 wlon = [-180.,180.] 104 elif area == "Close_North_Pole": 105 wlat = [75.,90.] 106 wlon = [-180.,180.] 107 elif area == "South_Pole": 108 wlat = [-90.,-50.] 109 wlon = [-180.,180.] 110 elif area == "Close_South_Pole": 111 wlat = [-90.,-75.] 112 wlon = [-180.,180.] 113 return wlon,wlat 73 #def latinterv (area): 74 # if area == "Europe": [wlat,wlon] = [[ 20., 80.],[- 50., 50.]] 75 # elif area == "Central_America": [wlat,wlon] = [[-10., 40.],[ 230., 300.]] 76 # elif area == "Africa": [wlat,wlon] = [[-20., 50.],[- 50., 50.]] 77 # elif area == "Whole": [wlat,wlon] = [[-90., 90.],[-180.,-180.]] 78 # elif area == "Southern_Hemisphere": [wlat,wlon] = [[-90., 60.],[-180.,-180.]] 79 # elif area == "Northern_Hemisphere": [wlat,wlon] = [[-60., 90.],[-180.,-180.]] 80 # elif area == "Tharsis": [wlat,wlon] = [[-30., 60.],[-170.,- 10.]] 81 # elif area == "Whole_No_High": [wlat,wlon] = [[-60., 60.],[-180., 180.]] 82 # elif area == "Chryse": [wlat,wlon] = [[-60., 60.],[- 60., 60.]] 83 # elif area == "North_Pole": [wlat,wlon] = [[ 50., 90.],[-180., 180.]] 84 # elif area == "Close_North_Pole": [wlat,wlon] = [[ 75., 90.],[-180., 180.]] 85 # elif area == "Far_South_Pole": [wlat,wlon] = [[-90.,-40.],[-180., 180.]] 86 # elif area == "South_Pole": [wlat,wlon] = [[-90.,-50.],[-180., 180.]] 87 # elif area == "Close_South_Pole": [wlat,wlon] = [[-90.,-75.],[-180., 180.]] 88 # return wlon,wlat 114 89 115 90 def definesubplot ( numplot, fig ): … … 142 117 elif numplot == 1: 143 118 sub = 99999 144 elif numplot < 0:119 elif numplot <= 0: 145 120 sub = 99999 146 121 else: … … 182 157 zeday = int(zetime[8]+zetime[9]) - int(zetimestart[8]+zetimestart[9]) 183 158 if zeday < 0: lschar="" ## might have crossed a month... fix soon 184 else: lschar="_Ls"+str( int( sol2ls ( getattr( nc, 'JULDAY' ) + zeday ) ))159 else: lschar="_Ls"+str( int( 10. * sol2ls ( getattr( nc, 'JULDAY' ) + zeday ) ) / 10. ) 185 160 ### 186 161 zetime2 = nc.variables['Times'][1] … … 472 447 return what_I_plot 473 448 449 def nolow(what_I_plot): 450 from mymath import max,min 451 lim = 0.15*0.5*(abs(max(what_I_plot))+abs(min(what_I_plot))) 452 print "on vire en dessous de ", lim 453 what_I_plot [ abs(what_I_plot) < lim ] = 1.e40 454 return what_I_plot 455 474 456 def zoomset (wlon,wlat,zoom): 475 457 dlon = abs(wlon[1]-wlon[0])/2. … … 492 474 "TAU_ICE": "%.2f",\ 493 475 "anomaly": "%.1f",\ 476 "W": "%.1f",\ 494 477 } 495 478 if whichvar not in fmtvar: … … 509 492 "ICETOT": "YlGnBu",\ 510 493 "TAU_ICE": "Blues",\ 494 "W": "jet",\ 511 495 "anomaly": "RdBu_r",\ 512 496 } 497 #W --> spectral ou jet 513 498 #spectral BrBG RdBu_r 499 print "predefined colorbars" 514 500 if whichone not in whichcolorb: 515 501 whichone = "def" … … 567 553 return whichlink 568 554 555 def latinterv (area="Whole"): 556 list = { \ 557 "Europe": [[ 20., 80.],[- 50., 50.]],\ 558 "Central_America": [[-10., 40.],[ 230., 300.]],\ 559 "Africa": [[-20., 50.],[- 50., 50.]],\ 560 "Whole": [[-90., 90.],[-180.,-180.]],\ 561 "Southern_Hemisphere": [[-90., 60.],[-180.,-180.]],\ 562 "Northern_Hemisphere": [[-60., 90.],[-180.,-180.]],\ 563 "Tharsis": [[-30., 60.],[-170.,- 10.]],\ 564 "Whole_No_High": [[-60., 60.],[-180., 180.]],\ 565 "Chryse": [[-60., 60.],[- 60., 60.]],\ 566 "North_Pole": [[ 50., 90.],[-180., 180.]],\ 567 "Close_North_Pole": [[ 75., 90.],[-180., 180.]],\ 568 "Far_South_Pole": [[-90.,-40.],[-180., 180.]],\ 569 "South_Pole": [[-90.,-50.],[-180., 180.]],\ 570 "Close_South_Pole": [[-90.,-75.],[-180., 180.]],\ 571 } 572 if area not in list: area = "Whole" 573 [olat,olon] = list[area] 574 return olon,olat 575 -
trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/domain.py
r225 r241 5 5 def domain (namefile,proj=None,back="vishires",target=None): 6 6 from netCDF4 import Dataset 7 from myplot import getcoord2d,define_proj,makeplotpng,simplinterv,getprefix,dumpbdy,getproj,latinterv,wrfinterv,simplinterv 8 from matplotlib.pyplot import contourf,rcParams 7 from myplot import getcoord2d,define_proj,makeplotres,simplinterv,getprefix,dumpbdy,getproj,latinterv,wrfinterv,simplinterv 8 from mymath import max,min 9 from matplotlib.pyplot import contourf,rcParams,pcolor 9 10 from numpy.core.defchararray import find 11 from numpy import arange 10 12 ### 11 13 nc = Dataset(namefile) … … 23 25 zeplot = getprefix(nc) + "domain" 24 26 ### 25 lon2d = dumpbdy(lon2d )26 lat2d = dumpbdy(lat2d )27 lon2d = dumpbdy(lon2d,5) 28 lat2d = dumpbdy(lat2d,5) 27 29 if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") 28 30 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) … … 32 34 x, y = m(lon2d, lat2d) 33 35 ### 34 what_I_plot = dumpbdy( nc.variables[var][0,:,:] ) 35 contourf(x, y, what_I_plot, 40) 36 what_I_plot = dumpbdy(nc.variables[var][0,:,:], 5) 37 #levinterv = 250. 38 #zelevels = arange(min(what_I_plot)-levinterv,max(what_I_plot)+levinterv,levinterv) 39 zelevels = 30 40 contourf(x, y, what_I_plot, zelevels) 41 #pcolor(x,y,what_I_plot) ## on voit trop les lignes ! 36 42 ### 37 43 if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot 38 44 else: zeplot = target + "/" + zeplot 39 45 ### 40 makeplotpng(zeplot,pad_inches_value=0.35) 46 pad_inches_value = 0.35 47 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature 48 makeplotres(zeplot,res=200.,pad_inches_value=pad_inches_value,disp=False) 49 #makeplotpng(zeplot,pad_inches_value=0.35) 41 50 #rcParams['savefig.facecolor'] = 'black' 42 51 #makeplotpng(zeplot+"b",pad_inches_value=0.35) -
trunk/MESOSCALE_DEV/PLOT/PYTHON/scripts/winds.py
r240 r241 16 16 numplot=2,\ 17 17 var=None,\ 18 colorb= True,\18 colorb="def",\ 19 19 winds=True,\ 20 20 addchar=None,\ … … 28 28 hole=False,\ 29 29 save="gui",\ 30 anomaly=False): 30 anomaly=False,\ 31 var2=None): 31 32 32 33 #################################################################################################################### … … 38 39 from myplot import getcoord2d,define_proj,makeplotres,simplinterv,vectorfield,ptitle,latinterv,getproj,wrfinterv,dumpbdy,\ 39 40 fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ 40 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth 41 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow 41 42 from mymath import deg,max,min,mean 42 43 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show … … 45 46 from numpy.core.defchararray import find 46 47 47 # rcParams['backend'] = 'PS'48 #if save == 'eps': rcParams['backend'] = 'PS' 48 49 49 50 ###################### … … 64 65 ### Define plot boundaries 65 66 if proj == "npstere": [wlon,wlat] = latinterv("North_Pole") 66 elif proj == "spstere": [wlon,wlat] = latinterv(" South_Pole")67 elif proj == "spstere": [wlon,wlat] = latinterv("Far_South_Pole") 67 68 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) 68 69 else: [wlon,wlat] = simplinterv(lon2d,lat2d) … … 77 78 print nc.variables 78 79 errormess("please set at least winds or var") 80 if anomaly: basename = 'd' + basename 79 81 basename = basename + getstralt(nc,nvert) ## can be moved elsewhere for a more generic routine 80 82 … … 90 92 nplot = 1 91 93 error = False 92 if itstep is None: itstep = int(24./numplot) 94 if itstep is None and numplot > 0: itstep = int(24./numplot) 95 else: itstep = 1 93 96 while error is False: 94 97 … … 109 112 ### If only one local time is requested (numplot < 0) 110 113 elif numplot <= 0: 111 if int(ltst) + numplot != 0: 114 if int(ltst) + numplot != 0: 112 115 itime += 1 113 116 if found_lct is True: break ## because it means LT was found at previous iteration … … 121 124 122 125 #### Contour plot 126 if var2: 127 what_I_contour, error = reducefield( getfield(nc,var2), d4=itime, d3=nvert ) 128 if not error: 129 if typefile in ['mesoapi','meso']: what_I_contour = dumpbdy(what_I_contour,6) 130 zevmin, zevmax = calculate_bounds(what_I_contour) 131 zelevels = np.linspace(zevmin,zevmax,num=20) 132 if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,2000.) 133 contour( x, y, what_I_contour, zelevels, colors='k', linewidths = 0.33 ) #colors='w' )# , alpha=0.5) 134 135 #### Shaded plot 123 136 if var: 124 137 what_I_plot, error = reducefield( getfield(nc,var), d4=itime, d3=nvert ) … … 132 145 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 133 146 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 134 if colorb i s True: colorb = defcolorb(fvar)135 palette = get_cmap(name=colorb)147 if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar)) 148 else: palette = get_cmap(name=colorb) 136 149 if not tile: 137 150 if not hole: what_I_plot = bounds(what_I_plot,zevmin,zevmax) 138 zelevels = np.linspace(zevmin,zevmax) 151 zelevels = np.linspace(zevmin,zevmax) #,num=20) 139 152 contourf( x, y, what_I_plot, zelevels, cmap = palette ) 140 else: 141 pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )142 #putpoints(m,fig)143 if var in ['HGT']: pass144 elif colorb:153 else: 154 if hole: what_I_plot = nolow(what_I_plot) 155 pcolor( x, y, what_I_plot, cmap = palette, \ 156 vmin=zevmin, vmax=zevmax ) 157 if colorb != 'nobar' or var == 'HGT': 145 158 ndiv = 10 146 159 colorbar(fraction=0.05,pad=0.1,format=fmtvar(fvar),\ … … 148 161 extend='neither',spacing='proportional') 149 162 # both min max neither 150 163 151 164 ### Vector plot 152 165 if winds: … … 192 205 pad_inches_value = 0.35 193 206 if save == 'png': 194 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value ,erase=True) ## a miniature207 makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature 195 208 makeplotres(zeplot,res=200.,pad_inches_value=pad_inches_value,disp=False) 196 209 elif save in ['eps','svg','pdf']: … … 214 227 outtab = ones(zelen) * -999999 215 228 else: 216 print zelen, len(tab)217 229 if zelen != len(tab): 218 230 print "not enough or too much values... setting same values all variables" … … 242 254 parser.add_option('-t', action='store',dest='target', type="string", default=None, help='destination folder') 243 255 parser.add_option('-s', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 244 parser.add_option('-v', action='append',dest='var', type="string", default=None, help='variable co ntoured (append)')256 parser.add_option('-v', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 245 257 parser.add_option('-n', action='store',dest='numplot', type="int", default=2, help='number of plots (def=1)(<0: 1 plot of LT -*numplot*)') 246 258 parser.add_option('-i', action='store',dest='interp', type="int", default=None, help='interpolation method (2: press, 3: z-amr, 4:z-als)') 247 parser.add_option('-c', action='store',dest='colorb', type="string", default= True, help='change colormap')259 parser.add_option('-c', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') 248 260 parser.add_option('-x', action='store_false',dest='winds', default=True, help='no wind vectors') 249 261 parser.add_option('-m', action='append',dest='vmin', type="float", default=None, help='bounding minimum value (append)') … … 257 269 parser.add_option('-S', action='store',dest='save', type="string", default="gui", help='save mode (png,eps,svg,pdf or gui)(def=gui)') 258 270 parser.add_option('-a', action='store_true',dest='anomaly', default=False, help='compute and plot relative anomaly in %') 271 parser.add_option('-w', action='store',dest='var2', type="string", default=None, help='variable contoured') 259 272 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 260 273 (opt,args) = parser.parse_args() … … 262 275 print "I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h" 263 276 exit() 277 if opt.var is None and opt.anomaly is True: 278 print "Cannot ask to compute anomaly if no variable is set" 279 exit() 264 280 print "Options:", opt 265 281 … … 296 312 if zefields == '' : zefields = listvar 297 313 else : zefields = zefields + "," + listvar 314 if opt.var2 is not None : zefields = zefields + "," + opt.var2 298 315 print zefields 299 316 zefile = api_onelevel ( path_to_input = '', \ … … 327 344 tile=opt.tile,zoom=opt.zoom,display=opt.display,\ 328 345 itstep=opt.itstep,hole=opt.hole,save=opt.save,\ 329 anomaly=opt.anomaly )346 anomaly=opt.anomaly,var2=opt.var2) 330 347 print 'Done: '+name 331 348 system("rm -f to_be_erased")
Note: See TracChangeset
for help on using the changeset viewer.