Changeset 612


Ignore:
Timestamp:
Apr 4, 2012, 1:59:05 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON
======

New options:

i) --mark lon,lat will superimpose a cross at lon,lat (floats) on a longitude latitude plot (mapmode 1)
ii) --lstyle let you customize linestyles for 1D plots. Works in the same way as --labels. Exemple: --lstyle "--r","-r","--b","-b"
iii) One can now ask for the variable -v slopexy or SLOPEXY to plot (or overplot with --var2 slopexy) the amplitude of the slope in mesoscale simulations
iv) One can now ask for the variable -v deltat or DELTAT to plot the temperature difference between surface temperature and an arbitrary model level. This automatically calls API with "tk,tsurf". One should use this in conjunction with -i 4 -l xxx so that the difference is made between 0m (surface) and xxx m.

Minor corrections:

Verification plot showing longitude latitude of a slice in a HGT map now also requires "display" to be true.
Winds can now be overplotted in --operation - maps.

Location:
trunk/UTIL/PYTHON
Files:
4 edited

Legend:

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

    r610 r612  
    105105
    106106## Author: AC
     107# Compute the norm of the winds
     108# The corresponding variable to call is UV or uvmet (to use api)
    107109def windamplitude (nc):
    108110    import numpy as np
     
    123125       zvint=zv
    124126    return np.sqrt(zuint**2 + zvint**2)
     127
     128## Author: AC
     129# Compute the norm of the slope angles
     130# The corresponding variable to call is SLOPEXY
     131def slopeamplitude (nc):
     132    import numpy as np
     133    varinfile = nc.variables.keys()
     134    if "slopex" in varinfile: zu=getfield(nc,'slopex')
     135    elif "SLOPEX" in varinfile: zu=getfield(nc,'SLOPEX')
     136    if "slopey" in varinfile: zv=getfield(nc,'slopey')
     137    elif "SLOPEY" in varinfile: zv=getfield(nc,'SLOPEY')
     138    znt,zny,znx = np.array(zu).shape
     139    zuint = np.zeros([znt,zny,znx])
     140    zvint = np.zeros([znt,zny,znx])
     141    zuint=zu
     142    zvint=zv
     143    return np.sqrt(zuint**2 + zvint**2)
     144
     145## Author: AC
     146# Compute the temperature difference between surface and first level.
     147# API is automatically called to get TSURF and TK.
     148# The corresponding variable to call is DELTAT
     149def deltat0t1 (nc):
     150    import numpy as np
     151    varinfile = nc.variables.keys()
     152    if "tsurf" in varinfile: zu=getfield(nc,'tsurf')
     153    elif "TSURF" in varinfile: zu=getfield(nc,'TSURF')
     154    if "tk" in varinfile: zv=getfield(nc,'tk')
     155    elif "TK" in varinfile: zv=getfield(nc,'TK')
     156    znt,zny,znx = np.array(zu).shape
     157    zuint = np.zeros([znt,zny,znx])
     158    zuint=zu - zv[:,0,:,:]
     159    return zuint
    125160
    126161## Author: AS + TN + AC
     
    814849             "TPOT":         "%.0f",\
    815850             "TSURF":        "%.0f",\
     851             "U_OUT1":       "%.0f",\
     852             "T_OUT1":       "%.0f",\
    816853             "def":          "%.1e",\
    817854             "PTOT":         "%.0f",\
     
    831868             "UM":           "%.0f",\
    832869             "WIND":         "%.0f",\
     870             "UVMET":         "%.0f",\
     871             "UV":         "%.0f",\
    833872             "ALBBARE":      "%.2f",\
    834873             "TAU":          "%.1f",\
  • trunk/UTIL/PYTHON/myscript.py

    r610 r612  
    3939    parser.add_option('--ylabel',       action='store',dest='ylab',       type="string",  default=None, help='customize the y-axis label')
    4040    parser.add_option('--labels',       action='store',dest='labels',     type="string",  default=None, help='customize 1D curve labels. Str comma-separated. [None]')
     41    parser.add_option('--lstyle',       action='store',dest='linestyle',  type="string",  default=None, help='customize 1D curve linestyles. String separated by commas. [None]')
    4142
    4243    ### SPECIFIC FOR MAPPING [MAPMODE 1]
     
    4849    parser.add_option('--blat',         action='store',dest='blat',      type="int",     default=None,  help='reference lat (or bounding lat for stere) [computed]')
    4950    parser.add_option('--blon',         action='store',dest='blon',      type="int",     default=None,  help='reference lon [computed]')
     51    parser.add_option('--mark',         action='append',dest='mark',  type="string",  default=None, help='superimpose a crossmark at given coords. lon,lat float separated by commas. [None]')
    5052
    5153    ### SPECIFIC FOR SLICING [MAPMODE 0]
  • trunk/UTIL/PYTHON/planetoplot.py

    r610 r612  
    6464           xlab=None,\
    6565           ylab=None,\
    66            lbls=None):
     66           lbls=None,\
     67           lstyle=None,\
     68           cross=None):
    6769
    6870    ####################################################################################################################
     
    7577                       fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\
    7678                       zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
    77                        getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,windamplitude
     79                       getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,\
     80                       windamplitude,slopeamplitude,deltat0t1
    7881    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    7982    import matplotlib as mpl
     
    148151    ### we get the names of variables to be read. in case only one available, we choose this one.
    149152      varname=var[vvv]
    150       if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet']))):
     153      if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet','slopexy','SLOPEXY','deltat','DELTAT']))):
    151154          if len(varinfile) == 1:   varname = varinfile[0]
    152155          else:                     varname = False
     
    205208          ###### principle: calculate correct indices then repopulate slon and slat
    206209          if slon is not None or slat is not None:
    207               if firstfile and save == 'png' and typefile == 'meso' and "HGT" in varinfile:   iwantawhereplot = nc     #show a topo map with a cross on the chosen point
     210              if firstfile and save == 'png' and typefile == 'meso' and "HGT" in varinfile and display:   iwantawhereplot = nc     #show a topo map with a cross on the chosen point
    208211              else:                                                                           iwantawhereplot = None   #do not show anything, just select indices
    209212              numlon = 1 ; numlat = 1
     
    278281      all_namefile[k] = namefile
    279282      all_time[k] = time
    280       if var2: all_var2[k] = getfield(nc,var2)
     283      if var2:
     284         if ((var2 in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (var2 not in nc.variables)): all_var2[k] = slopeamplitude(nc)
     285         else: all_var2[k] = getfield(nc,var2)
    281286      if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar)
    282287      #####################
     
    293298      elif ((varname in ['UV','uv','uvmet']) and (typefile in ['meso']) and (varname not in nc.variables)):
    294299          all_var[k]=windamplitude(nc)
     300      elif ((varname in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (varname not in nc.variables)):
     301          all_var[k]=slopeamplitude(nc)
     302      elif ((varname in ['DELTAT','deltat']) and (typefile in ['meso']) and (varname not in nc.variables)):
     303          all_var[k]=deltat0t1(nc)
    295304      else:
    296305      ##### GENERAL STUFF HERE
     
    310319                   if ((all_varname[k-1] in ['UV','uv','uvmet']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)):
    311320                      all_var[k] = windamplitude(ncref)
     321                   elif ((all_varname[k-1] in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)):
     322                      all_var[k] = slopeamplitude(ncref)
     323                   elif ((all_varname[k-1] in ['DELTAT','deltat']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)):
     324                      all_var[k]=deltat0t1(ncref)
    312325                   else:
    313326                      all_var[k] = getfield(ncref,all_varname[k-1])
    314327                   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]
     328                   if winds: all_windu[k] = getfield(ncref,uchar) ; all_windv[k] = getfield(ncref,vchar)
    315329                else: errormess("fileref is missing!")
    316330                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
     
    321335                    all_var[k+1]= 100.*(all_var[k-1] - masked)/masked
    322336                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
     337                if winds: all_windu[k+1] = all_windu[k-1]-all_windu[k] ; all_windv[k+1] = all_windv[k-1] - all_windv[k]
    323338             elif ope in ["cat"]:
    324339                tabtime = all_time[0];tab = all_var[0];k = 1
     
    349364    ### Time loop for plotting device
    350365    nplot = 1 ; error = False
    351     linecycler = cycle(["-","--","-.",":"])
     366    if lstyle is not None: linecycler = cycle(lstyle)
     367    else: linecycler = cycle(["-","--","-.",":"])
    352368    print "********************************************"
    353369    while error is False:
     
    492508
    493509                    if which == "unidim":
    494                         lbl = ""
    495                         if indexlat is not None:  lbl = lbl + " ix" + str(indexlat[0])
    496                         if indexlon is not None:  lbl = lbl + " iy" + str(indexlon[0])
    497                         if indexvert is not None: lbl = lbl + " iz" + str(indexvert[0])
    498                         if indextime is not None: lbl = lbl + " it" + str(indextime[0])
    499                         if lbl == "": lbl = namefiles[index_f]
    500                         if lbls is not None: lbl=lbls[nplot-1]
     510                        if lbls is not None: lbl=lbls[index_f]
     511                        else:
     512                           lbl = ""
     513                           if indexlat is not None:  lbl = lbl + " ix" + str(indexlat[0])
     514                           if indexlon is not None:  lbl = lbl + " iy" + str(indexlon[0])
     515                           if indexvert is not None: lbl = lbl + " iz" + str(indexvert[0])
     516                           if indextime is not None: lbl = lbl + " it" + str(indextime[0])
     517                           if lbl == "": lbl = namefiles[index_f]
    501518
    502519                        if mrate is not None: x = y  ## because swapaxes...
     
    523540                            if mapmode == 1:       m.contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans)
    524541                            elif mapmode == 0:     contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans)
     542                            if cross is not None and mapmode == 1:
     543                               idx,idy=m(cross[0][0],cross[0][1])
     544                               mpl.pyplot.plot([idx],[idy],'+k',mew=0.5,ms=18)
    525545                        else:
    526546                            if mapmode == 1:       m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax, alpha=trans)
     
    553573                        zevminc, zevmaxc = calculate_bounds(what_I_plot_frame, vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame))
    554574                        zelevels = np.linspace(zevminc,zevmaxc,ticks/2) #20)
    555                         if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,2000.)
     575                        if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,1000.)
    556576                        if mapmode == 0:   
    557577                            what_I_plot_frame, x, y = define_axis( lon,lat,vert,time,indexlon,indexlat,indexvert,\
    558578                                                              itime,what_I_plot_frame, len(all_var2[index_f].shape),vertmode )
    559                             cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)#, linestyles='solid')
    560                         elif mapmode == 1:  cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)# , linestyles='solid')
     579                            cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid')
     580                        elif mapmode == 1:  cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid')
    561581                    if which in ["regular","unidim"]:
    562582
     
    645665        if zetitle[0] != "fill": zecb.ax.set_xlabel(zetitle[index_f]) ; zetitle[index_f]=""
    646666
    647      
     667
    648668    ##########################################################################
    649669    ### Save the figure in a file in the data folder or an user-defined folder
  • trunk/UTIL/PYTHON/pp.py

    r610 r612  
    102102            ### winds or no winds
    103103            if opt.winds            :  zefields = 'uvmet'
     104            elif opt.var[j] in ['deltat','DELTAT'] : zefields = 'tk,TSURF'
    104105            else                    :  zefields = ''
    105106            ### var or no var
     
    170171                blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\
    171172                mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\
    172                 redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels))
     173                redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels),\
     174                lstyle=separatenames(opt.linestyle),cross=readslices(opt.mark))
    173175        print 'DONE: '+name
    174176        system("rm -f to_be_erased")
Note: See TracChangeset for help on using the changeset viewer.