- Timestamp:
- Oct 12, 2018, 7:32:27 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r2171 r2181 198 198 # plot_ZQradii: Function to plot following radial averages only at exact grid poins 199 199 # transform: Function to transform the values and the axes 200 # topography_shadow: Function to compute shaow topography 200 201 201 202 # From nc_var_tools.py … … 13827 13828 return mapenv, merids, parals, xmap, ymap 13828 13829 13830 def topography_shadow(geogf, hgtvn, lonvn, latvn, mapfmtS) 13831 """ Function to compute shaow topography 13832 geogf: file with the topography values 13833 hgtvn: name of the variable with the topography 13834 lonvn: name of the variable with the longitudes 13835 latvn: name of the variable with the latitudes 13836 mapfmt: [cbarmap]|[mapkind]|[lonlatbox] values for the map 13837 cbarmap: name of the colorbar for the map 13838 mapkind: kind of map to use in the plot 13839 'direct': values as they come 13840 'shadow',[pos],[enhance]: pseudo-shadding from a given location of the sun 13841 [pos]: 'N', 'NW' 13842 [enhance]: enhance factor for the shading ('auto' for 1./5.) 13843 lonlatbox: [lonSW],[latSW],[lonNE],[latNE] to plot only a lon,lat box 13844 'full': for the whole domain 13845 """ 13846 fname = 'topography_shadow' 13847 13848 # topography 13849 if not os.paths.isfile(geogf): 13850 print errormsg 13851 print ' ' + fname + ": topography file '" + geogf + "' does not exist !!" 13852 quit(-1) 13853 13854 ong = NetCDFFile(geogf,'r') 13855 13856 if not ong.variables.has_key(hgtvn): 13857 print errormsg 13858 print ' ' + fname + ": topography file '" + geogf + "' does not have " + \ 13859 "topgraphy as variable named: '" + hgtvn + "' !!" 13860 varns = ong.variables.keys() 13861 varns.sort() 13862 print ' available ones:', varns 13863 quit(-1) 13864 if not ong.variables.has_key(lonvn): 13865 print errormsg 13866 print ' ' + fname + ": topography file '" + geogf + "' does not have " + \ 13867 "longitudes as variable named: '" + lonvn + "' !!" 13868 varns = ong.variables.keys() 13869 varns.sort() 13870 print ' available ones:', varns 13871 quit(-1) 13872 if not ong.variables.has_key(hgtvn): 13873 print errormsg 13874 print ' ' + fname + ": topography file '" + geogf + "' does not have " + \ 13875 "latitudes as variable named: '" + latvn + "' !!" 13876 varns = ong.variables.keys() 13877 varns.sort() 13878 print ' available ones:', varns 13879 quit(-1) 13880 13881 otopo = ong.variables[hgtvn] 13882 olon = ong.variables[lonvn] 13883 olat = ong.variables[latvn] 13884 13885 if len(otopo.shape) == 3: valsmap = otopo[0,:,:] 13886 elif len(otopo.shape) == 2: valsmap = otopo[:] 13887 else: 13888 print errormsg 13889 print ' ' + fname + ": wring rank for topography variable '" + hgtvn + "' !!" 13890 print ' provided shape:', otopo.shape 13891 quit(-1) 13892 13893 lon,lat = gen.lonlat2D(olon[:], olat[:]) 13894 ong.close() 13895 13896 dx = valsmap.shape[1] 13897 dy = valsmap.shape[0] 13898 13899 mapfmt = mapfmtS.split 13900 13901 mapkind = mapfmt[1] 13902 if mapfmt[2] == 'full': 13903 lonlatbox = None 13904 elif len(mapfmt[2].split(',')) == 4: 13905 lonlatbox = [] 13906 for lL in mapfmt[2].split(','): 13907 lonlatbox.append(np.float(lL)) 13908 else: 13909 print errormsg 13910 print ' ' + fname + ": lonlatbox value '" + mapfmt[2] + "' not ready !!" 13911 print ' for a lonlatbox 4 values are required. Values passed:', \ 13912 mapfmt[2].splot(',') 13913 quit(-1) 13914 13915 if mapkind == 'direct': 13916 mapv = valsmap[:] 13917 elif mapkind[0:6] == 'shadow': 13918 mapv = np.zeros((dy,dx), dtype=np.float) 13919 sunpos = mapkind.split(',')[1] 13920 enhance = gen.auto_val(mapkind.split(',')[2], 1./5.) 13921 if sunpos == 'N': 13922 ## Linear shadow from N 13923 mapv[0:dy-1,:] = valsmap[1:dy,:] - valsmap[0:dy-1,:] 13924 elif sunpos == 'NW': 13925 ## Diagonal shadow from NW 13926 for i in range(dx-1): 13927 for j in range(dy-1): 13928 if (i-1 >= 0) and (j+1 <= dy-1): 13929 mapv[j,i] = valsmap[j+1,i-1] - valsmap[j,i] 13930 else: 13931 print errormsg 13932 print ' ' + fname + ": sun location for map sahdding '" + sunpos + \ 13933 "' not ready !!" 13934 print ' available ones:', availsunpos 13935 quit(-1) 13936 xmapv = np.max(mapv)*enhance 13937 mapv = np.where(mapv > xmapv, xmapv, mapv) 13938 mapv = ma.masked_less(mapv, 0.) 13939 else: 13940 print errormsg 13941 print ' ' + fname + ": kind of map '" + mapkind + "' not ready !!" 13942 print ' available ones:', availmapkind 13943 quit(-1) 13944 13945 return mapv
Note: See TracChangeset
for help on using the changeset viewer.