Changeset 760


Ignore:
Timestamp:
Aug 10, 2012, 2:03:29 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON

  • Possible to set colorbars in multivars and diff plots
  • A corollary : keyword --trycol to try a whole bunch of colorbars at once
  • Horizontal grid is now OK in LES tracing mode
  • Minor changes
    • changed name from select_case to select_getfield
    • a call to select_getfielf had too much arguments
    • curiosity coordinates in web stuff
Location:
trunk/UTIL/PYTHON
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/mcd/proto/index.html

    r723 r760  
    7272<li>Presets
    7373<!--<input type="button" value="Now!" onClick="DefaultDateValues();DefaultTimeValues();Convert2Ls();">-->
    74 <input type="button" value="Curiosity" onClick="DateAndTimeValues(2012,8,6,00,00,00);Convert2Ls();PlaceValues(137.2,-4.6)">
     74<input type="button" value="Curiosity" onClick="DateAndTimeValues(2012,8,6,05,30,00);Convert2Ls();PlaceValues(137.4,-4.6)">
    7575<input type="button" value="Phoenix" onClick="DateAndTimeValues(2008,5,25,23,38,23);Convert2Ls();PlaceValues(234.25,68.22)">
    7676<input type="button" value="Opportunity" onClick="DateAndTimeValues(2004,1,25,4,55,0);Convert2Ls();PlaceValues(354.47,-1.95)">
  • trunk/UTIL/PYTHON/myplot.py

    r754 r760  
    866866    #zelatmax = 90. - step/3
    867867    if char not in ["moll"]:
    868         m.drawmeridians(np.r_[-180.:180.:steplon], labels=[0,0,0,1], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, latmax=zelatmax)
    869         m.drawparallels(np.r_[-90.:90.:step], labels=[1,0,0,0], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, latmax=zelatmax)
     868        if wlon[1]-wlon[0] < 2.:  ## LOCAL MODE
     869            m.drawmeridians(np.r_[-1.:1.:0.05], labels=[0,0,0,1], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, fmt='%5.2f')
     870            m.drawparallels(np.r_[-1.:1.:0.05], labels=[1,0,0,0], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, fmt='%5.2f')
     871        else:  ## GLOBAL OR REGIONAL MODE
     872            m.drawmeridians(np.r_[-180.:180.:steplon], labels=[0,0,0,1], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, latmax=zelatmax)
     873            m.drawparallels(np.r_[-90.:90.:step], labels=[1,0,0,0], color=zecolor, linewidth=zelinewidth, fontsize=fontsizemer, latmax=zelatmax)
    870874    if back: m.warpimage(marsmap(back),scale=0.75)
    871875            #if not back:
     
    989993             "def":          "%.1e",\
    990994             "PTOT":         "%.0f",\
     995             "PSFC":         "%.1f",\
    991996             "HGT":          "%.1e",\
    992997             "USTM":         "%.2f",\
     
    14231428## Author : AC
    14241429## Handles calls to specific computations (e.g. wind norm, enrichment factor...)
    1425 def select_case(zvarname=None,znc=None,ztypefile=None,mode=None,ztsat=None,ylon=None,ylat=None,yalt=None,ytime=None):
     1430def select_getfield(zvarname=None,znc=None,ztypefile=None,mode=None,ztsat=None,ylon=None,ylat=None,yalt=None,ytime=None):
    14261431      from mymath import get_tsat
    14271432 
  • trunk/UTIL/PYTHON/myscript.py

    r748 r760  
    2929
    3030    ### GENERIC GRAPHICS SETTINGS
    31     parser.add_option('-c', '--color',  action='store',dest='clb',       type="string",  default="def", help='change colormap (also: nobar,onebar)')
     31    parser.add_option('-c', '--color',  action='store',dest='clb',       type="string",  default=None,  help='change colormapS (also: nobar,onebar,def)')
     32    parser.add_option('--trycol',       action='store_true',dest='trycol',               default=False, help='try 9 typical color palette')
    3233    parser.add_option('--div',          action='store',dest='ndiv',      type="int",     default=10,    help='number of divisions in colorbar [10]')
    3334    parser.add_option('--title',        action='store',dest='zetitle',   type="string",  default="fill",help='customize the whole title')
  • trunk/UTIL/PYTHON/planetoplot.py

    r754 r760  
    2323           stride=3,\
    2424           var=None,\
    25            colorb="def",\
     25           clb=None,\
    2626           winds=False,\
    2727           addchar=None,\
     
    7272           cross=None,\
    7373           facwind=1.,\
     74           trycol=False,\
    7475           streamflag=False):
    7576
     
    8485                       zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
    8586                       getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,\
    86                        getdimfromvar,select_case
     87                       getdimfromvar,select_getfield
    8788    from mymath import deg,max,min,mean,writeascii,fig2data,fig2img
    8889    import matplotlib as mpl
     
    113114### we initialize a few variables
    114115    initime=-1 ; sslon = None ; sslat = None
     116    k = 0 ; firstfile = True ; count = 0
     117### we perform sanity checks and correct for insufficient information
    115118    if slon is not None: sslon = np.zeros([1,2])
    116119    if slat is not None: sslat = np.zeros([1,2])
    117     k = 0 ; firstfile = True ; count = 0
     120    if clb is None:            clb = ["def"]*len(var)
     121    elif len(clb) < len(var):  clb = [clb[0]]*len(var) ; print "WARNING: less color than vars! setting all to 1st value."
     122### we set option trycol i.e. the user wants to try a set of colorbars
     123    if trycol: clb = ["Greys","Blues","YlOrRd","jet","spectral","hot","RdBu","RdYlBu","Paired"] ; zetitle = clb ; var = [var[0]]*9
    118124### we avoid specific cases not yet implemented
    119125    if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!")
    120 ### we prepare number of plot fields [zelen] and plot instances [numplot] according to user choices
     126### we prepare number of plot fields [zelen] and number of plot instances [numplot] according to user choices
    121127### --> we support multifile and multivar plots : files + vars separated by commas are on the same figure
    122128    nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime)
     
    131137### we define the arrays for plot fields -- which will be placed within multiplot loops
    132138    all_var  = [[]]*zelen ; all_var2  = [[]]*zelen
    133     all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen
     139    all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen ; all_colorb = [[]]*zelen
    134140    all_windu = [[]]*zelen ; all_windv = [[]]*zelen
    135  
     141
    136142#############################
    137143### LOOP OVER PLOT FIELDS ###
     
    163169    ### we get the names of variables to be read. in case only one available, we choose this one.
    164170    ### (we take out of the test specific names e.g. UV is not in the file but used to ask a wind speed computation)
    165       varname = select_case(zvarname=var[vvv],znc=nc,ztypefile=typefile,mode='check')
     171      varname = select_getfield(zvarname=var[vvv],znc=nc,ztypefile=typefile,mode='check')
    166172    ### we get the names of wind variables to be read (if any)
    167173      if winds:                                                   
     
    302308####################################################################
    303309
    304     ### we fill the arrays of varname, namefile, time at the current step considered (NB: why use both k and nnn ?)
     310    ### we fill the arrays of varname, namefile, time, colorbar at the current step considered (NB: why use both k and nnn ?)
    305311      all_varname[k] = varname
    306312      all_namefile[k] = namefile
    307313      all_time[k] = time
    308       if var2:  all_var2[k] = select_case(zvarname=var2,znc=nc,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k])
     314      all_colorb[k] = clb[vvv]
     315      if var2:  all_var2[k] = select_getfield(zvarname=var2,znc=nc,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k])
    309316      if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar)
    310317    ### we fill the arrays of fields to be plotted at the current step considered
    311       all_var[k] = select_case(zvarname=all_varname[k],znc=nc,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k])
     318      all_var[k] = select_getfield(zvarname=all_varname[k],znc=nc,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k])
    312319    ### we inform the user about the loop then increment the loop. this is the last line of "for namefile in namefiles"
    313320      print "**** GOT SUBDATA:",k," NAMEFILE:",namefile," VAR:",varname, var2 ; k += 1 ; firstfile = False
     
    324331                if fileref is not None:   
    325332                   ncref = Dataset(fileref)
    326                    all_var[k] = select_case(zvarname=all_varname[k-1],znc=ncref,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k],zvert=vert)
    327                    all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] ; all_var2[k] = all_var2[k-1]
     333                   all_var[k] = select_getfield(zvarname=all_varname[k-1],znc=ncref,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=lon,ylat=lat,yalt=vert,ytime=all_time[k])
     334                   all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] ; all_var2[k] = all_var2[k-1] ; all_colorb[k] = all_colorb[k-1]
    328335                   if winds: all_windu[k] = getfield(ncref,uchar) ; all_windv[k] = getfield(ncref,vchar)
    329336                else: errormess("fileref is missing!")
     
    334341                    masked.set_fill_value([np.NaN])
    335342                    all_var[k+1]= 100.*(all_var[k-1] - masked)/masked
    336                 all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; all_var2[k+1] = all_var2[k] ; numplot = numplot+2
     343                all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; all_var2[k+1] = all_var2[k] ; numplot = numplot+2
     344                if len(clb) >= zelen:  all_colorb[k+1] = clb[-1]   # last additional user-defined color is for operation plot
     345                else:                  all_colorb[k+1] = "RdBu_r"  # if no additional user-defined color... set a good default one
    337346                if winds: all_windu[k+1] = all_windu[k-1]-all_windu[k] ; all_windv[k+1] = all_windv[k-1] - all_windv[k]
    338347             elif ope in ["cat"]:
     
    355364             numplot = numplot + 1 ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1]
    356365             all_varname[k] = all_varname[k-2] + insert + all_varname[k-1]
    357              ### only the operation plot
     366             if len(clb) >= zelen: all_colorb[k] = clb[-1]   # last additional user-defined color is for operation plot
     367             else:                 all_colorb[k] = all_colorb[k-1]  # if no additional user-defined color... set same as var
     368             ### only the operation plot. do not mention colorb so that it is user-defined?
    358369             if "only" in ope:
    359370                 numplot = 1 ; all_var[0] = all_var[k]
     
    413424           if mult != 2718.:  what_I_plot = what_I_plot*mult
    414425           else:              what_I_plot = np.log10(what_I_plot) ; print "log plot"
    415                      
     426                 
    416427       if var2:      ### what is contoured.
    417428           what_I_plot_contour, error = reducefield( all_var2[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert, \
    418                                              yint=yintegral, alt=vert )
     429                                                     yint=yintegral, alt=vert )
    419430       if winds:     ### what is plot as vectors.
    420431           vecx, error = reducefield( all_windu[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert)
     
    443454       changesubplot = (numplot > 1) and (len(what_I_plot.shape) != 1)  ## default for 1D plots: superimposed. to be reworked for better flexibility.
    444455       if changesubplot: subplot(subv,subh,nplot) #; subplots_adjust(wspace=0,hspace=0)
     456       colorb = all_colorb[index_f]
    445457       ####################################################################
    446458       if error:
     
    466478               if (fileref is not None) and (index_f == numplot-1):    zevmin, zevmax = calculate_bounds(what_I_plot,vmin=minop,vmax=maxop)
    467479               else:                                                   zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax)
    468                if (fileref is not None) and (index_f == numplot-1):    colorb = "RdBu_r"
     480               #if (fileref is not None) and (index_f == numplot-1):    colorb = "RdBu_r"
    469481               if colorb in ["def","nobar","onebar"]:                  palette = get_cmap(name=defcolorb(fvar.upper()))
    470482               else:                                                   palette = get_cmap(name=colorb)
     
    750762    if mrate is None:
    751763        pad_inches_value = 0.35
     764        if wlon[1]-wlon[0] < 2.: pad_inches_value = 0.5  # LOCAL MODE (small values)
    752765        print "********** SAVE ", save
    753766        if save == 'png':
  • trunk/UTIL/PYTHON/pp.py

    r721 r760  
    5555      if typefile in ["meso"]:         
    5656          [lschar,zehour,zehourin] = getlschar ( zefiles[0] )
    57           if opt.var is None:  opt.var = ["HGT"] ; opt.clb = "nobar"
     57          if opt.var is None:  opt.var = ["HGT"] #; opt.clb = "nobar" # otherwise breaks the automatic one-var file capability
    5858      elif typefile in ["geo"]:
    5959          [lschar,zehour,zehourin] = ["",0,0]
     
    162162        name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\
    163163                proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevars,\
    164                 colorb=opt.clb,winds=opt.winds,\
     164                clb=separatenames(opt.clb),winds=opt.winds,\
    165165                addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\
    166166                tile=opt.tile,zoom=opt.zoom,display=opt.display,\
     
    175175                mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\
    176176                redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels),\
    177                 lstyle=separatenames(opt.linestyle),cross=readslices(opt.mark),facwind=opt.facwind,streamflag=opt.stream)
     177                lstyle=separatenames(opt.linestyle),cross=readslices(opt.mark),facwind=opt.facwind,\
     178                trycol=opt.trycol,streamflag=opt.stream)
    178179        print 'DONE: '+name
    179180        system("rm -f to_be_erased")
Note: See TracChangeset for help on using the changeset viewer.