Changeset 540 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 30, 2015, 11:40:50 AM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r539 r540 1175 1175 return 1176 1176 1177 def draw_barbs(ncfile s, values, varns):1177 def draw_barbs(ncfile, values, varns): 1178 1178 """ Function to plot wind barbs 1179 values= [ X/Y/Z/T]|[dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[mapvalues]:1179 values= [dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[mapvalues]: 1180 1180 [gtit]:[kindfig]:[figuren] 1181 [dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of:1181 'X/Y/Z/T'|[dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of: 1182 1182 [dimname]: name of the dimension in the file 1183 1183 [vardimname]: name of the variable with the values for the dimension in the file … … 1185 1185 No value takes all the range of the dimension 1186 1186 [vecvals]= [frequency],[color],[length] 1187 [freq v]: [xfreq]@[yfreq] frequency of values allong each axis ('None', all grid points;1187 [frequency]: [xfreq]@[yfreq] frequency of values allong each axis ('None', all grid points; 1188 1188 'auto', computed automatically to have 20 vectors along each axis) 1189 [color v]: color of the vectors ('None', for 'red')1190 [length v]: length of the wind barbs ('None', for 9)1189 [color]: color of the vectors ('auto', for 'red') 1190 [length]: length of the wind barbs ('auto', for 9) 1191 1191 [windlabs]= [windname],[windunits] 1192 1192 [windname]: name of the wind variable in the graph … … 1224 1224 dimvals = values.split(':')[0] 1225 1225 vecvals = values.split(':')[1] 1226 windlab s = values.split(':')[2]1226 windlabels = values.split(':')[2] 1227 1227 mapvalues = values.split(':')[3] 1228 1228 gtit = values.split(':')[4] … … 1235 1235 for dimv in dimvals.split(','): 1236 1236 dns = dimv.split('|') 1237 dims[dns[0]] = [dns[1], dns[2] ]1237 dims[dns[0]] = [dns[1], dns[2], dns[3]] 1238 1238 1239 1239 varNs = [] 1240 1240 for dn in dims.keys(): 1241 1241 if dn == 'X': 1242 varNs.append(dims[dn][2]) 1242 varNs.append(dims[dn][1]) 1243 dimx = len(of.dimensions[dims[dn][0]]) 1243 1244 elif dn == 'Y': 1244 varNs.append(dims[dn][2]) 1245 varNs.append(dims[dn][1]) 1246 dimy = len(of.dimensions[dims[dn][0]]) 1245 1247 1246 1248 ivar = 0 … … 1257 1259 ivar = 0 1258 1260 for varN in varNs: 1261 print varN,'...' 1259 1262 varslice = [] 1260 1263 1261 1264 ovarN = of.variables[varN] 1262 vard = ovarN.dimensions .keys()1265 vard = ovarN.dimensions 1263 1266 for vdn in vard: 1267 found = False 1264 1268 for dd in dims.keys(): 1265 if d d== vdn:1266 if dims[dd][ 1].find('@') != -1:1267 rvals = dims[dd][ 1].replace('@')1269 if dims[dd][0] == vdn: 1270 if dims[dd][2].find('@') != -1: 1271 rvals = dims[dd][2].split('@') 1268 1272 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]]))) 1273 elif dims[dd][2] == '-1': 1274 varslice.append(slice(0,len(of.dimensions[dims[dd][0]]))) 1275 else: 1276 varslice.append(int(dims[dd][2])) 1277 1278 found = True 1271 1279 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)]1280 if not found: 1281 varslice.append(slice(0,len(of.dimensions[dims[dd][0]]))) 1282 1283 if varN == dims['X'][1]: 1284 lonvals0 = np.squeeze(ovarN[tuple(varslice)]) 1285 elif varN == dims['Y'][1]: 1286 latvals0 = np.squeeze(ovarN[tuple(varslice)]) 1279 1287 elif ivar == 2: 1280 uwvals = ovarN[tuple(varslice)]1288 uwvals = np.squeeze(np.array(ovarN[tuple(varslice)])) 1281 1289 elif ivar == 3: 1282 vwvals = ovarN[tuple(varslice)] 1290 vwvals = np.squeeze(ovarN[tuple(varslice)]) 1291 1292 ivar = ivar + 1 1293 1294 # print 'Final shapes:',lonvals0.shape,':',latvals0.shape,':',uwvals.shape,':', 1295 # vwvals.shape 1296 1297 if len(uwvals.shape) != 2 or len(vwvals.shape) != 2: 1298 print errormsg 1299 print ' ' + fname + ': wrong size of the wind fields! they must be ' + \ 1300 '2-dimensional!' 1301 print ' u-winds shape:',uwvals.shape,'dims:',of.variables[varNs[2]] 1302 print ' v-winds shape:',vwvals.shape,'dims:',of.variables[varNs[3]] 1303 print ' provide more values for their dimensions!!' 1304 quit(-1) 1283 1305 1284 1306 if len(lonvals0.shape) == 1: 1285 1307 lonvals, latvals = np.meshgrid(lonvals0, latvals0) 1308 else: 1309 lonvals = lonvals0 1310 latvals = latvals0 1286 1311 1287 1312 # Vecor values 1288 freqv = vecvals.split(',')[0] 1313 if vecvals.split(',')[0] == 'None': 1314 freqv = None 1315 else: 1316 freqv = vecvals.split(',')[0] 1289 1317 colorv = vecvals.split(',')[1] 1290 1318 lengthv = vecvals.split(',')[2] -
trunk/tools/drawing_tools.py
r539 r540 5172 5172 return 5173 5173 5174 def plot_barbs(xvals,yvals, vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname):5174 def plot_barbs(xvals,yvals,uvals,vvals,vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname): 5175 5175 """ Function to plot wind barbs 5176 5176 xvals= values for the 'x-axis' … … 5213 5213 yfreq=int(vecfreq.split('@')[1]) 5214 5214 5215 if veccolor is None:5215 if veccolor == 'auto': 5216 5216 vcolor = "red" 5217 5217 else: 5218 5218 vcolor = veccolor 5219 5219 5220 if veclength is None:5220 if veclength == 'auto': 5221 5221 vlength = 9 5222 5222 else: … … 5266 5266 plt.ylabel('S-N') 5267 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') 5268 plt.barbs(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq], uvals[::yfreq,::xfreq],\ 5269 vvals[::yfreq,::xfreq], color=vcolor, pivot='tip') 5271 5270 5272 5271 plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')', \
Note: See TracChangeset
for help on using the changeset viewer.