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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.