Changeset 359 for trunk/UTIL
- Timestamp:
- Nov 8, 2011, 2:38:15 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/gcm.py
r357 r359 47 47 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 48 48 49 parser.add_option('-O','--output', action='store',dest='output', type="string", default=None, help='Output file name') 50 parser.add_option('--res', action='store',dest='res', type="float", default=200., help='Resolution for png outputs. --save png must be specified. (def=200.)') 51 parser.add_option('--operation', action='store',dest='operation', type="string", default=None, help='Basic operation to perform between input file and a specified reference file. Available: addition "+", soustraction "-". Operation is done as: file1 +or- fileref. The reference file must be specified using -fref option') 52 parser.add_option('--fref', action='store',dest='fref', type="string", default=None, help='Reference namefile for the --operation option.') 53 parser.add_option('--mope', action='store',dest='vminope', type="float", default=0., help='bounding minimum value for inter-file operation') 54 parser.add_option('--Mope', action='store',dest='vmaxope', type="float", default=0., help='bounding maximum value for inter-file operation') 55 parser.add_option('--titleref', action='store',dest='titref', type="string", default="fill", help='title for the reference file. Default: title of figure (1)') 56 49 57 ############# T.N. changes 50 58 #parser.add_option('-o','--operation',action='store',dest='operation',type="string", default=None ,help='matrix of operations between files (for now see code, sorry)') … … 53 61 parser.add_option('--vert', action='append',dest='svert',type="string", default=None, help='slices along vertical axis. One value, or two values separated by comas for averaging') # quelles coordonnees ? 54 62 parser.add_option('--time', action='append',dest='stime',type="string", default=None, help='slices along time. One value, or two values separated by comas for averaging') # quelles coordonnees ? 55 56 63 57 64 (opt,args) = parser.parse_args() … … 76 83 # vmintab = adjust_length (opt.vmin, zelen) 77 84 # vmaxtab = adjust_length (opt.vmax, zelen) 85 86 87 ################################ 88 ### General check 89 90 if opt.fref is not None: 91 if opt.operation is None: 92 print "you must specify an operation when using a reference file" 93 exit() 94 if opt.operation is not None: 95 if opt.fref is None: 96 print "you must specifiy a reference file when using inter-file operations" 97 exit() 98 99 ################################ 100 78 101 79 102 print "namefile, length", opt.namefile, len(opt.namefile) … … 158 181 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.first,\ 159 182 mult=opt.mult,zetitle=opt.zetitle,\ 160 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime) 183 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ 184 outputname=opt.output,resolution=opt.res,\ 185 ope=opt.operation,fileref=opt.fref,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref) 161 186 print 'Done: '+name 162 187 system("rm -f to_be_erased") -
trunk/UTIL/PYTHON/meso.py
r351 r359 54 54 parser.add_option('--time', action='append',dest='stime',type="string", default=None, help='slices along time. One value, or two values separated by comas for averaging') # quelles coordonnees ? 55 55 56 ############# A.C. changes 57 parser.add_option('-O','--output', action='store' ,dest='output',type="string", default=None, help='Output file name') 58 parser.add_option('--res', action='store' ,dest='res',type="float", default=200., help='Resolution for png outputs. --save png must be specified. (def=200.)') 56 59 57 60 (opt,args) = parser.parse_args() … … 152 155 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.first,\ 153 156 mult=opt.mult,zetitle=opt.zetitle,\ 154 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime) 157 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ 158 outputname=opt.output,resolution=opt.res) 155 159 print 'Done: '+name 156 160 system("rm -f to_be_erased") -
trunk/UTIL/PYTHON/myplot.py
r350 r359 138 138 rcParams['font.size'] = int( rcParams['font.size'] * 3. / 4. ) 139 139 elif numplot == 3: 140 subv = 3141 subh = 1140 subv = 2 141 subh = 2 142 142 fig.subplots_adjust(wspace = 0.5) 143 143 rcParams['font.size'] = int( rcParams['font.size'] * 1. / 2. ) -
trunk/UTIL/PYTHON/planetoplot.py
r357 r359 5 5 ### A. Spiga -- LMD -- 06~09/2011 -- General building and mapping capabilities 6 6 ### T. Navarro -- LMD -- 10~11/2011 -- Improved use for GCM and added sections + 1Dplot capabilities 7 ### A. Colaitis -- LMD -- -- Mostly minor improvements and inter-plot operation capabilities 7 8 8 9 def planetoplot (namefiles,\ … … 36 37 slat=None,\ 37 38 svert=None,\ 38 stime=None): 39 stime=None,\ 40 outputname=None,\ 41 resolution=200,\ 42 ope=None,\ 43 fileref=None,\ 44 minop=0.,\ 45 maxop=0.,\ 46 titleref="fill"): 47 39 48 40 49 #################################################################################################################### … … 53 62 import numpy as np 54 63 from numpy.core.defchararray import find 55 64 56 65 ################################ 57 66 ### Which plot needs to be done? … … 62 71 if numplot == None: numplot = zelen*nslices 63 72 print "len(namefiles), nslices, numplot: ", zelen, nslices, numplot 64 all_var = [[]]*zelen 65 all_var2 = [[]]*zelen 66 all_title = [[]]*zelen 73 if fileref is not None: 74 all_var = [[]]*(zelen+2) 75 else: 76 all_var = [[]]*zelen 77 all_var2 = [[]]*zelen 78 all_title = [[]]*zelen 67 79 68 80 ######################### … … 149 161 #### End of for namefile in namefiles 150 162 163 ################################## 164 ### Load reference file if there is one 165 if fileref is not None: 166 ncref = Dataset(fileref) 167 ### ... VAR 168 if var not in nc.variables: var = False 169 if var: 170 all_var[k] = getfield(ncref,var) 171 if ope is "-": 172 all_var[k+1]= all_var[k-1] - all_var[k] 173 elif ope is "+": 174 all_var[k+1]= all_var[k-1] + all_var[k] 175 elif ope is not None: 176 print "non-implemented operation. Available op. are + and -." 177 numplot = numplot+2 151 178 152 179 ################################## … … 210 237 indexvert = getsindex(svert,((nplot-1)//(nlon*nlat))%nvert,vert) 211 238 indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) 212 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%len(namefiles) 239 240 if fileref is not None: 241 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2) 242 else: 243 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%len(namefiles) 244 213 245 print nlon, nlat, nvert, ntime 214 246 print slon, slat, svert, stime … … 244 276 what_I_plot, error = reducefield(all_var[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert ) 245 277 what_I_plot = what_I_plot*mult 246 278 247 279 if not error: 248 280 fvar = var … … 259 291 what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ 260 292 indextime,what_I_plot, len(all_var[index_f].shape),vertmode) 261 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 293 if (fileref is not None) and (index_f is numplot-1): 294 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=minop,vmax=maxop) 295 else: 296 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 262 297 if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar.upper())) 263 298 else: palette = get_cmap(name=colorb) … … 274 309 pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax ) 275 310 if colorb != 'nobar' and var != 'HGT' : 276 colorbar(fraction=0.05,pad=0.03,format=fmtvar(fvar.upper()),\ 311 if (fileref is not None) and (index_f is numplot-1): 312 colorbar(fraction=0.05,pad=0.03,format="%.2f",\ 277 313 ticks=np.linspace(zevmin,zevmax,min([ndiv+1,20])),\ 278 314 extend='neither',spacing='proportional') 315 else: 316 colorbar(fraction=0.05,pad=0.03,format=fmtvar(fvar.upper()),\ 317 ticks=np.linspace(zevmin,zevmax,min([ndiv+1,20])),\ 318 extend='neither',spacing='proportional') 319 279 320 # both min max neither 280 321 ##### 1D field … … 316 357 else: plottitle = plottitle + "_LT"+str(ltst) 317 358 else: 318 plottitle = basename+' '+namefiles[index_f] 359 if fileref is not None: 360 if index_f is numplot-1: 361 plottitle = basename+' '+"fig(1) "+ope+" fig(2)" 362 elif index_f is numplot-2: 363 plottitle = basename+' '+fileref 364 else: 365 plottitle = basename+' '+namefiles[index_f] 366 else: 367 plottitle = basename+' '+namefiles[index_f] 319 368 if mult != 1: plottitle = str(mult) + "*" + plottitle 320 if zetitle != "fill": plottitle = zetitle 369 if zetitle != "fill": 370 plottitle = zetitle 371 if titleref is "fill": 372 titleref=zetitle 373 if fileref is not None: 374 if index_f is numplot-2: 375 plottitle = titleref 376 if index_f is numplot-1: 377 plottitle = "fig(1) "+ope+" fig(2)" 321 378 # if indexlon is not None: 322 379 # plottitle = plottitle + " lon: " + str(min(lon[indexlon])) +" "+ str(max(lon[indexlon])) … … 342 399 ########################################################################## 343 400 ### Save the figure in a file in the data folder or an user-defined folder 344 if typefile in ['meso','mesoapi']: prefix = getprefix(nc) 345 elif typefile in ['gcm']: prefix = 'LMD_GCM_' 346 else: prefix = '' 401 if outputname is None: 402 if typefile in ['meso','mesoapi']: prefix = getprefix(nc) 403 elif typefile in ['gcm']: prefix = 'LMD_GCM_' 404 else: prefix = '' 347 405 ### 348 zeplot = prefix + basename349 if addchar: zeplot = zeplot + addchar350 if numplot <= 0: zeplot = zeplot + "_LT"+str(abs(numplot))406 zeplot = prefix + basename 407 if addchar: zeplot = zeplot + addchar 408 if numplot <= 0: zeplot = zeplot + "_LT"+str(abs(numplot)) 351 409 ### 352 if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot353 else: zeplot = target + "/" + zeplot410 if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot 411 else: zeplot = target + "/" + zeplot 354 412 ### 413 else: 414 zeplot=outputname 415 355 416 if found_lct: 356 417 pad_inches_value = 0.35 … … 358 419 if save == 'png': 359 420 if display: makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature 360 makeplotres(zeplot,res= 200.,pad_inches_value=pad_inches_value,disp=False)421 makeplotres(zeplot,res=resolution,pad_inches_value=pad_inches_value,disp=False) 361 422 elif save in ['eps','svg','pdf']: 362 423 makeplotres(zeplot, pad_inches_value=pad_inches_value,disp=False,ext=save)
Note: See TracChangeset
for help on using the changeset viewer.