Changeset 540 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 30, 2015, 11:40:50 AM (10 years ago)
Author:
lfita
Message:

Working version of the `draw_barbs'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r539 r540  
    11751175    return
    11761176
    1177 def draw_barbs(ncfiles, values, varns):
     1177def draw_barbs(ncfile, values, varns):
    11781178    """ 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]:
    11801180        [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:
    11821182          [dimname]: name of the dimension in the file
    11831183          [vardimname]: name of the variable with the values for the dimension in the file
     
    11851185          No value takes all the range of the dimension
    11861186        [vecvals]= [frequency],[color],[length]
    1187           [freqv]: [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;
    11881188            '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)
     1189          [color]: color of the vectors ('auto', for 'red')
     1190          [length]: length of the wind barbs ('auto', for 9)
    11911191        [windlabs]= [windname],[windunits]
    11921192          [windname]: name of the wind variable in the graph
     
    12241224    dimvals = values.split(':')[0]
    12251225    vecvals = values.split(':')[1]
    1226     windlabs = values.split(':')[2]
     1226    windlabels = values.split(':')[2]
    12271227    mapvalues = values.split(':')[3]
    12281228    gtit = values.split(':')[4]
     
    12351235    for dimv in dimvals.split(','):
    12361236        dns = dimv.split('|')
    1237         dims[dns[0]] = [dns[1], dns[2]]
     1237        dims[dns[0]] = [dns[1], dns[2], dns[3]]
    12381238
    12391239    varNs = []
    12401240    for dn in dims.keys():
    12411241        if dn == 'X':
    1242             varNs.append(dims[dn][2])
     1242            varNs.append(dims[dn][1])
     1243            dimx = len(of.dimensions[dims[dn][0]])
    12431244        elif dn == 'Y':
    1244             varNs.append(dims[dn][2])
     1245            varNs.append(dims[dn][1])
     1246            dimy = len(of.dimensions[dims[dn][0]])
    12451247
    12461248    ivar = 0
     
    12571259    ivar = 0
    12581260    for varN in varNs:
     1261        print varN,'...'
    12591262        varslice = []
    12601263
    12611264        ovarN = of.variables[varN]
    1262         vard = ovarN.dimensions.keys()
     1265        vard = ovarN.dimensions
    12631266        for vdn in vard:
     1267            found = False
    12641268            for dd in dims.keys():
    1265                 if dd == 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('@')
    12681272                        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
    12711279                    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)])
    12791287        elif ivar == 2:
    1280             uwvals = ovarN[tuple(varslice)]
     1288            uwvals = np.squeeze(np.array(ovarN[tuple(varslice)]))
    12811289        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)
    12831305
    12841306    if len(lonvals0.shape) == 1:
    12851307        lonvals, latvals = np.meshgrid(lonvals0, latvals0)
     1308    else:
     1309        lonvals = lonvals0
     1310        latvals = latvals0
    12861311
    12871312# Vecor values
    1288     freqv = vecvals.split(',')[0]
     1313    if vecvals.split(',')[0] == 'None':
     1314        freqv = None
     1315    else:
     1316        freqv = vecvals.split(',')[0]
    12891317    colorv = vecvals.split(',')[1]
    12901318    lengthv = vecvals.split(',')[2]
  • trunk/tools/drawing_tools.py

    r539 r540  
    51725172    return
    51735173
    5174 def plot_barbs(xvals,yvals,vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname):
     5174def plot_barbs(xvals,yvals,uvals,vvals,vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname):
    51755175    """ Function to plot wind barbs
    51765176      xvals= values for the 'x-axis'
     
    52135213        yfreq=int(vecfreq.split('@')[1])
    52145214
    5215     if veccolor is None:
     5215    if veccolor == 'auto':
    52165216        vcolor = "red"
    52175217    else:
    52185218        vcolor = veccolor
    52195219
    5220     if veclength is None:
     5220    if veclength == 'auto':
    52215221        vlength = 9
    52225222    else:
     
    52665266        plt.ylabel('S-N')
    52675267
    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')
    52715270
    52725271    plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')',           \
Note: See TracChangeset for help on using the changeset viewer.