Changeset 451 for trunk/UTIL/PYTHON/planetoplot.py
- Timestamp:
- Dec 5, 2011, 2:42:33 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot.py
r448 r451 8 8 ### A. Spiga -- LMD -- 11~12/2011 -- Extended multivar subplot capabilities + cosmetic changes + general cleaning and tests 9 9 ### A. Colaitis -- LMD -- 12/2011 -- Added movie capability [mencoder must be installed] 10 ### A. Spiga -- LMD -- 12/2011 -- Added HTML animated page capability + general tests of consistency [winds, etc...] 10 11 11 12 def planetoplot (namefiles,\ … … 50 51 yintegral=False,\ 51 52 blat=None,\ 53 blon=None,\ 52 54 tsat=False,\ 53 55 flagnolow=False,\ … … 68 70 from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img 69 71 import matplotlib as mpl 70 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title 72 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close 71 73 from matplotlib.cm import get_cmap 72 74 import numpy as np … … 97 99 stime = readslices(str(0)) ; ntime=1 ## this is a default choice 98 100 print "WELL... nothing about time axis. I took default: first time reference stored in file." 101 if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!") 99 102 zelen = len(namefiles)*len(var) 100 103 numplot = zelen*nslices … … 103 106 if fileref is not None: zelen = zelen + 2 104 107 elif "var" in ope: zelen = zelen + 1 105 all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen 108 all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen ; all_windu = [[]]*zelen ; all_windv = [[]]*zelen 106 109 107 110 ################################################################################################# … … 191 194 all_time[k] = time 192 195 if var2: all_var2[k] = getfield(nc,var2) 196 if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar) 193 197 ##### SPECIFIC 194 198 if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat: … … 219 223 elif ope in ["cat"]: 220 224 tab = all_var[0];k = 1 221 while k != len(namefiles) -1:225 while k != len(namefiles): 222 226 tab = np.append(tab,all_var[k],axis=0) ; k += 1 223 227 all_time[0] = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better … … 252 256 253 257 ### Map projection 254 if mapmode == 1: m = define_proj(proj,wlon,wlat,back=back,blat=blat ) ; x, y = m(lon2d, lat2d)258 if mapmode == 1: m = define_proj(proj,wlon,wlat,back=back,blat=blat,blon=blon) ; x, y = m(lon2d, lat2d) 255 259 elif mapmode ==0: m = None ; x = None ; y = None 256 260 … … 264 268 if fileref is not None: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2) ## OK only 1 var, see test in the beginning 265 269 elif "var" in ope: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(var)+1) ## OK only 1 file, see test in the beginning 270 elif "cat" in ope: index_f = 0 266 271 else: yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah 267 272 time = all_time[index_f] … … 284 289 yint=yintegral, alt=vert, anomaly=anomaly ) 285 290 what_I_plot = what_I_plot*mult 286 if var2: ### what is contoured 291 if var2: ### what is contoured. 287 292 what_I_plot_contour, error = reducefield( all_var2[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert, \ 288 293 yint=yintegral, alt=vert ) 294 if winds: ### what is plot as vectors. 295 vecx, error = reducefield( all_windu[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert) 296 vecy, error = reducefield( all_windv[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert) 289 297 #################################################################### 290 298 … … 325 333 if mrate is None: what_I_plot_frame = what_I_plot 326 334 else: what_I_plot_frame = what_I_plot[imov,:,:] 335 if winds: 336 if mrate is None: vecx_frame = vecx ; vecy_frame = vecy 337 else: vecx_frame = vecx[imov,:,:] ; vecy_frame = vecy[imov,:,:] 327 338 elif which == "contour": 328 339 if mrate is None or what_I_plot_contour.ndim < 3: what_I_plot_frame = what_I_plot_contour … … 330 341 if mrate is not None: 331 342 if mapmode == 1: 332 m = define_proj(proj,wlon,wlat,back=back,blat=blat ) ## this is dirty, defined above but out of imov loop333 x, y = m(lon2d, lat2d) ## this is dirty, defined above but out of imov loop343 m = define_proj(proj,wlon,wlat,back=back,blat=blat,blon=blon) ## this is dirty, defined above but out of imov loop 344 x, y = m(lon2d, lat2d) ## this is dirty, defined above but out of imov loop 334 345 if typefile in ['mesoapi','meso'] and mapmode == 1: what_I_plot_frame = dumpbdy(what_I_plot_frame,6,condition=True) 335 346 if typefile in ['mesoideal']: what_I_plot_frame = dumpbdy(what_I_plot_frame,0,stag='W',condition=dumped_vert_stag) … … 362 373 colorbar( fraction=0.05,pad=0.03,format=daformat,\ 363 374 ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' ) 375 if winds: 376 if typefile in ['mesoapi','meso']: 377 [vecx_frame,vecy_frame] = [dumpbdy(vecx_frame,6,stag=uchar,condition=True), dumpbdy(vecy_frame,6,stag=vchar,condition=True)] 378 key = True 379 elif typefile in ['gcm']: 380 key = False 381 if metwind: [vecx_frame,vecy_frame] = m.rotate_vector(vecx_frame, vecy_frame, lon2d, lat2d) 382 if var: colorvec = definecolorvec(back) 383 else: colorvec = definecolorvec(colorb) 384 vectorfield(vecx_frame, vecy_frame, x, y, stride=stride, csmooth=2,\ 385 #scale=15., factor=300., color=colorvec, key=key) 386 scale=20., factor=250., color=colorvec, key=key) 387 #200. ## or csmooth=stride 364 388 elif which == "contour": 365 389 zevminc, zevmaxc = calculate_bounds(what_I_plot_frame) … … 375 399 if which == "regular": 376 400 if mrate is not None: 377 figframe=mpl.pyplot.gcf() 378 if mquality: figframe.set_dpi(600.) 379 else: figframe.set_dpi(200.) 380 mframe=fig2img(figframe) 381 if ((mrate is not None) and (imov is 0)): 382 moviename='test' ;W,H = figframe.canvas.get_width_height() 383 video = VideoSink((H,W), moviename, rate=mrate, byteorder="rgba") 384 video.run(mframe) ; mpl.pyplot.close() 401 ### THIS IS A MENCODER MOVIE 402 if mrate > 0: 403 figframe=mpl.pyplot.gcf() 404 if mquality: figframe.set_dpi(600.) 405 else: figframe.set_dpi(200.) 406 mframe=fig2img(figframe) 407 if imov == 0: 408 moviename='movie' ;W,H = figframe.canvas.get_width_height() 409 video = VideoSink((H,W), moviename, rate=mrate, byteorder="rgba") 410 video.run(mframe) ; close() 411 if imov == iend: video.close() 412 ### THIS IS A WEBPAGE MOVIE 413 else: 414 nameframe = "image"+str(1000+imov) 415 makeplotres(nameframe,res=100.,disp=False) ; close() 416 if imov == 0: myfile = open("zepics", 'w') 417 myfile.write("modImages["+str(imov)+"] = '"+nameframe+"_100.png';"+ '\n') 418 if imov == iend: 419 myfile.write("first_image = 0;"+ '\n') 420 myfile.write("last_image = "+str(iend)+";"+ '\n') 421 myfile.close() 385 422 if var2: which = "contour" 386 423 imov = imov+1 … … 388 425 which = "regular" 389 426 390 if mrate is not None: video.close()391 392 427 ##### 1D field 393 428 elif len(what_I_plot.shape) is 1: … … 395 430 if save == 'txt': writeascii(np.transpose(what_I_plot),'profile'+str(nplot)+'.txt') 396 431 397 #### Other cases: (maybe plot 3-D field one day or movie??)432 #### Other cases: (maybe plot 3-D field one day ??) 398 433 else: 399 434 print "WARNING!!! ",len(what_I_plot.shape),"-D PLOT NOT SUPPORTED !!! dimensions: ",what_I_plot.shape … … 402 437 errormess("There is an error in reducing field !") 403 438 404 ### Vector plot --- a adapter405 if winds:406 vecx, error = reducefield( getfield(nc,uchar), d4=indextime, d3=indexvert , yint=yintegral , alt=vert)407 vecy, error = reducefield( getfield(nc,vchar), d4=indextime, d3=indexvert , yint=yintegral , alt=vert)408 #what_I_plot, error = reducefield(all_var[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert )409 if not error:410 if typefile in ['mesoapi','meso']:411 [vecx,vecy] = [dumpbdy(vecx,6,stag=uchar,condition=True), dumpbdy(vecy,6,stag=vchar,condition=True)]412 key = True413 elif typefile in ['gcm']:414 key = False415 if metwind: [vecx,vecy] = m.rotate_vector(vecx, vecy, lon2d, lat2d)416 if varname == False: colorvec = definecolorvec(back)417 else: colorvec = definecolorvec(colorb)418 vectorfield(vecx, vecy,\419 x, y, stride=stride, csmooth=2,\420 #scale=15., factor=300., color=colorvec, key=key)421 scale=20., factor=250., color=colorvec, key=key)422 #200. ## or csmooth=stride423 424 439 ### Next subplot 425 440 basename = getname(var=varname,winds=winds,anomaly=anomaly) 426 basename = basename + getstralt(nc,level) 441 basename = basename + getstralt(nc,level) 442 if mrate is not None: basename = "movie_" + basename 427 443 if typefile in ['mesoapi','meso']: 428 444 if slon is not None: basename = basename + "_lon_" + str(int(lon2d[indices[1],indices[0]]))
Note: See TracChangeset
for help on using the changeset viewer.