Changeset 2251 in lmdz_wrf for trunk/tools
- Timestamp:
- Nov 27, 2018, 8:22:54 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2250 r2251 10961 10961 [desclat]: latitude values 10962 10962 [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') 10964 10964 [barcolordescid]: color bar to use to distinguish among selected rivers to draw 10965 10965 [rivercolor]: color for the river-flows of the non selected rivers 10966 10966 [rivernocolor]: color for the outflows of the non selected rivers 10967 10967 [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 10968 10971 [mapvalues]= map characteristics: [proj],[res] 10969 10972 see full documentation: http://matplotlib.org/basemap/ … … 11005 11008 [closefig]= whether figure should be closed or not 11006 11009 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' 11008 11012 'larger',[Npaths]: all river larger than [Npaths] grid points (NOT now) 11009 11013 """ … … 11063 11067 rivernocolor = '#CCCCCC' 11064 11068 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('|') 11067 11073 riverwidth = np.float(riverwdith) 11068 11074 … … 11159 11165 ostation.close() 11160 11166 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 11161 11183 # Getting river's ids: 11162 11184 if riverns.count(',') != 0: … … 11165 11187 if riverns == 'all': 11166 11188 rns = [] 11189 rns = list(set(list(bid[jmin:jmax,imin:imax].compressed()))) 11190 elif riverns == 'all_desc': 11191 rns = [] 11192 ## Following river desc 11167 11193 Ltail = len(TAILdesccoding) 11168 11194 allvarns = odesc.variables.keys() … … 11179 11205 "': ", allvarns 11180 11206 quit(-1) 11181 11182 11207 elif riverns[0:6] == 'larger': 11183 11208 print errormsg … … 11187 11212 rns = [riverns] 11188 11213 11189 print ' ' + fname + ': rivers to plot: [namne] [id] _____'11190 11214 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 11213 11226 11214 11227 # legend values … … 11221 11234 bflow[jmin:jmax,imin:imax], bid[jmin:jmax,imin:imax], codings, dlon, dlat, \ 11222 11235 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) 11224 11238 11225 11239 return -
trunk/tools/drawing_tools.py
r2250 r2251 7809 7809 def plot_multi_river_pattern(xvals, yvals, fvals, veccolor, descids, desclon, \ 7810 7810 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): 7812 7813 """ Function to plot ORCHIDEE's pattern or multiple rivers (following trip variable from 7813 7814 'routing.nc' and river description following 'river_desc.nc') … … 7839 7840 colornoriver= color for the non-river paths values 7840 7841 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 7841 7845 colorst= color for the stations 7842 7846 stsize= color for the size of the labels of the stations … … 7846 7850 """ 7847 7851 fname = 'plot_multi_river_pattern' 7852 availcolortracktype = ['ricerid', 'rivernum'] 7848 7853 7849 7854 figname = 'multi_river_pattern' … … 7880 7885 # Setting up colors for each label 7881 7886 # From: http://stackoverflow.com/questions/15235630/matplotlib-pick-up-one-color-associated-to-one-value-in-a-colorbar 7887 drawriverids = descids.values() 7888 7882 7889 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) 7887 7906 7888 7907 # Vector angles … … 7891 7910 7892 7911 print ' ' + fname + ': getting colors for the river-paths ...' 7912 drawnriver = [] 7893 7913 for j in range(0,dy): 7894 7914 for i in range(0,dx): … … 7934 7954 ilatlon[0] = gen.index_vec(difflat,mindiffL) 7935 7955 7936 if not gen.searchInlist(d escids.values(), veccolor[j,i]):7956 if not gen.searchInlist(drawriverids, veccolor[j,i]): 7937 7957 labcol.append(colornoriver) 7938 7958 colortrack.append(colornoriver) … … 7941 7961 # print 'Lluis right! mindiffl', mindiffl,'mindiffL:',mindiffL 7942 7962 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])))) 7944 7969 7945 7970 trackid.append(veccolor[j,i])
Note: See TracChangeset
for help on using the changeset viewer.