Changeset 721


Ignore:
Timestamp:
Jul 12, 2012, 8:02:52 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON. Added an option to set magnifying factor for winds. added support for GCM v5 files. added a handful of pretty cool background maps (titan, venus, triton, cobe, pluto). added the possibility to use div_var_only etc... instead of div_var to get only the operation plot. corrected bugs : if transparency is zero color for vectors must be set according to background not colorbar; added a line which avoid a bug with histograms and mesoscale files.

Location:
trunk/UTIL/PYTHON
Files:
4 edited

Legend:

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

    r717 r721  
    5858    if 'controle' in nc.variables:             typefile = 'gcm'
    5959    elif 'phisinit' in nc.variables:           typefile = 'gcm'
     60    elif 'phis' in nc.variables:               typefile = 'gcm'
    6061    elif 'time_counter' in nc.variables:       typefile = 'earthgcm'
    6162    elif hasattr(nc,'START_DATE'):             typefile = 'meso'
     
    744745    elif 'U' in varinfile:  [uchar,vchar] = ['U','V']   #; print "this is RAW meso file"
    745746    elif 'u' in varinfile:  [uchar,vchar] = ['u','v']   #; print "this is GCM file"
     747    elif 'vitu' in varinfile:  [uchar,vchar] = ['vitu','vitv']   #; print "this is GCM v5 file"
    746748     ### you can add choices here !
    747749    else:                   [uchar,vchar] = ['not found','not found']
     
    10681070                "gray":         "red",\
    10691071                "PuBu":         "black",\
     1072                "titan":        "red",\
    10701073                        }
    10711074        if whichone not in whichcolor:
     
    11051108                "blueclouds":  "http://eoimages.gsfc.nasa.gov/ve/2431/land_ocean_ice_cloud_2048.jpg",\
    11061109                "justclouds":  "http://eoimages.gsfc.nasa.gov/ve/2432/cloud_combined_2048.jpg",\
     1110                "pluto":       "http://www.boulder.swri.edu/~buie/pluto/pluto_all.png",\
     1111                "triton":      "http://laps.noaa.gov/albers/sos/neptune/triton/triton_rgb_cyl_www.jpg",\
     1112                "titan":       "http://laps.noaa.gov/albers/sos/saturn/titan/titan_rgb_cyl_www.jpg",\
     1113                #"titan":       "http://laps.noaa.gov/albers/sos/celestia/titan_50.jpg",\
     1114                "titanuni":    "http://maps.jpl.nasa.gov/pix/sat6fss1.jpg",\
     1115                "venus":       "http://laps.noaa.gov/albers/sos/venus/venus4/venus4_rgb_cyl_www.jpg",\
     1116                "cosmic":      "http://laps.noaa.gov/albers/sos/universe/wmap/wmap_rgb_cyl_www.jpg",\
    11071117                        }
    11081118        ### see http://www.mmedia.is/~bjj/planetary_maps.html
     
    11381148        "Sirenum_Crater_small":  [[-36.,-26.],[-168.,-156.]],\
    11391149        "Rupes":                 [[ 72., 90.],[-120.,- 20.]],\
     1150        "Xanadu":                [[-40., 20.],[  40., 120.]],\
    11401151              }
    11411152    if area not in list:   area = "Whole"
  • trunk/UTIL/PYTHON/myscript.py

    r647 r721  
    4242
    4343    ### SPECIFIC FOR MAPPING [MAPMODE 1]
    44     parser.add_option('-p', '--proj',   action='store',dest='proj',      type="string",  default=None,  help='projection')
    45     parser.add_option('-b', '--back',   action='store',dest='back',      type="string",  default=None,  help='background image [None]')
    46     parser.add_option('-W', '--winds',  action='store_true',dest='winds',                default=False, help='wind vectors [False]')
    47     parser.add_option('-s', '--stride', action='store',dest='ste',       type="int",     default=3,     help='stride vectors [3]')
    48     parser.add_option('-z', '--zoom',   action='store',dest='zoom',      type="float",   default=None,  help='zoom factor in %')
    49     parser.add_option('--blat',         action='store',dest='blat',      type="int",     default=None,  help='reference lat (or bounding lat for stere) [computed]')
    50     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 lon,lat [None]')
     44    parser.add_option('-p',  '--proj',     action='store',dest='proj',      type="string",  default=None,  help='projection')
     45    parser.add_option('-b',  '--back',     action='store',dest='back',      type="string",  default=None,  help='background image [None]')
     46    parser.add_option('-W',  '--winds',    action='store_true',dest='winds',                default=False, help='wind vectors [False]')
     47    parser.add_option('--facwind',         action='store',dest='facwind',   type="float",   default=1,     help='wind vectors magnifying factor [1]')
     48    parser.add_option('-s',  '--stride',   action='store',dest='ste',       type="int",     default=3,     help='stride vectors [3]')
     49    parser.add_option('-z',  '--zoom',     action='store',dest='zoom',      type="float",   default=None,  help='zoom factor in %')
     50    parser.add_option('--blat',            action='store',dest='blat',      type="int",     default=None,  help='reference lat (or bounding lat for stere) [computed]')
     51    parser.add_option('--blon',            action='store',dest='blon',      type="int",     default=None,  help='reference lon [computed]')
     52    parser.add_option('--mark',            action='append',dest='mark',  type="string",  default=None, help='superimpose a crossmark at given lon,lat [None]')
    5253
    5354    ### SPECIFIC FOR SLICING [MAPMODE 0]
     
    6667
    6768    ### OPERATIONS BETWEEN FILES
    68     parser.add_option('--operation',    action='store',dest='operat',  type="string",  default=None,  help='operation to perform on input files given through -f. "+" or "-" acts on each input file by adding or substracting the ref file specified through --fref. "cat" acts on all input files in-a-row. "add_var" "sub_var" "mul_var" "div_var" acts on two variables.')
     69    parser.add_option('--operation',    action='store',dest='operat',  type="string",  default=None,  help='operation to perform on input files given through -f. "+" or "-" acts on each input file by adding or substracting the ref file specified through --fref. "cat" acts on all input files in-a-row. "add_var" "sub_var" "mul_var" "div_var" acts on two variables (add _only to get only operation plot).')
    6970    parser.add_option('--fref',         action='store',dest='fref',    type="string",  default=None,  help='reference namefile for the --operation option.')
    7071    parser.add_option('--mope',         action='store',dest='vminope', type="float",   default=0.,  help='bounding minimum value for inter-file operation')
  • trunk/UTIL/PYTHON/planetoplot.py

    r718 r721  
    6767           lstyle=None,\
    6868           cross=None,\
     69           facwind=1.,\
    6970           streamflag=False):
    7071
     
    190191          elif "lon" in nc.variables:     lon = nc.variables["lon"][:]
    191192          ### ALT
    192           if "altitude" in nc.variables:  vert = nc.variables["altitude"][:]
    193           elif "Alt" in nc.variables:     vert = nc.variables["Alt"][:]
    194           elif "lev" in nc.variables:     vert = nc.variables["lev"][:]
    195           else:                           vert = [0.]
     193          if "altitude" in nc.variables:   vert = nc.variables["altitude"][:]
     194          elif "Alt" in nc.variables:      vert = nc.variables["Alt"][:]
     195          elif "lev" in nc.variables:      vert = nc.variables["lev"][:]
     196          elif "presnivs" in nc.variables: vert = nc.variables["presnivs"][:]
     197          else:                            vert = [0.]
    196198          ### AIRE (to weight means with the area)
    197199          if "aire" in nc.variables:      area = nc.variables["aire"][:,:] 
     
    364366             if len(namefiles) > 1: errormess("for this operation... please set only one file !") 
    365367             if len(var) > 2:       errormess("not sure this works for more than 2 vars... please check.")
    366              if   ope in ["div_var"]: all_var[k] = all_var[k-2] / all_var[k-1] ; insert = '_div_'
    367              elif ope in ["mul_var"]: all_var[k] = all_var[k-2] * all_var[k-1] ; insert = '_mul_'
    368              elif ope in ["add_var"]: all_var[k] = all_var[k-2] + all_var[k-1] ; insert = '_add_'
    369              elif ope in ["sub_var"]: all_var[k] = all_var[k-2] - all_var[k-1] ; insert = '_sub_'
     368             if   "div_var" in ope: all_var[k] = all_var[k-2] / all_var[k-1] ; insert = '_div_'
     369             elif "mul_var" in ope: all_var[k] = all_var[k-2] * all_var[k-1] ; insert = '_mul_'
     370             elif "add_var" in ope: all_var[k] = all_var[k-2] + all_var[k-1] ; insert = '_add_'
     371             elif "sub_var" in ope: all_var[k] = all_var[k-2] - all_var[k-1] ; insert = '_sub_'
    370372             else:                    errormess(ope+" : non-implemented operation. Check pp.py --help")
    371373             numplot = numplot + 1 ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1]
    372374             all_varname[k] = all_varname[k-2] + insert + all_varname[k-1]
     375             ### only the operation plot
     376             if "only" in ope:
     377                 numplot = 1 ; all_var[0] = all_var[k]
     378                 all_time[0] = all_time[k] ; all_namefile[0] = all_namefile[k]
     379                 all_varname[0] = all_varname[k-2] + insert + all_varname[k-1]
     380
     381
    373382    ##################################
    374383    ### Open a figure and set subplots
     
    604613                                key = False
    605614                            if metwind and mapmode == 1:   [vecx_frame,vecy_frame] = m.rotate_vector(vecx_frame, vecy_frame, lon2d, lat2d)
    606                             if var:       colorvec = definecolorvec(colorb)
    607                             else:         colorvec = definecolorvec(back)
     615                            if trans != 0.0:   colorvec = definecolorvec(colorb)
     616                            else:              colorvec = definecolorvec(back)
    608617                            vectorfield(vecx_frame, vecy_frame, x, y, stride=stride, csmooth=2,\
    609618                                             #scale=15., factor=300., color=colorvec, key=key)
    610                                              scale=20., factor=250., color=colorvec, key=key)
     619                                             scale=20., factor=250./facwind, color=colorvec, key=key)
    611620                                                              #200.         ## or csmooth=stride
     621                        ### THIS IS A QUITE SPECIFIC PIECE (does not work for mesoscale files)
    612622                        if ope == '-' and nplot == numplot: # this should work as long as ope is '-' guarantees 3 plots for 4 panels without contour
    613623                            subplot(subv,subh,nplot+1)
     
    616626                                latmin = -50.; latmax = 50. # latitude range for histogram of difference
    617627                                zeindexlat = (lat<latmax)*(lat>latmin)
     628                                if typefile in ['meso']: zeindexlat = 10
    618629                                # this follows the define_axis logic in myplot.py:
    619630                                if indextime is None or indexlon is None: what_I_plot_frame = what_I_plot_frame[zeindexlat,:]
     
    633644                        zevminc, zevmaxc = calculate_bounds(what_I_plot_frame, vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame))
    634645                        zelevels = np.linspace(zevminc,zevmaxc,ticks/2) #20)
    635                         if var2 == 'HGT':     zelevels = np.arange(-10000.,30000.,1000.)
    636                         elif var2 == 'tpot':  zelevels = np.arange(270,370,5)
    637                         elif var2 == 'tk':    zelevels = np.arange(150,250,5)
     646                        ### another dirty specific stuff in the wall
     647                        if var2 == 'HGT':        zelevels = np.arange(-10000.,30000.,1000.)
     648                        elif var2 == 'tpot':     zelevels = np.arange(270,370,5)
     649                        elif var2 == 'tk':       zelevels = np.arange(150,250,5)
     650                        elif var2 == 'wstar':    zelevels = np.arange(0,10,1.0)
     651                        elif var2 == 'zmax_th':  zelevels = np.arange(0,10,2.0) ; what_I_plot_frame = what_I_plot_frame / 1000.
     652                        ###
    638653                        if mapmode == 0:   
    639654                            what_I_plot_frame, x, y = define_axis( lonyeah,latyeah,vert,time,indexlon,indexlat,indexvert,\
     
    641656                            ## is this needed? only if len(all_var2[index_f].shape) != len(all_var[index_f].shape)
    642657                            cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33)#, alpha=0.5, linestyles='solid')
     658                            #cs = contour( x,y,what_I_plot_frame, zelevels, colors='w', linewidths = 0.5)#, alpha=0.5, linestyles='solid')
    643659                            clabel(cs, inline=1, fontsize = 4.*rcParams['font.size']/5., fmt=fmtvar(var2.upper()))
    644                         elif mapmode == 1:  cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33)#, alpha=0.5, linestyles='solid')
     660                        elif mapmode == 1: 
     661                            cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33)#, alpha=0.5, linestyles='solid')
     662                            #clabel(cs, inline=0, fontsize = rcParams['font.size'], fmt="%.0f") #fmtvar(var2.upper()))
    645663                    if which in ["regular","unidim"]:
    646664
     
    738756    ###
    739757       zeplot = prefix + basename
     758       if zoom:            zeplot = zeplot + "zoom"+str(abs(zoom))
    740759       if addchar:         zeplot = zeplot + addchar
    741760       if numplot <= 0:    zeplot = zeplot + "_LT"+str(abs(numplot))
  • trunk/UTIL/PYTHON/pp.py

    r647 r721  
    2323    ### Get options and variables
    2424    parser = OptionParser() ; getparseroptions(parser) ; (opt,args) = parser.parse_args()
    25     if opt.file is None:                                errormess("I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h")
     25    if opt.file is None:                                errormess("I want to eat one file at least ! Use pp.py -f name_of_my_file. Or type pp.py -h")
    2626    if opt.var is None and opt.anomaly is True:         errormess("Cannot ask to compute anomaly if no variable is set")
    2727    if opt.fref is not None and opt.operat is None:     errormess("you must specify an operation when using a reference file")
     
    6161      else:                                       
    6262          [lschar,zehour,zehourin] = ["",0,0]
    63           if opt.var is None:  opt.var = ["phisinit"] ; opt.clb = "nobar"
     63          if opt.var is None: 
     64             opt.var = ["phisinit"] ; opt.clb = "nobar"
     65             ### temporaire... en attendant mieux.
     66             if opt.back == "titan": opt.var = ["phis"] ; opt.clb = "nobar"
    6467
    6568      if opt.vmin is not None : zevmin  = opt.vmin[min(i,len(opt.vmin)-1)]
     
    172175                mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\
    173176                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),streamflag=opt.stream)
     177                lstyle=separatenames(opt.linestyle),cross=readslices(opt.mark),facwind=opt.facwind,streamflag=opt.stream)
    175178        print 'DONE: '+name
    176179        system("rm -f to_be_erased")
Note: See TracChangeset for help on using the changeset viewer.