Ignore:
Timestamp:
Nov 30, 2011, 5:41:30 PM (13 years ago)
Author:
acolaitis
Message:


PYTHON

Added... movies !


Example :


pp.py -f wrfout_d01_9999-01-01_07:11:40 --var upward --lat 50 --time 5 -m 0 -M 10 -c Spectral_r --div 20 --ymax 200

will generate a 2D altitude-latitude plot of upward tracer concentration, whereas :

pp.py -f wrfout_d01_9999-01-01_07:11:40 --var upward --lat 50 -m 0 -M 10 -c Spectral_r --div 20 --ymax 200

will generate a movie of the previous plot, along the time axis (default axis for movies for now).


Requirements :


The way the movie maker is written is very light-weight and fast, as no intermediary pictures are saved. The data is buffered and streamed right into an encoder.
I could not make this work with ffmpeg... So you MUST have mencoder installed. It is not on the farm... It is on ciclad, and I know that Aymeric installed it on his machine (at least before getting Ulrich).


Known problems :


I spent litteraly all day making this work, but the option is still basic for now, i.e. it is not yea possible to use -w with movies, or 1D plot movies. (several other stuff are not possible yet, like title specification, axis limits (ylim,xlim), etc... I know how to make it work, I just need some time.

Default name for the output movie is "test.avi" for now.

Tested with LES data without projections. Not test on meso or gcm in mapmode 1.


Details :


A videosink.py
----------------- New class that contains some routines for video stuff. This could either be transformed in a function in an other .py, or other functions could be added to this class to make it more usefull.

M 427 mymath.py
----------------- New routines to convert figures to RGBA data (4-dimensions arrays of pixel data) and figures to PIL images.

M * 428 planetoplot.py
----------------- Added support for movies of 2D plots without overlines

M * 428 myplot.py
----------------- Minor stuff about LES and dumpbdy for W. This could be made in a much cleaner way... maybe later.

File:
1 edited

Legend:

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

    r429 r430  
    5050           blat=None,\
    5151           tsat=False,\
    52            flagnolow=False):
     52           flagnolow=False,\
     53           movie_axis=0):
    5354
    5455
     
    6364                       zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
    6465                       getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds
    65     from mymath import deg,max,min,mean,get_tsat,writeascii
     66    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    6667    import matplotlib as mpl
    6768    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title
     
    6970    import numpy as np
    7071    from numpy.core.defchararray import find
     72    from videosink import VideoSink
    7173
    7274    ################################
     
    281283              if var2 == 'HGT':  zelevels = np.arange(-10000.,30000.,2000.)
    282284              if mapmode == 0:
     285                  if typefile in ['mesoideal']:    what_I_plot = dumpbdy(what_I_plot,0,stag='W')
     286                  itime=indextime
     287                  if len(what_I_plot.shape) is 3:itime=[0]
    283288                  what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\
    284                         indextime,what_I_plot, len(all_var2[index_f].shape),vertmode)
     289                        itime,what_I_plot, len(all_var2[index_f].shape),vertmode)
    285290              ### If we plot a 2-D field
    286291              if len(what_I_plot.shape) is 2:
     292                  zelevels=[-10.,-8.,-6.,-4.,-2.,0.,2.,4.,6.,8.,10.]
    287293                  cs = contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)
    288 #                  clabel(cs,#zelevels[::2],
    289 #                     inline=3,
    290 #                     fmt='%1.1e',
    291 #                     fontsize=7)
     294                  clabel(cs,zelevels,
     295                     inline=3,
     296                     fmt='%1.1f',
     297                     fontsize=7)
    292298              ### If we plot a 1-D field
    293299              elif len(what_I_plot.shape) is 1:
     
    308314                   if typefile in ['mesoapi','meso']:    what_I_plot = dumpbdy(what_I_plot,6)
    309315               elif mapmode == 0:
     316                   itime=indextime
     317                   if len(what_I_plot.shape) is 3:itime=[0]
    310318                   what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\
    311                          indextime,what_I_plot, len(all_var[index_f].shape),vertmode)
     319                         itime,what_I_plot, len(all_var[index_f].shape),vertmode)
    312320                   zxmin, zxmax = xaxis ; zymin, zymax = yaxis
    313321                   if zxmin is not None: mpl.pyplot.xlim(xmin=zxmin)
     
    322330               elif (fileref is not None) and (index_f is numplot-1): palette = get_cmap(name="RdBu_r")
    323331               else:                           palette = get_cmap(name=colorb)
    324                ##### 2D field
    325                if len(what_I_plot.shape) is 2:
    326                  if hole: what_I_plot = hole_bounds(what_I_plot,zevmin,zevmax)
    327                  else: what_I_plot = bounds(what_I_plot,zevmin,zevmax)
    328                  if flagnolow: what_I_plot = nolow(what_I_plot)
    329                  if not tile:
    330                      #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20)
    331                      zelevels = np.linspace(zevmin,zevmax,num=ticks)
    332                      print np.array(x).shape
    333                      print np.array(y).shape
    334                      print np.array(what_I_plot).shape
    335 
    336                      if mapmode == 1:       m.contourf( x, y, what_I_plot, zelevels, cmap = palette)
    337                      elif mapmode == 0:     contourf( x, y, what_I_plot, zelevels, cmap = palette)
    338                  else:
    339                      if mapmode == 1:       m.pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )
    340                      elif mapmode == 0:     pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )
    341                  if colorb != 'nobar':       
    342                      if (fileref is not None) and (index_f is numplot-1):   daformat = "%.3f"
    343                      else:                                                  daformat = fmtvar(fvar.upper())
    344                      colorbar( fraction=0.05,pad=0.03,format=daformat,\
    345                                ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' )
     332               ##### simple 2D field and movies of 2D fields
     333               if len(what_I_plot.shape) >= 2:
     334                 istart=0
     335                 if indextime is None:iend=len(time)-1
     336                 else:iend=istart
     337                 imov=istart
     338
     339                 while imov <= iend:
     340                    what_I_plot_frame=what_I_plot
     341                    if len(what_I_plot.shape) is 3:
     342                       what_I_plot_frame=what_I_plot[imov,:,:]
     343                       print "-> frame ",imov+1
     344                    if hole: what_I_plot_frame = hole_bounds(what_I_plot_frame,zevmin,zevmax)
     345                    else: what_I_plot_frame = bounds(what_I_plot_frame,zevmin,zevmax)
     346                    if flagnolow: what_I_plot_frame = nolow(what_I_plot_frame)
     347                    if not tile:
     348                        #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20)
     349                        zelevels = np.linspace(zevmin,zevmax,num=ticks)
     350                        if imov is 0:
     351                           print np.array(x).shape
     352                           print np.array(y).shape
     353                           print np.array(what_I_plot_frame).shape
     354   
     355                        if mapmode == 1:       m.contourf( x, y, what_I_plot_frame, zelevels, cmap = palette)
     356                        elif mapmode == 0:     contourf( x, y, what_I_plot_frame, zelevels, cmap = palette)
     357                    else:
     358                        if mapmode == 1:       m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax )
     359                        elif mapmode == 0:     pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax )
     360                    if colorb != 'nobar':       
     361                        if (fileref is not None) and (index_f is numplot-1):   daformat = "%.3f"
     362                        else:                                                  daformat = fmtvar(fvar.upper())
     363                        colorbar( fraction=0.05,pad=0.03,format=daformat,\
     364                                  ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' )
     365                        #mframe=mpl.pyplot.gci().to_rgba(mpl.pyplot.gci().get_array())
     366                        #mframe=mpl.pyplot.imshow()
     367                        #mframe=fig2data(mpl.pyplot.gcf())
     368                        mframe=fig2img(mpl.pyplot.gcf())
     369
     370                        if ((len(what_I_plot.shape) is 3) and (imov is 0)):
     371                            W,H = mpl.pyplot.gcf().canvas.get_width_height()
     372                            rate = 10
     373                            video = VideoSink((H,W), "test", rate=rate, byteorder="rgba")
     374                        if len(what_I_plot.shape) is 3:
     375                            video.run(mframe)
     376                            mpl.pyplot.close()
     377
     378                        imov=imov+1
     379                 if len(what_I_plot.shape) is 3: video.close
    346380               ##### 1D field
    347381               elif len(what_I_plot.shape) is 1:
Note: See TracChangeset for help on using the changeset viewer.