Changeset 2699 in lmdz_wrf
- Timestamp:
- Aug 16, 2019, 11:15:20 AM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2697 r2699 68 68 ## 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 69 69 ## 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' 70 71 71 72 ####### … … 11269 11270 reference) 11270 11271 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 11274 11276 title: title of the graph ('!' for spaces) 11275 11277 graphic_kind: kind of figure (jpg, pdf, png) … … 11294 11296 labels: labels to write in the graph ('!' for spaces) 11295 11297 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 11298 11311 mervals: [fontsize]|[color line]|[labels rotation]|[line width] values for 11299 11312 the meridians ([8,'#AAAAAA', 0, 0.5], auto) … … 11304 11317 countrylvals: [line width|color line] values for the countries (None for any, 11305 11318 [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, 11307 11320 [0.25, '#080808'], auto) 11308 11321 close: Whether figure should be finished or not … … 11320 11333 11321 11334 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]' 11324 11337 drw.check_arguments(fname,values,expectargs,':') 11325 11338 … … 11342 11355 legvals = values.split(':')[5] 11343 11356 boxlvals = values.split(':')[6] 11344 iix= values.split(':')[7]11357 ColorLeg = values.split(':')[7] 11345 11358 mervals = values.split(':')[8] 11346 11359 parvals = values.split(':')[9] 11347 11360 coastlvals = values.split(':')[10] 11348 11361 countrylvals = values.split(':')[11] 11349 ctylvals = values.split(':')[12]11362 stslvals = values.split(':')[12] 11350 11363 close = gen.Str_Bool(values.split(':')[13]) 11351 11364 … … 11406 11419 else: 11407 11420 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'] 11410 11429 11411 11430 if mervals != 'auto': … … 11424 11443 Coastlvals = [np.float(coastlvals.split('|')[0]), \ 11425 11444 str(coastlvals.split('|')[1])] 11445 elif coastlvals == 'None': 11446 Coastlvals = None 11426 11447 else: 11427 11448 Coastlvals = [0.25,'#161616'] … … 11430 11451 Countrylvals = [np.float(countrylvals.split('|')[0]), \ 11431 11452 str(countrylvals.split('|')[1])] 11453 elif countrylvals == 'None': 11454 Countrylvals = None 11432 11455 else: 11433 11456 Countrylvals = [0.25,'#161616'] 11434 11457 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'] 11439 11464 11440 11465 drw.plot_topofix_geogrid_boxes(topography, landsea, Xboxlines, Yboxlines, \ 11441 11466 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) 11443 11468 11444 11469 objdomf.close() -
trunk/tools/drawing_tools.py
r2697 r2699 185 185 # plot_topo_geogrid: 186 186 # 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 187 189 # plot_2D_shadow: Plot of a 2D field with shadow 188 190 # plot_2Dshad_map: Function to plot a map of mask values on top of a map in shadow … … 14567 14569 14568 14570 def 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'], \ 14570 14573 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, \ 14572 14575 closeif=True): 14573 14576 """ plotting geo_em.d[nn].nc topography from WPS files on a fixed low-level … … 14600 14603 Ncols = number of columns 14601 14604 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 14604 14618 mervals = values for the meridians [fontsize, color line, labels rotation, 14605 14619 line width] ([8,'#AAAAAA', 0, 0.5], default) … … 14610 14624 countrylvals = values for the countries [line width, color line] None for any 14611 14625 ([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, 14613 14627 default) 14614 14628 closeif= Boolean value if the figure has to be closed … … 14622 14636 [231,175,139], [202,149,132], [206,156,149], [228,182,192], [250,214,231], \ 14623 14637 [224,224,224], [255,255,255], [255,255,255]] 14638 availor = ['vertical', 'horizontal'] 14624 14639 14625 14640 if type(varv) == type('S') and varv == 'h': … … 14650 14665 masktopo = np.where(landsea == 1., varv, gen.fillValueF) 14651 14666 masktopo = ma.masked_equal(masktopo, gen.fillValueF) 14667 masklandsea = np.where(landsea == 0., 1., gen.fillValueF) 14668 masklandsea = ma.masked_equal(masklandsea, gen.fillValueF) 14652 14669 14653 14670 Ncolors = len(topobnds) … … 14656 14673 14657 14674 #cols = color_lines(len(boxlabels)) 14675 # Getting more `pastel' palette 14658 14676 cols = colorsauto 14659 14677 … … 14674 14692 fig, axmat = plt.subplots(1,1) 14675 14693 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], \ 14677 14697 vmax=topobnds[Ncolors-2]) 14678 14698 14679 14699 Nboxes = len(boxesX)/4 14680 14700 for ibox in range(Nboxes): 14701 bbcol = gen.modify_color(cols[ibox], 'hex', 32, 'darken') 14681 14702 plt.plot(boxesX[ibox*4], boxesY[ibox*4], linestyle=boxlvals[0], \ 14682 linewidth=boxlvals[1], color= cols[ibox],\14703 linewidth=boxlvals[1], color=bbcol, \ 14683 14704 label=gen.latex_text(boxlabels[ibox].replace('!',' '))) 14684 14705 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) 14687 14707 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) 14690 14709 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) 14693 14711 14694 14712 if coastlvals is not None: … … 14696 14714 if countrylvals is not None: 14697 14715 m.drawcountries(linewidth=countrylvals[0], color=countrylvals[1]) 14698 if ctylvals is not None:14699 m.draw counties(linewidth=ctylvals[0], color=ctylvals[1])14716 if stslvals is not None: 14717 m.drawstates(linewidth=stslvals[0], color=stslvals[1]) 14700 14718 14701 14719 m.drawmeridians(meridians, labels=[True,False,False,True], fontsize=mervals[0], \ … … 14705 14723 14706 14724 # FROM: https://matplotlib.org/examples/color/named_colors.html 14707 # Get height and width 14725 # Get height and width of the figure 14708 14726 ncols = 1 14709 14727 nrows = len(topobnds) 14710 14728 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] 14713 14733 14714 14734 cbox = unichr(9632)#+unichr(9632)+unichr(9632) 14715 14735 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') 14754 14804 14755 14805 figname = 'plot_topofix_geogrid'
Note: See TracChangeset
for help on using the changeset viewer.