Changeset 489


Ignore:
Timestamp:
Dec 21, 2011, 3:22:19 PM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON : 1) no more negative values for --time but use --axtime lt ; this actually fix a stupid bug with negative lat lon. 2) use of -l is now possible with GCM files, try it with -i 2. 3) now correct handling of sol/ls in mesoscale files 4) for mesoscale files with chosen lat+lon now shows a topo map with a cross on it.

Location:
trunk/UTIL/PYTHON
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/README.PP

    r483 r489  
    8484[only mesoscale for the moment]
    8585Goal: I want to plot results for two different LOCAL times in the file next to one another
    86 pp.py -f wrfout**** -v TSURF --time -4 -- time -7
     86pp.py -f wrfout**** -v TSURF --time 4 -- time 7 --axtime lt
    8787
    8888***********************************************************************************
  • trunk/UTIL/PYTHON/gcm_transformations.py

    r466 r489  
    99                    input_name      = None, \
    1010                    fields  = 'all', \
     11                    limites = None, \
    1112                    predefined = None):
    1213
     
    2122    outputfilename=""
    2223    f = open('zrecast.auto.def', 'w')
     24
    2325    for zfile in input_name:
    2426        f.write(zfile+"\n")
     
    5254                f.write("1"+"\n")
    5355                f.write("yes"+"\n")
    54                 f.write("370 0.1"+"\n")
     56                if limites[0] != -9999.:  f.write(str(limites[0])+" "+str(limites[-1])+"\n")
     57                else:                     f.write("370 0.1"+"\n")
     58                #f.write("1000000 100"+"\n")
    5559                f.write("20"+"\n")
    5660        else:
  • trunk/UTIL/PYTHON/myplot.py

    r483 r489  
    284284    nc  = Dataset(namefile)
    285285    zetime = None
     286    days_in_month = [61, 66, 66, 65, 60, 54, 50, 46, 47, 47, 51, 56]
     287    plus_in_month = [ 0, 61,127,193,258,318,372,422,468,515,562,613]
    286288    if 'Times' in nc.variables:
    287289        zetime = nc.variables['Times'][0]
     
    290292    if zetime is not None \
    291293       and 'vert' not in nc.variables:
    292         #### strangely enough this does not work for api or ncrcat results!
    293         zetimestart = getattr(nc, 'START_DATE')
    294         zeday = int(zetime[8]+zetime[9]) - int(zetimestart[8]+zetimestart[9]) - 1 ###?
    295         if zeday < 0:    dals = -99    ## might have crossed a month... fix soon
    296         else:            dals = int( 10. * sol2ls ( getattr( nc, 'JULDAY' ) + zeday ) ) / 10.
    297         if not getaxis:  lschar = "_Ls"+str(dals)
     294        ##### strangely enough this does not work for api or ncrcat results!
     295        zesol = plus_in_month[ int(zetime[5]+zetime[6])-1 ] + int(zetime[8]+zetime[9]) - 1 ##les sols GCM commencent a 0
     296        dals = int( 10. * sol2ls ( zesol ) ) / 10.
    298297        ###
    299298        zetime2 = nc.variables['Times'][1]
     
    302301        zehour    = one
    303302        zehourin  = abs ( next - one )
    304         ### A CORRIGER POUR LES SOLS IL FAUT LIRE LE MONTH !!!!
    305         if getaxis:
     303        if not getaxis:
     304            lschar = "_Ls"+str(dals)
     305        else:
    306306            zelen = len(nc.variables['Times'][:])
    307307            yeye = range(zelen) ; lsaxis = range(zelen) ; solaxis = range(zelen) ; ltaxis = range(zelen)
    308308            for iii in yeye:
    309                zetime = nc.variables['Times'][iii] ; zetimestart = getattr(nc, 'START_DATE')
    310                zeday = int(zetime[8]+zetime[9]) - int(zetimestart[8]+zetimestart[9]) - 1
     309               zetime = nc.variables['Times'][iii]
    311310               ltaxis[iii] = int(zetime[11]+zetime[12]) + int(zetime[14]+zetime[15])/37.
    312                solaxis[iii] = getattr( nc, 'JULDAY' ) + zeday +  ltaxis[iii] / 24.
     311               solaxis[iii] = ltaxis[iii] / 24. + plus_in_month[ int(zetime[5]+zetime[6])-1 ] + int(zetime[8]+zetime[9]) - 1 ##les sols GCM commencent a 0
    313312               lsaxis[iii] = sol2ls ( solaxis[iii] )
    314313               if ltaxis[iii] < ltaxis[iii-1]: ltaxis[iii] = ltaxis[iii] + 24.
    315                #print ltaxis[iii], solaxis[iii], lsaxis[iii]
     314               #print ltaxis[iii], solaxis[iii], lsaxis[iii], getattr( nc, 'JULDAY' )
    316315            lschar = lsaxis ; zehour = solaxis ; zehourin = ltaxis
    317316    else:
     
    982981      print idx,idy,lat2d[idy,idx],vlat
    983982      var = file.variables["HGT"][:,:,:]
    984       mpl.contourf(var[0,:,:],30,cmap = mpl.get_cmap(name="Greys_r") ) ; mpl.axis('off') ; mpl.plot(idx,idy,'bo')
     983      mpl.contourf(var[0,:,:],30,cmap = mpl.get_cmap(name="Greys_r") ) ; mpl.axis('off') ; mpl.plot(idx,idy,'mx',mew=4.0,ms=20.0)
    985984      mpl.show()
    986985   return idy,idx
     
    991990# output : all indexes to be taken into account for reducing field
    992991  import numpy as np
    993   ### added by AS to treat the case of stime = - LT
    994   if saxis is not None:
    995       if saxis[0][0] < 0: saxis = - saxis
    996   ###
    997992  if ( np.array(axis).ndim == 2):
    998993      axis = axis[:,0]
  • trunk/UTIL/PYTHON/myscript.py

    r483 r489  
    5050    parser.add_option('--vert',         action='append',dest='svert',  type="string",  default=None, help='slices along vert. 2 comma-separated values: averaging')
    5151    parser.add_option('--column',       action='store_true',dest='column',             default=False,help='changes --vert z1,z2 from MEAN to INTEGRATE along z')
    52     parser.add_option('--time',         action='append',dest='stime',  type="string",  default=None, help='slices along time. 2 comma-separated values: averaging. negative: local time [meso].')
     52    parser.add_option('--time',         action='append',dest='stime',  type="string",  default=None, help='slices along time. 2 comma-separated values: averaging')
    5353    parser.add_option('--xmax',         action='store',dest='xmax',    type="float",   default=None, help='max value for x-axis in contour-plots [max(xaxis)]')
    5454    parser.add_option('--ymax',         action='store',dest='ymax',    type="float",   default=None, help='max value for y-axis in contour-plots [max(yaxis)]')
     
    5757    parser.add_option('--inverty',      action='store_true',dest='inverty',            default=False,help='force decreasing values along y-axis (e.g. p-levels)')
    5858    parser.add_option('--logy',         action='store_true',dest='logy',               default=False,help='set y-axis to logarithmic')   
    59     parser.add_option('--axtime',       action='store',dest='axtime',  type="string",  default=None, help='choose "ls" or "sol" for time reference')
     59    parser.add_option('--axtime',       action='store',dest='axtime',  type="string",  default=None, help='choose "ls","sol","lt" for time ref (1D or --time)')
    6060
    6161    ### OPERATIONS BETWEEN FILES
  • trunk/UTIL/PYTHON/planetoplot.py

    r485 r489  
    7474    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    7575    import matplotlib as mpl
    76     from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel
     76    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis
    7777    from matplotlib.cm import get_cmap
    7878    import numpy as np
     
    147147      if ((proj == None) and (typefile not in ['mesoideal'])):   proj = getproj(nc)                 
    148148
    149 ##########################################################
     149      if firstfile:
     150         ##########################
     151         ### Define plot boundaries
     152         ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole")
     153         if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d)
     154         elif proj in ["lcc","laea"]:      [wlon,wlat] = wrfinterv(lon2d,lat2d)
     155         else:                             [wlon,wlat] = simplinterv(lon2d,lat2d)
     156         if zoom:                          [wlon,wlat] = zoomset(wlon,wlat,zoom)
     157         elif zarea is not None: [wlon,wlat] = latinterv(area=zarea)
     158
     159########################################################## LOAD 4D DIMENSIONS : x, y, z, t
    150160      if typefile == "gcm":
    151161          lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:]
     
    158168          ### the following lines are kind of dirty... not possible to ask for several lats and lons
    159169          if vlon is not None or vlat is not None:   
    160               indices = bidimfind(lon2d,lat2d,vlon,vlat) #,file=nc)  #placer un point sur carte
     170              if firstfile:  iwantawhereplot = nc
     171              else:          iwantawhereplot = None
     172              indices = bidimfind(lon2d,lat2d,vlon,vlat,file=iwantawhereplot)  #placer un point sur carte
    161173              lonp,latp = ( lon2d[indices[0],indices[1]] , lat2d[indices[0],indices[1]] )
    162174          if typefile in ['mesoapi','meso'] and mapmode == 1: lon2d = dumpbdy(lon2d,6) ; lat2d = dumpbdy(lat2d,6)  ### important to do that now and not before
     
    183195              elif "Time" in nc.variables:  time = count + np.arange(0,len(nc.variables["Time"]),1)
    184196              else:                         time = count + np.arange(0,1,1)
    185               count = time[-1] + 1  ## so that a cat is possible with simple subscripts
     197              if nnn > 0:  count = time[-1] + 1  ## so that a cat is possible with simple subscripts
     198              else:        count = 0
     199          if axtime in ["lt"]:
     200              for i in range(len(time)):  time[i] = localtime ( interv[0]+time[i]*interv[1], 0.5*(wlon[0]+wlon[1]) )
     201              print "LOCAL TIMES.... ", time
    186202          ###
    187203          if typefile in ['geo']:   vert = [0.] ; stime = readslices(str(0))
     
    198214       ## Faire d'autre checks sur les compatibilites entre fichiers!!
    199215##########################################################
    200 
    201       if firstfile:
    202          ##########################
    203          ### Define plot boundaries
    204          ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole")
    205          if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d)
    206          elif proj in ["lcc","laea"]:      [wlon,wlat] = wrfinterv(lon2d,lat2d)
    207          else:                             [wlon,wlat] = simplinterv(lon2d,lat2d)
    208          if zoom:                          [wlon,wlat] = zoomset(wlon,wlat,zoom)
    209          elif zarea is not None: [wlon,wlat] = latinterv(area=zarea)
    210216
    211217      all_varname[k] = varname
     
    246252                    if var2: tab2 = np.append(tab2,all_var2[k],axis=0)
    247253                    tabtime = np.append(tabtime,all_time[k]) ; tab = np.append(tab,all_var[k],axis=0) ; k += 1
    248                 #all_time[0] = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better
    249254                all_time[0] = np.array(tabtime) ; all_var[0] = np.array(tab) ; numplot = 1
    250255                if var2: all_var2[0] = np.array(tab2)
     
    287292       else:                            yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah
    288293       time = all_time[index_f]
    289        if stime is not None:
    290            if stime[0][0] < 0:
    291                if typefile in ['mesoapi','meso']:
    292                    for i in range(len(time)):  time[i] = localtime ( interv[0]+time[i]*interv[1], 0.5*(wlon[0]+wlon[1]) )
    293                    print "OK... WORKING WITH LOCAL TIMES"
    294                else: errormess("local times not supported. not too hard to modify the code though.")
    295294       if mrate is not None:                 indextime = None
    296295       else:                                 indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time)
     
    298297       if typefile in ['mesoapi','meso'] and indextime is not None:  ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 
    299298       print "********** INDEX LON:",indexlon," LAT:",indexlat," VERT:",indexvert," TIME:",indextime
     299       #var = nc.variables["phisinit"][:,:]
     300       #contourf(np.transpose(var),30,cmap = get_cmap(name="Greys_r") ) ; axis('off') ; plot(indexlat,indexlon,'mx',mew=4.0,ms=20.0)
     301       #show()
     302       #exit()
    300303       ####################################################################
    301304       ########## REDUCE FIELDS
     
    337340               if colorb in ["def","nobar"]:                           palette = get_cmap(name=defcolorb(fvar.upper()))
    338341               else:                                                   palette = get_cmap(name=colorb)
    339                ##### 1. ELIMINATE >3D CASES
    340                if len(what_I_plot.shape) >= 4:
     342               ##### 1. ELIMINATE 0D or >3D CASES
     343               if len(what_I_plot.shape) == 0:   
     344                 print "VALUE VALUE VALUE VALUE ::: ",what_I_plot
     345                 save = 'donothing'
     346               elif len(what_I_plot.shape) >= 4:
    341347                 print "WARNING!!! ",len(what_I_plot.shape),"-D PLOT NOT SUPPORTED !!! dimensions: ",what_I_plot.shape
    342348                 errormess("Are you sure you did not forget to prescribe a dimension ?")
     
    542548        elif save in ['eps','svg','pdf']:     makeplotres(zeplot,pad_inches_value=pad_inches_value,disp=False,ext=save)
    543549        elif save == 'gui':                   show()
     550        elif save == 'donothing':             pass
    544551        elif save == 'txt':                   print "Saved results in txt file."
    545552        else:
  • trunk/UTIL/PYTHON/pp.py

    r483 r489  
    4444        yeah = glob.glob(opt.file[0]) ; yeah.sort()
    4545        opt.file[0] = yeah[0]
    46         for file in yeah: opt.file[0] = opt.file[0] + "," + file
     46        for file in yeah[1:]: opt.file[0] = opt.file[0] + "," + file
    4747
    4848    #############################
     
    7979            zelevel = float(inputnvert[0])
    8080            ze_interp_levels = [-9999.]
     81        elif np.array(inputnvert).size == 2:
     82            zelevel = -99.
     83            ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),20)
    8184        else:
    8285            zelevel = -99.
     
    122125                    input_name=zefiles,\
    123126                    fields=inputvar,\
     127                    limites = ze_interp_levels,\
    124128                    predefined=opt.intas)
    125129
Note: See TracChangeset for help on using the changeset viewer.