Changeset 1147 in lmdz_wrf


Ignore:
Timestamp:
Oct 6, 2016, 3:04:05 PM (8 years ago)
Author:
lfita
Message:

Adding dxdyfmt', colorbarvalues' and `close' in 'draw_2D_shad_cont'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1137 r1147  
    1010## e.g. # drawing.py -f /media/data2/etudes/WRF_LMDZ/WL_HyMeX/IIphase/medic950116/wlmdza/wrfout/wrfout_d01_1995-01-13_00:00:00 -o create_movie -S 'draw_2D_shad#Time@WRFTimes@10@95@191@1#tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:None' -v T2
    1111## e.g. # drawing.py -f wrfout_d01_1980-03-01_00\:00\:00_Time_B0-E48-I1.nc -o draw_2D_shad -S 'tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:cyl,i' -v T2
    12 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:rainbow:fixc,k:%.2f:0,1:0.,3000.,10:landmask & height:pdf:False:lcc,i' -v LANDMASK,HGT_M
     12## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:auto:rainbow,auto,auto:fixc,k:%.2f:0.,1.:0.,3000.,10:landmask & height:pdf:None:lcc,i:True' -v LANDMASK,HGT_M
    1313## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'height,landmask:Time|0:Time|0:XLONG_M:XLAT_M:terrain:fixc,k:None:0.,3000.:0,1,10:MEDCORDEX height & landmask:pdf:False:lcc,i' -v HGT_M,LANDMASK
    1414## e.g. # drawing.py -o draw_2D_shad_line -f 'mean_dtcon-pluc-pres_lat.nc,mean_dtcon-pluc-pres_lat.nc' -S 'dtcon,prc:bottom_top|-1,south_north|-1:latmean:presmean:seismic,k:-5.,5.:monthly|dtcon|&|prc:pdf:flip@y:None:True' -v 'dtconmean,prcmean'
     
    407407    draw_2D_shad_cont(ncfile, values, varn)
    408408      ncfile= [ncfilevars],[ncfilevarc] files to use (one value, same file)
    409       values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[colorbar]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]
     409      values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyfmt]:[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]:[close]
    410410        [vnamefs],[vnamefc]: Name in the figure of the shaded and the contour variables
    411411        [dimvals/c]: list of [dimname]|[value] telling at which dimension of the
    412412          variable a given value is required (no dimension name, all the length)
    413413        [dimx/yvn]: names of the variables with the values of the dimensions for the plot
    414         [colorbar]: name of the color bar
     414        [dimxyfmt]=[dxf],[Ndx],[dyf],[Ndy]: format of the values at each axis
     415          [dxs]: style of x-axis ('auto' for 'pretty')
     416            'Nfix', values computed at even 'Ndx'
     417            'Vfix', values computed at even 'Ndx' increments
     418            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     419          [dxf]: format of the labels at the x-axis
     420          [Ndx]: Number of ticks at the x-axis
     421          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     422          [dys]: style of y-axis ('auto' for 'pretty')
     423          [dyf]: format of the labels at the y-axis
     424          [Ndy]: Number of ticks at the y-axis
     425          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     426        [colorbarvals]=[colbarn],[fmtcolorbar],[orientation]
     427          [colorbarn]: name of the color bar
     428          [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
     429          [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal')
    415430        [ckind]: kind of contours
    416431          'cmap': as it gets from colorbar
     
    418433          'fixsigc,[colname]': fixed color [colname], >0 stright, <0 dashed  line
    419434        [clabfmt]: format of the labels in the contour (None, also possible)
    420         [smin/axv]: minimum and maximum value for the shading
     435        [smin/axv]: minimum and maximum value for the shading or
     436          'Srange': for full range
     437          'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
     438          'Saroundminmax@val': for min*val,max*val
     439          'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
     440            percentile_(100-val)-median)
     441          'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
     442          'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
     443          'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
     444             percentile_(100-val)-median)
    421445        [sminc]:[smaxv]:[Nlev]: minimum, maximum and number of values for the contour
    422446        [figt]: title of the figure ('|' for spaces)
     
    434458            * 'h', high
    435459            * 'f', full
     460        [close]: Whether figure should be finished or not
    436461      valules= 'rh,ta:z|-1,x|-1:z|-1,x|-1:lat:pressure:BuPu:fixsigc,black:%d:0.,100.:195.,305.,7:Meridonal|average|of|rh|&|ta:pdf:flip@y:None'
    437462      varn= [varsn],[varcn] name of the variable to plot with shading variable with contour
     
    444469        quit()
    445470
    446     expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[colorbar]:'
    447     expectargs = expectargs + '[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],'
    448     expectargs = expectargs + '[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]'
     471    expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyf]:' +       \
     472      '[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:' +   \
     473      '[figt]:[kindfig]:[reverse]:[mapv]:[close]'
    449474 
    450475    drw.check_arguments(fname,values,expectargs,':')
     
    455480    vdimxn = values.split(':')[3]
    456481    vdimyn = values.split(':')[4]
    457     colbarn = values.split(':')[5]
    458     countkind = values.split(':')[6]
    459     countlabelfmt = values.split(':')[7]
    460     shadminmax = values.split(':')[8]
    461     contlevels = values.split(':')[9]
    462     figtitle = values.split(':')[10].replace('|',' ')
    463     figkind = values.split(':')[11]
    464     revals = values.split(':')[12]
    465     mapvalue = values.split(':')[13]
     482    dimxyf = values.split(':')[5]
     483    colorbarvals = values.split(':')[6]
     484    countkind = values.split(':')[7]
     485    countlabelfmt = values.split(':')[8]
     486    shadminmax = values.split(':')[9].split(',')
     487    contlevels = values.split(':')[10]
     488    figtitle = values.split(':')[11].replace('|',' ')
     489    figkind = values.split(':')[12]
     490    revals = values.split(':')[13]
     491    mapvalue = values.split(':')[14]
     492    close = gen.Str_Bool(values.split(':')[15])
    466493
    467494    if2filenames = ncfile.find(',')
     
    603630        countlfmt = countlabelfmt
    604631
    605     shading_nx = np.zeros((2), dtype=np.float)
    606     shading_nx[0] = np.float(shadminmax.split(',')[0])
    607     shading_nx[1] = np.float(shadminmax.split(',')[1])
    608 
     632    # Shading limits
     633    shading_nx = drw.graphic_range(shadminmax,valshad)
     634
     635    # Contour limits
    609636    clevmin = np.float(contlevels.split(',')[0])
    610637    clevmax = np.float(contlevels.split(',')[1])
     
    622649
    623650    if mapvalue == 'None': mapvalue = None
     651
     652    colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',')
     653
     654    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyf,',')
     655    xaxis = [xstyl, xaxf, Nxax, xaxor]
     656    yaxis = [ystyl, yaxf, Nyax, yaxor]
     657
    624658    if revals == 'None': revals = None
    625659
    626660    drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu,  \
    627       odimyu, dimnamesv, colbarn, countkind, countlfmt, shading_nx, levels_cont,     \
    628       varunits, figtitle, figkind, revals, mapvalue)
     661      odimyu, xaxis, yaxis, dimnamesv, colbarn, fmtcolbar, colbaror, countkind,      \
     662      countlfmt, shading_nx, levels_cont, varunits, figtitle, figkind, revals,       \
     663      mapvalue, close)
    629664
    630665    return
  • trunk/tools/drawing_tools.py

    r1134 r1147  
    18501850        elif u == 'ms-2': lu='$ms^{-2}$'
    18511851        elif u == 'minutes': lu='$minute$'
     1852        elif u == 'meters MSL': lu='$m$'
     1853        elif u == 'none': lu='-'
    18521854        elif u == 'Pa/s': lu='$Pas^{-1}$'
    18531855        elif u == 'Pas-1': lu='$Pas^{-1}$'
     
    27092711    rangegrph = np.zeros((2), dtype=np.float)
    27102712# Changing limits of the colors
    2711     if type(vrng[0]) != type(np.float(1.)) and type(vrng[0]) != type(np.float64(1.)):
     2713    if vrng[0][0:1] == 'S':
    27122714        if vrng[0] == 'Srange':
    27132715            rangegrph[0] = np.min(varsV)
     
    27652767        print '    ' + fname + ': modified shadow min,max:',rangegrph
    27662768    else:
    2767         rangegrph[0] = vrng[0]
    2768         rangegrph[1] = vrng[1]
     2769        rangegrph[0] = np.float(vrng[0])
     2770        rangegrph[1] = np.float(vrng[1])
    27692771
    27702772    return rangegrph
     
    44434445    return
    44444446
    4445 def plot_2D_shadow_contour(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,          \
    4446   colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv):
     4447def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv,   \
     4448  yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig,    \
     4449  reva, mapv, ifclose):
    44474450    """ Adding labels and other staff to the graph
    44484451      varsv= 2D values to plot with shading
     
    44514454      dim[x/y]v = values at the axes of x and y
    44524455      dim[x/y]u = units at the axes of x and y
     4456      xaxv= list with the x-axis paramteres [style, format, number and orientation]
     4457      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    44534458      dimn= dimension names to plot
    44544459      colorbar= name of the color bar to use
     4460      cbarfmt= format of the numbers in the colorbar
     4461      cbaror= orientation of the colorbar
    44554462      ckind= contour kind
    44564463        'cmap': as it gets from colorbar
     
    44774484          * 'h', high
    44784485          * 'f', full
     4486      ifclose= boolean value whether figure should be close (finish) or not
    44794487    """
    44804488##    import matplotlib as mpl
     
    44884496        quit()
    44894497
     4498    if len(varsv.shape) != 2:
     4499        print errormsg
     4500        print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     4501        quit(-1)
     4502    if len(varcv.shape) != 2:
     4503        print errormsg
     4504        print '  ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!'
     4505        quit(-1)
     4506
     4507    # Axis ticks
    44904508    # Usually axis > x must be the lon, thus...
    44914509    dimxv0 = dimxv.copy()
    44924510    dimyv0 = dimyv.copy()
    4493     dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10))
    4494     dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10))
     4511
     4512    dxn = dimxv.min()
     4513    dxx = dimxv.max()
     4514    dyn = dimyv.min()
     4515    dyx = dimyv.max()
     4516
     4517    if xaxv[0] == 'pretty':
     4518        dimxt0 = np.array(pretty_int(dxn,dxx,xaxv[2]))
     4519    elif xaxv[0] == 'Nfix':
     4520        dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
     4521    elif xaxv[0] == 'Vfix':
     4522        dimxt0 = np.arange(0,dxx,xaxv[2])
     4523    if yaxv[0] == 'pretty':
     4524        dimyt0 = np.array(pretty_int(dyn,dyx,yaxv[2]))
     4525    elif yaxv[0] == 'Nfix':
     4526        dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
     4527    elif yaxv[0] == 'Vfix':
     4528        dimyt0 = np.arange(0,dyx,yaxv[2])
     4529
    44954530    dimxl0 = []
    4496     for i in range(len(dimxt0)): dimxl0.append('{:.1f}'.format(dimxt0[i]))
     4531    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1]))
    44974532    dimyl0 = []
    4498     for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i]))
     4533    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1]))
     4534
    44994535    dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
    45004536    dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
     
    45924628
    45934629    else:
    4594         x,y = gen.lonlat2D(dimxv,dimyv)
     4630        # No following data values
     4631        #x = dimxv
     4632        #y = dimyv
     4633        x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
     4634        y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
    45954635
    45964636    plt.rc('text', usetex=True)
    45974637
    45984638    plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1])
    4599     cbar = plt.colorbar()
     4639    if cbaror == 'horizontal':
     4640        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4641        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
     4642        ticklabels= cbar.ax.get_xticklabels()
     4643        Nticks = len(ticklabels)
     4644        ticklabs = []
     4645        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
     4646        cbar.ax.set_xticklabels(ticklabs,rotation=90)
     4647    else:
     4648        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
    46004649
    46014650# contour
     
    46384687        plt.ylabel(dimyT)
    46394688
    4640         plt.xticks(dimxt, dimxl)
    4641         plt.yticks(dimyt, dimyl)
     4689        plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     4690        plt.yticks(dimyt, dimyl, rotation=yaxv[3])
    46424691
    46434692# set the limits of the plot to the limits of the data
     
    46464695
    46474696# units labels
    4648     cbar.set_label(vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')')
    4649     plt.annotate(vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' +  \
     4697    cbar.set_label(gen.latex_text(vnames[0]) + ' (' + units_lunits(uts[0]) + ')')
     4698    plt.annotate(gen.latex_text(vnames[1]) +' (' + units_lunits(uts[1]) + ') [' +  \
    46504699      mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction',    \
    46514700      color=coln)
    46524701
    46534702    figname = '2Dfields_shadow-contour'
    4654     graphtit = vtit.replace('_','\_').replace('&','\&')
     4703    graphtit = gen.latex_text(vtit)
    46554704
    46564705    plt.title(graphtit)
    46574706   
    4658     output_kind(kfig, figname, True)
     4707    output_kind(kfig, figname, ifclose)
    46594708
    46604709    return
Note: See TracChangeset for help on using the changeset viewer.