- Timestamp:
- Aug 15, 2019, 5:25:20 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2696 r2697 110 110 # draw_topo_geogrid: plotting geo_em.d[nn].nc topography from WPS files 111 111 # draw_topo_geogrid_boxes: plotting different geo_em.d[nn].nc topography from WPS files 112 # draw_topofix_geogrid_boxes: plotting different geo_em.d[nn].nc topography from WPS files 113 # on a fixed low-level enhanced color mode 112 114 # draw_trajectories: Function to draw different trajectories at the same time 113 115 # draw_vals_trajectories: Function to draw values from the outputs from 'compute_tevolboxtraj' … … 146 148 'draw_stations_map', 'draw_Taylor', \ 147 149 'draw_time_lag', 'draw_timeSeries', 'draw_topo_geogrid', \ 148 'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories', \ 150 'draw_topo_geogrid_boxes', 'draw_topofix_geogrid_boxes', 'draw_trajectories', \ 151 'draw_vals_trajectories', \ 149 152 'draw_vectors', 'draw_vertical_levels', 'list_graphics', 'draw_WindRose', \ 150 153 'draw_WRFeta_levels', 'movie_2D_shad', 'variable_values'] … … 1912 1915 """ plotting different geo_em.d[nn].nc topography from WPS files 1913 1916 draw_topo_geogrid_boxes(ncfiles, values) 1914 ncfiles= ',' list of geo_em.d[nn].nc files to use (fi srt as topographyc reference)1917 ncfiles= ',' list of geo_em.d[nn].nc files to use (first as topographyc reference) 1915 1918 values= [minTopo],[maxTopo]:[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:[close] 1916 1919 [min/max]Topo: minimum and maximum values of topography to draw … … 1930 1933 * 'f', full 1931 1934 legvals: [locleg]|[fontsize]: 1932 [locleg]: location of the legend (0, aut moatic)1935 [locleg]: location of the legend (0, automatic) 1933 1936 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 1934 1937 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 2228 2231 [title]: title of the plot ('|' for spaces) 2229 2232 [legvals]=[locleg]|[fontsize]: 2230 [locleg]: location of the legend (0, aut moatic)2233 [locleg]: location of the legend (0, automatic) 2231 2234 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 2232 2235 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 2421 2424 [tfmt]; desired format 2422 2425 [legvals]=[locleg]|[fontsize]|[Ncols] 2423 [locleg]: location of the legend (0, aut moatic)2426 [locleg]: location of the legend (0, automatic) 2424 2427 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 2425 2428 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 3111 3114 [pointlabels]: ',' of labels [only used if [collab]='None'] ('None' for no labels, '!' for spaces) 3112 3115 [legvals]=[locleg]|[fontsize]: 3113 [locleg]: location of the legend (0, aut moatic)3116 [locleg]: location of the legend (0, automatic) 3114 3117 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3115 3118 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 3349 3352 [labels]: ',' list of labels to use 3350 3353 [legvals]=[locleg]|[fontsize]: 3351 [locleg]: location of the legend (0, aut moatic)3354 [locleg]: location of the legend (0, automatic) 3352 3355 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3353 3356 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 3481 3484 [leglabs]: ',' separated list of labels for the lines 3482 3485 [legvals]=[locleg]|[fontsize]: legend values 3483 [locleg]: location of the legend (0, aut moatic)3486 [locleg]: location of the legend (0, automatic) 3484 3487 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3485 3488 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 3686 3689 * 'f', full 3687 3690 [legvals]=[locleg]@[fontsize]: legend values 3688 [locleg]: location of the legend (0, aut moatic)3691 [locleg]: location of the legend (0, automatic) 3689 3692 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3690 3693 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 4028 4031 [leglabels]: ',' separated list of labels for the legend 4029 4032 [legvals]=[locleg]|[fontsize]: 4030 [locleg]: location of the legend (0, aut moatic)4033 [locleg]: location of the legend (0, automatic) 4031 4034 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 4032 4035 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 4936 4939 [kindfig]= kind of figure (png, ps, pdf) 4937 4940 [legvals]=[locleg]|[fontsize]: 4938 [locleg]: location of the legend (0, aut moatic)4941 [locleg]: location of the legend (0, automatic) 4939 4942 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 4940 4943 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 5104 5107 [graphic_kind]= kind of figure (jpg, pdf, png) 5105 5108 [legvals]=[locleg]|[fontsize] 5106 [locleg]: location of the legend (0, aut moatic)5109 [locleg]: location of the legend (0, automatic) 5107 5110 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 5108 5111 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 5290 5293 [graphtit]= title of the graph ('|', for spaces) 5291 5294 [legvals]=[locleg]|[fontsize]: 5292 [locleg]: location of the legend (0, aut moatic)5295 [locleg]: location of the legend (0, automatic) 5293 5296 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 5294 5297 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 5407 5410 [labelaxis]: label in the figure of the common axis ('!' for spaces) 5408 5411 [legvals]=[locleg]|[fontsize]: 5409 [locleg]: location of the legend (0, aut moatic)5412 [locleg]: location of the legend (0, automatic) 5410 5413 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 5411 5414 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 5590 5593 [labelaxis]: label in the figure of the common axis ('!' for spaces) 5591 5594 [legvals]=[locleg]|[fontsize]: 5592 [locleg]: location of the legend (0, aut moatic)5595 [locleg]: location of the legend (0, automatic) 5593 5596 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 5594 5597 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 6560 6563 [graphtit]: title of the figure '!' for spaces 6561 6564 [legvalues]=[locleg]|[fontsize]: 6562 [locleg]: location of the legend (0, aut moatic)6565 [locleg]: location of the legend (0, automatic) 6563 6566 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 6564 6567 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 6717 6720 [graphtit]: title of the figure '!' for spaces 6718 6721 [legvalues]=[locleg]|[fontsize]: 6719 [locleg]: location of the legend (0, aut moatic)6722 [locleg]: location of the legend (0, automatic) 6720 6723 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 6721 6724 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 6928 6931 [graphtit]: title of the figure '!' for spaces 6929 6932 [legvalues]=[locleg]|[fontsize]: 6930 [locleg]: location of the legend (0, aut moatic)6933 [locleg]: location of the legend (0, automatic) 6931 6934 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 6932 6935 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 7152 7155 [graphtit]: title of the figure '!' for spaces 7153 7156 [legvalues]=[locleg]|[fontsize]: 7154 [locleg]: location of the legend (0, aut moatic)7157 [locleg]: location of the legend (0, automatic) 7155 7158 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 7156 7159 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 7450 7453 [graphtit]: title of the figure '!' for spaces 7451 7454 [legvalues]=[locleg]|[fontsize]: 7452 [locleg]: location of the legend (0, aut moatic)7455 [locleg]: location of the legend (0, automatic) 7453 7456 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 7454 7457 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 7723 7726 [graphtit]: title of the figure '!' for spaces 7724 7727 [legvalues]=[locleg]|[fontsize]: 7725 [locleg]: location of the legend (0, aut moatic)7728 [locleg]: location of the legend (0, automatic) 7726 7729 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 7727 7730 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 8268 8271 [graphtit]: title of the figure '!' for spaces 8269 8272 [legvalues]=[locleg]|[fontsize]: 8270 [locleg]: location of the legend (0, aut moatic)8273 [locleg]: location of the legend (0, automatic) 8271 8274 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 8272 8275 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 11016 11019 [kindfig]= kind of figure (png, ps, pdf) 11017 11020 [legvals]= [locleg]|[fontsize]|[Ncol] ('auto' for 0|12|1) 11018 [locleg]: location of the legend (0, aut moatic)11021 [locleg]: location of the legend (0, automatic) 11019 11022 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11020 11023 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 11260 11263 #draw_river_pattern(values, riverns) 11261 11264 11265 def draw_topofix_geogrid_boxes(ncfiles, values): 11266 """ plotting different geo_em.d[nn].nc topography from WPS files 11267 draw_topo_geogrid_boxes(ncfiles, values) on a fixed low-level enhanced color mode 11268 ncfiles= ',' list of geo_em.d[nn].nc files to use (first as topographyc 11269 reference) 11270 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 11274 title: title of the graph ('!' for spaces) 11275 graphic_kind: kind of figure (jpg, pdf, png) 11276 mapvalues: map characteristics [proj],[res] 11277 see full documentation: http://matplotlib.org/basemap/ 11278 [proj]: projection 11279 * 'cyl', cilindric 11280 * 'lcc', lambert conformal 11281 [res]: resolution: 11282 * 'c', crude 11283 * 'l', low 11284 * 'i', intermediate 11285 * 'h', high 11286 * 'f', full 11287 legvals: [locleg]|[fontsize]|[Ncol]: 11288 [locleg]: location of the legend (0, automatic) 11289 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11290 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 11291 9: 'upper center', 10: 'center' 11292 [fontsize]: font size for the legend (auto for 12) 11293 [Ncol]: number of columns (1) 11294 labels: labels to write in the graph ('!' for spaces) 11295 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 mervals: [fontsize]|[color line]|[labels rotation]|[line width] values for 11299 the meridians ([8,'#AAAAAA', 0, 0.5], auto) 11300 parvals: [fontsize]|[color line]|[labels rotation]|[line width] values for 11301 the parallels ([8,'#AAAAAA', 0, 0.5], auto) 11302 coastlvals: [line width|color line] values for the coastline (None for any, 11303 [0.25,'#161616'], auto) 11304 countrylvals: [line width|color line] values for the countries (None for any, 11305 [0.25, '#161616'], auto) 11306 ctylvals: [line width|color line] values for the counties (None for any, None, 11307 [0.25, '#080808'], auto) 11308 close: Whether figure should be finished or not 11309 """ 11310 # import matplotlib as mpl 11311 # mpl.use('Agg') 11312 import matplotlib.pyplot as plt 11313 11314 fname = 'draw_topofix_geogrid_boxes' 11315 11316 if values == 'h': 11317 print fname + '_____________________________________________________________' 11318 print draw_topofix_geogrid_boxes.__doc__ 11319 quit() 11320 11321 expectargs = '[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:'+ \ 11322 '[boxlvals]:[iix]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:[ctyvals]:'+\ 11323 '[close]' 11324 drw.check_arguments(fname,values,expectargs,':') 11325 11326 lonlatLS = values.split(':')[0] 11327 lonlatLv = lonlatLS.split(',')[0] 11328 11329 if lonlatLv == 'None': 11330 lonlatL = None 11331 else: 11332 lonlatL = np.zeros((4), dtype=np.float) 11333 lonlatL[0] = np.float(lonlatLS.split(',')[0]) 11334 lonlatL[1] = np.float(lonlatLS.split(',')[1]) 11335 lonlatL[2] = np.float(lonlatLS.split(',')[2]) 11336 lonlatL[3] = np.float(lonlatLS.split(',')[3]) 11337 11338 grtit = values.split(':')[1].replace('!', ' ') 11339 kindfig = values.split(':')[2] 11340 mapvalues = values.split(':')[3] 11341 labels = values.split(':')[4] 11342 legvals = values.split(':')[5] 11343 boxlvals = values.split(':')[6] 11344 iix = values.split(':')[7] 11345 mervals = values.split(':')[8] 11346 parvals = values.split(':')[9] 11347 coastlvals = values.split(':')[10] 11348 countrylvals = values.split(':')[11] 11349 ctylvals = values.split(':')[12] 11350 close = gen.Str_Bool(values.split(':')[13]) 11351 11352 ncfile = ncfiles.split(',')[0] 11353 if not os.path.isfile(ncfile): 11354 print errormsg 11355 print ' ' + fname + ': domain file "' + ncfile + '" does not exist !!' 11356 quit(-1) 11357 11358 objdomf = NetCDFFile(ncfile, 'r') 11359 11360 objhgt = objdomf.variables['HGT_M'] 11361 objlandsea = objdomf.variables['LANDMASK'] 11362 objlon0 = objdomf.variables['XLONG_M'] 11363 objlat0 = objdomf.variables['XLAT_M'] 11364 11365 topography = objhgt[0,:,:] 11366 landsea = objlandsea[0,:,:] 11367 11368 Nfiles = len(ncfiles.split(',')) 11369 boxlabels = labels.split(',') 11370 11371 Xboxlines = [] 11372 Yboxlines = [] 11373 11374 for ifile in range(Nfiles): 11375 ncfile = ncfiles.split(',')[ifile] 11376 # print ifile, ncfile 11377 if not os.path.isfile(ncfile): 11378 print errormsg 11379 print ' ' + fname + ': domain file "' + ncfile + '" does not exist !!' 11380 quit(-1) 11381 11382 objdomfi = NetCDFFile(ncfile, 'r') 11383 11384 objlon = objdomfi.variables['XLONG_M'] 11385 objlat = objdomfi.variables['XLAT_M'] 11386 11387 dx = objlon.shape[2] 11388 dy = objlon.shape[1] 11389 11390 Xboxlines.append(objlon[0,0,:]) 11391 Yboxlines.append(objlat[0,0,:]) 11392 Xboxlines.append(objlon[0,dy-1,:]) 11393 Yboxlines.append(objlat[0,dy-1,:]) 11394 Xboxlines.append(objlon[0,:,0]) 11395 Yboxlines.append(objlat[0,:,0]) 11396 Xboxlines.append(objlon[0,:,dx-1]) 11397 Yboxlines.append(objlat[0,:,dx-1]) 11398 11399 objdomfi.close() 11400 11401 # Legend 11402 legvals = drw.legend_values(legvals,'|') 11403 11404 if boxlvals != 'auto': 11405 Boxlvals = [str(boxlvals.split('|')[0]), int(boxlvals.split('|')[0])] 11406 else: 11407 Boxlvals = ['-', 3] 11408 if iix != 'auto': Iix = np.float(iix) 11409 else: Iix = 0.8 11410 11411 if mervals != 'auto': 11412 Mervals = [int(mervals.split('|')[0]), str(mervals.split('|')[1]), \ 11413 np.float(mervals.split('|')[2]), np.float(mervals.split('|')[3])] 11414 else: 11415 Mervals = [8,'#AAAAAA', 0, 0.5] 11416 11417 if parvals != 'auto': 11418 Parvals = [int(parvals.split('|')[0]), str(parvals.split('|')[1]), \ 11419 np.float(parvals.split('|')[2]), np.float(parvals.split('|')[3])] 11420 else: 11421 Parvals = [8,'#AAAAAA', 0, 0.5] 11422 11423 if coastlvals != 'auto': 11424 Coastlvals = [np.float(coastlvals.split('|')[0]), \ 11425 str(coastlvals.split('|')[1])] 11426 else: 11427 Coastlvals = [0.25,'#161616'] 11428 11429 if countrylvals != 'auto': 11430 Countrylvals = [np.float(countrylvals.split('|')[0]), \ 11431 str(countrylvals.split('|')[1])] 11432 else: 11433 Countrylvals = [0.25,'#161616'] 11434 11435 if ctylvals != 'auto': 11436 Ctylvals = [np.float(ctylvals.split('|')[0]), str(ctylvals.split('|')[1])] 11437 else: 11438 Ctylvals = [0.25,'#080808'] 11439 11440 drw.plot_topofix_geogrid_boxes(topography, landsea, Xboxlines, Yboxlines, \ 11441 boxlabels, objlon0, objlat0, lonlatL, grtit, kindfig, mapvalues, legvals, \ 11442 Boxlvals, Iix, Mervals, Parvals, Coastlvals, Countrylvals, Ctylvals, close) 11443 11444 objdomf.close() 11445 11446 return 11447 11262 11448 #quit() 11263 11449 … … 11287 11473 'draw_lines_time', 'draw_multiWindRose', 'draw_points', 'draw_river_pattern', \ 11288 11474 'draw_Taylor', \ 11289 'draw_time_lag', 'draw_topo_geogrid_boxes', 11475 'draw_time_lag', 'draw_topo_geogrid_boxes', 'draw_topofix_geogrid_boxes', \ 11290 11476 'draw_trajectories', 'draw_vals_trajectories', 'draw_WRFeta_levels', \ 11291 11477 'variable_values'] … … 11328 11514 11329 11515 if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and \ 11330 not drw.searchInlist(Notcheckingfile, oper):11516 not gen.searchInlist(Notcheckingfile, oper): 11331 11517 print errormsg 11332 11518 print ' ' + mainn + ': File ' + opts.ncfile + ' does not exist !!' … … 11413 11599 elif oper == 'draw_topo_geogrid_boxes': 11414 11600 draw_topo_geogrid_boxes(opts.ncfile, opts.values) 11601 elif oper == 'draw_topofix_geogrid_boxes': 11602 draw_topofix_geogrid_boxes(opts.ncfile, opts.values) 11415 11603 elif oper == 'draw_trajectories': 11416 11604 draw_trajectories(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r2696 r2697 3305 3305 tit= title of the graph 3306 3306 linesn= list of values fot the legend 3307 lloc= location of the legend (0, aut moatic)3307 lloc= location of the legend (0, automatic) 3308 3308 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 3309 3309 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 4390 4390 * 'h', high 4391 4391 * 'f', full 4392 gloc= location of the legend (0, aut moatic)4392 gloc= location of the legend (0, automatic) 4393 4393 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 4394 4394 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 6372 6372 vunit= units of the vaxis 6373 6373 gtit= main title 6374 gloc= location of the legend (0, aut moatic)6374 gloc= location of the legend (0, automatic) 6375 6375 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 6376 6376 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 6756 6756 vmax= maximum value for the axis-value 'auto' for use the extreme 6757 6757 legv = [gloc, gsize, Ncol] legend values 6758 gloc= location of the legend (0, aut moatic)6758 gloc= location of the legend (0, automatic) 6759 6759 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 6760 6760 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 10155 10155 width= size of the column 10156 10156 gtit= title of the figure 10157 lloc= location of the legend (0, aut moatic)10157 lloc= location of the legend (0, automatic) 10158 10158 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10159 10159 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 10323 10323 width= size of the column 10324 10324 gtit= title of the figure 10325 lloc= location of the legend (0, aut moatic)10325 lloc= location of the legend (0, automatic) 10326 10326 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10327 10327 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 10462 10462 ptf= frequency of point plotting, 'all' for all time steps 10463 10463 gtit= title of the figure 10464 lloc= location of the legend (0, aut moatic)10464 lloc= location of the legend (0, automatic) 10465 10465 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10466 10466 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 10684 10684 ptf= frequency of point plotting, 'all' for all time steps 10685 10685 gtit= title of the figure 10686 lloc= location of the legend (0, aut moatic)10686 lloc= location of the legend (0, automatic) 10687 10687 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10688 10688 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 10888 10888 tlab= labels of the time-ticks 10889 10889 gtit= title of the figure 10890 lloc= location of the legend (0, aut moatic)10890 lloc= location of the legend (0, automatic) 10891 10891 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 10892 10892 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 11190 11190 tlabs= labels of the time-ticks 11191 11191 gtit= title of the figure 11192 lloc= location of the legend (0, aut moatic)11192 lloc= location of the legend (0, automatic) 11193 11193 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11194 11194 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 11451 11451 tlabs= labels of the time-ticks 11452 11452 gtit= title of the figure 11453 lloc= location of the legend (0, aut moatic)11453 lloc= location of the legend (0, automatic) 11454 11454 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11455 11455 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', … … 14565 14565 14566 14566 return 14567 14568 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, \ 14570 mervals=[8,'#AAAAAA',0,0.5], parvals=[8,'#AAAAAA',0,0.5], \ 14571 coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], ctylvals=None, \ 14572 closeif=True): 14573 """ plotting geo_em.d[nn].nc topography from WPS files on a fixed low-level 14574 enhanced color mode 14575 varv= topography values of the first domain 14576 landseamask= landseamask values of the first domain 14577 boxesX/Y= 4-line sets to draw the boxes 14578 boxlabels= labels for the legend of the boxes 14579 o[lon/lat]= longitude and latitude objects 14580 lonlatLims: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] 14581 gtit= title of the graph 14582 kfig= kind of figure (jpg, pdf, png) 14583 mapv= map characteristics: [proj],[res] 14584 see full documentation: http://matplotlib.org/basemap/ 14585 [proj]: projection 14586 * 'cyl', cilindric 14587 * 'lcc', lamvbert conformal 14588 [res]: resolution: 14589 * 'c', crude 14590 * 'l', low 14591 * 'i', intermediate 14592 * 'h', high 14593 * 'f', full 14594 legvals = [gloc, gsize, Ncols], values for the legend ([0,8,1], default) 14595 gloc= location of the legend (0, automatic) 14596 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 14597 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 14598 9: 'upper center', 10: 'center' 14599 gsiz= fontsize of the legend 14600 Ncols = number of columns 14601 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) 14604 mervals = values for the meridians [fontsize, color line, labels rotation, 14605 line width] ([8,'#AAAAAA', 0, 0.5], default) 14606 parvals = values for the parallels [fontsize, color line, labels rotation, 14607 line width] ([8,'#AAAAAA', 0, 0.5], default) 14608 coastlvals = values for the coastline [line width, color line] None for any 14609 ([0.25,'#161616'], default) 14610 countrylvals = values for the countries [line width, color line] None for any 14611 ([0.25, '#161616'], default) 14612 ctylvals = values for the counties [line width, color line] None for any (None, 14613 default) 14614 closeif= Boolean value if the figure has to be closed 14615 """ 14616 fname = 'plot_topofix_geogrid' 14617 14618 topobnds=[-140., 0., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.,\ 14619 1500., 2000., 3000., 4000., 7000.] 14620 RGBtopocolors = [[119,152,93], [149,181,112], [189,209,137], [233,238,154], \ 14621 [248,242,168], [251,231,163], [252,225,144], [248,213,133], [251,189,141], \ 14622 [231,175,139], [202,149,132], [206,156,149], [228,182,192], [250,214,231], \ 14623 [224,224,224], [255,255,255], [255,255,255]] 14624 14625 if type(varv) == type('S') and varv == 'h': 14626 print fname + '_____________________________________________________________' 14627 print plot_topofix_geogrid.__doc__ 14628 quit() 14629 14630 # Topography 14631 topobndsS = [] 14632 for t in topobnds: topobndsS.append(str(t)) 14633 14634 HEXtopocolors = [] 14635 Ncolors = len(RGBtopocolors) 14636 for ic in range(Ncolors): 14637 rgbv = np.array(RGBtopocolors[ic], dtype=np.float)/255. 14638 #rgbvx = np.float(np.max(rgbv)) 14639 #if not np.all(rgbv == rgbvx): 14640 # for ii in range(3): 14641 # print rgbv[ii] - rgbvx 14642 # if rgbv[ii] == rgbvx: rgbv[ii] = 1. 14643 14644 rgbv = np.where(rgbv > 0.1, rgbv - 0.1, 0.) 14645 if np.all(rgbv == 0.9): rgbv = rgbv/0.9 14646 14647 hexcol = gen.coldec_hex(rgbv) 14648 HEXtopocolors.append(hexcol) 14649 14650 masktopo = np.where(landsea == 1., varv, gen.fillValueF) 14651 masktopo = ma.masked_equal(masktopo, gen.fillValueF) 14652 14653 Ncolors = len(topobnds) 14654 cmap = mpl.colors.ListedColormap(HEXtopocolors) 14655 normc = mpl.colors.BoundaryNorm(topobnds, cmap.N) 14656 14657 #cols = color_lines(len(boxlabels)) 14658 cols = colorsauto 14659 14660 dx=varv.shape[1] 14661 dy=varv.shape[0] 14662 14663 # plt.rc('text', usetex=True) 14664 14665 if mapv is None: 14666 print emsg 14667 print ' ' + fname + ': A projection parameter is needed None given !!' 14668 quit(-1) 14669 14670 m, meridians, parallels, x, y= mapFigure(olon[:], olat[:], lonlatLims, mapv, 5, 5) 14671 14672 # plt.rc('font', family='serif') 14673 14674 fig, axmat = plt.subplots(1,1) 14675 14676 plt.pcolormesh(x,y,masktopo,cmap=cmap, norm=normc, vmin=topobnds[0], \ 14677 vmax=topobnds[Ncolors-2]) 14678 14679 Nboxes = len(boxesX)/4 14680 for ibox in range(Nboxes): 14681 plt.plot(boxesX[ibox*4], boxesY[ibox*4], linestyle=boxlvals[0], \ 14682 linewidth=boxlvals[1], color=cols[ibox], \ 14683 label=gen.latex_text(boxlabels[ibox].replace('!',' '))) 14684 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('!',' '))) 14687 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('!',' '))) 14690 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('!',' '))) 14693 14694 if coastlvals is not None: 14695 m.drawcoastlines(linewidth=coastlvals[0], color=coastlvals[1]) 14696 if countrylvals is not None: 14697 m.drawcountries(linewidth=countrylvals[0], color=countrylvals[1]) 14698 if ctylvals is not None: 14699 m.drawcounties(linewidth=ctylvals[0], color=ctylvals[1]) 14700 14701 m.drawmeridians(meridians, labels=[True,False,False,True], fontsize=mervals[0], \ 14702 color=mervals[1], rotation=mervals[2], linewidth=mervals[3]) 14703 m.drawparallels(parallels, labels=[True,False,False,True], fontsize=parvals[0], \ 14704 color=parvals[1], rotation=parvals[2], linewidth=parvals[3]) 14705 14706 # FROM: https://matplotlib.org/examples/color/named_colors.html 14707 # Get height and width 14708 ncols = 1 14709 nrows = len(topobnds) 14710 X, Y = fig.get_dpi() * fig.get_size_inches() 14711 h = Y / (nrows + 1) 14712 w = X / ncols 14713 14714 cbox = unichr(9632)#+unichr(9632)+unichr(9632) 14715 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') 14754 14755 figname = 'plot_topofix_geogrid' 14756 graphtit = gen.latex_text(gtit) 14757 #cbar.set_label('height ($m$)') 14758 14759 plt.title(graphtit) 14760 plt.legend(loc=legvals[0], prop={'size':legvals[1]}, ncol=legvals[2]) 14761 14762 output_kind(kfig, figname, closeif) 14763 14764 return 14765
Note: See TracChangeset
for help on using the changeset viewer.