Changeset 2699 in lmdz_wrf


Ignore:
Timestamp:
Aug 16, 2019, 11:15:20 AM (6 years ago)
Author:
lfita
Message:

Adding:

  • `draw_topofix_geogrid_boxes': plotting different geo_em.d[nn].nc topography from WPS files on a fixed low-level enhanced color mode
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2697 r2699  
    6868## e.g. # drawing.py -o draw_2Dshad_map -S 'orog;$conv^{ini}$;lat|-1,lon|-1;lon;lat;auto;rainbow#auto#auto#time@minutes!since!1949-12-01!00:00:00|exct,6,h|%d$^{%H}$|date!([DD]$^{[HH]}$);Srange,Srange;convini|Case1|1a;pdf;binary|shadow,NW,auto|-70.,-36,-62.,-30.;cyl,c;yes' -v convini -f UBA_ERA-I_1a_2D.nc
    6969## e.g. # $pyHOME/drawing.py -o draw_river_pattern -S 'ORCHIDEEdef:ORCHIDEEdef:auto:cyl,l:None:-100.|-65.|-20.|15.:False:True:South|America|ORCHIDEE|routing|0.5|deg:pdf:0|10|1:True' -v Parana,Amazon
     70## e.g. # python ${pyHOME}/drawing.py -o draw_topofix_geogrid_boxes -f geo_em.d01.nc,geo_em.d02.nc -S 'None:RELAMPAGO!explicit!convection!configuration:pdf:cyl,i:d01$_{8k}$,d02$_{1.6k}$:0|10|1:auto:0.17|horizontal|8|10|-45.|0.8|0.15|#CCCCFF:auto:auto:auto:auto:auto:True'
    7071
    7172#######
     
    1126911270        reference)
    1127011271      values= [lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:
    11271           [boxlvals]:[iix]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:[ctylvals]
    11272           :[close]
    11273         lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] or None
     11272          [boxlvals]:[ColorLeg]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:
     11273          [stslvals]:[close]
     11274        lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax]
     11275          or None
    1127411276        title: title of the graph ('!' for spaces)
    1127511277        graphic_kind: kind of figure (jpg, pdf, png)
     
    1129411296        labels: labels to write in the graph ('!' for spaces)
    1129511297        boxlvals: [line style]|[line width] values for the boxes (['-', 3], auto)
    11296         iix = starting x-figure fraction coordinate to plot the legend with the
    11297           colors (0.8, auto)
     11298        [ColorLeg] = [ijstart, orientation, labsize, sqsize, labrotation,
     11299          totboxlength, ibox, seacolor] values for the legend of colors of the
     11300          topography ([0.95, 'vertical', 10., 10., 0., 0.8, 0.85, '#CCCCFF'], default)
     11301          ijstart: initial position as fraction of figure on the oposite axis of
     11302            orientation
     11303          orientation: orientation of the legend
     11304          labsize: font size of the labels
     11305          sqsize: size of the squares of the legend
     11306          labrotation: rotation of the labels of the legend
     11307          totboxlength: total length of the color legend as percentage of the figure
     11308             size along the given orientation
     11309          ibox: starting at the given orientation as percentage of the figure
     11310          seacolor: color for the sea
    1129811311        mervals: [fontsize]|[color line]|[labels rotation]|[line width] values for
    1129911312          the meridians  ([8,'#AAAAAA', 0, 0.5], auto)
     
    1130411317        countrylvals: [line width|color line] values for the countries (None for any,
    1130511318          [0.25, '#161616'], auto)
    11306         ctylvals: [line width|color line] values for the counties (None for any, None,
     11319        stslvals: [line width|color line] values for the states (None for any, None,
    1130711320          [0.25, '#080808'], auto)
    1130811321        close: Whether figure should be finished or not
     
    1132011333
    1132111334    expectargs = '[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:'+ \
    11322        '[boxlvals]:[iix]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:[ctyvals]:'+\
    11323        '[close]'
     11335       '[boxlvals]:[ColorLeg]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:'+     \
     11336       '[stsvals]:[close]'
    1132411337    drw.check_arguments(fname,values,expectargs,':')
    1132511338
     
    1134211355    legvals = values.split(':')[5]
    1134311356    boxlvals = values.split(':')[6]
    11344     iix = values.split(':')[7]
     11357    ColorLeg = values.split(':')[7]
    1134511358    mervals = values.split(':')[8]
    1134611359    parvals = values.split(':')[9]
    1134711360    coastlvals = values.split(':')[10]
    1134811361    countrylvals = values.split(':')[11]
    11349     ctylvals = values.split(':')[12]
     11362    stslvals = values.split(':')[12]
    1135011363    close = gen.Str_Bool(values.split(':')[13])
    1135111364
     
    1140611419    else:
    1140711420        Boxlvals = ['-', 3]
    11408     if iix != 'auto': Iix = np.float(iix)
    11409     else: Iix = 0.8
     11421
     11422    if ColorLeg != 'auto':
     11423        colorleg = [np.float(ColorLeg.split('|')[0]), ColorLeg.split('|')[1],        \
     11424          np.float(ColorLeg.split('|')[2]), np.float(ColorLeg.split('|')[3]),        \
     11425          np.float(ColorLeg.split('|')[4]), np.float(ColorLeg.split('|')[5]),        \
     11426          np.float(ColorLeg.split('|')[6]), ColorLeg.split('|')[7]]
     11427    else:
     11428        colorleg = [0.8, 'vertical', 10., 10., 0., 0.8, 0.1, '#CCCCFF']
    1141011429
    1141111430    if mervals != 'auto':
     
    1142411443        Coastlvals = [np.float(coastlvals.split('|')[0]),                            \
    1142511444          str(coastlvals.split('|')[1])]
     11445    elif coastlvals == 'None':
     11446        Coastlvals = None
    1142611447    else:
    1142711448        Coastlvals = [0.25,'#161616']
     
    1143011451        Countrylvals = [np.float(countrylvals.split('|')[0]),                        \
    1143111452          str(countrylvals.split('|')[1])]
     11453    elif countrylvals == 'None':
     11454        Countrylvals = None
    1143211455    else:
    1143311456        Countrylvals = [0.25,'#161616']
    1143411457
    11435     if ctylvals != 'auto':
    11436         Ctylvals = [np.float(ctylvals.split('|')[0]), str(ctylvals.split('|')[1])]
    11437     else:
    11438         Ctylvals = [0.25,'#080808']
     11458    if stslvals != 'auto':
     11459        Stslvals = [np.float(stslvals.split('|')[0]), str(stslvals.split('|')[1])]
     11460    elif stslvals == 'None':
     11461        Stslvals = None
     11462    else:
     11463        Stslvals = [0.25,'#080808']
    1143911464
    1144011465    drw.plot_topofix_geogrid_boxes(topography, landsea, Xboxlines, Yboxlines,        \
    1144111466      boxlabels, objlon0, objlat0, lonlatL, grtit, kindfig, mapvalues, legvals,      \
    11442       Boxlvals, Iix, Mervals, Parvals, Coastlvals, Countrylvals, Ctylvals, close)
     11467      Boxlvals, colorleg, Mervals, Parvals, Coastlvals, Countrylvals, Stslvals, close)
    1144311468
    1144411469    objdomf.close()
  • trunk/tools/drawing_tools.py

    r2697 r2699  
    185185# plot_topo_geogrid:
    186186# plot_topo_geogrid_boxes:
     187# plot_topofix_geogrid_boxes: plotting geo_em.d[nn].nc topography from WPS files on
     188#   a fixed low-level enhanced color mode
    187189# plot_2D_shadow: Plot of a 2D field with shadow
    188190# plot_2Dshad_map: Function to plot a map of mask values on top of a map in shadow
     
    1456714569
    1456814570def plot_topofix_geogrid_boxes(varv, landsea, boxesX, boxesY, boxlabels, olon, olat, \
    14569   lonlatLims, gtit, kfig, mapv, legvals=[0,8,1], boxlvals=['-', 3], iix=0.8,         \
     14571  lonlatLims, gtit, kfig, mapv, legvals=[0,8,1], boxlvals=['-', 3],                  \
     14572  legcolv=[0.8,'vertical',10.,10.,0.,0.8,0.85,'#6464AA'],                            \
    1457014573  mervals=[8,'#AAAAAA',0,0.5], parvals=[8,'#AAAAAA',0,0.5],                          \
    14571   coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], ctylvals=None,         \
     14574  coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], stslvals=None,         \
    1457214575  closeif=True):
    1457314576    """ plotting geo_em.d[nn].nc topography from WPS files on a fixed low-level     
     
    1460014603        Ncols = number of columns
    1460114604      boxlvals = values for the boxes [line style, line width] (['-', 3], default)
    14602       iix = starting x-figure fraction coordinate to plot the legend with the colors
    14603         (0.8, default)
     14605      legcolv = [ijstart, orientation, labsize, sqsize, labrotation, totboxlength,
     14606        ibox, seacolor] values for the legend of colors of the topography ([0.8, 'vertical',
     14607        10., 10., 0., 0.8, 0.85, '#CCCCFF'], default)
     14608          ijstart: initial position as fraction of figure on the oposite axis of
     14609            orientation
     14610          orientation: orientation of the legend
     14611          labsize: font size of the labels
     14612          sqsize: size of the squares of the legend
     14613          labrotation: rotation of the labels of the legend
     14614          totboxlength: total length of the color legend as percentage of the figure
     14615             size along the given orientation
     14616          ibox: starting at the given orientation as percentage of the figure
     14617          seacolor: color for the sea
    1460414618      mervals = values for the meridians [fontsize, color line, labels rotation,
    1460514619        line width] ([8,'#AAAAAA', 0, 0.5], default)
     
    1461014624      countrylvals = values for the countries [line width, color line] None for any
    1461114625        ([0.25, '#161616'], default)
    14612       ctylvals = values for the counties [line width, color line] None for any (None,
     14626      ststlvals = values for the states [line width, color line] None for any (None,
    1461314627        default)
    1461414628      closeif= Boolean value if the figure has to be closed
     
    1462214636      [231,175,139], [202,149,132], [206,156,149], [228,182,192], [250,214,231],     \
    1462314637      [224,224,224], [255,255,255], [255,255,255]]
     14638    availor = ['vertical', 'horizontal']
    1462414639
    1462514640    if type(varv) == type('S') and varv == 'h':
     
    1465014665    masktopo = np.where(landsea == 1., varv, gen.fillValueF)
    1465114666    masktopo = ma.masked_equal(masktopo, gen.fillValueF)
     14667    masklandsea = np.where(landsea == 0., 1., gen.fillValueF)
     14668    masklandsea = ma.masked_equal(masklandsea, gen.fillValueF)
    1465214669
    1465314670    Ncolors = len(topobnds)
     
    1465614673
    1465714674    #cols = color_lines(len(boxlabels))
     14675    # Getting more `pastel' palette
    1465814676    cols = colorsauto
    1465914677
     
    1467414692    fig, axmat = plt.subplots(1,1)
    1467514693
    14676     plt.pcolormesh(x,y,masktopo,cmap=cmap, norm=normc, vmin=topobnds[0],             \
     14694    im = plt.subplot(1,1,1)
     14695    plt.pcolormesh(x, y, masklandsea, color=legcolv[7], vmin=0.99, vmax=1.01)
     14696    plt.pcolormesh(x, y, masktopo, cmap=cmap, norm=normc, vmin=topobnds[0],          \
    1467714697      vmax=topobnds[Ncolors-2])
    1467814698
    1467914699    Nboxes = len(boxesX)/4
    1468014700    for ibox in range(Nboxes):
     14701        bbcol = gen.modify_color(cols[ibox], 'hex', 32, 'darken')
    1468114702        plt.plot(boxesX[ibox*4], boxesY[ibox*4], linestyle=boxlvals[0],              \
    14682           linewidth=boxlvals[1], color=cols[ibox],                                   \
     14703          linewidth=boxlvals[1], color=bbcol,                                        \
    1468314704          label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
    1468414705        plt.plot(boxesX[ibox*4+1], boxesY[ibox*4+1], linestyle=boxlvals[0],          \
    14685           linewidth=boxlvals[1], color=cols[ibox],                                   \
    14686           label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14706          linewidth=boxlvals[1], color=bbcol)
    1468714707        plt.plot(boxesX[ibox*4+2], boxesY[ibox*4+2], linestyle=boxlvals[0],          \
    14688           linewidth=boxlvals[1], color=cols[ibox],                                   \
    14689           label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14708          linewidth=boxlvals[1], color=bbcol)
    1469014709        plt.plot(boxesX[ibox*4+3], boxesY[ibox*4+3], linestyle=boxlvals[0],          \
    14691           linewidth=boxlvals[1], color=cols[ibox],                                   \
    14692           label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14710          linewidth=boxlvals[1], color=bbcol)
    1469314711
    1469414712    if coastlvals is not None:
     
    1469614714    if countrylvals is not None:
    1469714715        m.drawcountries(linewidth=countrylvals[0], color=countrylvals[1])
    14698     if ctylvals is not None:
    14699         m.drawcounties(linewidth=ctylvals[0], color=ctylvals[1])
     14716    if stslvals is not None:
     14717        m.drawstates(linewidth=stslvals[0], color=stslvals[1])
    1470014718
    1470114719    m.drawmeridians(meridians, labels=[True,False,False,True], fontsize=mervals[0],  \
     
    1470514723
    1470614724    # FROM: https://matplotlib.org/examples/color/named_colors.html
    14707     # Get height and width
     14725    # Get height and width of the figure
    1470814726    ncols = 1
    1470914727    nrows = len(topobnds)
    1471014728    X, Y = fig.get_dpi() * fig.get_size_inches()
    14711     h = Y / (nrows + 1)
    14712     w = X / ncols
     14729
     14730    # Dimensions of the color-legend
     14731    totboxlength = legcolv[5]
     14732    ibox = legcolv[6]
    1471314733
    1471414734    cbox = unichr(9632)#+unichr(9632)+unichr(9632)
    1471514735    bbox = unichr(9633)
    14716     for i in range(1,Ncolors-2):
    14717         name = topobnds[i]
    14718         col = i % ncols
    14719         row = i // ncols
    14720         y = Y - (row*h) - h
    14721 
    14722         xi_line = w*(col+0.05)
    14723         xf_line = w*(col+0.25)
    14724         xi_text = X*0.6+w*(col+0.3)
    14725 
    14726         #axf.text(xi_text, y, str(name), fontsize=(h * 0.8), horizontalalignment='left',   \
    14727         #  verticalalignment='center')
    14728         #axf.hlines(y+h*0.1, xi_line, xf_line, color=HEXtopocolors[i], linewidth=(h*0.6))
    14729         #ax.annotate()
    14730 
    14731         plt.annotate(str(name), xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction',    \
    14732           fontsize=10)
    14733         plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',    \
    14734           fontsize=10, color=HEXtopocolors[i])
    14735         plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',    \
    14736           fontsize=10, color='k')
    14737 
    14738     i = 0
    14739     plt.annotate('< 0', xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction',            \
    14740       fontsize=10)
    14741     plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
    14742       fontsize=10, color=HEXtopocolors[i])
    14743     plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
    14744       fontsize=10, color='k')
    14745 
    14746     i = Ncolors - 2
    14747     name = topobnds[i]
    14748     plt.annotate('> ' + str(name), xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction', \
    14749       fontsize=10)
    14750     plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
    14751       fontsize=10, color=HEXtopocolors[i])
    14752     plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
    14753       fontsize=10, color='k')
     14736
     14737    ccs = np.arange(0.,totboxlength,totboxlength/(nrows+1))
     14738
     14739    iix = legcolv[0]
     14740    Ns = []
     14741    Cs = []
     14742    Xs = []
     14743    Ys = []
     14744    if legcolv[1] == 'vertical':
     14745        bw = totboxlength / (nrows + 1)
     14746        bh = bw * X / Y
     14747        Ns.append('> ' + str(topobnds[Ncolors-2]))
     14748        Cs.append(Ncolors-2)
     14749        Xs.append([iix,iix-bh])
     14750        Ys.append(ibox - ccs[0])
     14751        for i in range(1,Ncolors-2):
     14752            Ns.append(str(topobnds[Ncolors-2-i]))
     14753            Cs.append(Ncolors-2-i)
     14754            Xs.append([iix,iix-bh])
     14755            Ys.append(ibox - ccs[i])
     14756        Ns.append('< 0')
     14757        Cs.append(0)
     14758        Xs.append([iix,iix-bh])
     14759        Ys.append(ibox - ccs[Ncolors-2])
     14760
     14761    elif legcolv[1] == 'horizontal':
     14762        bw = totboxlength / (nrows + 1)
     14763        bh = bw * Y / X
     14764
     14765        Ns.append('< 0')
     14766        Cs.append(0)
     14767        Xs.append(ibox+ccs[0])
     14768        Ys.append([iix-bh,iix])
     14769        for i in range(1,Ncolors-2):
     14770            Ns.append(str(topobnds[i]))
     14771            Cs.append(i)
     14772            Xs.append(ibox + ccs[i])
     14773            Ys.append([iix-bh,iix])
     14774        Ns.append('> ' + str(topobnds[Ncolors-2]))
     14775        Cs.append(Ncolors-2)
     14776        Xs.append(ibox + ccs[Ncolors-2])
     14777        Ys.append([iix-bh,iix])
     14778    else:
     14779        print errormsg
     14780        print '  ' + fname + ": oritnation of legend of colors of topography " +     \
     14781          "scale '" + legcolv[1] + "' not ready !!"
     14782        print '    available ones:', availor
     14783        quit(-1)
     14784
     14785    for ib in range(0,Ncolors-1):
     14786        Nb = Ns[ib]
     14787        if legcolv[1] == 'vertical':
     14788            ix = Xs[ib][0]
     14789            iy = Ys[ib]
     14790        elif legcolv[1] == 'horizontal':
     14791            ix = Xs[ib]
     14792            iy = Ys[ib][0]
     14793        print ib, ':', Nb, ix, iy, '<>', bw, bh
     14794        plt.annotate(Nb, xy=(ix,iy), xycoords='figure fraction', fontsize=legcolv[2],\
     14795          rotation=legcolv[4])
     14796        if legcolv[1] == 'vertical':
     14797            ix = Xs[ib][1]
     14798        elif legcolv[1] == 'horizontal':
     14799            iy = Ys[ib][1]
     14800        plt.annotate(cbox, xy=(ix,iy), xycoords='figure fraction',                   \
     14801          fontsize=legcolv[3], color=HEXtopocolors[Cs[ib]])
     14802        plt.annotate(bbox, xy=(ix,iy), xycoords='figure fraction',                   \
     14803          fontsize=legcolv[3], color='k')
    1475414804
    1475514805    figname = 'plot_topofix_geogrid'
Note: See TracChangeset for help on using the changeset viewer.