Changeset 489
- Timestamp:
- Dec 21, 2011, 3:22:19 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/README.PP
r483 r489 84 84 [only mesoscale for the moment] 85 85 Goal: I want to plot results for two different LOCAL times in the file next to one another 86 pp.py -f wrfout**** -v TSURF --time -4 -- time -786 pp.py -f wrfout**** -v TSURF --time 4 -- time 7 --axtime lt 87 87 88 88 *********************************************************************************** -
trunk/UTIL/PYTHON/gcm_transformations.py
r466 r489 9 9 input_name = None, \ 10 10 fields = 'all', \ 11 limites = None, \ 11 12 predefined = None): 12 13 … … 21 22 outputfilename="" 22 23 f = open('zrecast.auto.def', 'w') 24 23 25 for zfile in input_name: 24 26 f.write(zfile+"\n") … … 52 54 f.write("1"+"\n") 53 55 f.write("yes"+"\n") 54 f.write("370 0.1"+"\n") 56 if limites[0] != -9999.: f.write(str(limites[0])+" "+str(limites[-1])+"\n") 57 else: f.write("370 0.1"+"\n") 58 #f.write("1000000 100"+"\n") 55 59 f.write("20"+"\n") 56 60 else: -
trunk/UTIL/PYTHON/myplot.py
r483 r489 284 284 nc = Dataset(namefile) 285 285 zetime = None 286 days_in_month = [61, 66, 66, 65, 60, 54, 50, 46, 47, 47, 51, 56] 287 plus_in_month = [ 0, 61,127,193,258,318,372,422,468,515,562,613] 286 288 if 'Times' in nc.variables: 287 289 zetime = nc.variables['Times'][0] … … 290 292 if zetime is not None \ 291 293 and 'vert' not in nc.variables: 292 #### strangely enough this does not work for api or ncrcat results! 293 zetimestart = getattr(nc, 'START_DATE') 294 zeday = int(zetime[8]+zetime[9]) - int(zetimestart[8]+zetimestart[9]) - 1 ###? 295 if zeday < 0: dals = -99 ## might have crossed a month... fix soon 296 else: dals = int( 10. * sol2ls ( getattr( nc, 'JULDAY' ) + zeday ) ) / 10. 297 if not getaxis: lschar = "_Ls"+str(dals) 294 ##### strangely enough this does not work for api or ncrcat results! 295 zesol = plus_in_month[ int(zetime[5]+zetime[6])-1 ] + int(zetime[8]+zetime[9]) - 1 ##les sols GCM commencent a 0 296 dals = int( 10. * sol2ls ( zesol ) ) / 10. 298 297 ### 299 298 zetime2 = nc.variables['Times'][1] … … 302 301 zehour = one 303 302 zehourin = abs ( next - one ) 304 ### A CORRIGER POUR LES SOLS IL FAUT LIRE LE MONTH !!!! 305 if getaxis: 303 if not getaxis: 304 lschar = "_Ls"+str(dals) 305 else: 306 306 zelen = len(nc.variables['Times'][:]) 307 307 yeye = range(zelen) ; lsaxis = range(zelen) ; solaxis = range(zelen) ; ltaxis = range(zelen) 308 308 for iii in yeye: 309 zetime = nc.variables['Times'][iii] ; zetimestart = getattr(nc, 'START_DATE') 310 zeday = int(zetime[8]+zetime[9]) - int(zetimestart[8]+zetimestart[9]) - 1 309 zetime = nc.variables['Times'][iii] 311 310 ltaxis[iii] = int(zetime[11]+zetime[12]) + int(zetime[14]+zetime[15])/37. 312 solaxis[iii] = getattr( nc, 'JULDAY' ) + zeday + ltaxis[iii] / 24.311 solaxis[iii] = ltaxis[iii] / 24. + plus_in_month[ int(zetime[5]+zetime[6])-1 ] + int(zetime[8]+zetime[9]) - 1 ##les sols GCM commencent a 0 313 312 lsaxis[iii] = sol2ls ( solaxis[iii] ) 314 313 if ltaxis[iii] < ltaxis[iii-1]: ltaxis[iii] = ltaxis[iii] + 24. 315 #print ltaxis[iii], solaxis[iii], lsaxis[iii] 314 #print ltaxis[iii], solaxis[iii], lsaxis[iii], getattr( nc, 'JULDAY' ) 316 315 lschar = lsaxis ; zehour = solaxis ; zehourin = ltaxis 317 316 else: … … 982 981 print idx,idy,lat2d[idy,idx],vlat 983 982 var = file.variables["HGT"][:,:,:] 984 mpl.contourf(var[0,:,:],30,cmap = mpl.get_cmap(name="Greys_r") ) ; mpl.axis('off') ; mpl.plot(idx,idy,' bo')983 mpl.contourf(var[0,:,:],30,cmap = mpl.get_cmap(name="Greys_r") ) ; mpl.axis('off') ; mpl.plot(idx,idy,'mx',mew=4.0,ms=20.0) 985 984 mpl.show() 986 985 return idy,idx … … 991 990 # output : all indexes to be taken into account for reducing field 992 991 import numpy as np 993 ### added by AS to treat the case of stime = - LT994 if saxis is not None:995 if saxis[0][0] < 0: saxis = - saxis996 ###997 992 if ( np.array(axis).ndim == 2): 998 993 axis = axis[:,0] -
trunk/UTIL/PYTHON/myscript.py
r483 r489 50 50 parser.add_option('--vert', action='append',dest='svert', type="string", default=None, help='slices along vert. 2 comma-separated values: averaging') 51 51 parser.add_option('--column', action='store_true',dest='column', default=False,help='changes --vert z1,z2 from MEAN to INTEGRATE along z') 52 parser.add_option('--time', action='append',dest='stime', type="string", default=None, help='slices along time. 2 comma-separated values: averaging . negative: local time [meso].')52 parser.add_option('--time', action='append',dest='stime', type="string", default=None, help='slices along time. 2 comma-separated values: averaging') 53 53 parser.add_option('--xmax', action='store',dest='xmax', type="float", default=None, help='max value for x-axis in contour-plots [max(xaxis)]') 54 54 parser.add_option('--ymax', action='store',dest='ymax', type="float", default=None, help='max value for y-axis in contour-plots [max(yaxis)]') … … 57 57 parser.add_option('--inverty', action='store_true',dest='inverty', default=False,help='force decreasing values along y-axis (e.g. p-levels)') 58 58 parser.add_option('--logy', action='store_true',dest='logy', default=False,help='set y-axis to logarithmic') 59 parser.add_option('--axtime', action='store',dest='axtime', type="string", default=None, help='choose "ls" or "sol" for time reference')59 parser.add_option('--axtime', action='store',dest='axtime', type="string", default=None, help='choose "ls","sol","lt" for time ref (1D or --time)') 60 60 61 61 ### OPERATIONS BETWEEN FILES -
trunk/UTIL/PYTHON/planetoplot.py
r485 r489 74 74 from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img 75 75 import matplotlib as mpl 76 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel 76 from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis 77 77 from matplotlib.cm import get_cmap 78 78 import numpy as np … … 147 147 if ((proj == None) and (typefile not in ['mesoideal'])): proj = getproj(nc) 148 148 149 ########################################################## 149 if firstfile: 150 ########################## 151 ### Define plot boundaries 152 ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole") 153 if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d) 154 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) 155 else: [wlon,wlat] = simplinterv(lon2d,lat2d) 156 if zoom: [wlon,wlat] = zoomset(wlon,wlat,zoom) 157 elif zarea is not None: [wlon,wlat] = latinterv(area=zarea) 158 159 ########################################################## LOAD 4D DIMENSIONS : x, y, z, t 150 160 if typefile == "gcm": 151 161 lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:] … … 158 168 ### the following lines are kind of dirty... not possible to ask for several lats and lons 159 169 if vlon is not None or vlat is not None: 160 indices = bidimfind(lon2d,lat2d,vlon,vlat) #,file=nc) #placer un point sur carte 170 if firstfile: iwantawhereplot = nc 171 else: iwantawhereplot = None 172 indices = bidimfind(lon2d,lat2d,vlon,vlat,file=iwantawhereplot) #placer un point sur carte 161 173 lonp,latp = ( lon2d[indices[0],indices[1]] , lat2d[indices[0],indices[1]] ) 162 174 if typefile in ['mesoapi','meso'] and mapmode == 1: lon2d = dumpbdy(lon2d,6) ; lat2d = dumpbdy(lat2d,6) ### important to do that now and not before … … 183 195 elif "Time" in nc.variables: time = count + np.arange(0,len(nc.variables["Time"]),1) 184 196 else: time = count + np.arange(0,1,1) 185 count = time[-1] + 1 ## so that a cat is possible with simple subscripts 197 if nnn > 0: count = time[-1] + 1 ## so that a cat is possible with simple subscripts 198 else: count = 0 199 if axtime in ["lt"]: 200 for i in range(len(time)): time[i] = localtime ( interv[0]+time[i]*interv[1], 0.5*(wlon[0]+wlon[1]) ) 201 print "LOCAL TIMES.... ", time 186 202 ### 187 203 if typefile in ['geo']: vert = [0.] ; stime = readslices(str(0)) … … 198 214 ## Faire d'autre checks sur les compatibilites entre fichiers!! 199 215 ########################################################## 200 201 if firstfile:202 ##########################203 ### Define plot boundaries204 ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole")205 if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d)206 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d)207 else: [wlon,wlat] = simplinterv(lon2d,lat2d)208 if zoom: [wlon,wlat] = zoomset(wlon,wlat,zoom)209 elif zarea is not None: [wlon,wlat] = latinterv(area=zarea)210 216 211 217 all_varname[k] = varname … … 246 252 if var2: tab2 = np.append(tab2,all_var2[k],axis=0) 247 253 tabtime = np.append(tabtime,all_time[k]) ; tab = np.append(tab,all_var[k],axis=0) ; k += 1 248 #all_time[0] = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better249 254 all_time[0] = np.array(tabtime) ; all_var[0] = np.array(tab) ; numplot = 1 250 255 if var2: all_var2[0] = np.array(tab2) … … 287 292 else: yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah 288 293 time = all_time[index_f] 289 if stime is not None:290 if stime[0][0] < 0:291 if typefile in ['mesoapi','meso']:292 for i in range(len(time)): time[i] = localtime ( interv[0]+time[i]*interv[1], 0.5*(wlon[0]+wlon[1]) )293 print "OK... WORKING WITH LOCAL TIMES"294 else: errormess("local times not supported. not too hard to modify the code though.")295 294 if mrate is not None: indextime = None 296 295 else: indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) … … 298 297 if typefile in ['mesoapi','meso'] and indextime is not None: ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 299 298 print "********** INDEX LON:",indexlon," LAT:",indexlat," VERT:",indexvert," TIME:",indextime 299 #var = nc.variables["phisinit"][:,:] 300 #contourf(np.transpose(var),30,cmap = get_cmap(name="Greys_r") ) ; axis('off') ; plot(indexlat,indexlon,'mx',mew=4.0,ms=20.0) 301 #show() 302 #exit() 300 303 #################################################################### 301 304 ########## REDUCE FIELDS … … 337 340 if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar.upper())) 338 341 else: palette = get_cmap(name=colorb) 339 ##### 1. ELIMINATE >3D CASES 340 if len(what_I_plot.shape) >= 4: 342 ##### 1. ELIMINATE 0D or >3D CASES 343 if len(what_I_plot.shape) == 0: 344 print "VALUE VALUE VALUE VALUE ::: ",what_I_plot 345 save = 'donothing' 346 elif len(what_I_plot.shape) >= 4: 341 347 print "WARNING!!! ",len(what_I_plot.shape),"-D PLOT NOT SUPPORTED !!! dimensions: ",what_I_plot.shape 342 348 errormess("Are you sure you did not forget to prescribe a dimension ?") … … 542 548 elif save in ['eps','svg','pdf']: makeplotres(zeplot,pad_inches_value=pad_inches_value,disp=False,ext=save) 543 549 elif save == 'gui': show() 550 elif save == 'donothing': pass 544 551 elif save == 'txt': print "Saved results in txt file." 545 552 else: -
trunk/UTIL/PYTHON/pp.py
r483 r489 44 44 yeah = glob.glob(opt.file[0]) ; yeah.sort() 45 45 opt.file[0] = yeah[0] 46 for file in yeah : opt.file[0] = opt.file[0] + "," + file46 for file in yeah[1:]: opt.file[0] = opt.file[0] + "," + file 47 47 48 48 ############################# … … 79 79 zelevel = float(inputnvert[0]) 80 80 ze_interp_levels = [-9999.] 81 elif np.array(inputnvert).size == 2: 82 zelevel = -99. 83 ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),20) 81 84 else: 82 85 zelevel = -99. … … 122 125 input_name=zefiles,\ 123 126 fields=inputvar,\ 127 limites = ze_interp_levels,\ 124 128 predefined=opt.intas) 125 129
Note: See TracChangeset
for help on using the changeset viewer.