Changeset 502


Ignore:
Timestamp:
Jan 23, 2012, 5:04:36 PM (13 years ago)
Author:
acolaitis
Message:

Python. Minor corrections to several subroutines. Added possibility to label manually x and y axis. (use --xlabel and --ylabel). Corrected make_netcdf for certain tricky cases. Modified mcs.py to be complied with recent modifs in hrecast and zrecast. Treated cases with division by 0 in operation -%.

Location:
trunk/UTIL/PYTHON
Files:
6 edited

Legend:

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

    r409 r502  
    8282                 if j is 0:                ##this should solve most conflicts with Time
    8383                    zzvardim[j]=a[1]
     84                 elif j is 3:
     85                    zzvardim[j]=a[1]
    8486                 else:
    8587                    zzvardim[j]=a[0]
  • trunk/UTIL/PYTHON/mcs.py

    r465 r502  
    5353   filename=opt.file
    5454
    55    if opt.hrecast:
    56       if (path.exists(filename[0:len(filename)-3]+"_h.nc") and (not opt.override)):
    57          print "--> "+filename[0:len(filename)-3]+"_h.nc"
    58          print "Recasted file is already there, skipping interpolation. [use --override to force interpolation]"
    59          filename=filename[0:len(filename)-3]+"_h.nc"
    60       else:
    61          print "--> "+filename[0:len(filename)-3]+"_h.nc"
    62          filename=call_hrecast (  input_name      = [filename], \
    63                     fields  = varznames, \
    64                     predefined = 'mcs')[0]
     55#   if opt.hrecast:
     56#      if (path.exists(filename[0:len(filename)-3]+"_h.nc") and (not opt.override)):
     57#         print "--> "+filename[0:len(filename)-3]+"_h.nc"
     58#         print "Recasted file is already there, skipping interpolation. [use --override to force interpolation]"
     59#         filename=filename[0:len(filename)-3]+"_h.nc"
     60#      else:
     61#         print "--> "+filename[0:len(filename)-3]+"_h.nc"
     62#         filename=call_hrecast (  input_name      = [filename], \
     63#                    fields  = varznames, \
     64#                    predefined = 'mcs')[0]
    6565
    6666   if opt.zrecast:
     
    7575                    fields  = varznames, \
    7676                    predefined = 'mcs')[0]
     77
     78   if opt.hrecast:
     79      if (path.exists(filename[0:len(filename)-3]+"_h.nc") and (not opt.override)):
     80         print "--> "+filename[0:len(filename)-3]+"_h.nc"
     81         print "Recasted file is already there, skipping interpolation. [use --override to force interpolation]"
     82         filename=filename[0:len(filename)-3]+"_h.nc"
     83      else:
     84         print "--> "+filename[0:len(filename)-3]+"_h.nc"
     85         filename=call_hrecast (  input_name      = [filename], \
     86                    fields  = varznames, \
     87                    predefined = 'mcs')[0]
     88
     89
    7790   # Files
    7891
  • trunk/UTIL/PYTHON/myplot.py

    r494 r502  
    722722def fmtvar (whichvar="def"):
    723723    fmtvar    =     { \
     724             "MIXED":        "%.0f",\
     725             "UPDRAFT":      "%.0f",\
     726             "DOWNDRAFT":    "%.0f",\
    724727             "TK":           "%.0f",\
    725728             # Variables from TES ncdf format
  • trunk/UTIL/PYTHON/myscript.py

    r489 r502  
    3535    parser.add_option('--trans',        action='store',dest='trans',     type="float",   default=1.,    help='shaded plot transparency, 0 to 1 (=opaque) [1]')
    3636    parser.add_option('--area',         action='store',dest='area',       type="string",   default=None,  help='area on the map to be plot [None]')
     37    parser.add_option('--xlabel',       action='store',dest='xlab',       type="string",  default=None, help='customize the x-axis label')
     38    parser.add_option('--ylabel',       action='store',dest='ylab',       type="string",  default=None, help='customize the y-axis label')
    3739
    3840    ### SPECIFIC FOR MAPPING [MAPMODE 1]
  • trunk/UTIL/PYTHON/planetoplot.py

    r494 r502  
    5959           zarea=None,\
    6060           axtime=None,\
    61            redope=None):
     61           redope=None,\
     62           xlab=None,\
     63           ylab=None):
    6264
    6365
     
    7476    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    7577    import matplotlib as mpl
    76     from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis
     78    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis, ylabel
    7779    from matplotlib.cm import get_cmap
    7880    #from mpl_toolkits.basemap import cm
     
    265267                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
    266268                elif ope == "+":   all_var[k+1]= all_var[k-1] + all_var[k]
    267                 elif ope == "-%":  all_var[k+1]= 100.*(all_var[k-1] + all_var[k])/all_var[k]
     269                elif ope == "-%":
     270                    masked = np.ma.masked_where(all_var[k] == 0,all_var[k])
     271                    masked.set_fill_value([np.NaN])
     272                    all_var[k+1]= 100.*(all_var[k-1] - masked)/masked
    268273                all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; numplot = numplot+2
    269274             elif ope in ["cat"]:
     
    440445                        else:                                             plot(what_I_plot_frame,x,label=lbl)  ## vertical profile
    441446                        if nplot > 1: legend(loc='best')
    442                         if indextime is None and axtime is not None    xlabel(axtime.upper()) ## define the right label
     447                        if indextime is None and axtime is not None and xlab is None:    xlabel(axtime.upper()) ## define the right label
    443448                        if save == 'txt':  writeascii(np.transpose(what_I_plot),'profile'+str(nplot*1000+imov)+'.txt')
    444449
     
    498503                           if ylog:      mpl.pyplot.semilogy()
    499504                           if invert_y:  ax = mpl.pyplot.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
     505                           if xlab is not None: xlabel(xlab)
     506                           if ylab is not None: ylabel(ylab)
    500507
    501508                        if mrate is not None:
  • trunk/UTIL/PYTHON/pp.py

    r489 r502  
    157157                blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\
    158158                mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\
    159                 redope=opt.redope)
     159                redope=opt.redope,xlab=opt.xlab,ylab=opt.ylab)
    160160        print 'DONE: '+name
    161161        system("rm -f to_be_erased")
Note: See TracChangeset for help on using the changeset viewer.