Changeset 399
- Timestamp:
- Nov 18, 2011, 8:43:59 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r398 r399 2 2 def errormess(text,printvar=None): 3 3 print text 4 if printvar : print printvar4 if printvar is not None: print printvar 5 5 exit() 6 6 return … … 829 829 return zesaxis 830 830 831 ## Author: AS 832 def bidimfind(lon2d,lat2d,vlon,vlat): 833 import numpy as np 834 if vlat is None: array = (lon2d - vlon)**2 835 elif vlon is None: array = (lat2d - vlat)**2 836 else: array = (lon2d - vlon)**2 + (lat2d - vlat)**2 837 idy,idx = np.unravel_index( np.argmin(array), lon2d.shape ) 838 if vlon is not None: 839 #print lon2d[idy,idx],vlon 840 if (np.abs(lon2d[idy,idx]-vlon)) > 5: errormess("longitude not found ",printvar=lon2d) 841 if vlat is not None: 842 #print lat2d[idy,idx],vlat 843 if (np.abs(lat2d[idy,idx]-vlat)) > 5: errormess("latitude not found ",printvar=lat2d) 844 return idx,idy 845 831 846 ## Author: TN 832 def 847 def getsindex(saxis,index,axis): 833 848 # input : all the desired slices and the good index 834 849 # output : all indexes to be taken into account for reducing field … … 890 905 print "CHECK: x.shape, y.shape", x.shape, y.shape 891 906 if len(shape) == 1: 892 print shape[0]893 907 if shape[0] != len(x): 894 908 print "WARNING HERE !!!" 895 909 x = y 896 910 elif len(shape) == 2: 897 print shape[1], len(y), shape[0], len(x)898 911 if shape[1] == len(y) and shape[0] == len(x) and shape[0] != shape[1]: 899 912 what_I_plot = swapaxes(what_I_plot,0,1) 900 913 print "INFO: swapaxes", what_I_plot.shape, shape 901 #x0 = x902 #x = y903 #y = x0904 #print "define_axis", x, y905 914 return what_I_plot,x,y 906 915 -
trunk/UTIL/PYTHON/myscript.py
r394 r399 44 44 parser.add_option('--lon', action='append',dest='slon', type="string", default=None, help='slices along lon. 2 comma-separated values: averaging') 45 45 parser.add_option('--vert', action='append',dest='svert', type="string", default=None, help='slices along vert. 2 comma-separated values: averaging') 46 parser.add_option('--column', action='store_true',dest='column', default=False,help='changes the function of--vert z1,z2 from MEAN to INTEGRATE along z')46 parser.add_option('--column', action='store_true',dest='column', default=False,help='changes --vert z1,z2 from MEAN to INTEGRATE along z') 47 47 parser.add_option('--time', action='append',dest='stime', type="string", default=None, help='slices along time. 2 comma-separated values: averaging') 48 48 parser.add_option('--xmax', action='store',dest='xmax', type="float", default=None, help='max value for x-axis in contour-plots [max(xaxis)]') -
trunk/UTIL/PYTHON/planetoplot.py
r398 r399 18 18 var=None,\ 19 19 colorb="def",\ 20 winds= True,\20 winds=False,\ 21 21 addchar=None,\ 22 22 interv=[0,1],\ … … 64 64 fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ 65 65 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\ 66 getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices 66 getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar 67 67 from mymath import deg,max,min,mean,get_tsat 68 68 import matplotlib as mpl … … 86 86 ################################ 87 87 nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime) 88 vlon = None ; vlat = None 89 if slon is not None: vlon = slon[0][0] 90 if slat is not None: vlat = slat[0][0] 88 91 if mapmode == 0: winds=False 89 92 elif mapmode == 1: … … 93 96 print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot 94 97 print "********** MAPMODE: ", mapmode 95 if fileref is not None: all_var = [[]]*(zelen+2) ; all_varname = [[]]*(zelen+2) 96 else: all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen 98 if fileref is not None: all_var = [[]]*(zelen+2) ; all_varname = [[]]*(zelen+2) ; all_namefile = [[]]*(zelen+2) 99 else: all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen 97 100 98 101 ################################################################################################# 99 102 ### Loop over the files + vars initially separated by commas to be plotted on the same figure ### 100 103 ################################################################################################# 101 k = 0 102 firstfile = True 104 k = 0 ; firstfile = True 103 105 for nnn in range(len(namefiles)): 104 106 for vvv in range(len(var)): … … 127 129 if not varname and not winds: errormess("please set at least winds or var",printvar=nc.variables) 128 130 ### ... COORDINATES, could be moved below 129 [lon2d,lat2d] = getcoorddef(nc) 131 [lon2d,lat2d] = getcoorddef(nc) 130 132 ### ... PROJECTION 131 133 if proj == None: proj = getproj(nc) … … 144 146 vert = nc.variables["altitude"][:] 145 147 elif typefile in ['meso','mesoapi']: 148 if vlon is not None or vlat is not None: indices = bidimfind(lon2d,lat2d,vlon,vlat) ; print '********** INDICES: ', indices 149 if slon is not None: slon[0][0] = indices[0] ; slon[0][1] = indices[0] 150 if slat is not None: slat[0][0] = indices[1] ; slat[0][1] = indices[1] 146 151 if varname in ['PHTOT','W']: vertdim='BOTTOM-TOP_PATCH_END_STAG' 147 152 else: vertdim='BOTTOM-TOP_PATCH_END_UNSTAG' … … 173 178 else: [wlon,wlat] = simplinterv(lon2d,lat2d) 174 179 if zoom: [wlon,wlat] = zoomset(wlon,wlat,zoom) 175 ### ... NAME FOR TITLE and FILE (have to do something for multiple vars...)176 basename = getname(var=varname,winds=winds,anomaly=anomaly)177 basename = basename + getstralt(nc,level) ## can be moved elsewhere for a more generic routine178 180 179 181 ##### SPECIFIC … … 183 185 else: tinput=tt 184 186 all_var[k]=get_tsat(vert,tinput,zlon=lon,zlat=lat,zalt=vert,ztime=time) 185 all_varname[k] = varname186 187 else: 187 188 ##### GENERAL STUFF HERE 188 189 all_var[k] = getfield(nc,varname) 189 all_varname[k] = varname 190 all_varname[k] = varname 191 all_namefile[k] = namefile 190 192 if var2: all_var2[k] = getfield(nc,var2) 191 193 … … 208 210 numplot = numplot+2 209 211 elif ope in ["cat"]: 210 tab = all_var[0];k = 0212 tab = all_var[0];k = 1 211 213 while k != len(namefiles)-1: 212 214 tab = np.append(tab,all_var[k],axis=0) … … 276 278 #print slon, slat, svert, stime 277 279 #print index_f 278 #print "index lon,lat,vert,time", max(indexlon), max(indexlat), max(indexvert), max(indextime)280 #print "index lon,lat,vert,time", indexlon, indexlat, indexvert, indextime 279 281 #if varname != all_varname[index_f]: indextime = first 280 282 #################################################################### … … 401 403 ### Next subplot 402 404 basename = getname(var=varname,winds=winds,anomaly=anomaly) 405 basename = basename + getstralt(nc,level) 403 406 if typefile in ['mesoapi','meso']: 407 if slon is not None: basename = basename + "_lon_" + str(int(lon2d[indices[1],indices[0]])) 408 if slat is not None: basename = basename + "_lat_" + str(int(lat2d[indices[1],indices[0]])) 404 409 plottitle = basename 405 if addchar: plottitle = plottitle + addchar + "_LT"+str(ltst) 410 if addchar: 411 [addchar,gogol,gogol2] = getlschar ( all_namefile[index_f] ) 412 plottitle = plottitle + addchar + "_LT"+str(ltst) 406 413 else: plottitle = plottitle + "_LT"+str(ltst) 407 414 else:
Note: See TracChangeset
for help on using the changeset viewer.