Changeset 1277 in lmdz_wrf for trunk


Ignore:
Timestamp:
Nov 8, 2016, 12:15:59 AM (8 years ago)
Author:
lfita
Message:

Improving `draw_Neighbourghood_evol'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1274 r1277  
    2929## e.g. # $ drawing.py -f WRF/current/hurs_wrfout_tturb_xmean_last.nc,WRF/micro1/hurs_wrfout_tturb_xmean_last.nc,WRF/micro2/hurs_wrfout_tturb_xmean_last.nc,WRF_LMDZ/AR40/hurs_wrfout_tturb_xmean_last.nc,WRF_LMDZ/NPv31/hurs_wrfout_tturb_xmean_last.nc,LMDZ/AR40/hurs_reproj-histins_tturb_xmean_last.nc,LMDZ/NPv31/hurs_reproj-histins_tturb_xmean_last.nc -o draw_lines -S 'lat:x:lat ($degrees\ North$):auto:wcurr,wmp1,wmp2,wlmdza,wlmdzb,lmdza,lmdzb:hurs:all model-experiments meridional hurs$_{[tturb\ xmean\ last]}$:0|auto:None:-:,:2.:2.:all:Nlines_hurs_wrfout_tturb-xmean-last:png:True' -v hursturbmean
    3030## e.g. # drawing.py -o draw_lines_time -f wrfout_d01_2001-11-11_00:00:00_west_east_B20-E20-I1_south_north_B20-E20-I1.nc,wrfout_d01_2001-11-11_00:00:00_west_east_B25-E25-I1_south_north_B25-E25-I1.nc,wrfout_d01_2001-11-11_00:00:00_west_east_B35-E35-I1_south_north_B35-E35-I1.nc -S 'WRFtime;y;time ([DD]${[HH]}$);auto;we=20$\times$sn=20,we=25$\times$sn=25,we=35$\times$sn=35;tas;tas|evolution|at|3|different|grid|points;None;time|hours!since!1949-12-01_00:00:00|exct,3,h|%d$^{%H}$;0|12;pdf;-;r,g,b;.;2.;2.;all;-1;True' -v T2
     31## e.g. # drawing.py -o draw_Neighbourghood_evol -S 'vas:Time|-1|WRFtime,south_north|44|XLAT,west_east|88|XLONG:south_north,west_east:5:auto:time|($[DD]^{[HH]}$),time|($[DD]^{[HH]}$):exct,1,h|exct,3,h:$%d^{%H}$,$%d^{%H}$:5|pts|neighbourghood|temporal|evolution|on|2001|Nov.|at|x=88,|y=44:0.0,20.:rainbow,auto,auto:auto:png:vas_Neigh_evol:True' -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -v V10
    3132
    3233
     
    26662667      filen= netCDF file name
    26672668      values= [gvarname]:[dimsval]:[neigdims]:[Nneig]:[Ncol]:[timetits]:[tkinds]:
    2668        [timefmts]:[gtitle]:[shadxtrms]:[cbar]:[gkind]:[ofile]
     2669       [timefmts]:[gtitle]:[shadxtrms]:[colobarvals]:[neighlinevals]:[gkind]:[ofile]:[close]
     2670        [gvarname]: ':' list of names of the variables in the plot
    26692671        [dimsval]: [dimn1]|[val1]|[dimv1],...,[dimnN]|[valN]|[dimvN] dimension names, values to get
    26702672          (-1, for all; no name/value pair given full length) and variable with values of the dimension
     2673          'WRFtime' for WRF times
    26712674          NOTE: when dimsval[X,Y] == neigdims[X,Y], valX,valY --> valX,valY-Nneig/2, valX,valY+Nneig/2
    26722675        [neigdims]: [dimnX],[dimnY] dimensions mnames along which the neigbourghood should be defined
     
    26832686        [timefmts]: [tfmtX],[tfmtY] format of the time labels
    26842687        [gtitle]: title of the graphic ('|' for spaces)
    2685         [shadxtrms]: Extremes for the shading
    2686         [cbar]: colorbar to use
     2688        [shadxtrms]: minimum and maximum value for the shading or:
     2689          'Srange': for full range
     2690          'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
     2691          'Saroundminmax@val': for min*val,max*val
     2692          'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
     2693            percentile_(100-val)-median)
     2694          'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
     2695          'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
     2696          'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
     2697             percentile_(100-val)-median)
     2698        [colorbarvals]=[colbarn],[fmtcolorbar],[orientation] characteristics of the colormap and colorbar
     2699          [colorbarn]: name of the color bar
     2700          [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
     2701          [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal')
     2702        [neighlinevals]=[linecol],[linestyle],[linewidth] characterisitcs of the lines to mark the limits of the neighborhood
     2703          ('auto' for: ['#646464', '-', 2.])
     2704          [linecol]: color of the line
     2705          [linestyle]: style of the line
     2706          [linewidth]: width of the line
    26872707        [gkind]: kind of graphical output
    26882708        [ofile]: True/False whether the netcdf with data should be created or not
     2709        [close]: Whether figure should be finished or not
    26892710      variable= name of the variable
    26902711      values = 'q:Time|-1|Times,bottom_top|6|ZNU,south_north|3|XLAT,west_east|26|XLONG:south_north,west_east:5:auto:time|($[DD]^{[HH]}$),time|($[DD]^{[HH]}$):exct,2,h|exct,1,d:$%d^{%H}$,$%d^{%H}$:5|pts|neighbourghood|temporal|evolution:0.0,0.004:BuPu:pdf:True'
     
    26992720
    27002721    expectargs = '[gvarname]:[dimsval]:[neigdims]:[Nneig]:[Ncol]:' +                 \
    2701       '[timetits]:[tkinds]:[timefmts]:[gtitle]:[shadxtrms]:[cbar]:[gkind]:[ofile]'
     2722      '[timetits]:[tkinds]:[timefmts]:[gtitle]:[shadxtrms]:[colorbarvals]:' +        \
     2723      '[neighlinevals]:[gkind]:[ofile]:[close]'
    27022724 
    27032725    drw.check_arguments(fname,values,expectargs,':')
     
    27132735    gtitle = values.split(':')[8].replace('|',' ')
    27142736    shadxtrms = values.split(':')[9].split(',')
    2715     cbar = values.split(':')[10]
    2716     gkind = values.split(':')[11]
    2717     ofile = values.split(':')[12]
     2737    colorbarvals = values.split(':')[10]
     2738    neighlinevals = values.split(':')[11]
     2739    gkind = values.split(':')[12]
     2740    ofile = values.split(':')[13]
     2741    close = gen.Str_Bool(values.split(':')[14])
    27182742
    27192743    if Ncol0 != 'auto':
     
    27272751    if np.mod(Nneig,2) == 0:
    27282752        print errormsg
    2729         print '  ' + fname + ": an odd value for 'Nneig':",Nneig,'is required !!!'
     2753        print '  ' + fname + ": an odd value for 'Nneig':", Nneig, 'is required !!!'
    27302754        quit(-1)
    27312755
     
    27562780            slicevar.append(slice(0, dimsize+1))
    27572781            newdimn.append(dimn)
    2758             newdimsvar[dimn] = dimseize
     2782            newdimsvar[dimn] = dimsize
    27592783
    27602784        for dimslicen in dimvslice.keys():
     
    27952819            dimtime = dim1
    27962820
     2821    # Number of columns and rows
    27972822    if Ncol == 'auto':
    2798         dimtsqx = int(np.sqrt(dimt)) + 1
    2799         dimtsqy = int(np.sqrt(dimt)) + 1
     2823        dimtsqx = int(np.sqrt(dimt))
    28002824    else:
    28012825        dimtsqx = int(Ncol)
    2802         dimtsqy = dimt/dimtsqx + 1
     2826
     2827    dimtsqy = dimt/dimtsqx + 1
     2828    print '  ' + fname + '; plotting ', dimtsqx, 'x', dimtsqy, 'time-windows of:',   \
     2829      Nneig, 'x', Nneig, 'grid-points'
    28032830
    28042831    neighbourghood = np.ones((dimtsqy*Nneig,dimtsqx*Nneig), dtype=np.float)*fillValue
     
    28212848
    28222849# Time values at the X/Y axes
    2823     if ncobj.variables[dimvvalues[dimtime]].dtype == '|S1':
    2824         print '    ' + fname + ': WRF time variable!'
     2850    if dimvvalues[dimtime] == 'WRFtime':
     2851        print '    ' + fname + ": WRF time variable!: 'Times'"
    28252852        refdate = '19491201000000'
    28262853        tunitsval = 'hours'
    28272854        dimtvalues = np.zeros((dimt), dtype=np.float)
    2828         tvals = ncobj.variables[dimvvalues[dimtime]]
     2855        tvals = ncobj.variables['Times']
    28292856        yrref=refdate[0:4]
    28302857        monref=refdate[4:6]
     
    28682895        newnc.close()
    28692896        print fname + ": Successfull generation of file '" + ofilen + "' !!"
     2897# Colorbar values
     2898    colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',')
     2899    colormapv = [colbarn, fmtcolbar, colbaror]
     2900
     2901# Neighborhood line values
     2902    if neighlinevals == 'auto':
     2903        neiglinev = ['#646464', '-', 2.]
     2904    else:
     2905        neiglinev = neighlinevals.split(',')
    28702906
    28712907# Time ticks
     
    28812917
    28822918    drw.plot_Neighbourghood_evol(neighbourghood, dimxv, dimyv, gvarname, timetits,   \
    2883       timepos, timelabels, cbar, Nneig, shadxtrms, vunits, gtitle, gkind, True)
     2919      timepos, timelabels, colormapv, neiglinev, Nneig, shadxtrms, vunits, gtitle,   \
     2920      gkind, close)
    28842921
    28852922def draw_points(filen, values):
     
    50535090    varn=opts.varname
    50545091    oper=opts.operation
     5092
     5093    if opts.operation is None:
     5094        print errormsg
     5095        print '  No operation provided !!'
     5096        print "  an operation must be provided as '-o [operationname]' "
     5097        quit(-1)
    50555098
    50565099    if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and                   \
  • trunk/tools/drawing_tools.py

    r1274 r1277  
    55605560    return
    55615561
    5562 def plot_Neighbourghood_evol(varsv, dxv, dyv, vnames, ttits, tpos, tlabels, colorbar, \
    5563   Nng, vs, uts, gtit, kfig, ifclose):
     5562def plot_Neighbourghood_evol(varsv, dxv, dyv, vnames, ttits, tpos, tlabels, cbarv,  \
     5563  neighv, Nng, vs, uts, gtit, kfig, ifclose):
    55645564    """ Plotting neighbourghood evolution
    55655565      varsv= 2D values to plot with shading
     
    55695569      tpos= positions of the time ticks
    55705570      tlabels= labels of the time ticks
    5571       colorbar= name of the color bar to use
     5571      cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror]
     5572        colorbar: name of the color bar to use
     5573        cbarfmt: format of the numbers in the colorbar
     5574        cbaror: orientation of the colorbar
     5575      neighv = list with the parameters for the lines of the limits of the neighborhood [color, style, width]
    55725576      Nng= Number of grid points of the full side of the box (odd value)
    55735577      vs= minmum and maximum values to plot in shadow or:
     
    56715675
    56725676#    plt.pcolormesh(dxv, dyv, varsv, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1])
    5673     plt.pcolormesh(varsvmask, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1])
    5674     cbar = plt.colorbar()
    5675 
    5676     newtposx = (tpos[0][:] - np.min(dxv)) * len(dxv) * Nng / (np.max(dxv) - np.min(dxv))
    5677     newtposy = (tpos[1][:] - np.min(dyv)) * len(dyv) * Nng / (np.max(dyv) - np.min(dyv))
    5678 
    5679     plt.xticks(newtposx, tlabels[0])
    5680     plt.yticks(newtposy, tlabels[1])
     5677    plt.pcolormesh(varsvmask, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0], vmax=vsend[1])
     5678    if cbarv[2] == 'horizontal':
     5679        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
     5680        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
     5681        ticklabels= cbar.ax.get_xticklabels()
     5682        Nticks = len(ticklabels)
     5683        ticklabs = []
     5684        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
     5685        cbar.ax.set_xticklabels(ticklabs,rotation=90)
     5686    else:
     5687        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
     5688
     5689    newtposx = (tpos[0][:] - np.min(dxv)) * (len(dxv)-1) * Nng / (np.max(dxv) -      \
     5690      np.min(dxv))
     5691    newtposy = (tpos[1][:] - np.min(dyv)) * (len(dyv)-1) * Nng / (np.max(dyv) -      \
     5692      np.min(dyv))
     5693
     5694    plt.xlim(np.min(newtposx), np.max(newtposx))
     5695    plt.ylim(np.min(newtposy), np.max(newtposy)+Nng)
     5696
     5697    # Plotting neighborhood boundaries
     5698    Nng2 = Nng/2.
     5699    for iy in range(len(dyv)):
     5700        plt.plot([np.min(newtposx),np.max(newtposx)], [newtposy[iy],newtposy[iy]],   \
     5701          linestyle=neighv[1], color=neighv[0], linewidth=neighv[2])
     5702    for ix in range(len(dxv)):
     5703        plt.plot([newtposx[ix],newtposx[ix]],[np.min(newtposy),np.max(newtposy)+Nng],\
     5704          linestyle=neighv[1], color=neighv[0], linewidth=neighv[2])
     5705    # Plotting center
     5706    for iy in range(len(dyv)):
     5707        for ix in range(len(dxv)):
     5708            plt.plot([newtposx[ix]+Nng2,newtposx[ix]+Nng2], [newtposy[iy]+Nng2-0.125,\
     5709              newtposy[iy]+Nng2+0.125], linestyle=neighv[1], color=neighv[0],        \
     5710              linewidth=neighv[2])
     5711            plt.plot([newtposx[ix]+Nng2-0.125,newtposx[ix]+Nng2+0.125],              \
     5712              [newtposy[iy]+Nng2,newtposy[iy]+Nng2], linestyle=neighv[1],            \
     5713              color=neighv[0], linewidth=neighv[2])
     5714           
     5715    plt.xticks(newtposx+Nng/2., tlabels[0])
     5716    plt.yticks(newtposy+Nng/2., tlabels[1])
    56815717    plt.xlabel(ttits[0])
    56825718    plt.ylabel(ttits[1])
     
    56885724
    56895725# units labels
    5690     cbar.set_label(vnames.replace('_','\_') + ' (' + units_lunits(uts) + ')')
     5726    cbar.set_label(gen.latex_text(vnames) + ' (' + units_lunits(uts) + ')')
    56915727
    56925728    figname = 'Neighbourghood_evol'
    5693     graphtit = gtit.replace('_','\_').replace('&','\&')
     5729    graphtit = gen.latex_text(gtit)
    56945730
    56955731    plt.title(graphtit, position=(0.5,1.05))
Note: See TracChangeset for help on using the changeset viewer.