Changeset 2777 in lmdz_wrf for trunk/tools
- Timestamp:
- Dec 1, 2019, 5:03:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r2774 r2777 3080 3080 print ' provided:', projvals 3081 3081 quit(-1) 3082 m = Basemap(projection=proj, lat_0=projvals[0], lon_0=projvals[1],\3083 llcrnrlon=projvals[2], llcrnrlat=projvals[3], urcrnrlon=projvals[4],\3084 3082 defmap = Basemap(projection=proj, lat_0=projvals[0], lon_0=projvals[1], \ 3083 llcrnrlon=projvals[2], llcrnrlat=projvals[3], urcrnrlon=projvals[4], \ 3084 urcrnrlat=projvals[5], resolution=res) 3085 3085 3086 3086 elif proj == 'npstere': … … 15104 15104 return 15105 15105 15106 def shad_simple(vv, vn, vu, xv, yv, vmin, vmax, parameters): 15106 def shad_simple(vv, xv, yv, vmin, vmax, vn='var', vu='-', \ 15107 parameters=['Reds',0.85,'vertical','%6g']): 15107 15108 """ Function to plot using pcolormesh 15108 15109 vv: variable values … … 15123 15124 cmapv = parameters[0] 15124 15125 15125 splot = plt.pcolormesh(xv, yv, vv, cmap=cmapv, vmin=vmin, \ 15126 vmax=vmax) 15126 splot = plt.pcolormesh(xv, yv, vv, cmap=cmapv, vmin=vmin, vmax=vmax) 15127 15127 orien = gen.auto_val(parameters[2], 'vertical') 15128 15128 cbtkf = gen.auto_val(parameters[3], '%6g') … … 15139 15139 cbar = plt.colorbar(format=cbtkf, orientation=orien) 15140 15140 15141 cbar.set_label(gen.latex_text(extrapar[0]) +'('+ gen.units_lunits(extrapar[6]) + \ 15142 ')') 15141 cbar.set_label(gen.latex_text(vn) +'('+ gen.units_lunits(vu) + ')') 15143 15142 15144 15143 return splot 15145 15144 15146 def cnt_simple(vv, xv, yv, vmin, vmax, contkind, parameters): 15145 def cnt_simple(vv, xv, yv, vmin, vmax, contkind, vn='var', vu='-', \ 15146 parameters=['auto','auto','%g']): 15147 15147 """ Function to plot using contour 15148 vv: va riables15148 vv: values variable 15149 15149 xv, yv: x,y coordinates 15150 15150 vmin, vmax: minimum and maximum rang of the plot … … 15158 15158 freqv: frequency of the lines ('auto', pretty(minxv, maxv, 10)) 15159 15159 fmtlabs: format of the labels in the contour (None, also possible) ('auto', 15160 '% d')15160 '%g') 15161 15161 """ 15162 15162 fname = 'cnt_simple' … … 15164 15164 availcontkind = ['cmap', 'fixc', 'fixsigc'] 15165 15165 15166 clabfmt = gen.auto_val(parameters[2], '% d')15166 clabfmt = gen.auto_val(parameters[2], '%g') 15167 15167 if clabfmt == 'None': clabmt = None 15168 15168 15169 if freqv== 'auto':15169 if parameters[1] == 'auto': 15170 15170 vc = pretty(vmin, vmax, 10) 15171 15171 else: 15172 vc = np.arange(vmin, vmax+freqv, freqv) 15173 15174 contkind = ckind.split(',')[0] 15172 vc = np.arange(vmin, vmax+parameters[1], parameters[1]) 15173 15175 15174 if contkind == 'cmap': 15176 15175 colorval = gen.auto_val(parameters[0], 'Reds') 15177 15176 cplot = plt.contour(xv, yv, vv, levels=vc, cmap=plt.get_cmap(colorval)) 15177 colorval = 'k' 15178 15178 elif contkind == 'fixc': 15179 15179 colorval = gen.auto_val(parameters[0], '#FF0000') … … 15198 15198 maxcntS = '{:g}'.format(vc[len(vc)-1]) 15199 15199 15200 plt.annotate(vn + ': '+ gen.units_lunits(vu), xy=(0.01,0.05), \ 15201 xycoords='figure fraction', color=colorval) 15202 15200 15203 return cplot 15201 15204 15202 def plot_multivar_multikind(infilen, figv, figtitle, mapv=None, legvals=[0,8,1], \ 15205 def plot_multivar_multikind(infilen, figv, figtitle, kfig='png', \ 15206 fign='plot_multivar_multikind', mapv=None, legvals=[0,8,1], \ 15203 15207 mervals=[8,'#AAAAAA',0,0.5], parvals=[8,'#AAAAAA',0,0.5], \ 15204 15208 coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], \ … … 15208 15212 mapv= [m,meridians,parallels,x,y]: map environtment (from basemap) [None for 15209 15213 no map] 15210 figv = {'lvars': ['vari', ...], 'vari': [valsi, drawtype,minv,maxv,dtypev]}:15214 figv = {'lvars': ['vari', ...], 'vari': [valsi,vu,drawtype,minv,maxv,dtypev]}: 15211 15215 dictionary with the information of the variables 15212 15216 'lvars': key with a sorted list of the variables to plot 15213 15217 vari: a sort of name to be used in `variables_values' 15218 vu: units of the variable 15214 15219 valsi: matrix values to plot 15215 15220 drawtype: type of figure to draw with this variable … … 15253 15258 dvar1 = figv[var1] 15254 15259 var1v = dvar1[0] 15260 if len(var1v.shape) != 2: 15261 print errormsg 15262 print ' ' + fname + ": variable '" + lvars[0] + "' has not 2D rank !!" 15263 print ' var shape', var1v.shape 15264 quit(-1) 15255 15265 dx = var1v.shape[1] 15256 15266 dy = var1v.shape[0] … … 15268 15278 15269 15279 for varn in lvars: 15280 CFvals = gen.variables_values(varn) 15270 15281 dvari = figv[varn] 15282 Nvari = len(dvari) 15271 15283 valsi = dvari[0] 15272 figt = dvari[1] 15273 vn = dvari[2] 15274 vx = dvari[3] 15275 parfigt = dvari[4] 15284 vu = dvari[1] 15285 figt = dvari[2] 15286 vn = dvari[3] 15287 vx = dvari[4] 15288 parfigt = dvari[5:Nvari] 15276 15289 15277 15290 if figt == 'cnt_cmap': 15278 15291 figk = 'cmap' 15279 ifp = cont_simple(valsi, x, y, vn, vx, figk, parfigt) 15292 ifp = cnt_simple(valsi, x, y, vn, vx, figk, vn=CFvals[0], vu=vu, \ 15293 parameters=parfigt) 15280 15294 elif figt == 'cnt_fixc': 15281 15295 figk = 'fixc' 15282 ifp = cont_simple(valsi, x, y, vn, vx, figk, parfigt) 15296 ifp = cnt_simple(valsi, x, y, vn, vx, figk, vn=CFvals[0], vu=vu, \ 15297 parameters=parfigt) 15283 15298 elif figt == 'cnt_fixsigc': 15284 15299 figk = 'fixsigc' 15285 ifp = cont_simple(valsi, x, y, vn, vx, figk, parfigt) 15300 ifp = cnt_simple(valsi, x, y, vn, vx, figk, vn=CFvals[0], vu=vu, \ 15301 parameters=parfigt) 15286 15302 elif figt == 'shad': 15287 ifp = shad_simple(valsi, x, y, vn, vx, parfigt) 15303 ifp = shad_simple(valsi, x, y, vn, vx, vn=CFvals[0], vu=vu, \ 15304 parameters=parfigt) 15288 15305 else: 15289 15306 print errormsg
Note: See TracChangeset
for help on using the changeset viewer.