Changeset 539 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 29, 2015, 7:44:30 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r531 r539 30 30 namegraphics = ['create_movie', 'draw_2D_shad', 'draw_2D_shad_time', \ 31 31 'draw_2D_shad_cont', 'draw_2D_shad_cont_time', 'draw_2D_shad_line', \ 32 'draw_2D_shad_line_time', 'draw_ timeSeries', 'draw_topo_geogrid',\32 'draw_2D_shad_line_time', 'draw_barbs', 'draw_timeSeries', 'draw_topo_geogrid', \ 33 33 'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories', \ 34 34 'draw_lines', 'draw_lines_time', 'draw_Neighbourghood_evol', 'list_graphics', \ … … 1175 1175 return 1176 1176 1177 def draw_barbs(ncfiles, values, varns): 1178 """ Function to plot wind barbs 1179 values= [X/Y/Z/T]|[dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[mapvalues]: 1180 [gtit]:[kindfig]:[figuren] 1181 [dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of: 1182 [dimname]: name of the dimension in the file 1183 [vardimname]: name of the variable with the values for the dimension in the file 1184 [value]: which value of the given dimension (-1, all; [ibeg]@[iend], i-range beginning, end) 1185 No value takes all the range of the dimension 1186 [vecvals]= [frequency],[color],[length] 1187 [freqv]: [xfreq]@[yfreq] frequency of values allong each axis ('None', all grid points; 1188 'auto', computed automatically to have 20 vectors along each axis) 1189 [colorv]: color of the vectors ('None', for 'red') 1190 [lengthv]: length of the wind barbs ('None', for 9) 1191 [windlabs]= [windname],[windunits] 1192 [windname]: name of the wind variable in the graph 1193 [windunits]: units of the wind variable in the graph ('None', for the value in the file) 1194 [mapvalues]= map characteristics: [proj],[res] 1195 see full documentation: http://matplotlib.org/basemap/ 1196 [proj]: projection 1197 * 'cyl', cilindric 1198 * 'lcc', lambert conformal 1199 [res]: resolution: 1200 * 'c', crude 1201 * 'l', low 1202 * 'i', intermediate 1203 * 'h', high 1204 * 'f', full 1205 gtit= title of the graph ('|', for spaces) 1206 kindfig= kind of figure 1207 figuren= name of the figure 1208 ncfile= file to use 1209 varns= [uwind],[ywind] ',' list of the name of the variables with the u-wind,y-wind component 1210 """ 1211 fname = 'draw_barbs' 1212 1213 if values == 'h': 1214 print fname + '_____________________________________________________________' 1215 print draw_barbs.__doc__ 1216 quit() 1217 1218 expectargs = '[X/Y/Z/T]|[dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:' + \ 1219 '[mapvalues]:[gtit]:[kindfig]:[figuren]' 1220 1221 drw.check_arguments(fname,len(expectargs.split(':')),values,':', \ 1222 expectargs.split(':')) 1223 1224 dimvals = values.split(':')[0] 1225 vecvals = values.split(':')[1] 1226 windlabs = values.split(':')[2] 1227 mapvalues = values.split(':')[3] 1228 gtit = values.split(':')[4] 1229 kindfig = values.split(':')[5] 1230 figuren = values.split(':')[6] 1231 1232 of = NetCDFFile(ncfile,'r') 1233 1234 dims = {} 1235 for dimv in dimvals.split(','): 1236 dns = dimv.split('|') 1237 dims[dns[0]] = [dns[1], dns[2]] 1238 1239 varNs = [] 1240 for dn in dims.keys(): 1241 if dn == 'X': 1242 varNs.append(dims[dn][2]) 1243 elif dn == 'Y': 1244 varNs.append(dims[dn][2]) 1245 1246 ivar = 0 1247 for wvar in varns.split(','): 1248 if not drw.searchInlist(of.variables.keys(), wvar): 1249 print errormsg 1250 print ' ' + fname + ": file does not have variable '" + wvar + "' !!" 1251 quit(-1) 1252 if ivar == 0: 1253 varNs.append(wvar) 1254 else: 1255 varNs.append(wvar) 1256 1257 ivar = 0 1258 for varN in varNs: 1259 varslice = [] 1260 1261 ovarN = of.variables[varN] 1262 vard = ovarN.dimensions.keys() 1263 for vdn in vard: 1264 for dd in dims.keys(): 1265 if dd == vdn: 1266 if dims[dd][1].find('@') != -1: 1267 rvals = dims[dd][1].replace('@') 1268 varslice.append(slice(int(rvals[0]), int(rvals[1]))) 1269 elif dims[dd][1] == '-1': 1270 varslice.append(slice(0,len(of.dimensions[dims[dd]]))) 1271 break 1272 else: 1273 varslice.append(slice(0,len(of.dimensions[dims[dd]]))) 1274 1275 if ivar == 0: 1276 lonvals0 = ovarN[tuple(varslice)] 1277 elif ivar == 1: 1278 latvals0 = ovarN[tuple(varslice)] 1279 elif ivar == 2: 1280 uwvals = ovarN[tuple(varslice)] 1281 elif ivar == 3: 1282 vwvals = ovarN[tuple(varslice)] 1283 1284 if len(lonvals0.shape) == 1: 1285 lonvals, latvals = np.meshgrid(lonvals0, latvals0) 1286 1287 # Vecor values 1288 freqv = vecvals.split(',')[0] 1289 colorv = vecvals.split(',')[1] 1290 lengthv = vecvals.split(',')[2] 1291 1292 # Vector labels 1293 windname = windlabels.split(',')[0] 1294 windunits = windlabels.split(',')[1] 1295 1296 drw.plot_barbs(lonvals, latvals, uwvals, vwvals, freqv, colorv, lengthv, 1297 windname, windunits, mapvalues, gtit, kindfig, figuren) 1298 1299 return 1300 1177 1301 def draw_topo_geogrid(ncfile, values): 1178 1302 """ plotting geo_em.d[nn].nc topography from WPS files … … 2518 2642 elif oper == 'draw_2D_shad_line_time': 2519 2643 draw_2D_shad_line_time(opts.ncfile, opts.values, opts.varname) 2644 elif oper == 'draw_barbs': 2645 draw_barbs(opts.ncfile, opts.values, opts.varname) 2520 2646 elif oper == 'draw_Neighbourghood_evol': 2521 2647 draw_Neighbourghood_evol(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r531 r539 68 68 if x == nameFind: 69 69 return True 70 break 70 71 return False 71 72 … … 5170 5171 5171 5172 return 5173 5174 def plot_barbs(xvals,yvals,vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname): 5175 """ Function to plot wind barbs 5176 xvals= values for the 'x-axis' 5177 yvals= values for the 'y-axis' 5178 vecfreq= [xfreq],[yfreq] frequency of values allong each axis (None, all grid points; 5179 'auto', computed automatically to have 20 vectors along each axis) 5180 veccolor= color of the vectors (None, for 'red') 5181 veclength= length of the wind barbs (None, for 9) 5182 windn= name of the wind variable in the graph 5183 wuts= units of the wind variable in the graph 5184 mapv= map characteristics: [proj],[res] 5185 see full documentation: http://matplotlib.org/basemap/ 5186 [proj]: projection 5187 * 'cyl', cilindric 5188 * 'lcc', lambert conformal 5189 [res]: resolution: 5190 * 'c', crude 5191 * 'l', low 5192 * 'i', intermediate 5193 * 'h', high 5194 * 'f', full 5195 graphtit= title of the graph ('|', for spaces) 5196 kfig= kind of figure 5197 figname= name of the figure 5198 """ 5199 fname = 'plot_barbs' 5200 5201 dx=xvals.shape[1] 5202 dy=xvals.shape[0] 5203 5204 # Frequency of vectors 5205 if vecfreq is None: 5206 xfreq = 1 5207 yfreq = 1 5208 elif vecfreq == 'auto': 5209 xfreq = dx/20 5210 yfreq = dy/20 5211 else: 5212 xfreq=int(vecfreq.split('@')[0]) 5213 yfreq=int(vecfreq.split('@')[1]) 5214 5215 if veccolor is None: 5216 vcolor = "red" 5217 else: 5218 vcolor = veccolor 5219 5220 if veclength is None: 5221 vlength = 9 5222 else: 5223 vlength = veclength 5224 5225 plt.rc('text', usetex=True) 5226 5227 if not mapv is None: 5228 lon00 = np.where(xvals[:] < 0., 360. + xvals[:], xvals[:]) 5229 lat00 = yvals[:] 5230 5231 map_proj=mapv.split(',')[0] 5232 map_res=mapv.split(',')[1] 5233 5234 nlon = np.min(xvals[::yfreq,::xfreq]) 5235 xlon = np.max(xvals[::yfreq,::xfreq]) 5236 nlat = np.min(yvals[::yfreq,::xfreq]) 5237 xlat = np.max(yvals[::yfreq,::xfreq]) 5238 5239 lon2 = xvals[dy/2,dx/2] 5240 lat2 = yvals[dy/2,dx/2] 5241 5242 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ 5243 xlon, ',', xlat 5244 5245 if map_proj == 'cyl': 5246 m = Basemap(projection=map_proj, llcrnrlon=nlon, llcrnrlat=nlat, \ 5247 urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 5248 elif map_proj == 'lcc': 5249 m = Basemap(projection=map_proj, lat_0=lat2, lon_0=lon2, llcrnrlon=nlon, \ 5250 llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 5251 else: 5252 print errormsg 5253 print ' ' + fname + ": projection '" + map_proj + "' not ready!!" 5254 print ' projections available: cyl, lcc' 5255 quit(-1) 5256 5257 m.drawcoastlines() 5258 5259 meridians = pretty_int(nlon,xlon,5) 5260 m.drawmeridians(meridians,labels=[True,False,False,True],color="black") 5261 5262 parallels = pretty_int(nlat,xlat,5) 5263 m.drawparallels(parallels,labels=[False,True,True,False],color="black") 5264 5265 plt.xlabel('W-E') 5266 plt.ylabel('S-N') 5267 5268 plt.barbs(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq], \ 5269 uvals[timev,lev,::yfreq,::xfreq],vvals[timev,lev,::yfreq,::xfreq],color=vcolor,\ 5270 pivot='tip') 5271 5272 plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')', \ 5273 xy=(0.85,-0.10), xycoords='axes fraction', color=vcolor) 5274 5275 plt.title(graphtit.replace('|',' ').replace('&','\&')) 5276 5277 ## NOT WORKING ## 5278 5279 # No legend so it is imposed 5280 ## windlabel=windn.replace('_','\_') +' (' + units_lunits(wuts[1]) + ')' 5281 ## vecpatch = mpatches.Patch(color=vcolor, label=windlabel) 5282 5283 ## plt.legend(handles=[vecpatch]) 5284 5285 ## vecline = mlines.Line2D([], [], color=vcolor, marker='.', markersize=10, label=windlabel) 5286 ## plt.legend(handles=[vecline], loc=1) 5287 5288 output_kind(kfig, figname, True) 5289 5290 return
Note: See TracChangeset
for help on using the changeset viewer.