Changeset 2250 in lmdz_wrf
- Timestamp:
- Nov 27, 2018, 7:49:55 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r2153 r2250 67 67 ## e.g. # drawing.py -o draw_WRFeta_levels -f 120lev/simin_vars.nc,80lev/simin_vars.nc,50lev/simin_vars.nc,50lev_assigned/simin_vars.nc,38lev/simin_vars.nc -f '120lev,80lev,50lev,50leva,38lev:auto:auto:0|6|2:FPS!Alps!vert!levels:pdf:no:true' 68 68 ## e.g. # drawing.py -o draw_2Dshad_map -S 'orog;$conv^{ini}$;lat|-1,lon|-1;lon;lat;auto;rainbow#auto#auto#time@minutes!since!1949-12-01!00:00:00|exct,6,h|%d$^{%H}$|date!([DD]$^{[HH]}$);Srange,Srange;convini|Case1|1a;pdf;binary|shadow,NW,auto|-70.,-36,-62.,-30.;cyl,c;yes' -v convini -f UBA_ERA-I_1a_2D.nc 69 ## e.g. # $pyHOME/drawing.py -o draw_river_pattern -S 'ORCHIDEEdef:ORCHIDEEdef:auto:cyl,l:None:-100.|-65.|-20.|15.:False:True:South|America|ORCHIDEE|routing|0.5|deg:pdf:0|10|1:True' -v Parana,Amazon 69 70 70 71 ####### … … 101 102 # draw_points_lonlat: Function to plot a series of lon/lat points 102 103 # draw_ptZvals: Function to plot a given list of points by their Z value and a colorbar 104 # draw_river_pattern: Function to plot rivers' patterns from ORCHIDEE's routing scheme file 105 # ('routing.nc' and 'river_desc.nc') 103 106 # draw_SkewT: creation of a SkewT-logP diagram using matplotlib's API example 104 107 # draw_stations_map: Function to plot a map with the stations … … 139 142 'draw_Neighbourghood_evol', \ 140 143 'draw_points', 'draw_points_lonlat', \ 141 'draw_ptZvals', 'draw_river_desc', 'draw_SkewT', 'draw_subbasin', \ 144 'draw_ptZvals', 'draw_river_desc', 'draw_river_pattern', 'draw_SkewT', \ 145 'draw_subbasin', \ 142 146 'draw_stations_map', 'draw_Taylor', \ 143 147 'draw_time_lag', 'draw_timeSeries', 'draw_topo_geogrid', \ … … 10909 10913 #draw_2Dshad_map(ncfile, values, 'convini', axfig=None, fig=None) 10910 10914 10915 def draw_river_pattern(values, riverns): 10916 """ Function to plot rivers' patterns from ORCHIDEE's routing scheme file 10917 ('routing.nc' and 'river_desc.nc') 10918 values= [routingvars]:[descvalues]:[rivervalues]:[mapvalues]:[stationsvalues]: 10919 [lonlatbox]:[drawcountry]:[drawbasinid]:[gtit]:[kindfig]:[legvals]: 10920 [closefig] 10921 [routingvars]= '|' list of [basinsfilen]|[basinsvarid]|[basinslonname]| 10922 [basinslatname]|[basinsflowname], names of the variables in routing 10923 scheme file with the required values to make the plot (use 'ORCHIDEEdef' 10924 to use its default values 'routing.nc|basins|nav_lon|nav_lat|trip') 10925 [basinsfilen]: name of the file with the basins' information 10926 [basinsvarid]: basins' id 10927 [basinslonname]: name of the variable with the longitudes 10928 [basinslatname]: name of the variable with the latitudes 10929 [basinsflowname]: name with the variable with the flow directions 10930 (1-8: N, NE, E, ..., NW; 97: sub-basin; 98: small to sea; 99: large to 10931 sea) 10932 [descvalues]= '|' list of [descfilen]|[TAILdesccoding]|[desclon]|[desclat], 10933 names of the variables from routing output required for the plot (use 10934 'ORCHIDEEdef' to use its default values 'river_desc.nc|_coding|lon|lat') 10935 [descfilen]: netCDF file with the description of the rivers as in ORCHIDEE 10936 One ASCII variable per name of river with (e.g. Parana): 10937 double Parana_frac(lat, lon) ; 10938 Parana_frac:units = "-" ; 10939 Parana_frac:long_name = "Fraction of basin Parana per grid box" ; 10940 Parana_frac:missing_value = 1.e+20 ; 10941 Parana_frac:Nb_of_grid_points_in_basin = 380 ; 10942 Parana_frac:Longitude_of_outflow_point = -58.5 ; 10943 Parana_frac:Latitude_of_outflow_point = -34.5 ; 10944 Parana_frac:Number_of_streams = 380 ; 10945 Parana_frac:Total_number_of_hops_to_ocean = 6840 ; 10946 Parana_frac:Minimum_number_of_hops_to_ocean_for_any_stream = 1 ; 10947 Parana_frac:Average_number_of_hops_to_ocean_for_any_stream = 18 ; 10948 Parana_frac:Maximum_number_of_hops_to_ocean_for_any_stream = 32 ; 10949 Parana_frac:Average_residence_time_in_basin = 19153.2279625174 ; 10950 double Parana_upstream(lat, lon) ; 10951 Parana_upstream:units = "m^2" ; 10952 Parana_upstream:long_name = "Upstream area of basin Parana in the grid box" ; 10953 Parana_upstream:missing_value = 1.e+20 ; 10954 int Parana_coding(lat, lon) ; 10955 Parana_coding:units = "-" ; 10956 Parana_coding:long_name = "Pfafstetter codes of grid boxes in basin Parana" ; 10957 Parana_coding:missing_value = 999999999 ; 10958 [TAILdesccoding]: tail of the variable with the river coding as: 10959 [rivername][TAILdescoding] 10960 [desclon]: longitude values 10961 [desclat]: latitude values 10962 [rivervalues]= '|' separated list of [colordescid]|[rivercolor]|[rivernocolor]|[riverwidth] 10963 [riverwidth] (use 'auto' for 'rainbow|#AAAAAAA|#CCCCCC|0.5') 10964 [barcolordescid]: color bar to use to distinguish among selected rivers to draw 10965 [rivercolor]: color for the river-flows of the non selected rivers 10966 [rivernocolor]: color for the outflows of the non selected rivers 10967 [riverwidth]: width of the lines of the rivers' path 10968 [mapvalues]= map characteristics: [proj],[res] 10969 see full documentation: http://matplotlib.org/basemap/ 10970 [proj]: projection 10971 * 'cyl', cilindric 10972 * 'lcc', lambert conformal 10973 [res]: resolution: 10974 * 'c', crude 10975 * 'l', low 10976 * 'i', intermediate 10977 * 'h', high 10978 * 'f', full 10979 [stationsvalues]= '|' list of values in order to add stations and its labels 10980 into the plot (use 'None' for no stations file) [stationsfilen]|[stname]| 10981 [stlonn]|[stlatn]|[stcol]|[stsize] 10982 [stationsfilen]: name of the netCDF file with the values of the stations 10983 |stloname]: variable with the name of the stations 10984 |stlonn]: variable with the longitude of the stations 10985 [stlatn]: variable with the latitude of the stations 10986 [stcol]: color to use for the labels of the stations 10987 [stsize]: character size to use for the labels of the stations 10988 [lonlatbox]= '|' separated list of [SWlon]|[SWlat]|[NElon]|[NElat] to define 10989 only a given region to plot as a lonlat box ('all' for all the area in file) 10990 [SWlon]: longitude SW vertex 10991 [SWlat]: latitude SW vertex 10992 [NElon]: longitude NE vertex 10993 [NElat]: latitude NE vertex 10994 [drawcountry]= whether country lines should be plotted or not 10995 [drawbasinid]= whether basins id should be plotted or not 10996 [gtit]= title of the graph ('|', for spaces) 10997 [kindfig]= kind of figure (png, ps, pdf) 10998 [legvals]= [locleg]|[fontsize]|[Ncol] ('auto' for 0|12|1) 10999 [locleg]: location of the legend (0, autmoatic) 11000 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', 11001 5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center', 11002 9: 'upper center', 10: 'center' 11003 [fontsize]: font size for the legend (auto for 12) 11004 [Ncol]: numnber of columns 11005 [closefig]= whether figure should be closed or not 11006 riverns= ',' list of the names of the rivers to plot (as in [descfilen]) 11007 'all': for all rivers in file 11008 'larger',[Npaths]: all river larger than [Npaths] grid points (NOT now) 11009 """ 11010 import numpy.ma as ma 11011 fname = 'draw_river_pattern' 11012 11013 if values == 'h': 11014 print fname + '_____________________________________________________________' 11015 print draw_river_desc.__doc__ 11016 quit() 11017 11018 expectargs = '[routingvars]:[descvalues]:[rivervalues]:[mapvalues]:' + \ 11019 '[stationsvalues]:[lonlatbox]:[drawcountry]:[drawbasinid]:[gtit]:[kindfig]:' + \ 11020 '[legvals]:[closefig]' 11021 11022 drw.check_arguments(fname,values,expectargs,':') 11023 11024 routingvars = values.split(':')[0] 11025 descvalues = values.split(':')[1] 11026 rivervalues = values.split(':')[2] 11027 mapvals = values.split(':')[3] 11028 stationvalues = values.split(':')[4] 11029 lonlatbox = values.split(':')[5] 11030 drawcountry = gen.Str_Bool(values.split(':')[6]) 11031 drawbasinid = gen.Str_Bool(values.split(':')[7]) 11032 gtit = values.split(':')[8].replace('|',' ') 11033 kindfig = values.split(':')[9] 11034 legvals = values.split(':')[10] 11035 closefig = gen.Str_Bool(values.split(':')[11]) 11036 11037 if routingvars == 'ORCHIDEEdef': 11038 basinsfilen = 'routing.nc' 11039 basinsvarid = 'basins' 11040 basinslonname = 'nav_lon' 11041 basinslatname = 'nav_lat' 11042 basinsflowname = 'trip' 11043 else: 11044 [basinsfilen, basinsvarid, basinslonname, basinslatname, basinsflowname] = \ 11045 routingvars.split('|') 11046 basinsvarns = [basinsvarid, basinslonname, basinslatname, basinsflowname] 11047 basinsexpectvars = ['basinsvarid', 'basinslonname', 'basinslatname', \ 11048 'basinsflowname'] 11049 11050 if descvalues == 'ORCHIDEEdef': 11051 descfilen = 'river_desc.nc' 11052 TAILdesccoding = '_coding' 11053 desclon = 'lon' 11054 desclat = 'lat' 11055 else: 11056 [descfilen, TAILdesccoding, desclon, desclat] = descvalues.split('|') 11057 descvarns = [desclon, desclat] 11058 descexpectvarns = ['desclon', 'desclat'] 11059 11060 if rivervalues == 'auto': 11061 barcolordescid = 'rainbow' 11062 rivercolor = '#AAAAAA' 11063 rivernocolor = '#CCCCCC' 11064 riverwidth = 0.5 11065 else: 11066 [barcolordescid, rivercolor, rivernocolor, riverwidth]= rivervalues.split('|') 11067 riverwidth = np.float(riverwdith) 11068 11069 if stationvalues == 'None': 11070 stationsfilen = None 11071 stn = None 11072 stlon = None 11073 stlat = None 11074 stcol = None 11075 stsize = None 11076 else: 11077 [stationsfilen, stname, stlonn, stlatn, stcol, stsize] = \ 11078 stationvalues.split('|') 11079 stsize = int(stsize) 11080 stvarns = [stname, stlonn, stlatn] 11081 stexpectvarns = ['stname', 'stlonn', 'stlatn'] 11082 11083 # Getting rivers' information 11084 if not os.path.isfile(basinsfilen): 11085 print errormsg 11086 print ' ' + fname + ": file with basins information '" + basinsfilen + \ 11087 "' does not exist !!" 11088 quit(-1) 11089 oriver = NetCDFFile(basinsfilen, 'r') 11090 ivar = 0 11091 for vn in basinsexpectvars: 11092 if not oriver.variables.has_key(basinsvarns[ivar]): 11093 print errormsg 11094 print ' ' +fname+ ": basins file '" + basinfilen + "' does not have " + \ 11095 vn + " as '" + basinsvarns[ivar] + "' !!" 11096 ivar = ivar + 1 11097 obid = oriver.variables[basinsvarid] 11098 oblon = oriver.variables[basinslonname] 11099 oblat = oriver.variables[basinslatname] 11100 obflow = oriver.variables[basinsflowname] 11101 11102 if routingvars == 'ORCHIDEEdef': 11103 # Data is fliped along latitudes 11104 bid = obid[::-1,:] 11105 blon = oblon[::-1,:] 11106 blat = oblat[::-1,:] 11107 bflow = obflow[::-1,:] 11108 else: 11109 bid = obid[:] 11110 blon = oblon[:] 11111 blat = oblat[:] 11112 bflow = obflow[:] 11113 oriver.close() 11114 11115 # Getting rivers' description 11116 if not os.path.isfile(descfilen): 11117 print errormsg 11118 print ' ' + fname + ": file with decription information '" + descfilen + \ 11119 "' does not exist !!" 11120 quit(-1) 11121 odesc = NetCDFFile(descfilen, 'r') 11122 ivar = 0 11123 for vn in descexpectvarns: 11124 if not odesc.variables.has_key(descvarns[ivar]): 11125 print errormsg 11126 print ' '+fname+": dfescription file '"+descfilen+"' does not have " + \ 11127 vn + " as '" + descvarns[ivar] + "' !!" 11128 ivar = ivar + 1 11129 odlon = odesc.variables[desclon] 11130 odlat = odesc.variables[desclat] 11131 dlon = odlon[:] 11132 dlat = odlat[:] 11133 11134 if stationsfilen is not None: 11135 # Getting staions' information 11136 if not os.path.isfile(stationsfilen): 11137 print errormsg 11138 print ' ' + fname + ": file with stations information '" + \ 11139 stationsfilen + "' does not exist !!" 11140 quit(-1) 11141 ostation = NetCDFFile(stationsfilen, 'r') 11142 ivar = 1 11143 for vn in stexpectvars: 11144 if not ostation.variables.has_key(stvarns[ivar]): 11145 print errormsg 11146 print ' ' + fname + ": stations file '" + stationsfilen + \ 11147 "' does not have " + vn + " as '" + stvarns[ivar] + "' !!" 11148 ivar = ivar + 1 11149 stname , stlonn, stlatn 11150 ostn = ostation.variables[stname] 11151 ostlon = ostation.variables[stlonn] 11152 ostlat = ostation.variables[stlatn] 11153 11154 Lstr = ostn.dimensions[1] 11155 lenstr = len(ostaton.dimensions(Lstr)) 11156 stn = ncvar.get_str_nc(ostn, lenstr) 11157 stlon = ostlon[:] 11158 stlat = ostlat[:] 11159 ostation.close() 11160 11161 # Getting river's ids: 11162 if riverns.count(',') != 0: 11163 rns = riverns.split(',') 11164 else: 11165 if riverns == 'all': 11166 rns = [] 11167 Ltail = len(TAILdesccoding) 11168 allvarns = odesc.variables.keys() 11169 for vn in allvarns: 11170 if vn.find(TAILdesccoding) != -1: 11171 Lvn = len(vn) 11172 rns.append(vn[0:Lvn-Ltail]) 11173 if len(rns) == 0: 11174 print errormsg 11175 print ' ' + fname + ": no river description found as '[rivername]"+ \ 11176 TAILdesccoding + "' !!" 11177 allvarns.sort() 11178 print " variables found in description file '" + descfilen + \ 11179 "': ", allvarns 11180 quit(-1) 11181 11182 elif riverns[0:6] == 'larger': 11183 print errormsg 11184 print ' ' + fname + ": riverns == 'larger' not ready yet !!" 11185 quit(-1) 11186 else: 11187 rns = [riverns] 11188 11189 print ' ' + fname + ': rivers to plot: [namne] [id] _____' 11190 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) 11213 11214 # legend values 11215 if legvals != 'auto': 11216 legvalues = drw.legend_values(legvals, '|') 11217 else: 11218 legvalues = [0, 12, 1] 11219 11220 drw.plot_multi_river_pattern(lon[jmin:jmax,imin:imax], lat[jmin:jmax,imin:imax], \ 11221 bflow[jmin:jmax,imin:imax], bid[jmin:jmax,imin:imax], codings, dlon, dlat, \ 11222 stn, stlon, stlat, drawcountry, drawbasinid, barcolordescid, rivercolor, \ 11223 rivernocolor, riverwidth, stcol, stsize, gtit, mapvals, kindfig, rns) 11224 11225 return 11226 11227 #values = 'ORCHIDEEdef:ORCHIDEEdef:auto:cyl,l:None:all:False:False:ORCHIDEEE|routing|' + \ 11228 # '0.5|deg:pdf:0|10|1:True' 11229 #riverns = 'all' 11230 #draw_river_pattern(values, riverns) 11231 10911 11232 #quit() 10912 11233 … … 10934 11255 'draw_cycle', 'draw_ensembles_time', 'draw_multi_2D_shad', 'draw_multi_SkewT', \ 10935 11256 'draw_lines', \ 10936 'draw_lines_time', 'draw_multiWindRose', 'draw_points', 'draw_Taylor', \ 11257 'draw_lines_time', 'draw_multiWindRose', 'draw_points', 'draw_river_pattern', \ 11258 'draw_Taylor', \ 10937 11259 'draw_time_lag', 'draw_topo_geogrid_boxes', \ 10938 11260 'draw_trajectories', 'draw_vals_trajectories', 'draw_WRFeta_levels', \ … … 11043 11365 elif oper == 'draw_river_desc': 11044 11366 draw_river_desc(opts.ncfile, opts.values, opts.varname) 11367 elif oper == 'draw_river_pattern': 11368 draw_river_pattern(opts.values, opts.varname) 11045 11369 elif oper == 'draw_subbasin': 11046 11370 draw_subbasin(opts.ncfile, opts.values) -
trunk/tools/drawing_tools.py
r2248 r2250 189 189 # plot_lines: Function to plot a collection of lines 190 190 # plot_multiWindRose: Function to plot multi wind roses (from where the dinw blows) 191 # plot_river_pattern: Function to plot ORCHIDEE's pattern or rivers (following trip 192 # variable from 'routing.nc' and river description following 'river_desc.nc') 191 193 # plot_SkewT: Function to plot a SkewT-logP diagram using matplotlib's API example 192 194 # plot_stations_map: Function to plot a map with a series of stations … … 1822 1824 def legend_values(legstring, char): 1823 1825 """ Function to determine the values for the legend 1824 legstring= char separated list of [locleg][char][fontsize]:1826 legstring= [char] separated list of [locleg][char][fontsize][char][ncol]: 1825 1827 [locleg]: location of the legend (0, automatic) 1826 1828 1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right', … … 7584 7586 stn, stlon, stlat, drawcountry, drawbasinid, colordescid, coloriver, colornoriver, \ 7585 7587 colorst, stsize, graphtit, mapv, kfig, figname): 7586 """ Function to plot vectors 7588 """ Function to plot ORCHIDEE's pattern of one river (following trip variable from 7589 'routing.nc' and river description following 'river_desc.nc') 7587 7590 xvals= values for the x-axis 7588 7591 yvals= values for the y-axis … … 7590 7593 veccolor= basin id 7591 7594 descid= description id 7592 , desclon, desclat, 7595 desclon= longitude of description 7596 desclat= latitude of description 7597 stn= name of the stations 7598 stlon= longitude of the stations 7599 stlat= latitude of the stations 7593 7600 mapv= map characteristics: [proj],[res] 7594 7601 see full documentation: http://matplotlib.org/basemap/ … … 7604 7611 drawcountry= whether country lines should be plotted or not 7605 7612 drawbasinid= whether basins id should be plotted or not 7613 colordescid= color map for the id of the rivers 7614 coloriver= color for the non-selected rivers in the plot 7615 colornoriver= color for the non-river paths values 7616 colorst= color for the stations 7617 stsize= color for the size of the labels of the stations 7606 7618 graphtit= title of the graph ('|', for spaces) 7607 7619 kfig= kind of figure … … 7794 7806 7795 7807 return 7808 7809 def plot_multi_river_pattern(xvals, yvals, fvals, veccolor, descids, desclon, \ 7810 desclat, stn, stlon, stlat, drawcountry, drawbasinid, colordescid, coloriver, \ 7811 colornoriver, pathwidth, colorst, stsize, graphtit, mapv, kfig, riverns): 7812 """ Function to plot ORCHIDEE's pattern or multiple rivers (following trip variable from 7813 'routing.nc' and river description following 'river_desc.nc') 7814 xvals= values for the x-axis 7815 yvals= values for the y-axis 7816 fvals= values for the flow (1-8: N, NE, E, ..., NW; 97: sub-basin; 98: small to sea; 99: large to sea) 7817 veccolor= basin id 7818 descids= dictionary with the description of each river 7819 desclon= longitude of description 7820 desclat= latitude of description 7821 stn= name of the stations 7822 stlon= longitude of the stations 7823 stlat= latitude of the stations 7824 mapv= map characteristics: [proj],[res] 7825 see full documentation: http://matplotlib.org/basemap/ 7826 [proj]: projection 7827 * 'cyl', cilindric 7828 * 'lcc', lambert conformal 7829 [res]: resolution: 7830 * 'c', crude 7831 * 'l', low 7832 * 'i', intermediate 7833 * 'h', high 7834 * 'f', full 7835 drawcountry= whether country lines should be plotted or not 7836 drawbasinid= whether basins id should be plotted or not 7837 colordescid= color map for the id of the rivers 7838 coloriver= color for the non-selected rivers in the plot 7839 colornoriver= color for the non-river paths values 7840 pathwidth= width of the line with the river paths 7841 colorst= color for the stations 7842 stsize= color for the size of the labels of the stations 7843 graphtit= title of the graph ('|', for spaces) 7844 kfig= kind of figure 7845 riverns= list with the name of the rivers to be plotted 7846 """ 7847 fname = 'plot_multi_river_pattern' 7848 7849 figname = 'multi_river_pattern' 7850 7851 dx=xvals.shape[1] 7852 dy=xvals.shape[0] 7853 xmin = np.min(xvals) 7854 xmax = np.max(xvals) 7855 ymin = np.min(yvals) 7856 ymax = np.max(yvals) 7857 7858 # flow direction 7859 7860 plt.rc('text', usetex=True) 7861 7862 ddx = np.abs(xvals[dy/2+1,dx/2] - xvals[dy/2,dx/2]) 7863 ddy = np.abs(yvals[dy/2,dx/2+1] - yvals[dy/2,dx/2]) 7864 fontcharac = {'family': 'serif', 'weight': 'normal', 'size': 3} 7865 7866 xlabpos = [] 7867 ylabpos = [] 7868 labels = [] 7869 labcol = [] 7870 flow = [] 7871 flowvals = [] 7872 xtrack = [] 7873 ytrack = [] 7874 colortrack = [] 7875 trackid = [] 7876 stnlL = [] 7877 stlonlL = [] 7878 stlatlL = [] 7879 7880 # Setting up colors for each label 7881 # From: http://stackoverflow.com/questions/15235630/matplotlib-pick-up-one-color-associated-to-one-value-in-a-colorbar 7882 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) 7887 7888 # Vector angles 7889 lengthtrac = np.float(xvals[0,1] - xvals[0,0]) 7890 lengthtrac2 = lengthtrac*np.sqrt(2.) 7891 7892 print ' ' + fname + ': getting colors for the river-paths ...' 7893 for j in range(0,dy): 7894 for i in range(0,dx): 7895 if veccolor[j,i] != '--': 7896 # ibeg = xvals[j,i]-lengthtrac/2. 7897 # jbeg = yvals[j,i]-lengthtrac/2. 7898 ibeg = xvals[j,i] 7899 jbeg = yvals[j,i] 7900 labels.append(int(veccolor[j,i])) 7901 flowvals.append(fvals[j,i]) 7902 angle = (fvals[j,i] - 1)*np.pi/4 7903 if gen.searchInlist([2,4,6,8], fvals[j,i]): 7904 iend = ibeg + lengthtrac2*np.sin(angle) 7905 jend = jbeg + lengthtrac2*np.cos(angle) 7906 elif gen.searchInlist([1,3,5,7], fvals[j,i]): 7907 iend = ibeg + lengthtrac*np.sin(angle) 7908 jend = jbeg + lengthtrac*np.cos(angle) 7909 else: 7910 ibeg = xvals[j,i] 7911 jbeg = yvals[j,i] 7912 iend = None 7913 jend = None 7914 7915 xlabpos.append(ibeg) 7916 ylabpos.append(jbeg) 7917 xtrack.append(ibeg) 7918 xtrack.append(iend) 7919 xtrack.append(None) 7920 ytrack.append(jbeg) 7921 ytrack.append(jend) 7922 ytrack.append(None) 7923 if len(desclon.shape) == 2: 7924 difflonlat = np.sqrt((desclon-xvals[j,i])**2 + (desclat-yvals[j,i])**2) 7925 mindiffLl = np.min(difflonlat) 7926 ilatlon = gen.index_mat(difflonlat, mindiffLl) 7927 else: 7928 ilatlon = np.zeros((2), dtype=int) 7929 difflon = np.abs(desclon - xvals[j,i]) 7930 mindiffl = np.min(difflon) 7931 ilatlon[1] = gen.index_vec(difflon,mindiffl) 7932 difflat = np.abs(desclat - yvals[j,i]) 7933 mindiffL = np.min(difflat) 7934 ilatlon[0] = gen.index_vec(difflat,mindiffL) 7935 7936 if not gen.searchInlist(descids.values(), veccolor[j,i]): 7937 labcol.append(colornoriver) 7938 colortrack.append(colornoriver) 7939 # print 'Lluis: veccol:', veccolor[j,i], 'mindiffl', mindiffl,'mindiffL:',mindiffL 7940 else: 7941 # print 'Lluis right! mindiffl', mindiffl,'mindiffL:',mindiffL 7942 labcol.append(coloriver) 7943 colortrack.append(my_cmap(norm(veccolor[j,i]))) 7944 7945 trackid.append(veccolor[j,i]) 7946 7947 totvals = len(flowvals) 7948 7949 if not mapv is None: 7950 lon00 = np.where(xvals[:] < 0., 360. + xvals[:], xvals[:]) 7951 lat00 = yvals[:] 7952 7953 map_proj=mapv.split(',')[0] 7954 map_res=mapv.split(',')[1] 7955 7956 nlon = np.min(xvals) 7957 xlon = np.max(xvals) 7958 nlat = np.min(yvals) 7959 xlat = np.max(yvals) 7960 7961 lon2 = xvals[dy/2,dx/2] 7962 lat2 = yvals[dy/2,dx/2] 7963 7964 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ 7965 xlon, ',', xlat 7966 7967 if map_proj == 'cyl': 7968 m = Basemap(projection=map_proj, llcrnrlon=nlon, llcrnrlat=nlat, \ 7969 urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 7970 elif map_proj == 'lcc': 7971 m = Basemap(projection=map_proj, lat_0=lat2, lon_0=lon2, llcrnrlon=nlon, \ 7972 llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 7973 else: 7974 print errormsg 7975 print ' ' + fname + ": projection '" + map_proj + "' not ready!!" 7976 print ' projections available: cyl, lcc' 7977 quit(-1) 7978 7979 m.drawcoastlines() 7980 drawcountry = True 7981 if drawcountry: m.drawcountries() 7982 7983 meridians = gen.pretty_int(nlon,xlon,5) 7984 m.drawmeridians(meridians,labels=[True,False,False,True],color="black") 7985 7986 parallels = gen.pretty_int(nlat,xlat,5) 7987 m.drawparallels(parallels,labels=[False,True,True,False],color="black") 7988 7989 Npaths = len(xlabpos) 7990 print ' ' + fname + ' plotting ', Npaths ,'river-paths ...' 7991 j = 0 7992 for i in range(Npaths): 7993 gen.percendone(i,Npaths,5.,' ' + fname + ': drawn') 7994 plt.plot(xtrack[j:j+2], ytrack[j:j+2], color=colortrack[i], \ 7995 linewidth=pathwidth) 7996 j = j + 3 7997 7998 # Sea-flow 7999 for i in range(len(xlabpos)): 8000 if flowvals[i] == 97: 8001 plt.plot(xlabpos[i], ylabpos[i], 'x', color=colortrack[i], \ 8002 markersize=lengthtrac2) 8003 elif flowvals[i] == 98: 8004 plt.plot(xlabpos[i], ylabpos[i], '*', color=colortrack[i], \ 8005 markersize=lengthtrac2) 8006 elif flowvals[i] == 99: 8007 plt.plot(xlabpos[i], ylabpos[i], 'h', color=colortrack[i], \ 8008 markersize=lengthtrac2) 8009 8010 plt.xlim(xmin,xmax) 8011 plt.ylim(ymin,ymax) 8012 8013 if drawbasinid: 8014 print ' ' + fname + ' drawing basins ids ...' 8015 idlabelled = [] 8016 for i in range(len(xlabpos)): 8017 if not gen.searchInlist(idlabelled, labels[i]): 8018 plt.text(xlabpos[i]+0.05*lengthtrac, ylabpos[i]+0.05*lengthtrac, \ 8019 labels[i], color=labcol[i], fontdict=fontcharac) 8020 idlabelled.append(labels[i]) 8021 8022 # plt.text(xlabpos[i]+0.1*lengthtrac, ylabpos[i]+0.1*lengthtrac, trackid[i], \ 8023 # color=colortrack[i], fontdict=fontcharac) 8024 # plt.text(xlabpos[i]+0.1*lengthtrac, ylabpos[i]+0.1*lengthtrac, str(flowvals[i]), \ 8025 # color=colortrack[i], fontdict=fontcharac) 8026 8027 if stn is not None: 8028 for ist in range(len(stlon)): 8029 if stlon[ist] > xmin and stlon[ist] < xmax and stlat[ist] > ymin and \ 8030 stlat[ist] < ymax: 8031 stname = '*' 8032 for ic in range(len(stn[ist,:])): 8033 stname = stname + stn[ist,ic] 8034 # plt.annotate(stname, xy=(stlon[ist],stlat[ist]), color=colorst, ) 8035 plt.text(stlon[ist], stlat[ist], stname, color=colorst, fontsize=stsize) 8036 8037 # cbar = plt.colorbar() 8038 plt.title(graphtit.replace('&','\&')) 8039 8040 output_kind(kfig, figname, True) 8041 8042 return 8043 7796 8044 7797 8045 def var_3desc(ovar): -
trunk/tools/generic_tools.py
r2238 r2250 10383 10383 latexsymb = {} 10384 10384 10385 if type(itext) != type('S.'): 10386 print warnmsg 10387 print ' ' + fname + ": passed text '", itext, "' is not a string type !!" 10388 print ' passed type:', type(itext), 'transforming it to string' 10389 itext = str(itext) 10390 10385 10391 Litext = len(itext) 10386 10392 for ic in range(Litext):
Note: See TracChangeset
for help on using the changeset viewer.