Changeset 444
- Timestamp:
- Dec 1, 2011, 3:58:28 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r441 r444 376 376 377 377 ## Author: AS + AC 378 def dumpbdy (field,n,stag=None): 379 nx = len(field[0,:])-1 380 ny = len(field[:,0])-1 381 if stag == 'U': nx = nx-1 382 if stag == 'V': ny = ny-1 383 if stag == 'W': nx = nx+1 #special les case when we dump stag on W 378 def dumpbdy (field,n,stag=None,condition=False): 379 if condition: 380 nx = len(field[0,:])-1 381 ny = len(field[:,0])-1 382 if stag == 'U': nx = nx-1 383 if stag == 'V': ny = ny-1 384 if stag == 'W': nx = nx+1 #special les case when we dump stag on W 384 385 return field[n:ny-n,n:nx-n] 385 386 386 ## Author: AS 387 ## Author: AS + AC 387 388 def getcoorddef ( nc ): 388 389 import numpy as np … … 1040 1041 1041 1042 def call_contour(what_I_plot,error,x,y,m,lon,lat,vert,time,vertmode,ze_var2,indextime,indexlon,indexlat,indexvert,yintegral,mapmode,typefile,var2,ticks): 1042 from matplotlib.pyplot import contour, plot 1043 from matplotlib.pyplot import contour, plot, clabel 1043 1044 import numpy as np 1044 1045 #what_I_plot = what_I_plot*mult … … 1057 1058 ### If we plot a 2-D field 1058 1059 if len(what_I_plot.shape) is 2: 1059 #zelevels=[ 0.2,0.4,0.6,0.8,1.]1060 #zelevels=[1.] 1060 1061 if mapmode == 0:cs = contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5) 1061 1062 elif mapmode == 1:cs = m.contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5) -
trunk/UTIL/PYTHON/myscript.py
r432 r444 62 62 parser.add_option('--tsat', action='store_true',dest='tsat', default=False,help='convert temperature field T in Tsat-T using pressure') 63 63 parser.add_option('--rate', action='store' ,dest='rate', type="int", default=None, help='Output is a movie along Time dimension. --time must not be specified. [None]') 64 parser.add_option('--quality', action='store_true',dest='quality', default=False,help='For movie mode: improves movie quality.(slower)') 64 65 65 66 return parser -
trunk/UTIL/PYTHON/planetoplot.py
r443 r444 52 52 tsat=False,\ 53 53 flagnolow=False,\ 54 mrate=None): 54 mrate=None,\ 55 mquality=False): 55 56 56 57 … … 73 74 from numpy.core.defchararray import find 74 75 from videosink import VideoSink 76 import subprocess 75 77 76 78 ################################ … … 153 155 if varname in ['PHTOT','W']: vertdim='BOTTOM-TOP_PATCH_END_STAG' 154 156 else: vertdim='BOTTOM-TOP_PATCH_END_UNSTAG' 157 if (var2 is not None and var2 not in ['PHTOT','W']): 158 vertdim='BOTTOM-TOP_PATCH_END_UNSTAG' 159 dumped_vert_stag=True 155 160 if varname in ['V']: latdim='SOUTH-NORTH_PATCH_END_STAG' 156 161 else: latdim='SOUTH-NORTH_PATCH_END_UNSTAG' … … 291 296 yint=yintegral, alt=vert, anomaly=anomaly ) 292 297 what_I_plot = what_I_plot*mult 293 #if typefile in ['mesoideal']: what_I_plot = dumpbdy(what_I_plot,0,stag='W')298 # if typefile in ['mesoideal']: what_I_plot = dumpbdy(what_I_plot,0,stag='W') 294 299 if not error: 295 300 fvar = varname … … 324 329 if mrate is not None: 325 330 what_I_plot_frame = what_I_plot[imov,:,:] ; print "-> frame ",imov+1 326 if mapmode == 1: 331 if mapmode == 1: 327 332 m = define_proj(proj,wlon,wlat,back=back,blat=blat) ## this is dirty, defined above but out of imov loop 328 333 x, y = m(lon2d, lat2d) ## this is dirty, defined above but out of imov loop 329 if typefile in ['mesoapi','meso'] and mapmode == 1: what_I_plot_frame = dumpbdy(what_I_plot_frame,6) 334 if typefile in ['mesoapi','meso'] and mapmode == 1: what_I_plot_frame = dumpbdy(what_I_plot_frame,6,condition=True) 335 if typefile in ['mesoideal']: what_I_plot_frame = dumpbdy(what_I_plot_frame,0,stag='W',condition=dumped_vert_stag) 336 330 337 if hole: what_I_plot_frame = hole_bounds(what_I_plot_frame,zevmin,zevmax) 331 338 else: what_I_plot_frame = bounds(what_I_plot_frame,zevmin,zevmax) … … 358 365 colorbar( fraction=0.05,pad=0.03,format=daformat,\ 359 366 ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' ) 360 mframe=fig2img(mpl.pyplot.gcf()) 367 figframe=mpl.pyplot.gcf() 368 if mrate is not None: 369 if mquality: figframe.set_dpi(600.) 370 else: figframe.set_dpi(200.) 371 mframe=fig2img(figframe) 361 372 if ((mrate is not None) and (imov is 0)): 362 W,H = mpl.pyplot.gcf().canvas.get_width_height() 363 video = VideoSink((H,W), "test", rate=mrate, byteorder="rgba") 373 moviename='test' 374 W,H = figframe.canvas.get_width_height() 375 video = VideoSink((H,W), moviename, rate=mrate, byteorder="rgba") 364 376 if mrate is not None: 365 377 video.run(mframe) 366 378 mpl.pyplot.close() 367 379 imov=imov+1 368 if mrate is not None: video.close 380 if mrate is not None: video.close() 369 381 ##### 1D field 370 382 elif len(what_I_plot.shape) is 1: … … 386 398 if not error: 387 399 if typefile in ['mesoapi','meso']: 388 [vecx,vecy] = [dumpbdy(vecx,6,stag=uchar ), dumpbdy(vecy,6,stag=vchar)]400 [vecx,vecy] = [dumpbdy(vecx,6,stag=uchar,condition=True), dumpbdy(vecy,6,stag=vchar,condition=True)] 389 401 key = True 390 402 elif typefile in ['gcm']: … … 469 481 show() 470 482 483 ################################## 484 ### Getting more out of this video 485 486 if mrate is not None: 487 print "Re-encoding movie.. first pass" 488 video.first_pass(filename=moviename,quality=mquality) 489 print "Re-encoding movie.. second pass" 490 video.second_pass(filename=moviename,quality=mquality) 491 471 492 ############### 472 493 ### Now the end -
trunk/UTIL/PYTHON/pp.py
r432 r444 137 137 ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ 138 138 invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ 139 blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow,mrate=opt.rate )139 blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow,mrate=opt.rate,mquality=opt.quality) 140 140 print 'DONE: '+name 141 141 system("rm -f to_be_erased") -
trunk/UTIL/PYTHON/videosink.py
r430 r444 1 1 import numpy as np 2 2 import subprocess 3 from os import system 3 4 4 5 class VideoSink(object) : … … 10 11 '-demuxer', 'rawvideo', 11 12 '-rawvideo', 'w=%i:h=%i'%size[::-1]+":fps=%i:format=%s"%(rate,byteorder), 12 '-o', filename+'.avi', 13 '-ovc', 'lavc', 13 '-o', filename+'_raw.avi', 14 '-nosound', 15 '-ovc', 'x264', 16 # '-ovc', 'lavc', 14 17 ) 15 18 self.p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE, shell=False) … … 18 21 #assert image.shape[0:2] == self.size 19 22 self.p.stdin.write(image.tostring()) 23 24 def first_pass(self,filename="output",quality=False) : 25 26 27 bitrate="7200" 28 if quality:bitrate="50000" 29 cmdstring = ('mencoder', 30 filename+'_raw.avi', 31 '-of', 'rawvideo', 32 '-nosound', 33 '-ovc', 'x264', 34 '-x264encopts', 'subq=1:frameref=1:bitrate='+bitrate+':bframes=1:pass=1', 35 '-vf', 'scale=1280:720', 36 '-o', filename+'_first.264' 37 ) 38 subprocess.call(cmdstring,shell=False) 39 40 def second_pass(self,filename="output",quality=False) : 41 bitrate="7200" 42 if quality:bitrate="50000" 43 cmdstring = ('mencoder', 44 filename+'_first.264', 45 '-of', 'rawvideo', 46 '-nosound', 47 '-ovc', 'x264', 48 '-x264encopts', 'subq=6:frameref=5:bitrate='+bitrate+':me=umh:partitions=all:bframes=1:me_range=16:cabac:weightb:deblock:pass=2', 49 '-vf', 'scale=1280:720', 50 '-o', filename+'.avi' 51 ) 52 system('rm -f '+filename+'_raw.avi') 53 subprocess.call(cmdstring,shell=False) 54 system('rm -f '+filename+'_first.264') 55 20 56 def close(self) : 21 57 self.p.stdin.close() 58 self.p.wait() 59
Note: See TracChangeset
for help on using the changeset viewer.