Changeset 1241 in lmdz_wrf


Ignore:
Timestamp:
Oct 31, 2016, 7:22:58 PM (8 years ago)
Author:
lfita
Message:

Improving `draw_2D_shad_line_time'
Enhancing `draw_barbs'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1231 r1241  
    1010import os
    1111from netCDF4 import Dataset as NetCDFFile
     12import nc_var_tools as ncvar
    1213import drawing_tools as drw
    1314import generic_tools as gen
     
    2223## e.g. # drawing.py -o draw_2D_shad_cont_time -f wrfout_d01_2001-11-11_00:00:00 -S 'hfls,tas;west_east|-1,south_north|27,Time|-1;south_north|27;XLONG;WRFtime;auto;BuPu,auto,auto;fixc,y;%3g;Srange,Srange;260,300,9;huss|&|tas|evolution|at|south_north=27;png;None;WRFtime|hours!since!1949-12-01|exct,1,h|$%d^{%H}$|date!($[DD]^{[HH]}$);True' -v LH,T2
    2324## e.g. # drawing.py -o draw_2D_shad_line -f wrfout_d01_2001-11-11_00:00:00,wrfout_d01_2001-11-11_00:00:00 -S 'hus,hgt:west_east|-1,south_north|96,Time|2,bottom_top|-1:XLONG:ZNU:auto:rainbow,auto,horizontal:Srange,Srange:k,0.,4000.,auto,auto,auto,45.:vert.|sec.|hus|at|y=96|on|2001-11-11|02|UTC:png:flip@y:None:True' -v QVAPOR,HGT
     25## e.g. # drawing.py -o draw_barbs -f wrfout_d01_2001-11-11_00:00:00 -S 'west_east|XLONG|-1,west_east_stag|XLONG|0@239@1,south_north|XLAT|15,bottom_top|ZNU|-1,bottom_top_stag|ZNW|0@39@1,Time|WRFtime|3:10@2,colormap@rainbow,7.:uw,ms-1:XLONG:ZNW:None:auto:flip@y:vertical|cross|section|wind|speed|at|y=15|on|2001-11-10|03|UTC:png:wind_barbs_2001111003_uw:True' -v U,W
    2426## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'height,landmask:Time|0:Time|0:XLONG_M:XLAT_M:terrain:fixc,k:None:0.,3000.:0,1,10:MEDCORDEX height & landmask:pdf:False:lcc,i' -v HGT_M,LANDMASK
    2527## e.g. # drawing.py -o draw_2D_shad_line -f 'mean_dtcon-pluc-pres_lat.nc,mean_dtcon-pluc-pres_lat.nc' -S 'dtcon,prc:bottom_top|-1,south_north|-1:latmean:presmean:seismic,k:-5.,5.:monthly|dtcon|&|prc:pdf:flip@y:None:True' -v 'dtconmean,prcmean'
     
    11111113          [Ndl]: Number of ticks at the line-axis ('auto' for 5)
    11121114          [ordl]: angle of orientation of ticks at the line-axis ('auto' for horizontal)
    1113         [smin/axv]: minimum and maximum value for the shading
    11141115        [figt]: title of the figure ('|' for spaces)
    11151116        [kindfig]: kind of figure
     
    12821283    draw_2D_shad_line(ncfile, values, varn)
    12831284      ncfile= [ncfiles],[ncfilel] files to use to draw with shading and the line
    1284       values= [vnamefs],[vanemefl]:[dimvals]:[dimxvn]:[dimyvn]:[colorbar]:[sminv],[smaxv]:[figt]:
    1285        [kindfig]:[reverse]:[timevals]:[close]
     1285      values= [vnamefs],[vanemefl];[dimvals];[dimxvn];[dimyvn];[dimxyfmt];[colorbarvals];[sminv],[smaxv];
     1286        [figt];[kindfig];[reverse];[timevals];[close]
    12861287        [vnamefs]: Name in the figure of the variable to be shaded
    12871288        [vnamefl]: Name in the figure of the variable to be lined
     
    12891290          variable a given value is required (-1, all the length)
    12901291        [dimx/yvn]: name of the variables with the values of the final dimensions (x,y)
    1291         [colorbar]: name of the color bar
    1292         [smin/axv]: minimum and maximum value for the shading
     1292        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordx]: format of the values at each axis (or 'auto')
     1293          [dxs]: style of x-axis ('auto' for 'pretty')
     1294            'Nfix', values computed at even 'Ndx'
     1295            'Vfix', values computed at even 'Ndx' increments
     1296            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     1297          [dxf]: format of the labels at the x-axis ('auto' for '%5g')
     1298          [Ndx]: Number of ticks at the x-axis ('auto' for 5)
     1299          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     1300          [dys]: style of y-axis ('auto' for 'pretty')
     1301          [dyf]: format of the labels at the y-axis ('auto' for '%5g')
     1302          [Ndy]: Number of ticks at the y-axis ('auto' for 5)
     1303          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     1304        [colorbarvals]=[colbarn],[fmtcolorbar],[orientation]
     1305          [colorbarn]: name of the color bar
     1306          [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
     1307          [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal')
     1308        [smin/axv]: minimum and maximum value for the shading or:
     1309          'Srange': for full range
     1310          'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
     1311          'Saroundminmax@val': for min*val,max*val
     1312          'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
     1313            percentile_(100-val)-median)
     1314          'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
     1315          'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
     1316          'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
     1317             percentile_(100-val)-median)
     1318        [linevalues]=[colline],[sminl],[smaxl],[dls],[dlf],[Ndl],[ordl]
     1319          [colline]: name of the color for the line
     1320          [smin/axv]: minimum and maximum value for the line or:
     1321            'Srange': for full range
     1322             'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
     1323            'Saroundminmax@val': for min*val,max*val
     1324            'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
     1325              percentile_(100-val)-median)
     1326            'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
     1327            'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
     1328            'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
     1329               percentile_(100-val)-median)
     1330          [dls]: style of line-axis ('auto' for 'pretty')
     1331          [dlf]: format of the labels at the line-axis ('auto' for '%5g')
     1332          [Ndl]: Number of ticks at the line-axis ('auto' for 5)
     1333          [ordl]: angle of orientation of ticks at the line-axis ('auto' for horizontal)
    12931334        [figt]: title of the figure ('|' for spaces)
    12941335        [kindfig]: kind of figure
     
    13191360        quit()
    13201361
    1321     farguments = '[vnamefs],[vanemefl]:[dimvals]:[dimxvn]:[dimyvn]:' +               \
    1322       '[colorbar]:[sminv],[smaxv]:[figt]:[kindfig]:[reverse]:[timevals]:[close]'
    1323     drw.check_arguments(fname,values,farguments,':')
    1324 
    1325     vnamesfig = values.split(':')[0].split(',')[0]
    1326     dimvals= values.split(':')[1].replace('|',':')
    1327     vdimxn = values.split(':')[2]
    1328     vdimyn = values.split(':')[3]
    1329     colbarn = values.split(':')[4]
    1330     shadminmax = values.split(':')[5]
    1331     figtitle = values.split(':')[6].replace('|',' ')
    1332     figkind = values.split(':')[7]
    1333     revals = values.split(':')[8]
    1334     timevals = values.split(':')[9]
    1335     close = values.split(':')[10]
     1362    farguments = '[vnamefs],[vanemefl];[dimvals];[dimxvn];[dimyvn];[dimxyfmt];' +    \
     1363      '[colorbarvals];[sminv],[smaxv];[linevalues];[figt];[kindfig];[reverse];[timevals];[close]'
     1364    drw.check_arguments(fname,values,farguments,';')
     1365
     1366    vnamesfig = values.split(';')[0]
     1367    dimvals= values.split(';')[1].replace('|',':')
     1368    vdimxn = values.split(';')[2]
     1369    vdimyn = values.split(';')[3]
     1370    dimxyfmt = values.split(';')[4]
     1371    colorbarvals = values.split(';')[5]
     1372    shadminmax = values.split(';')[6]
     1373    linevalues = values.split(';')[7]
     1374    figtitle = values.split(';')[8].replace('|',' ')
     1375    figkind = values.split(';')[9]
     1376    revals = values.split(';')[10]
     1377    timevals = values.split(';')[11]
     1378    close = gen.Str_Bool(values.split(';')[12])
    13361379
    13371380    ncfiles = ncfile.split(',')[0]
     1381    ncfilel = ncfile.split(',')[1]
     1382
     1383    vshadn = vnamesfig.split(',')[0]
     1384    vlinen = vnamesfig.split(',')[1]
    13381385   
    13391386    if not os.path.isfile(ncfiles):
    13401387        print errormsg
    13411388        print '  ' + fname + ': shading file "' + ncfiles + '" does not exist !!'
     1389        quit(-1)   
     1390    if not os.path.isfile(ncfilel):
     1391        print errormsg
     1392        print '  ' + fname + ': line file "' + ncfilel + '" does not exist !!'
    13421393        quit(-1)   
    13431394
     
    13611412    varunits = objvars.getncattr('units')
    13621413
    1363     if not objsf.variables.has_key(vdimxn):
     1414    if vdimxn != 'WRFtime' and not objsf.variables.has_key(vdimxn):
    13641415        print errormsg
    13651416        print '  ' + fname + ': shading file "' + ncfiles +                          \
    13661417          '" does not have dimension variable "' +  vdimxn + '" !!'
    13671418        quit(-1)
    1368     if not objsf.variables.has_key(vdimyn):
     1419    if vdimyn != 'WRFtime' and not objsf.variables.has_key(vdimyn):
    13691420        print errormsg
    13701421        print '  ' + fname + ': shading file "' + ncfiles +                          \
    13711422          '" does not have dimension variable "' +  vdimyn + '" !!'
    1372         quit(-1)
    1373 
    1374     objdimx = objsf.variables[vdimxn]
    1375     objdimy = objsf.variables[vdimyn]
    1376     odimxu = objdimx.getncattr('units')
    1377     odimyu = objdimy.getncattr('units')
    1378 
    1379     if len(objdimx.shape) <= 2:
    1380         odimxv = objdimx[:]
    1381         odimyv = objdimy[:]
    1382 
    1383     elif len(objdimx.shape) == 3:
    1384         odimxv = objdimx[0,:]
    1385         odimyv = objdimy[0,:]
    1386     else:
    1387         print errormsg
    1388         print '  ' + fname + ': shape of dimension variable:', objdimx.shape,        \
    1389           ' not ready!!'
    13901423        quit(-1)
    13911424
     
    13961429    timelabel = timevals.split('|')[4].replace('!',' ')
    13971430
     1431    # Getting time as WRF Times
     1432    if timename == 'WRFtime':
     1433        dictslice = {}
     1434        for dnv in dimvals.split(','):
     1435            dimn = dnv.split(':')[0]
     1436            dimv = dnv.split(':')[1]
     1437            if dimv.find(',') != -1:
     1438                dictslice[dimn] = list(np.array(dimv.split(','), dtype=int))
     1439            else:
     1440                dictslice[dimn] = int(dimv)
     1441
     1442        wrft = objsf.variables['Times']
     1443        slicewrft, dwrfd = ncvar.SliceVarDict(wrft, dictslice)
     1444        timewrfv = wrft[tuple(slicewrft)]
     1445        if len(timeunit.split(' ')) > 3:
     1446            refdateS = timeunit.split(' ')[2] + ' ' + timeunit.split(' ')[3]
     1447        else:
     1448            refdateS = timeunit.split(' ')[2] + ' 00:00:00'
     1449        tunitsval = timeunit.split(' ')[0]
     1450
     1451        yrref=refdateS[0:4]
     1452        monref=refdateS[5:7]
     1453        dayref=refdateS[8:10]
     1454        horref=refdateS[11:13]
     1455        minref=refdateS[14:16]
     1456        secref=refdateS[17:19]
     1457
     1458        refdate = yrref + monref + dayref + horref + minref + secref
     1459
     1460        dt = timewrfv.shape[0]
     1461        cftimes = np.zeros((dt), dtype=np.float)
     1462        for it in range(dt):
     1463            wrfdates = gen.datetimeStr_conversion(timewrfv[it,:],        \
     1464              'WRFdatetime', 'matYmdHMS')
     1465            cftimes[it] = gen.realdatetime1_CFcompilant(wrfdates,        \
     1466              refdate, tunitsval)
     1467        tunits = tunitsval + ' since ' + refdateS
     1468
    13981469    if vdimxn == timename:
    1399         odimxv = objsf.variables[vdimxn][:]
     1470        if timename != 'WRFtime':
     1471            odimxv = objsf.variables[vdimxn][:]
     1472        else:
     1473            odimxv = cftimes
    14001474        odimxu = timelabel
    14011475        timeaxis = 'x'
    1402         odimyv = objsf.variables[vdimyn]
    1403         odimyu = odimyv.getncattr('units')
     1476        objdimyv = objsf.variables[vdimyn]
     1477        odimyv = objdimyv[:]
     1478        odimyu = objdimyv.getncattr('units')
    14041479        timepos, timelabels = drw.CFtimes_plot(odimxv, timeunit, timekind, timefmt)
    14051480    elif vdimyn == timename:
    1406         odimyv = objsf.variables[vdimyn][:]
     1481        if timename != 'WRFtime':
     1482            odimyv = objsf.variables[vdimxn][:]
     1483        else:
     1484            odimyv = cftimes
    14071485        odimyu = timelabel
    14081486        timeaxis = 'y'
    1409         odimxv = objsf.variables[vdimxn]
    1410         odimxu = odimxv.getncattr('units')
     1487        objdimxv = objsf.variables[vdimxn]
     1488        odimxv = objdimxv[:]
     1489        odimxu = objdimxv.getncattr('units')
    14111490        timepos, timelabels = drw.CFtimes_plot(odimyv, timeunit, timekind, timefmt)
    14121491    else:
     
    14151494        quit(-1)
    14161495
    1417     shading_nx = np.zeros((2), dtype=np.float)
    1418     shading_nx[0] = np.float(shadminmax.split(',')[0])
    1419     shading_nx[1] = np.float(shadminmax.split(',')[1])
    1420 
    1421     closeval = drw.Str_Bool(close)
    1422 
    1423     drw.plot_2D_shadow_time(valshad, vnamesfig, odimxv, odimyv, odimxu, odimyu,      \
    1424       dimnamesv, colbarn, shading_nx, varunits, figtitle, figkind, revals, timeaxis, \
    1425       timepos, timelabels, False)
     1496    shading_nx = shadminmax.split(',')
    14261497
    14271498# Line values
    14281499##
    1429     ncfilel = ncfile.split(',')[1]
     1500    linearg = linevalues.split(',')
     1501    if linevalues.split(',')[1][0:1] != 'S':
     1502        linearg[1] = np.float(linevalues.split(',')[1])
     1503    if linevalues.split(',')[2][0:1] != 'S':
     1504        linearg[2] = np.float(linevalues.split(',')[2])
     1505    if linearg[3] == 'auto': linearg[3] = 'pretty'
     1506    if linearg[4] == 'auto': linearg[4] = '5g'
     1507    if linearg[5] == 'auto': linearg[5] = 5
     1508    if linearg[6] == 'auto': linearg[6] = 0.
    14301509
    14311510    vnamelfig = values.split(':')[0].split(',')[1]
     
    14351514    objlvar = objlf.variables[varnl]
    14361515
    1437     linevals = objlvar[:]
    1438     if reva0 == 'tranpose':
    1439         plt.plot (linevals, odimxv, '-', color='k')
    1440     else:
    1441         plt.plot (odimxv, linevals, '-', color='k')
     1516    linevals, dimsline = drw.slice_variable(objlvar, dimvals.replace(',','|'))
     1517    varlunits = objlvar.units
     1518
     1519    colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',')
     1520    colormapv = [colbarn, fmtcolbar, colbaror]
     1521
     1522    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
     1523    xaxis = [xstyl, xaxf, Nxax, xaxor]
     1524    yaxis = [ystyl, yaxf, Nyax, yaxor]
     1525
     1526    if revals == 'None':
     1527        revals = None
     1528
     1529    drw.plot_2D_shadow_line_time(valshad, linevals, vshadn, vlinen, odimxv, odimyv,  \
     1530      odimxu, odimyu, dimnamesv, xaxis, yaxis, colormapv, linearg, shading_nx,       \
     1531      varunits, varlunits, figtitle, figkind, revals, timeaxis, timepos, timelabels, \
     1532      close)
    14421533
    14431534    objsf.close()
    1444     objsl.close()
     1535    objlf.close()
    14451536
    14461537    return
     
    14481539def draw_barbs(ncfile, values, varns):
    14491540    """ Function to plot wind barbs
    1450       values= [dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[mapvalues]:
    1451         [gtit]:[kindfig]:[figuren]
    1452         'X/Y/Z/T'|[dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of:
     1541      draw_barbs(ncfile, values, varns)
     1542      values= [dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[dimxv]:[dimyv]:[mapvalues]:[dimxyfmt]:
     1543        [reverse]:[gtit]:[kindfig]:[figuren]:[close]
     1544        [dimname]|[vardimname]|[value]: ',', list for each basic dimension '|' separated of:
    14531545          [dimname]: name of the dimension in the file
    14541546          [vardimname]: name of the variable with the values for the dimension in the file
     
    14581550          [frequency]: [xfreq]@[yfreq] frequency of values allong each axis ('None', all grid points;
    14591551            'auto', computed automatically to have 20 vectors along each axis)
    1460           [color]: color of the vectors ('auto', for 'red')
     1552          [color]: color of the vectors ('auto', for 'red') two options:
     1553            [colorname]: name of the color fixed for all vectors
     1554            'colormap'@[colormapname]: use colormap to provide the colors tacking wind speed as reference
    14611555          [length]: length of the wind barbs ('auto', for 9)
    14621556        [windlabs]= [windname],[windunits]
    14631557          [windname]: name of the wind variable in the graph
    14641558          [windunits]: units of the wind variable in the graph ('None', for the value in the file)
     1559        [dimxvn]: Variables with the final values for the x dimension
     1560        [dimyvn]: Variables with the final values for the y dimension
    14651561        [mapvalues]= map characteristics: [proj],[res]
    14661562          see full documentation: http://matplotlib.org/basemap/
     
    14741570            * 'h', high
    14751571            * 'f', full
    1476         gtit= title of the graph ('|', for spaces)
    1477         kindfig= kind of figure
    1478         figuren= name of the figure
     1572        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordx]: format of the values at each axis (or 'auto')
     1573          [dxs]: style of x-axis ('auto' for 'pretty')
     1574            'Nfix', values computed at even 'Ndx'
     1575            'Vfix', values computed at even 'Ndx' increments
     1576            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     1577          [dxf]: format of the labels at the x-axis ('auto' for '%5g')
     1578          [Ndx]: Number of ticks at the x-axis ('auto' for 5)
     1579          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     1580          [dys]: style of y-axis ('auto' for 'pretty')
     1581          [dyf]: format of the labels at the y-axis ('auto' for '%5g')
     1582          [Ndy]: Number of ticks at the y-axis ('auto' for 5)
     1583          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     1584        [reverse]: Transformation of the values
     1585          * 'transpose': reverse the axes (x-->y, y-->x)
     1586          * 'flip'@[x/y]: flip the axis x or y
     1587        [gtit]= title of the graph ('|', for spaces)
     1588        [kindfig]= kind of figure
     1589        [figuren]= name of the figure
     1590        [close]= whether figure should be finished or not
    14791591      ncfile= file to use
    14801592      varns= [uwind],[ywind] ',' list of the name of the variables with the u-wind,y-wind component
     
    14871599        quit()
    14881600
    1489     expectargs = '[X/Y/Z/T]|[dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:' +  \
    1490       '[mapvalues]:[gtit]:[kindfig]:[figuren]'
     1601    expectargs = '[dimname]|[vardimname]|[value]:[vecvals]:[windlabs]:[dimxv]:' +   \
     1602      '[dimyv]:[mapvalues]:[reverse]:[dimxyfmt]:[gtit]:[kindfig]:[figuren]:[close]'
    14911603 
    14921604    drw.check_arguments(fname,values,expectargs,':')
     
    14951607    vecvals = values.split(':')[1]
    14961608    windlabels = values.split(':')[2]
    1497     mapvalues = values.split(':')[3]
    1498     gtit = values.split(':')[4]
    1499     kindfig = values.split(':')[5]
    1500     figuren = values.split(':')[6]
     1609    dimxvn = values.split(':')[3]
     1610    dimyvn = values.split(':')[4]
     1611    mapvalues = values.split(':')[5]
     1612    dimxyfmt = values.split(':')[6]
     1613    reverse = values.split(':')[7]
     1614    gtit = values.split(':')[8]
     1615    kindfig = values.split(':')[9]
     1616    figuren = values.split(':')[10]
     1617    close = gen.Str_Bool(values.split(':')[11])
    15011618
    15021619    of = NetCDFFile(ncfile,'r')
    15031620
     1621    # Dictionary with the dimension name and its associated variable and slice
    15041622    dims = {}
    15051623    for dimv in dimvals.split(','):
    15061624        dns = dimv.split('|')
    1507         dims[dns[0]] = [dns[1], dns[2], dns[3]]
    1508 
    1509     varNs = []
     1625        dims[dns[0]] = [dns[1], dns[2]]
     1626
     1627    varNs = [dimxvn, dimyvn]
    15101628    for dn in dims.keys():
    1511         if dn == 'X':
    1512             varNs.append(dims[dn][1])
    1513             dimx = len(of.dimensions[dims[dn][0]])
    1514         elif dn == 'Y':
    1515             varNs.append(dims[dn][1])
    1516             dimy = len(of.dimensions[dims[dn][0]])
     1629        vdn = dims[dn]
     1630        if vdn == dimxvn:
     1631            dimx = len(of.dimensions[dn])
     1632        elif vdn == dimyvn:
     1633            dimy = len(of.dimensions[dn])
     1634
     1635    # x-y variable-dimensions' names
     1636    xydimns = [dimxvn, dimyvn]
     1637    # x-y variable-dimensions' units
     1638    xydimus = []
     1639    odimx = of.variables[xydimns[0]]
     1640    odimax = odimx.ncattrs()
     1641    if gen.searchInlist(odimax,'units'):
     1642        xydimus.append(odimx.getncattr('units'))
     1643        odimy = of.variables[xydimns[1]]
     1644        xydimus.append(odimy.getncattr('units'))
     1645    else:
     1646        xydimus= [gen.variable_values(xydimns[0])[4],gen.variable_values(xydimns[1])[4]]
    15171647
    15181648    ivar = 0
     
    15361666            found = False
    15371667            for dd in dims.keys():
    1538                 if dims[dd][0] == vdn:
    1539                     if dims[dd][2].find('@') != -1:
    1540                         rvals = dims[dd][2].split('@')
     1668                if dd == vdn:
     1669                    if dims[dd][1].find('@') != -1:
     1670                        rvals = dims[dd][1].split('@')
    15411671                        varslice.append(slice(int(rvals[0]), int(rvals[1])))
    1542                     elif dims[dd][2] == '-1':
    1543                         varslice.append(slice(0,len(of.dimensions[dims[dd][0]])))
     1672                    elif dims[dd][1] == '-1':
     1673                        varslice.append(slice(0,len(of.dimensions[dd])))
    15441674                    else:
    1545                         varslice.append(int(dims[dd][2]))
     1675                        varslice.append(int(dims[dd][1]))
    15461676
    15471677                    found = True
    15481678                    break
    15491679            if not found:
    1550                 varslice.append(slice(0,len(of.dimensions[dims[dd][0]])))
    1551 
    1552         if varN == dims['X'][1]:
     1680                varslice.append(slice(0,len(of.dimensions[vdn])))
     1681
     1682        if ivar == 0:
    15531683            lonvals0 = np.squeeze(ovarN[tuple(varslice)])
    1554         elif varN == dims['Y'][1]:
     1684        elif ivar == 1:
    15551685            latvals0 = np.squeeze(ovarN[tuple(varslice)])
    15561686        elif ivar == 2:
     
    15911721    windunits = windlabels.split(',')[1]
    15921722
    1593     drw.plot_barbs(lonvals, latvals, uwvals, vwvals, freqv, colorv, lengthv,
    1594       windname, windunits, mapvalues, gtit, kindfig, figuren)
     1723    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
     1724    xaxis = [xstyl, xaxf, Nxax, xaxor]
     1725    yaxis = [ystyl, yaxf, Nyax, yaxor]
     1726
     1727    if mapvalues == 'None':
     1728        mapvs = None
     1729    else:
     1730        mapvs = mapvalues
     1731
     1732    if reverse == 'None':
     1733        revs = None
     1734    else:
     1735        revs = reverse
     1736
     1737    drw.plot_barbs(lonvals, latvals, uwvals, vwvals, freqv, colorv, lengthv,         \
     1738      windname, windunits, xaxis, yaxis, xydimns, xydimus, mapvs, revs, gtit,        \
     1739      kindfig, figuren, close)
    15951740
    15961741    return
  • trunk/tools/drawing_tools.py

    r1231 r1241  
    39953995    if len(varsv.shape) != 2:
    39963996        print errormsg
    3997         print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     3997        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,           \
     3998          'is has to be 2D!!'
    39983999        quit(-1)
    39994000
     
    42514252    if len(varsv.shape) != 2:
    42524253        print errormsg
    4253         print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     4254        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,           \
     4255          'is has to be 2D!!'
    42544256        quit(-1)
    42554257
     
    44244426      ifclose= boolean value whether figure should be close (finish) or not
    44254427    """
    4426 ##    import matplotlib as mpl
    4427 ##    mpl.use('Agg')
    4428 ##    import matplotlib.pyplot as plt
    44294428    fname = 'plot_2D_shadow_contour'
    44304429
     
    44364435    if len(varsv.shape) != 2:
    44374436        print errormsg
    4438         print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     4437        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,           \
     4438          'is has to be 2D!!'
    44394439        quit(-1)
    44404440    if len(varcv.shape) != 2:
    44414441        print errormsg
    4442         print '  ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!'
     4442        print '  ' + fname + ': wrong variable contour rank:', varcv.shape,          \
     4443          'is has to be 2D!!'
    44434444        quit(-1)
    44444445
     
    47164717    if len(varsv.shape) != 2:
    47174718        print errormsg
    4718         print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     4719        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,           \
     4720          'is has to be 2D!!'
    47194721        quit(-1)
    47204722    if len(varcv.shape) != 2:
    47214723        print errormsg
    4722         print '  ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!'
     4724        print '  ' + fname + ': wrong variable contour rank:', varcv.shape,          \
     4725          'is has to be 2D!!'
    47234726        quit(-1)
    47244727
     
    51195122    if len(varsv.shape) != 2:
    51205123        print errormsg
    5121         print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     5124        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,            \
     5125          'is has to be 2D!!'
    51225126        quit(-1)
    51235127    if len(varlv.shape) != 1:
    51245128        print errormsg
    5125         print '  ' + fname + ': wrong line shape:',varlv.shape,'is has to be 1D!!'
     5129        print '  ' + fname + ': wrong variable line rank:', varlv.shape,                \
     5130          'is has to be 1D!!'
    51265131        quit(-1)
    51275132
     
    53175322#        plt.annotate(tllabels[it], xy=(1.01,tllabels[it]/np.max(varlv)),             \
    53185323#          xycoords='axes fraction')
     5324
     5325    plt.annotate(gen.latex_text(vnamel)+ ' ('+units_lunits(utl)+')', xy=(0.75,0.04), \
     5326      xycoords='figure fraction', color=linev[0])
     5327    figname = '2Dfields_shadow_line'
     5328    graphtit = gen.latex_text(vtit)
     5329
     5330    plt.title(graphtit)
     5331   
     5332    output_kind(kfig, figname, ifclose)
     5333
     5334    return
     5335
     5336def plot_2D_shadow_line_time(varsv, varlv, vnames, vnamel, dimxv, dimyv, dimxu,      \
     5337  dimyu, dimn, xaxv, yaxv, cbarv, linev, vs, uts, utl, vtit, kfig, reva, taxis,      \
     5338  tpos, tlabs, ifclose):
     5339    """ Plotting a 2D field with shadows and another one with a line evolving along time
     5340      varsv= 2D values to plot with shading
     5341      varlv= 1D values to plot with line
     5342      vnames= variable names for the shadow variable in the figure
     5343      vnamel= variable names for the line varibale in the figure
     5344      dim[x/y]v = values at the axes of x and y
     5345      dim[x/y]u = units at the axes of x and y
     5346      dimn= dimension names to plot
     5347      xaxv= list with the x-axis paramteres [style, format, number and orientation]
     5348      yaxv= list with the y-axis paramteres [style, format, number and orientation]
     5349      cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror]
     5350        colorbar: name of the color bar to use
     5351        cbarfmt: format of the numbers in the colorbar
     5352        cbaror: orientation of the colorbar
     5353      linev= list with the values for the line [colorline, min, max, ticks: style, format, number and orientation]
     5354      vs= minmum and maximum values to plot in shadow
     5355        'Srange': for full range
     5356        'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
     5357        'Saroundminmax@val': for min*val,max*val
     5358        'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
     5359          percentile_(100-val)-median)
     5360        'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
     5361        'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
     5362        'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
     5363           percentile_(100-val)-median)
     5364      uts= units of the variable to shadow
     5365      utl= units of the variable to line
     5366      vtit= title of the variable
     5367      kfig= kind of figure (jpg, pdf, png)
     5368      reva=
     5369        * 'transpose': reverse the axes (x-->y, y-->x)
     5370        * 'flip'@[x/y]: flip the axis x or y
     5371      taxis= axis in which provide time
     5372      tpos= position of the time ticks
     5373      tlabs= labels of the time ticks
     5374      ifclose= boolean value whether figure should be close (finish) or not
     5375    """
     5376##    import matplotlib as mpl
     5377##    mpl.use('Agg')
     5378##    import matplotlib.pyplot as plt
     5379    fname = 'plot_2D_shadow_line_time'
     5380
     5381    if varsv == 'h':
     5382        print fname + '_____________________________________________________________'
     5383        print plot_2D_shadow_line_time.__doc__
     5384        quit()
     5385
     5386    if len(varsv.shape) != 2:
     5387        print errormsg
     5388        print '  ' + fname + ': wrong variable shadow rank:', varsv.shape,           \
     5389          'is has to be 2D!!'
     5390        quit(-1)
     5391    if len(varlv.shape) != 1:
     5392        print errormsg
     5393        print '  ' + fname + ': wrong variable line rank:', varlv.shape,                \
     5394          'is has to be 1D!!'
     5395        quit(-1)
     5396
     5397    # Axis ticks
     5398    dimxv0 = dimxv.copy()
     5399    dimyv0 = dimyv.copy()
     5400
     5401    dxn = dimxv.min()
     5402    dxx = dimxv.max()
     5403    dyn = dimyv.min()
     5404    dyx = dimyv.max()
     5405
     5406# Definning ticks labels
     5407    if taxis == 'x':
     5408        dimxt0 = (tpos-np.min(tpos))/(np.max(tpos)-np.min(tpos))
     5409        dimxl0 = tlabs
     5410        dimxT0 = dimxu
     5411        if yaxv[0] == 'pretty':
     5412            dimyt0 = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
     5413        elif yaxv[0] == 'Nfix':
     5414            dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
     5415        elif yaxv[0] == 'Vfix':
     5416            dimyt0 = np.arange(0,dyx,yaxv[2])
     5417        dimyl0 = []
     5418        for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i],    \
     5419          style=xaxv[1]))
     5420        dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
     5421
     5422        # No following data values
     5423        dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0))
     5424        pixkind = 'fixpixel'
     5425
     5426    else:
     5427        if xaxv[0] == 'pretty':
     5428            dimxt0 = np.array(gen.pretty_int(dxn,dxx,xaxv[2]))
     5429        elif xaxv[0] == 'Nfix':
     5430            dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
     5431        elif xaxv[0] == 'Vfix':
     5432            dimxt0 = np.arange(0,dxx,xaxv[2])
     5433        dimxl0 = []
     5434        for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i],    \
     5435          style=yaxv[1]))
     5436        dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
     5437
     5438        dimyt0 = (tpos-np.min(tpos))/(np.max(tpos)-np.min(tpos))
     5439        dimyl0 = tlabs
     5440        dimyT0 = dimyu
     5441        # No following data values
     5442        dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0))
     5443        pixkind = 'fixpixel'
     5444
     5445    if reva is not None:
     5446        varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT =              \
     5447          transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0,     \
     5448          dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0)
     5449    else:
     5450        dimxv = dimxv0
     5451        dimyv = dimyv0
     5452        dimxt = dimxt0
     5453        dimyt = dimyt0
     5454        dimxl = dimxl0
     5455        dimyl = dimyl0
     5456        dimxT = dimxT0
     5457        dimyT = dimyT0
     5458
     5459    if len(dimxv[:].shape) == 3:
     5460        xdims = '1,2'
     5461    elif len(dimxv[:].shape) == 2:
     5462        xdims = '0,1'
     5463    elif len(dimxv[:].shape) == 1:
     5464        xdims = '0'
     5465
     5466    if len(dimyv[:].shape) == 3:
     5467        ydims = '1,2'
     5468    elif len(dimyv[:].shape) == 2:
     5469        ydims = '0,1'
     5470    elif len(dimyv[:].shape) == 1:
     5471        ydims = '0'
     5472
     5473#    lon0 = dimxv
     5474#    lat0 = dimyv
     5475    lon0, lat0 = dxdy_lonlat(dimxv,dimyv, xdims, ydims)
     5476
     5477#    x0 = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
     5478#    y0 = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
     5479    x = (lon0-np.min(lon0))/(np.max(lon0) - np.min(lon0))
     5480    y = (lat0-np.min(lat0))/(np.max(lat0) - np.min(lat0))
     5481
     5482# Changing limits of the colors
     5483    vsend = graphic_range(vs,varsv)
     5484
     5485    plt.rc('text', usetex=True)
     5486
     5487    plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0],          \
     5488      vmax=vsend[1])
     5489    if cbarv[2] == 'horizontal':
     5490        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
     5491        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
     5492        ticklabels= cbar.ax.get_xticklabels()
     5493        Nticks = len(ticklabels)
     5494        ticklabs = []
     5495        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
     5496        cbar.ax.set_xticklabels(ticklabs,rotation=90)
     5497    else:
     5498        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
     5499
     5500    plt.xlabel(dimxT)
     5501    plt.ylabel(dimyT)
     5502
     5503# Line
     5504##
     5505    # Line does not suffer the flipping of the y-axis it is independent to it
     5506#    if reva is not None and reva[0:4] == 'flip' and reva.split('@')[1] == 'y':
     5507#        b=-np.max(y)/np.max(varlv)
     5508#        a=np.max(y)
     5509#    else:
     5510#        b=np.max(y)/np.max(varlv)
     5511#        a=0.
     5512    vlsend = graphic_range([linev[1],linev[2]],varlv)
     5513
     5514    newlinv = (varlv-np.min(varlv))/(np.max(varlv)-np.min(varlv))
     5515    if reva is not None and reva == 'transpose':
     5516        plt.plot(newlinv, y, '-', color=linev[0], linewidth=2)
     5517    else:
     5518        plt.plot(x, newlinv, '-', color=linev[0], linewidth=2)
     5519
     5520    plt.axis([x.min(), x.max(), y.min(), y.max()])
     5521
     5522    plt.tick_params(axis='y',right='off')
     5523    plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     5524    plt.yticks(dimyt, dimyl, rotation=yaxv[3])
     5525
     5526# units labels
     5527    cbar.set_label(gen.latex_text(vnames) + ' (' + units_lunits(uts) + ')')
     5528
     5529    # line ticks
     5530    dln = vlsend[0]
     5531    dlx = vlsend[1]
     5532   
     5533    if linev[3] == 'pretty':
     5534        dimlt = np.array(gen.pretty_int(dln,dlx,yaxv[2]))
     5535    elif linev[3] == 'Nfix':
     5536        dimlt = np.arange(dln,dlx,(dlx-dln)/(1.*yaxv[2]))
     5537    elif linev[3] == 'Vfix':
     5538        dimlt = np.arange(0,dlx,yaxv[2])
     5539
     5540    dimll = []
     5541    for i in range(len(dimlt)): dimll.append('{:{style}}'.format(dimlt[i], style=linev[4]))
     5542
     5543    for it in range(1,len(dimlt)):
     5544        yval = (dimlt[it]-np.min(varlv))/(np.max(varlv)-np.min(varlv))
     5545        plt.plot([x.max()*0.97, x.max()], [yval, yval], '-', color='k')
     5546        plt.annotate(dimll[it], xy=(1.01,yval), xycoords='axes fraction')
    53195547
    53205548    plt.annotate(gen.latex_text(vnamel)+ ' ('+units_lunits(utl)+')', xy=(0.75,0.04), \
     
    59616189    return
    59626190
    5963 def plot_barbs(xvals,yvals,uvals,vvals,vecfreq,veccolor,veclength,windn,wuts,mapv,graphtit,kfig,figname):
     6191def plot_barbs(xvals, yvals, uvals, vvals, vecfreq, veccolor, barblength, windn,     \
     6192  wuts, xaxv, yaxv, dimn, dimu, mapv, reva, graphtit, kfig, figname, ifclose):
    59646193    """ Function to plot wind barbs
    59656194      xvals= x position of the values
     
    59696198      vecfreq= [xfreq],[yfreq] frequency of values allong each axis (None, all grid points;
    59706199        'auto', computed automatically to have 20 vectors along each axis)
    5971       veccolor= color of the vectors (None, for 'red')
    5972       veclength= length of the wind barbs (None, for 9)
     6200      veccolor= color of the vectors ('auto', for 'red') two options:
     6201        [colorname]: name of the color fixed for all vectors
     6202        'colormap',[colormapname]: use colormap to provide the colors tacking wind speed as reference
     6203      barblength= length of the wind barbs ('auto', for 9)
    59736204      windn= name of the wind variable in the graph
    59746205      wuts= units of the wind variable in the graph
     6206      xaxv= list with the x-axis paramteres [style, format, number and orientation]
     6207      yaxv= list with the y-axis paramteres [style, format, number and orientation]
     6208      dimn= name of the X,Y variable-dimensions
     6209      dimu= units of the X,Y variable-dimensions
    59756210      mapv= map characteristics: [proj],[res]
    59766211        see full documentation: http://matplotlib.org/basemap/
     
    59876222      kfig= kind of figure
    59886223      figname= name of the figure
     6224      ifclose= boolean value whether figure should be close (finish) or not
    59896225    """
    59906226    fname = 'plot_barbs'
    59916227 
     6228    if len(xvals.shape) != 2:
     6229        print errormsg
     6230        print '  ' + fname + ': wrong variable xvals rank:', xvals.shape,           \
     6231          'is has to be 2D!!'
     6232        quit(-1)
     6233    if len(yvals.shape) != 2:
     6234        print errormsg
     6235        print '  ' + fname + ': wrong variable yvals rank:', yvals.shape,           \
     6236          'is has to be 2D!!'
     6237        quit(-1)
     6238    if len(uvals.shape) != 2:
     6239        print errormsg
     6240        print '  ' + fname + ': wrong variable uvals rank:', uvals.shape,           \
     6241          'is has to be 2D!!'
     6242        quit(-1)
     6243    if len(vvals.shape) != 2:
     6244        print errormsg
     6245        print '  ' + fname + ': wrong variable vvals rank:', vvals.shape,           \
     6246          'is has to be 2D!!'
     6247        quit(-1)
     6248
    59926249    dx=xvals.shape[1]
    59936250    dy=xvals.shape[0]
     6251
     6252    # Axis ticks
     6253    # Usually axis > x must be the lon, thus...
     6254    if mapv is None:
     6255        dimxv0 = xvals[0,:]
     6256        dimyv0 = yvals[:,0]
     6257    else:
     6258        dimxv0 = xvals.copy()
     6259        dimyv0 = yvals.copy()
     6260
     6261    dxn = dimxv0.min()
     6262    dxx = dimxv0.max()
     6263    dyn = dimyv0.min()
     6264    dyx = dimyv0.max()
     6265
     6266    if xaxv[0] == 'pretty':
     6267        dimxt0 = np.array(gen.pretty_int(dxn,dxx,xaxv[2]))
     6268    elif xaxv[0] == 'Nfix':
     6269        dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
     6270    elif xaxv[0] == 'Vfix':
     6271        dimxt0 = np.arange(0,dxx,xaxv[2])
     6272    if yaxv[0] == 'pretty':
     6273        dimyt0 = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
     6274    elif yaxv[0] == 'Nfix':
     6275        dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
     6276    elif yaxv[0] == 'Vfix':
     6277        dimyt0 = np.arange(0,dyx,yaxv[2])
     6278
     6279    dimxl0 = []
     6280    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i],        \
     6281        style=xaxv[1]))
     6282    dimyl0 = []
     6283    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i],        \
     6284         style=yaxv[1]))
     6285
     6286    dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimu[0]) + ')'
     6287    dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimu[1]) + ')'
     6288
     6289    if mapv is not None:
     6290        pixkind = 'data'
     6291    else:
     6292        # No following data values
     6293#        dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0))
     6294#        dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0))
     6295        pixkind = 'fixpixel'
     6296
     6297    if reva is not None:
     6298        uvals, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT =              \
     6299          transform(uvals, reva)
     6300        vvals, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT =              \
     6301          transform(vvals, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0,     \
     6302          dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0)
     6303    else:
     6304        dimxv = dimxv0
     6305        dimyv = dimyv0
     6306        dimxt = dimxt0
     6307        dimyt = dimyt0
     6308        dimxl = dimxl0
     6309        dimyl = dimyl0
     6310        dimxT = dimxT0
     6311        dimyT = dimyT0
    59946312
    59956313# Frequency of vectors
     
    60056323
    60066324    if veccolor == 'auto':
     6325        bctype = 'fix'
    60076326        vcolor = "red"
    60086327    else:
    6009         vcolor = veccolor
    6010 
    6011     if veclength == 'auto':
    6012         vlength = 9
    6013     else:
    6014         vlength = veclength
     6328        if veccolor.find('@') != -1:
     6329            vcvals = veccolor.split('@')
     6330            if vcvals[0] == 'colormap':
     6331                wscol = []
     6332                bctype = 'cmap'
     6333                cmap = vcvals[1]
     6334                wspeed = np.sqrt(uvals[::yfreq,::xfreq]*uvals[::yfreq,::xfreq] +     \
     6335                  vvals[::yfreq,::xfreq]*vvals[::yfreq,::xfreq])
     6336            else:
     6337                print errormsg
     6338                print '  '+fname+ ": barb color type '" + vcvals[0] + "' not redy !!"
     6339        else:
     6340            bctype = 'fix'
     6341            vcolor = veccolor
     6342
     6343    if barblength == 'auto':
     6344        blength = 9
     6345    else:
     6346        blength = np.float(barblength)
    60156347
    60166348    plt.rc('text', usetex=True)
     
    60566388        plt.xlabel('W-E')
    60576389        plt.ylabel('S-N')
    6058 
    6059     plt.barbs(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq], uvals[::yfreq,::xfreq],\
    6060       vvals[::yfreq,::xfreq], color=vcolor, pivot='tip')
    6061 
    6062     plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')',           \
    6063       xy=(0.85,-0.10), xycoords='axes fraction', color=vcolor)
    6064 
    6065     plt.title(graphtit.replace('|',' ').replace('&','\&'))
     6390    else:
     6391        plt.xlabel(dimxT)
     6392        plt.ylabel(dimyT)
     6393
     6394#    plt.axis([x.min(), x.max(), y.min(), y.max()])
     6395
     6396    if mapv is None:
     6397        plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     6398        plt.yticks(dimyt, dimyl, rotation=yaxv[3])
     6399
     6400    if bctype == 'fix':
     6401        plt.barbs(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq],                    \
     6402          uvals[::yfreq,::xfreq], vvals[::yfreq,::xfreq], color=vcolor, pivot='tip', \
     6403          length=blength)
     6404        plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')',       \
     6405          xy=(0.85,-0.10), xycoords='axes fraction', color=vcolor)
     6406
     6407    elif bctype == 'cmap':
     6408        plt.barbs(xvals[::yfreq,::xfreq], yvals[::yfreq,::xfreq],                    \
     6409          uvals[::yfreq,::xfreq], vvals[::yfreq,::xfreq], wspeed, pivot='tip',        \
     6410          length=blength, cmap=plt.get_cmap(cmap))
     6411        plt.annotate(windn.replace('_','\_') +' (' + units_lunits(wuts) + ')',       \
     6412          xy=(0.85,-0.10), xycoords='axes fraction', color='k')
     6413#        cbar = plt.colorbar()
     6414
     6415    plt.title(gen.latex_text(graphtit.replace('|',' ')))
    60666416
    60676417## NOT WORKING ##
     
    60766426##    plt.legend(handles=[vecline], loc=1)
    60776427
    6078     output_kind(kfig, figname, True)
     6428    output_kind(kfig, figname, ifclose)
    60796429
    60806430    return
Note: See TracChangeset for help on using the changeset viewer.