Changeset 1996 in lmdz_wrf


Ignore:
Timestamp:
Jul 31, 2018, 9:18:15 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `draw_multiWindRose': Function to plot multiple wind rose (from where the dinw blows)
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1982 r1996  
    6363## e.g. # drawing.py -o draw_2D_shad_contdisc_time -f 'simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta;y;auto|exct,12,h|%d$^{%H}$|time!($[DD]^{[HH]}$);Vfix,auto,50.,auto;auto;Srange,Srange;auto;obs!&!sim!Ezeiza!airport!sounding;pdf;flip@y;None;yes'
    6464## e.g. # drawing.py -o draw_2D_shad_contdisc -f 'simout_sfcdiags.nc;tdas;XLONG;XLAT;Time|0,time|0,west_east|-1,south_north|-1@all_single-stations.nc;tdas;stslon;stslat;time|0,lon|-1,lat|-1' -S 'tdas:west_east,south_north:auto:YlGnBu,auto,auto:286.,298.:auto:obs!&!sim!tdas!on!1995/01/01!00!UTC:png:None:cyl,f:sponge,0.1,0.1:yes'
     65## e.g. # drawing.py -o draw_multiWindRose -f '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/sounding_uava_10868.nc@pres|-1;time|1@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_38lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev_assigned.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_80lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_120lev.nc@bottom_top|-1;time|0@ua,va#/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_NOaerosol.nc@bottom_top|-1;time|0@ua,va' -S 'linepoint;multicol;pres;-;auto;spectral;auto:obs,38lev,50lev,50leva,80lev,120lev:WindRose!obs!sim!comparison!on!2012/10/23!00!UTC:png:auto:True'
    6566
    6667#######
     
    9192# draw_multi_2D_shad: plotting multiple 2D fields with same projection with shading and sharing colorbar
    9293# draw_multi_SkewT: creation of a SkewT-logP diagram with multiple lines using matplotlib's API example
     94# draw_multiWindRose: Function to plot multiple wind rose (from where the dinw blows)
    9395# draw_Neighbourghood_evol: Function to draw the temporal evolution of a neighbourghood around a point
    9496# draw_points: Function to plot a series of points
     
    124126  'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time',       \
    125127  'draw_bar_time', 'draw_barbs', 'draw_basins', 'draw_cycle', 'draw_ensembles_time', \
    126   'draw_2lines', 'draw_2lines_time', 'draw_multi_2D_shad', 'draw_multi_SkewT',       \
     128  'draw_2lines', 'draw_2lines_time',                                                 \
    127129  'draw_lines', 'draw_lines_time',                                                   \
     130  'draw_multi_2D_shad', 'draw_multi_SkewT', 'draw_multiWindRose',                    \
    128131  'draw_Neighbourghood_evol',                                                        \
    129132  'draw_points', 'draw_points_lonlat',                                               \
     
    98949897#draw_2D_shad_contdisc_time(contfilen+'@'+discfilen, values, axfig=None, fig=None)
    98959898
     9899def draw_multiWindRose(ncfiles, values):
     9900    """ Function to plot multiple wind rose (from where the dinw blows)
     9901      ncfiles='#' separated list of [filen]@[dimvals]@[uvarn],[vvarn]
     9902        [filen]: name of the file
     9903        [dimvals]: ';' list of [dimn]|[dvalue] dimension and slice along dimension to retrieve the winds
     9904          [dimn]: name of the dimension
     9905          [dvalue]: value for the slice in the given dimension
     9906            * [integer]: which value of the dimension
     9907            * -1: all along the dimension
     9908            * -9: last value of the dimension
     9909            * [beg],[end],[freq] slice from [beg] to [end] every [freq]
     9910            * NOTE, no dim name all the dimension size
     9911          No value takes all the range of the dimension
     9912        [uvarn],[vvarn]: name of the x and y wind components
     9913      values=[kindRose]:[labels]:[imgtit]:[imgkind]:[kindlabelsangle]:[close]
     9914        [kindRose]: [kind];[value1];[...[valueN]] Kind of rose to plot and values of the kind
     9915          'linepoint': consecutive (time, height, level, ...) line-point angle and speed values. Three different species
     9916            'multicol': line-marker color changing according to a third variable [extravarn]
     9917               values: [extravarn];[lines];[markers];[colbar];[Nang]
     9918            'multicoltime': line-marker color changing according to a temporal variable [extravarn]
     9919               values: [extravarn];[lines];[markers];[colbar];[Nang];[timekind];[timefmt];[timelabel]
     9920            'singlecol': same color for the line-marker
     9921               values: [lines];[markers];[cols];[Nang]
     9922          'scatter': a marker for each wind at different values (time, height, level, ...). Three different species
     9923            'multicol':marker color changing according to a third variable [extravarn]
     9924               values: [extravarn];[markers];[colbar];[Nang]
     9925            'multicoltime': marker color changing according to a temporal variable [extravarn]
     9926               values: [extravarn];[lines];[markers];[colbar];[Nang];[timekind];[timefmt];[timelabel]
     9927            'singlecol': same color for all the markers
     9928              values: [markers];[cols];[Nang]
     9929           meaning (where apply):
     9930             [extravarn]: name of the extra variable
     9931             [lines]: '@' separated list of type of lines (matplotlib ref)
     9932             [markers]: '@' separated list of type of markers to use (matplotlib ref)
     9933             [cols] = '@' separated list of colors ('#[RR][GG][BB])
     9934             [colbar]: name of the colorbar ('auto' for 'spectral_r')
     9935             [Nang]: number of angles to divide the rose ('auto' for 8)
     9936             [Nspeed]: number of speeds to divide the wind speed distribution ('auto' for 8)
     9937             [maxspeed]: maximum wind speed used to compute the frequency of distributions ('auto' for 40.)
     9938             [timekind]; time computation of ticks
     9939               'Nval': according to a given number of values as 'Nval',[Nval]
     9940               'exct': according to an exact time unit as 'exct',[tunit];
     9941                 tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month,
     9942                  'w': week, 'd': day, 'h': hour, 'i': minute, 's': second,
     9943                  'l': milisecond
     9944             [timefmt]; desired format of time labels (C-like)
     9945             [timelabel]; label of time colorbar at the graph ('!' for spaces)
     9946        labels: ',' separated list of labels for the legend ('None' for no label)
     9947        imgtit: title of the image ('!' for spaces)
     9948        imgkind: kind of file output of the image (ps, pns, pdf, ...)
     9949        kindlabelsangle: kind of labels for the angles of the wind Rose
     9950          'cardianals': Following combinations of 'N', 'E', 'S', 'W' according to Nang
     9951        close: whether figure should be closed or not
     9952    """
     9953    fname = 'draw_WindRose'
     9954
     9955    if values == 'h':
     9956        print fname + '_____________________________________________________________'
     9957        print draw_multiWindRose.__doc__
     9958        quit()
     9959
     9960    expectargs = '[kindRose]:[labels]:[imgtit]:[imgkind]:[kindlabelsangle]:' + \
     9961      '[close]'
     9962    drw.check_arguments(fname,values,expectargs,':')
     9963
     9964    dimvariables = values.split(':')[0]
     9965
     9966    KindRose = values.split(':')[0]
     9967    labels = values.split(':')[1].split(',')
     9968    imgtit = values.split(':')[2].replace('!',' ')
     9969    imgkind = values.split(':')[3]
     9970    kindlabelsangle = values.split(':')[4]
     9971    close = gen.Str_Bool(values.split(':')[5])
     9972   
     9973    windrosekinds = ['linepoint', 'scatter']
     9974
     9975    if KindRose.find(';') == -1:
     9976        print errormsg
     9977        print '  ' + fname + ": all types '" + KindRose + "' require extra values !!"
     9978        print "    'linepoint';'singlecol';[line];[marker];[col];[Nang]"
     9979        print "    'linepoint';'multiecoltime';[extravar];[line];[marker];[colbar];"+\
     9980          "[Nang];[timekind];[timefmt];[timelabel]"
     9981        print "    'linepoint';'multiecol';[extravar];[line];[marker];[colbar];[Nang]"
     9982        print "    'scatter';'multiecol';[extravar];[marker];[colbar]"
     9983        print "    'scatter';'multiecoltime';[extravar];[marker];[colbar];[Nang];" + \
     9984          "[timekind];[timefmt];[timelabel]"
     9985        print "    'scatter';'singlecol';[marker];[col];[Nang]"
     9986        print "  values provided: '" + KindRose + "'"
     9987        quit(-1)
     9988
     9989    lpvals = KindRose.split(';')
     9990    lkind = lpvals[1]
     9991
     9992    extravarn = None
     9993
     9994    if lpvals[0] == 'linepoint':
     9995        if lkind == 'multicol':
     9996            if len(lpvals) != 7:
     9997                print errormsg
     9998                print '  ' + fname + ": line-point kind '" + lkind + "' requires " + \
     9999                  "6 values !!"
     10000                print "    'multiecol';[extravarn];[line];[marker];[colbar];[Nang]"
     10001                print '    provided:', lpvals
     10002                quit(-1)     
     10003            extravarn = lpvals[2]
     10004        elif lkind == 'multicoltime':
     10005            if len(lpvals) != 10:
     10006                print errormsg
     10007                print '  '+fname + ": scatter kind '"+lkind+ "' requires 9 values !!"
     10008                print "    'multicol';[extravarn];[line];[marker];[colbar];[Nang];"+ \
     10009                  "[timekind];[timefmt];[timelabel]"
     10010                print '    provided:', lpvals
     10011                quit(-1)     
     10012            extravarn = lpvals[2]
     10013            timekind = lpvals[6]
     10014            timefmt = lpvals[7]
     10015        elif lkind == 'singlecol':
     10016            if len(lpvals) != 6:
     10017                print errormsg
     10018                print '  '+fname+": line-point kind '"+lkind+ "' requires 5 values !!"
     10019                print "    'singlecol';[line];[marker];[col];[Nang]"
     10020                print '    provided:', lpvals
     10021                quit(-1)     
     10022        else:
     10023            print errormsg
     10024            print '  ' + fname + ": line-point kind '" + lkind + "' not ready !!"
     10025            print '    ready ones: multicol, multicoltime, singlecol '
     10026            quit(-1)
     10027
     10028    elif lpvals[0] == 'scatter':
     10029        if lkind == 'multicol':
     10030            if len(lpvals) != 6:
     10031                print errormsg
     10032                print '  '+fname+": scatter kind '"+lkind+"' requires 5 values !!"
     10033                print "    'multicol';[extravarn];[marker];[colbar];[Nang]"
     10034                print '    provided:', lpvals
     10035                quit(-1)     
     10036            extravarn = lpvals[2]
     10037        elif lkind == 'multicoltime':
     10038            if len(lpvals) != 9:
     10039                print errormsg
     10040                print '  ' + fname + ": scatter kind '"+lkind+"' requires 8 values !!"
     10041                print "    'multicol';[extravarn];[marker];[colbar];[Nang];" +       \
     10042                  "[timekind];[timefmt];[timelabel]"
     10043                print '    provided:', lpvals
     10044                quit(-1)     
     10045            extravarn = lpvals[2]
     10046            timekind = lpvals[5]
     10047            timefmt = lpvals[6]
     10048        elif lkind == 'singlecol':
     10049            if len(lpvals) != 5:
     10050                print errormsg
     10051                print '  '+fname + ": scatter kind '"+lkind+ "' requires 4 values !!"
     10052                print "    'singlecol';[marker];[col];[Nang]"
     10053                print '    provided:', lpvals
     10054                quit(-1)     
     10055        else:
     10056            print errormsg
     10057            print '  ' + fname + ": scatter kind '" + lkind + "' not ready !!"
     10058            print '    ready ones: multicol, multicoltime, singlecol '
     10059            quit(-1)
     10060
     10061    else:
     10062        print gen.errormsg
     10063        print '  ' +  fname + ": kind of WindRose '" + lpvals[0] + "' not ready !!"
     10064        print '    available ones:', windrosekinds
     10065        quit(-1)
     10066
     10067    angles = []
     10068    speeds = []
     10069    extravs = []
     10070    fvarns = ncfiles.split('#')
     10071    for fvn in fvarns:
     10072        ncfile = fvn.split('@')[0]
     10073        dimvariables = fvn.split('@')[1]
     10074        uvarn = fvn.split('@')[2].split(',')[0]
     10075        vvarn = fvn.split('@')[2].split(',')[1]
     10076
     10077        if not os.path.isfile(ncfile):
     10078            print errormsg
     10079            print '  ' + fname + ": file '" + ncfile + "' does not exist !!"
     10080            quit(-1)
     10081
     10082        onc = NetCDFFile(ncfile,'r')
     10083        oncvars0 = onc.variables.keys()
     10084        oncvars = oncvars0 + []
     10085        oncvars.sort()
     10086
     10087        if not gen.searchInlist(oncvars,uvarn):
     10088            print errormsg
     10089            print '  ' + fname + ": file '" + ncfile + "' does not have variable " +     \
     10090              "u_wind '" + uvarn + "' !!"
     10091            print '    available variables:', oncvars
     10092            quit(-1)
     10093        if not gen.searchInlist(oncvars,vvarn):
     10094            print errormsg
     10095            print '  ' + fname + ": file '" + ncfile + "' does not have variable " +     \
     10096              "v_wind '" + vvarn + "' !!"
     10097            print '    available variables:', oncvars
     10098            quit(-1)
     10099        if extravarn is not None:
     10100            if not gen.searchInlist(oncvars,extravarn):
     10101                print errormsg
     10102                print '  ' + fname + ": file '" + ncfile + "' does not have extra " +    \
     10103                  "variable '" + extravarn + "' !!"
     10104                print '    available variables:', oncvars
     10105                quit(-1)
     10106
     10107        # Getting the slice
     10108        dictslice = {}
     10109        for dnv in dimvariables.split(';'):
     10110            dimn = dnv.split('|')[0]
     10111            dimv = dnv.split('|')[1]
     10112            if dimv.find(',') != -1:
     10113                dictslice[dimn] = list(np.array(dimv.split(','), dtype=int))
     10114            else:
     10115                dictslice[dimn] = int(dimv)
     10116
     10117        # Getting variables
     10118        ou = onc.variables[uvarn]
     10119        sliceu, du = ncvar.SliceVarDict(ou, dictslice)
     10120        uv = ou[tuple(sliceu)]
     10121        ov = onc.variables[vvarn]
     10122        slicev, dv = ncvar.SliceVarDict(ov, dictslice)
     10123        vv = ov[tuple(slicev)]
     10124        wunit = ov.getncattr('units')
     10125        if extravarn is not None:
     10126            oe = onc.variables[extravarn]
     10127            slicee, de = ncvar.SliceVarDict(oe, dictslice)
     10128            extrav = oe[tuple(slicee)]
     10129            dime = extrav.shape[0]
     10130            extraunit = oe.getncattr('units')
     10131        else:
     10132            dime = uv.shape[0]
     10133            extrav = None
     10134            extraunit = None
     10135   
     10136        onc.close()
     10137
     10138        # Wind Rose is with the winds from where they come from!
     10139        ang = np.arctan2(-vv, -uv)
     10140        speed = np.sqrt(uv*uv + vv*vv)
     10141
     10142        # re-setting to [0, 2pi]
     10143        ang = np.where(ang <= 0., 2.*np.pi+ang, ang)
     10144        ang = np.where(np.mod(ang,2.*np.pi) == 0., 0., ang)
     10145
     10146        angles.append(ang)
     10147        speeds.append(speed)
     10148        if extrav is not None: extravs.append(extrav)
     10149
     10150    drw.plot_multiWindRose(angles, speeds, dime, lpvals, kindlabelsangle, wunit,     \
     10151      labels, imgtit, imgkind, 'multi_WindRose', close, evs=extravs, eunit=extraunit)
     10152
     10153    return
     10154
     10155#filenames='/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/sounding_uava_10868.nc@pres|-1;time|1@ua,va#' + \
     10156#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_38lev.nc@bottom_top|-1;time|12@ua,va#' +  \
     10157#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev.nc@bottom_top|-1;time|12@ua,va#' +  \
     10158#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_50lev_assigned.nc@bottom_top|-1;time|12@ua,va#' +  \
     10159#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_80lev.nc@bottom_top|-1;time|12@ua,va#' +  \
     10160#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_120lev.nc@bottom_top|-1;time|12@ua,va#' + \
     10161#  '/media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out/simout_vars_sndpt_10868_NOaerosol.nc@bottom_top|-1;time|12@ua,va'
     10162#wrkind='linepoint;multicol;pres;-;x;spectral;auto'
     10163#figvalues=wrkind + ':obs,38lev,50lev,50leva,80lev,120lev:WindRose!obs!,!sim!comparison!on!2012/10/23!12!UTC:png:auto:True'
     10164
     10165#draw_multiWindRose(filenames, figvalues)
    989610166
    989710167#quit()
     
    992010190  'draw_cycle', 'draw_ensembles_time', 'draw_multi_2D_shad', 'draw_multi_SkewT',     \
    992110191  'draw_lines',                                                                      \
    9922   'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_time_lag',                  \
    9923   'draw_topo_geogrid_boxes',                                                         \
     10192  'draw_lines_time', 'draw_multiWindRose', 'draw_points', 'draw_Taylor',             \
     10193  'draw_time_lag', 'draw_topo_geogrid_boxes',                                        \
    992410194  'draw_trajectories', 'draw_vals_trajectories', 'variable_values']
    992510195
     
    1001510285    elif oper == 'draw_multi_SkewT':
    1001610286        draw_multi_SkewT(opts.ncfile, opts.values)
     10287    elif oper == 'draw_multiWindRose':
     10288        draw_multiWindRose(opts.ncfile, opts.values)
    1001710289    elif oper == 'draw_points':
    1001810290        draw_points(opts.ncfile, opts.values)
  • trunk/tools/drawing_tools.py

    r1976 r1996  
    117117pointkindsauto = ['.', 'x', '+', '*', '|', '_', '1', '2', '3', '4', 'o', '<', '>',   \
    118118  'v', '^', 's', 'D', 'p' ,'h' ,'H']
     119
    119120linekindsauto = ['-', '--', '-.', ':']
    120121linewidthsauto = [1.]
     
    184185# plot_cycle: Function to plot a variale with a circular cycle
    185186# plot_lines: Function to plot a collection of lines
     187# plot_multiWindRose: Function to plot multi wind roses (from where the dinw blows)
    186188# plot_SkewT: Function to plot a SkewT-logP diagram using matplotlib's API example
    187189# plot_Taylor: Function to draw a Taylor diagram (Taylor 2001)
     
    88388840    return
    88398841
     8842def plot_multiWindRose(angs, speeds, dime, lpvals, thetalabs, windu, labs, titimg,   \
     8843  kfig, figname, close, evs=None, eunit=None):
     8844    """ Function to plot multi wind roses (from where the dinw blows)
     8845      angs= list of angles of the winds
     8846      speeds= list of speed of the winds
     8847      Nang= number of angles to split the total circumference
     8848      Nspeed= number of speed sections to split the wind distribution
     8849      maxspeed= maximum wind speed to be plotted
     8850      dime= number of winds to plot
     8851      lpvals= values to configure the kind of Wind Rose to plot
     8852        lpvals[0]: kind of Wind Rose
     8853        lpvals[1]: specie of kind of Wind Rose
     8854        lpvals[>=2]: specific values for the specie Wind Rose
     8855        'linepoint';[kind];[val1];[...;[valN]]: consecutive (time, height, level, ...) line-point angle and speed values
     8856          'multicol';[extravarn];[lines];[markers];[colbar]
     8857          'multicoltime';[extravarn];[lines];[markers];[colbar];[timekind];[timefmt];[timelabel]
     8858          'singlecol';[lines];[markers];[cols]
     8859        'scatter';[kind];[val1];[...;[valN]]: a cross for each wind at different values (time, height, level, ...)
     8860          'multicol';[extravarn];[markers];[colbar]
     8861          'multicoltime';[extravarn];[lines];[markers];[colbar];[timekind];[timefmt];[timelabel]
     8862          'singlecol';[markers];[cols]
     8863      windu= units of the wind speed
     8864      thetalabs= kind of labels for the angles of the wind-rose
     8865        'cardianals': Following combinations of 'N', 'E', 'S', 'W' according to Nang
     8866      titimg= title of the image
     8867      kfig= kind of figure's file output
     8868      labs= list of labels ('None' for no label)
     8869      figname= name of the figure
     8870      close= wether figure has to be closed or not
     8871      evs= extra values (for certain Wind Roses: 'linepoint/scatter' 'multicol' & 'multicoltime')
     8872      eunits= units of the extravalues (for certain Wind Roses)
     8873    """
     8874    fname = 'plot_multiWindRose'
     8875   
     8876    Nsnds = len(labs)
     8877
     8878    lkind = lpvals[1]
     8879
     8880    # Getting time values and ticks
     8881    if lkind == 'multicoltime':
     8882        if lpvals[0] == 'linepoint':
     8883            timekind = lpvals[7]
     8884            timefmt = lpvals[8]
     8885        elif lpvals[0] == 'scatter':
     8886            timekind = lpvals[6]
     8887            timefmt = lpvals[7]
     8888        timepos, timelabels = CFtimes_plot(evs[0], eunit, timekind, timefmt)
     8889   
     8890    # Plot
     8891    plt.rc('text', usetex=True)
     8892    ax = plt.subplot(111, projection='polar')
     8893
     8894    # Rosekind
     8895    if lpvals[0] == 'linepoint':
     8896        if lkind == 'multicol':
     8897            colbar = gen.auto_val(lpvals[5],'spectral_r')
     8898            Nang = gen.auto_val(lpvals[6],8)
     8899            # Setting up colors for each label
     8900            #   From: http://stackoverflow.com/questions/15235630/matplotlib-pick-up-one-color-associated-to-one-value-in-a-colorbar
     8901            vcolmin = 100000.
     8902            vcolmax = -1.*vcolmin
     8903            for isnds in range(Nsnds):
     8904                ev = evs[isnds]
     8905                nvc = np.min(ev)
     8906                xvc = np.max(ev)
     8907                if nvc < vcolmin: vcolmin = nvc
     8908                if xvc > vcolmax: vcolmax = xvc
     8909
     8910            my_cmap = plt.cm.get_cmap(colbar)
     8911            norm = mpl.colors.Normalize(vcolmin, vcolmax)
     8912
     8913            ltyps = gen.auto_val_list(lpvals[3].split('@'), Nsnds, linekindsauto)
     8914            lmrks = gen.auto_val_list(lpvals[4].split('@'), Nsnds, pointkindsauto)
     8915
     8916            for isnds in range(Nsnds):
     8917                ang = angs[isnds]
     8918                speed = speeds[isnds]
     8919                ev = evs[isnds]
     8920                ltyp = ltyps[isnds]
     8921                lmrk = lmrks[isnds]
     8922
     8923                sndS = labs[isnds]
     8924                dime = ang.shape[0]
     8925
     8926                for ie in range(dime-1):
     8927                    labcol = my_cmap(norm(ev[ie]))
     8928                    if ie == 0 and sndS != 'None':
     8929                        plt.plot([ang[ie], ang[ie+1]], [speed[ie], speed[ie+1]],     \
     8930                          ltyp, marker=lmrk, color=labcol, label=gen.latex_text(sndS))
     8931                    else:
     8932                        plt.plot([ang[ie], ang[ie+1]], [speed[ie], speed[ie+1]],     \
     8933                          ltyp, marker=lmrk, color=labcol)
     8934
     8935                ie = dime-1
     8936                labcol = my_cmap(norm(ev[ie]))
     8937                lcolS = gen.coldec_hex(labcol[0:3])
     8938                plt.plot(ang[ie], speed[ie], ltyp, marker=lmrk, color=lcolS)
     8939
     8940            # FROM: http://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots
     8941            # For matplotlib v1.3 or greater the code becomes:
     8942            sm = plt.cm.ScalarMappable(cmap=colbar, norm=norm)
     8943            # fake up the array of the scalar mappable. Urgh...
     8944            sm._A = []
     8945            cbar = plt.colorbar(sm)
     8946            cbar.set_label(lpvals[2] + ' (' + units_lunits(eunit) + ')')
     8947
     8948        elif lkind == 'multicoltime':
     8949            colbar = gen.auto_val(lpvals[5],'spectral_r')
     8950            Nang = gen.auto_val(lpvals[6],8)
     8951            timekind = lpvals[7]
     8952            timefmt = lpvals[8]
     8953            timelabel = lpvals[9].replace('!',' ')
     8954            # Setting up colors for each label
     8955            #   From: http://stackoverflow.com/questions/15235630/matplotlib-pick-up-one-color-associated-to-one-value-in-a-colorbar
     8956            vcolmin = np.min(ev)
     8957            vcolmax = np.max(ev)
     8958            my_cmap = plt.cm.get_cmap(colbar)
     8959            norm = mpl.colors.Normalize(vcolmin, vcolmax)
     8960
     8961            for isnds in range(Nsnds):
     8962                ang = angs[isnds]
     8963                speed = speeds[isnds]
     8964                ltyp = gen.auto_val(lpvals[3].split('@')[isnds],'-')
     8965                lmrk = gen.auto_val(lpvals[4].split('@')[isnds],'x')
     8966                sndS = labs[isnds]
     8967
     8968                for ie in range(dime-1):
     8969                    labcol = my_cmap(norm(ev[ie]))
     8970                    lcolS = gen.coldec_hex(labcol[0:3])
     8971
     8972                    if ie == 0 and sndS != 'None':
     8973                        plt.plot([ang[ie], ang[ie+1]], [speed[ie], speed[ie+1]],     \
     8974                          ltyp, marker=lmrk, color=lcolS, label=sndS)
     8975                    else:
     8976                        plt.plot([ang[ie], ang[ie+1]], [speed[ie], speed[ie+1]],     \
     8977                          ltyp, marker=lmrk, color=lcolS)
     8978
     8979                ie = dime-1
     8980                labcol = my_cmap(norm(ev[ie]))
     8981                lcolS = gen.coldec_hex(labcol[0:3])
     8982                plt.plot(ang[ie], speed[ie], ltyp, marker=lmrk, color=lcolS)
     8983   
     8984            # FROM: http://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots
     8985            # For matplotlib v1.3 or greater the code becomes:
     8986            sm = plt.cm.ScalarMappable(cmap=colbar, norm=norm)
     8987            # fake up the array of the scalar mappable. Urgh...
     8988            sm._A = []
     8989            cbar = plt.colorbar(sm, ticks=timepos)
     8990            cbar.set_label(timelabel)
     8991            cbar.ax.set_yticklabels(timelabels)
     8992
     8993            # An attempt using text...
     8994            #maxt = np.max(timepos)
     8995            #for it in range(len(timelabels)):
     8996            #    daxistT = 0.6
     8997            #    iaxistT = (1. - daxistT)/2.
     8998            #    itt = (timepos[it]-timepos[0])*daxistT/(maxt-timepos[0])
     8999            #    labcol = my_cmap(norm(timepos[it]))
     9000            #    plt.annotate(timelabels[it], xy=(0.87,iaxistT+itt), color=labcol,        \
     9001            #      xycoords='figure fraction', multialignment='center')
     9002            #plt.annotate(timelabel, xy=(0.97,0.5), color='k', rotation=90,               \
     9003            #  rotation_mode="anchor", xycoords='figure fraction', horizontalalignment='center')
     9004        elif lkind == 'singlecol':
     9005            Nang = gen.auto_val(lpvals[5],8)
     9006            for isnds in range(Nsnds):
     9007                ang = angs[isnds]
     9008                speed = speeds[isnds]
     9009                ltyp = gen.auto_val(lpvals[2].split('@')[isnds],'-')
     9010                lmrk = gen.auto_val(lpvals[3].split('@')[isnds],'x')
     9011                lcol = gen.auto_val(lpvals[4].split('@')[isnds],'b')
     9012                sndS = labs[isnds]
     9013
     9014                if sndS != 'None':
     9015                    plt.plot(ang, speed, ltyp, marker=lmrk, color=lcol, label=sndS)
     9016                else:
     9017                    plt.plot(ang, speed, ltyp, marker=lmrk, color=lcol)
     9018   
     9019    elif lpvals[0] == 'scatter':
     9020        if lkind == 'multicol':
     9021            colbar = gen.auto_val(lpvals[4],'spectral_r')
     9022            Nang = gen.auto_val(lpvals[5],8)
     9023
     9024            for isnds in range(Nsnds):
     9025                ang = angs[isnds]
     9026                speed = speeds[isnds]
     9027                lmrk = gen.auto_val(lpvals[3].split('@')[isnds],'x')
     9028                sndS = labs[isnds]
     9029
     9030                if sndS != 'None':
     9031                    plt.scatter(ang, speed, c=ev, cmap=colbar, marker=lmrk,label=sndS)
     9032                else:
     9033                    plt.scatter(ang, speed, c=ev, cmap=colbar, marker=lmrk)
     9034
     9035            cbar = plt.colorbar()
     9036            cbar.set_label(lpvals[2] + ' (' + units_lunits(eunit) + ')')
     9037        elif lkind == 'multicoltime':
     9038            colbar = gen.auto_val(lpvals[4],'spectral_r')
     9039            Nang = gen.auto_val(lpvals[5],8)
     9040            timekind = lpvals[6]
     9041            timefmt = lpvals[7]
     9042            timelabel = lpvals[8].replace('!',' ')
     9043            for isnds in range(Nsnds):
     9044                ang = angs[isnds]
     9045                speed = speeds[isnds]
     9046                lmrk = gen.auto_val(lpvals[3].split('@')[isnds],'x')
     9047                sndS = labs[isnds]
     9048
     9049                if sndS != 'None':
     9050                    plt.scatter(ang, speed, c=ev, cmap=colbar, marker=lmrk,label=sndS)
     9051                else:
     9052                    plt.scatter(ang, speed, c=ev, cmap=colbar, marker=lmrk)
     9053 
     9054            cbar = plt.colorbar(ticks=timepos)
     9055            cbar.set_label(timelabel)
     9056            cbar.ax.set_yticklabels(timelabels)
     9057        elif lkind == 'singlecol':
     9058            Nang = gen.auto_val(lpvals[4],8)
     9059
     9060            for isnds in range(Nsnds):
     9061                ang = angs[isnds]
     9062                speed = speeds[isnds]
     9063                lmrk = gen.auto_val(lpvals[2].split('@')[isnds],'x')
     9064                lcol = gen.auto_val(lpvals[3].split('@')[isnds],'b')
     9065                sndS = labs[isnds]
     9066
     9067                if sndS != 'None':
     9068                    plt.plot(ang, speed, ',', marker=lmrk, color=lcol, label=sndS)
     9069                else:
     9070                    plt.plot(ang, speed, ',', marker=lmrk, color=lcol)
     9071   
     9072    if thetalabs == 'cardinals':
     9073        if Nang == 4:
     9074            thetalabs = ['N', 'E', 'S', 'W']
     9075        elif Nang == 8:
     9076            thetalabs = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
     9077        elif Nang == 16:
     9078            thetalabs= ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW',\
     9079              'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
     9080        else:
     9081            print errormsg
     9082            print '  ' + fname + ': number of angles:', Nang, "not ready for '" +    \
     9083              thetalabs + "' !!"
     9084            print '    available ones: 4, 8, 16'
     9085            quit(-1)
     9086
     9087        dang = 2.*np.pi / (Nang)       
     9088        angs = np.arange(Nang,dtype=np.float)*dang - dang/2.
     9089        ax.set_thetagrids((angs+dang/2.)*180./np.pi, thetalabs)
     9090   
     9091    ax.set_theta_zero_location('N')
     9092    ax.set_theta_direction(-1)
     9093    plt.annotate('wind (' + units_lunits(windu) + ')', xy=(0.75,0.06), color='k',    \
     9094      xycoords='figure fraction', horizontalalignment='center')
     9095
     9096    plt.legend()
     9097    plt.title(gen.latex_text(titimg))
     9098
     9099    output_kind(kfig, figname, close)
     9100
     9101    return
     9102
    88409103def plot_Taylor(stdv, corrv, corrpv, vunits, mtyp, mcol, msize, mlabs, labkind,      \
    88419104  tkind, itit, kfig, closefig):
Note: See TracChangeset for help on using the changeset viewer.