- Timestamp:
- Nov 12, 2019, 1:20:22 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2739 r2751 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 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' 71 ## e.g. # drawing.py -o draw_geogrid_landuse -f geo_em.d01.nc -S None:PICT!AMBA-NO!WRF!domains!land-use!d0!(15!km):pdf-png:cyl,l:usgs|0.9:auto:auto:auto:auto:auto:True 71 72 72 73 ####### … … 94 95 # draw_cycle: Function to plot a variale with a circular cycle 95 96 # draw_ensembles_time: Function to plot an ensembles of data following an axis-time 97 # draw_geogrid_landuse: plotting land-use data from geo_em.d[nn].nc WPS files 96 98 # draw_lines: Function to draw different lines at the same time from different files 97 99 # draw_lines_time: Function to draw different lines at the same time from different files with times … … 140 142 'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', \ 141 143 'draw_bar_time', 'draw_barbs', 'draw_basins', 'draw_cycle', 'draw_ensembles_time', \ 142 'draw_2lines', 'draw_2lines_time', 144 'draw_2lines', 'draw_2lines_time', 'draw_geogrid_landuse', \ 143 145 'draw_lines', 'draw_lines_time', \ 144 146 'draw_multi_2D_shad', 'draw_multi_SkewT', 'draw_multiWindRose', \ … … 11479 11481 return 11480 11482 11483 def draw_geogrid_landuse(ncfile, values): 11484 """ plotting land-use data from geo_em.d[nn].nc WPS files 11485 ncfile= geo_em.d[nn].nc file to use 11486 values=[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[ColorLeg]:[mervals]:[parvals]: 11487 [coastlvals]:[countrylvals]:[stslvals]:[close] 11488 lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] 11489 or None 11490 title: title of the graph ('!' for spaces) 11491 graphic_kind: kind of figure (jpg, pdf, png) 11492 mapvalues: map characteristics [proj],[res] 11493 see full documentation: http://matplotlib.org/basemap/ 11494 [proj]: projection 11495 * 'cyl', cilindric 11496 * 'lcc', lambert conformal 11497 [res]: resolution: 11498 * 'c', crude 11499 * 'l', low 11500 * 'i', intermediate 11501 * 'h', high 11502 * 'f', full 11503 ColorLeg= [ijstart]|[lucolors] values for the legend of colors of the land-use 11504 ([0.85, 'usgscolors'], default) 11505 ijstart: initial position as fraction of figure on the oposite axis of 11506 orientation 11507 lucolors: name of the dictionary with the equivalences between land-use and 11508 color 11509 mervals: [fontsize]|[color line]|[labels rotation]|[line width] values for 11510 the meridians ([8,'#AAAAAA', 0, 0.5], auto) 11511 parvals: [fontsize]|[color line]|[labels rotation]|[line width] values for 11512 the parallels ([8,'#AAAAAA', 0, 0.5], auto) 11513 coastlvals: [line width|color line] values for the coastline (None for any, 11514 [0.25,'#161616'], auto) 11515 countrylvals: [line width|color line] values for the countries (None for any, 11516 [0.25, '#161616'], auto) 11517 stslvals: [line width|color line] values for the states (None for any, None, 11518 [0.25, '#080808'], auto) 11519 close: Whether figure should be finished or not 11520 """ 11521 import matplotlib.pyplot as plt 11522 11523 fname = 'draw_geogrid_landuse' 11524 lucolorsavail = ['modifmodis', 'ugs'] 11525 11526 if values == 'h': 11527 print fname + '_____________________________________________________________' 11528 print draw_geogrid_landuse.__doc__ 11529 quit() 11530 11531 expectargs = '[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[ColorLeg]:' + \ 11532 '[mervals]:[parvals]:[coastlvals]:[countrylvals]: [stslvals]:[close]' 11533 drw.check_arguments(fname,values,expectargs,':') 11534 11535 lonlatLS = values.split(':')[0] 11536 lonlatLv = lonlatLS.split(',')[0] 11537 11538 if lonlatLv == 'None': 11539 lonlatL = None 11540 else: 11541 lonlatL = np.zeros((4), dtype=np.float) 11542 lonlatL[0] = np.float(lonlatLS.split(',')[0]) 11543 lonlatL[1] = np.float(lonlatLS.split(',')[1]) 11544 lonlatL[2] = np.float(lonlatLS.split(',')[2]) 11545 lonlatL[3] = np.float(lonlatLS.split(',')[3]) 11546 11547 grtit = values.split(':')[1].replace('!', ' ') 11548 kindfig = values.split(':')[2] 11549 mapvalues = values.split(':')[3] 11550 ColorLeg = values.split(':')[4] 11551 mervals = values.split(':')[5] 11552 parvals = values.split(':')[6] 11553 coastlvals = values.split(':')[7] 11554 countrylvals = values.split(':')[8] 11555 stslvals = values.split(':')[9] 11556 close = gen.Str_Bool(values.split(':')[10]) 11557 11558 objdomf = NetCDFFile(ncfile, 'r') 11559 11560 objhgt = objdomf.variables['HGT_M'] 11561 objlandsea = objdomf.variables['LANDMASK'] 11562 objlon0 = objdomf.variables['XLONG_M'] 11563 objlat0 = objdomf.variables['XLAT_M'] 11564 objlu = objdomf.variables['LU_INDEX'] 11565 11566 lon = objlon0[0,:,:] 11567 lat = objlat0[0,:,:] 11568 topography = objhgt[0,:,:] 11569 landsea = objlandsea[0,:,:] 11570 lu = objlu[0,:,:] 11571 11572 lucolorsS = ColorLeg.split('|')[0] 11573 ixleg = np.float(ColorLeg.split('|')[1]) 11574 if lucolorsS == 'usgs': 11575 lucolors = drw.usgscolors 11576 elif lucolorsS == 'modifmodis': 11577 lucolors = drw.modigbpmodisnoahcolors 11578 else: 11579 print errormsg 11580 print ' ' + fname + ": land-use colors dictinoary '" +lucolorsS + \ 11581 "' not available !!" 11582 print ' available ones:', lucolorsavail 11583 quit(-1) 11584 11585 if mervals != 'auto': 11586 Mervals = [int(mervals.split('|')[0]), str(mervals.split('|')[1]), \ 11587 np.float(mervals.split('|')[2]), np.float(mervals.split('|')[3])] 11588 else: 11589 Mervals = [8,'#AAAAAA', 0, 0.5] 11590 11591 if parvals != 'auto': 11592 Parvals = [int(parvals.split('|')[0]), str(parvals.split('|')[1]), \ 11593 np.float(parvals.split('|')[2]), np.float(parvals.split('|')[3])] 11594 else: 11595 Parvals = [8,'#AAAAAA', 0, 0.5] 11596 11597 if coastlvals != 'auto': 11598 Coastlvals = [np.float(coastlvals.split('|')[0]), \ 11599 str(coastlvals.split('|')[1])] 11600 elif coastlvals == 'None': 11601 Coastlvals = None 11602 else: 11603 Coastlvals = [0.25,'#161616'] 11604 11605 if countrylvals != 'auto': 11606 Countrylvals = [np.float(countrylvals.split('|')[0]), \ 11607 str(countrylvals.split('|')[1])] 11608 elif countrylvals == 'None': 11609 Countrylvals = None 11610 else: 11611 Countrylvals = [0.25,'#161616'] 11612 11613 if stslvals != 'auto': 11614 Stslvals = [np.float(stslvals.split('|')[0]), str(stslvals.split('|')[1])] 11615 elif stslvals == 'None': 11616 Stslvals = None 11617 else: 11618 Stslvals = [0.25,'#080808'] 11619 11620 drw.plot_landuse(lu, lon, lat, lonlatL ,mapvalues, ixleg, lucolors, grtit, \ 11621 kindfig, fname, Mervals, Parvals, Coastlvals, Countrylvals, Stslvals, close) 11622 11623 return 11624 11481 11625 #quit() 11482 11626 … … 11590 11734 elif oper == 'draw_ensembles_time': 11591 11735 draw_ensembles_time(opts.ncfile, opts.values) 11736 elif oper == 'draw_geogrid_landuse': 11737 draw_geogrid_landuse(opts.ncfile, opts.values) 11592 11738 elif oper == 'draw_Neighbourghood_evol': 11593 11739 draw_Neighbourghood_evol(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r2748 r2751 219 219 # plot_2Dshad_map: Function to plot a map of mask values on top of a map in shadow 220 220 # plot_2D_shadow_time: Plotting a 2D field with one of the axes being time 221 # plot_landuse: Function to plot a landuse map 221 222 # plot_Neighbourghood_evol:Plotting neighbourghood evolution 222 223 # plot_time_lag: Function to plot a time-lag figure (x, previous values; y, future values) … … 14950 14951 14951 14952 return 14953 14954 def plot_landuse(luv, olon, olat, lonlatLims, mapv, ixleg, landcols,figtitle, kfig, \ 14955 fign, mervals=[8,'#AAAAAA',0,0.5], parvals=[8,'#AAAAAA',0,0.5], \ 14956 coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], stslvals=None, \ 14957 close=True): 14958 """ Function to plot a landuse map 14959 luv: land-use data 14960 olon,olat: objects with longitudes and latitudes 14961 lonlatLims: limits of the plot 14962 mapv: map values 14963 mervals = values for the meridians [fontsize, color line, labels rotation, 14964 line width] ([8,'#AAAAAA', 0, 0.5], default) 14965 parvals = values for the parallels [fontsize, color line, labels rotation, 14966 line width] ([8,'#AAAAAA', 0, 0.5], default) 14967 coastlvals = values for the coastline [line width, color line] None for any 14968 ([0.25,'#161616'], default) 14969 countrylvals = values for the countries [line width, color line] None for any 14970 ([0.25, '#161616'], default) 14971 ststlvals = values for the states [line width, color line] None for any (None, 14972 default) 14973 ixleg: initial position of the legend of the colors 14974 landcols: dictionary with the land colors 14975 figtitle: title of the figure 14976 kfig: kind of output graphical file 14977 fign: name of the graphical output file 14978 close: whether figure has to be close or not 14979 """ 14980 fname = 'plot_landuse' 14981 14982 # https://matplotlib.org/tutorials/colors/colorbar_only.html 14983 usgsc = [] 14984 Ncolors = len(landcols.keys()) 14985 labs = [] 14986 for iv in range(Ncolors): 14987 vvals = landcols[iv+1] 14988 labs.append(vvals[0]) 14989 usgsc.append(vvals[2]) 14990 14991 bounds = range(Ncolors) 14992 cmap = mpl.colors.ListedColormap(usgsc) 14993 norm = mpl.colors.BoundaryNorm(bounds, cmap.N) 14994 14995 if not mapv is None: 14996 if len(olon[:].shape) == 3: 14997 lon0 = olon[0,] 14998 lat0 = olat[0,] 14999 elif len(olon[:].shape) == 2: 15000 lon0 = olon[:] 15001 lat0 = olat[:] 15002 elif len(olon[:].shape) == 1: 15003 lon00 = olon[:] 15004 lat00 = olat[:] 15005 lon0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 15006 lat0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 15007 15008 for iy in range(len(lat00)): 15009 lon0[iy,:] = lon00 15010 for ix in range(len(lon00)): 15011 lat0[:,ix] = lat00 15012 15013 map_proj=mapv.split(',')[0] 15014 map_res=mapv.split(',')[1] 15015 dx = lon0.shape[1] 15016 dy = lon0.shape[0] 15017 15018 if lonlatLims is not None: 15019 print ' ' + fname + ': cutting the domain to plot !!!!' 15020 print ' limits: W-E', lonlatLims[0], lonlatLims[2] 15021 print ' limits: N-S', lonlatLims[1], lonlatLims[3] 15022 nlon = lonlatLims[0] 15023 xlon = lonlatLims[2] 15024 nlat = lonlatLims[1] 15025 xlat = lonlatLims[3] 15026 15027 if map_proj == 'lcc': 15028 lon2 = (lonlatLims[0] + lonlatLims[2])/2. 15029 lat2 = (lonlatLims[1] + lonlatLims[3])/2. 15030 else: 15031 nlon = np.min(lon0) 15032 xlon = np.max(lon0) 15033 nlat = np.min(lat0) 15034 xlat = np.max(lat0) 15035 lon2 = lon0[dy/2,dx/2] 15036 lat2 = lat0[dy/2,dx/2] 15037 15038 plt.xlim(nlon, xlon) 15039 plt.ylim(nlat, xlat) 15040 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ 15041 xlon, ',', xlat 15042 15043 m, meridians, parallels, x, y = mapFigure(olon,olat,lonlatLims,mapv,5,5) 15044 15045 plt.pcolormesh(x,y,luv,cmap=cmap, vmin=1, vmax=Ncolors) 15046 cbar = plt.colorbar(ticks=np.arange(Ncolors)+0.5) 15047 cbar.ax.set_yticklabels(labs, fontsize=6) 15048 15049 if coastlvals is not None: 15050 m.drawcoastlines(linewidth=coastlvals[0], color=coastlvals[1]) 15051 if countrylvals is not None: 15052 m.drawcountries(linewidth=countrylvals[0], color=countrylvals[1]) 15053 if stslvals is not None: 15054 m.drawstates(linewidth=stslvals[0], color=stslvals[1]) 15055 15056 m.drawmeridians(meridians, labels=[True,False,False,True], fontsize=mervals[0], \ 15057 color=mervals[1], rotation=mervals[2], linewidth=mervals[3]) 15058 m.drawparallels(parallels, labels=[True,False,False,True], fontsize=parvals[0], \ 15059 color=parvals[1], rotation=parvals[2], linewidth=parvals[3]) 15060 15061 plt.title(figtitle) 15062 15063 output_kind(kfig, fign, close) 15064 return 15065
Note: See TracChangeset
for help on using the changeset viewer.