Changeset 2251 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Nov 27, 2018, 8:22:54 PM (6 years ago)
Author:
lfita
Message:

Improving 'plot_multi_river_pattern' by adding:

  • 'colortracktype': methodology to choice color of the river
  • 'all_desc': using only rivers from ' river_desc'
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2250 r2251  
    1096110961          [desclat]: latitude values
    1096210962        [rivervalues]= '|' separated list of [colordescid]|[rivercolor]|[rivernocolor]|[riverwidth]
    10963             [riverwidth] (use 'auto' for 'rainbow|#AAAAAAA|#CCCCCC|0.5')
     10963            [riverwidth]|[rivercolortype] (use 'auto' for 'rainbow|#AAAAAAA|#CCCCCC|0.5|rivernum')
    1096410964          [barcolordescid]: color bar to use to distinguish among selected rivers to draw
    1096510965          [rivercolor]: color for the river-flows of the non selected rivers
    1096610966          [rivernocolor]: color for the outflows of the non selected rivers
    1096710967          [riverwidth]: width of the lines of the rivers' path
     10968          [rivercolortype]: method to deterine color of the tracks of the rivers
     10969            'riverid': following ids of the rivers
     10970            'rivernum': following number of rivers to be plotted
    1096810971        [mapvalues]= map characteristics: [proj],[res]
    1096910972          see full documentation: http://matplotlib.org/basemap/
     
    1100511008        [closefig]= whether figure should be closed or not
    1100611009      riverns= ',' list of the names of the rivers to plot (as in [descfilen])
    11007         'all': for all rivers in file
     11010        'all': for all rivers in 'routing.nc'
     11011        'all_desc': for all rivers in `river_desc.nc'
    1100811012        'larger',[Npaths]: all river larger than [Npaths] grid points (NOT now)
    1100911013    """
     
    1106311067        rivernocolor = '#CCCCCC'
    1106411068        riverwidth = 0.5
    11065     else:
    11066         [barcolordescid, rivercolor, rivernocolor, riverwidth]= rivervalues.split('|')
     11069        rivercolortype = 'rivernum'
     11070    else:
     11071        [barcolordescid, rivercolor, rivernocolor, riverwidth, rivercolortype] =     \
     11072          rivervalues.split('|')
    1106711073        riverwidth = np.float(riverwdith)
    1106811074
     
    1115911165        ostation.close()
    1116011166
     11167    # Lonlat box
     11168    lon, lat = drw.lonlat2D(blon, blat)
     11169
     11170    if lonlatbox == 'all':
     11171        nlon = np.min(lon)
     11172        nlat = np.min(lat)
     11173        xlon = np.max(lon)
     11174        xlat = np.max(lat)
     11175    else:
     11176        nlon = np.float(lonlatbox.split('|')[0])
     11177        nlat = np.float(lonlatbox.split('|')[1])
     11178        xlon = np.float(lonlatbox.split('|')[2])
     11179        xlat = np.float(lonlatbox.split('|')[3])
     11180
     11181    imin, imax, jmin, jmax = gen.ijlonlat(lon, lat, nlon, xlon, nlat, xlat)
     11182
    1116111183    # Getting river's ids:
    1116211184    if riverns.count(',') != 0:
     
    1116511187        if riverns == 'all':
    1116611188            rns = []
     11189            rns = list(set(list(bid[jmin:jmax,imin:imax].compressed())))
     11190        elif riverns == 'all_desc':
     11191            rns = []
     11192## Following river desc
    1116711193            Ltail = len(TAILdesccoding)
    1116811194            allvarns = odesc.variables.keys()
     
    1117911205                  "': ", allvarns
    1118011206                quit(-1)
    11181 
    1118211207        elif riverns[0:6] == 'larger':
    1118311208            print errormsg
     
    1118711212            rns = [riverns]
    1118811213
    11189     print '  ' + fname + ': rivers to plot: [namne] [id] _____'
    1119011214    codings = {}
    11191     for rn in rns:
    11192         ocoding = odesc.variables[rn + TAILdesccoding]
    11193         maskcoding = ocoding[:].mask
    11194         rnid = bid[~maskcoding][0]
    11195         if rnid != gen.mamat[0]:
    11196             codings[rn] = rnid
    11197             print rn ,':', rnid
    11198 
    11199     lon, lat = drw.lonlat2D(blon, blat)
    11200 
    11201     if lonlatbox == 'all':
    11202         nlon = np.min(lon)
    11203         nlat = np.min(lat)
    11204         xlon = np.max(lon)
    11205         xlat = np.max(lat)
    11206     else:
    11207         nlon = np.float(lonlatbox.split('|')[0])
    11208         nlat = np.float(lonlatbox.split('|')[1])
    11209         xlon = np.float(lonlatbox.split('|')[2])
    11210         xlat = np.float(lonlatbox.split('|')[3])
    11211 
    11212     imin, imax, jmin, jmax = gen.ijlonlat(lon, lat, nlon, xlon, nlat, xlat)
     11215    if riverns != 'all':
     11216        print '  ' + fname + ': rivers to plot: [namne] [id] _____'
     11217        for rn in rns:
     11218            ocoding = odesc.variables[rn + TAILdesccoding]
     11219            maskcoding = ocoding[:].mask
     11220            rnid = bid[~maskcoding][0]
     11221            if rnid != gen.mamat[0]:
     11222                codings[rn] = rnid
     11223                print rn ,':', rnid
     11224    else:
     11225        for rn in rns: codings[rn] = rn
    1121311226
    1121411227    # legend values
     
    1122111234      bflow[jmin:jmax,imin:imax], bid[jmin:jmax,imin:imax], codings, dlon, dlat,     \
    1122211235      stn, stlon, stlat, drawcountry, drawbasinid, barcolordescid, rivercolor,       \
    11223       rivernocolor, riverwidth, stcol, stsize, gtit, mapvals, kindfig, rns)
     11236      rivernocolor, riverwidth, rivercolortype, stcol, stsize, gtit, mapvals,        \
     11237      kindfig, rns)
    1122411238
    1122511239    return
  • trunk/tools/drawing_tools.py

    r2250 r2251  
    78097809def plot_multi_river_pattern(xvals, yvals, fvals, veccolor, descids, desclon,        \
    78107810  desclat, stn, stlon, stlat, drawcountry, drawbasinid, colordescid, coloriver,      \
    7811   colornoriver, pathwidth, colorst, stsize, graphtit, mapv, kfig, riverns):
     7811  colornoriver, pathwidth, colortracktype, colorst, stsize, graphtit, mapv, kfig,    \
     7812  riverns):
    78127813    """ Function to plot ORCHIDEE's pattern or multiple rivers (following trip variable from
    78137814        'routing.nc' and river description following 'river_desc.nc')
     
    78397840      colornoriver= color for the non-river paths values
    78407841      pathwidth= width of the line with the river paths
     7842      colortracktype: method to deterine color of the tracks of the rivers
     7843        'riverid': following ids of the rivers
     7844        'rivernum': following number of rivers to be plotted
    78417845      colorst= color for the stations
    78427846      stsize= color for the size of the labels of the stations
     
    78467850    """
    78477851    fname = 'plot_multi_river_pattern'
     7852    availcolortracktype = ['ricerid', 'rivernum']
    78487853
    78497854    figname = 'multi_river_pattern'
     
    78807885# Setting up colors for each label
    78817886#   From: http://stackoverflow.com/questions/15235630/matplotlib-pick-up-one-color-associated-to-one-value-in-a-colorbar
     7887    drawriverids = descids.values()
     7888
    78827889    my_cmap = plt.cm.get_cmap(colordescid)
    7883     vcolmin = np.min(descids.values())
    7884     vcolmax = np.max(descids.values())
    7885 
    7886     norm = mpl.colors.Normalize(vcolmin, vcolmax)
     7890    vcolmin = np.min(drawriverids)
     7891    vcolmax = np.max(drawriverids)
     7892    Nrivers = len(drawriverids)
     7893
     7894    print '  ' + fname + ': river range ids to plot:', vcolmin, vcolmax,             \
     7895      'Number of rivers:', Nrivers
     7896
     7897    if colortracktype == 'riverid':
     7898        norm = mpl.colors.Normalize(vcolmin, vcolmax)
     7899    elif colortracktype == 'rivernum':
     7900        norm = mpl.colors.Normalize(0, Nrivers)
     7901    else:
     7902        print errormsg
     7903        print '  ' + fname + ": river track type '" + colortracktype + "' not ready !!"
     7904        print '    available ones:', availcolortracktype
     7905        quit(-1)
    78877906
    78887907# Vector angles
     
    78917910
    78927911    print '  ' + fname + ': getting colors for the river-paths ...'
     7912    drawnriver = []
    78937913    for j in range(0,dy):
    78947914        for i in range(0,dx):
     
    79347954                    ilatlon[0] = gen.index_vec(difflat,mindiffL)
    79357955
    7936                 if not gen.searchInlist(descids.values(), veccolor[j,i]):
     7956                if not gen.searchInlist(drawriverids, veccolor[j,i]):
    79377957                    labcol.append(colornoriver)
    79387958                    colortrack.append(colornoriver)
     
    79417961#                        print 'Lluis right! mindiffl', mindiffl,'mindiffL:',mindiffL
    79427962                    labcol.append(coloriver)
    7943                     colortrack.append(my_cmap(norm(veccolor[j,i])))
     7963                    if not gen.searchInlist(drawnriver, veccolor[j,i]):
     7964                        drawnriver.append(veccolor[j,i])
     7965                    if colortracktype == 'riverid':
     7966                        colortrack.append(my_cmap(norm(veccolor[j,i])))
     7967                    elif colortracktype == 'rivernum':
     7968                        colortrack.append(my_cmap(norm(drawnriver.index(veccolor[j,i]))))
    79447969
    79457970                trackid.append(veccolor[j,i])
Note: See TracChangeset for help on using the changeset viewer.