Ignore:
Timestamp:
Dec 1, 2011, 3:58:28 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON. Improved quality of movies for really small weight. Also added an option to force even better quality (option is --quality, weight is also reasonnable but rendering is slower).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot.py

    r443 r444  
    5252           tsat=False,\
    5353           flagnolow=False,\
    54            mrate=None):
     54           mrate=None,\
     55           mquality=False):
    5556
    5657
     
    7374    from numpy.core.defchararray import find
    7475    from videosink import VideoSink
     76    import subprocess
    7577
    7678    ################################
     
    153155          if varname in ['PHTOT','W']:    vertdim='BOTTOM-TOP_PATCH_END_STAG'
    154156          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
    155160          if varname in ['V']:  latdim='SOUTH-NORTH_PATCH_END_STAG'
    156161          else:                 latdim='SOUTH-NORTH_PATCH_END_UNSTAG'
     
    291296                                             yint=yintegral, alt=vert, anomaly=anomaly )
    292297           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')
    294299           if not error:
    295300               fvar = varname
     
    324329                    if mrate is not None:     
    325330                        what_I_plot_frame = what_I_plot[imov,:,:] ; print "-> frame ",imov+1
    326                         if mapmode == 1: 
     331                        if mapmode == 1:
    327332                            m = define_proj(proj,wlon,wlat,back=back,blat=blat)  ## this is dirty, defined above but out of imov loop
    328333                            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
    330337                    if hole:         what_I_plot_frame = hole_bounds(what_I_plot_frame,zevmin,zevmax)
    331338                    else:            what_I_plot_frame = bounds(what_I_plot_frame,zevmin,zevmax)
     
    358365                        colorbar( fraction=0.05,pad=0.03,format=daformat,\
    359366                                  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)
    361372                    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")
    364376                    if mrate is not None:
    365377                        video.run(mframe)
    366378                        mpl.pyplot.close()
    367379                    imov=imov+1
    368                  if mrate is not None: video.close
     380                 if mrate is not None: video.close()
    369381               ##### 1D field
    370382               elif len(what_I_plot.shape) is 1:
     
    386398           if not error:
    387399               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)]
    389401                   key = True
    390402               elif typefile in ['gcm']:           
     
    469481            show()
    470482
     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
    471492    ###############
    472493    ### Now the end
Note: See TracChangeset for help on using the changeset viewer.