Changeset 377
- Timestamp:
- Nov 13, 2011, 5:31:05 PM (13 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/gcm.py
r372 r377 15 15 from os import system 16 16 from planetoplot import planetoplot 17 17 from myscript import getparseroptions 18 18 import numpy as np 19 19 … … 21 21 ### Get options and variables 22 22 parser = OptionParser() 23 parser.add_option('-f', '--file', action='append',dest='namefile', type="string", default=None, help='[NEEDED] name of WRF file (append). Plot files separated by comas in the same figure') 24 parser.add_option('-l', '--level', action='store',dest='nvert', type="string", default="0", help='level or start,stop,step (def=0)(-i 2: p,mbar)(-i 3,4: z,km)') 25 parser.add_option('-p', '--proj', action='store',dest='proj', type="string", default=None, help='projection') 26 parser.add_option('-b', '--back', action='store',dest='back', type="string", default=None, help='background image (def: None)') 27 parser.add_option('-t', '--target', action='store',dest='target', type="string", default=None, help='destination folder') 28 parser.add_option('-s', '--stride', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 29 parser.add_option('-v', '--var', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 30 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default=None, help='plot number (def=2)(<0: plot LT -*numplot*)') 31 parser.add_option('-i', '--interp', action='store',dest='interp', type="int", default=None, help='interpolation (2: p, 3: z-amr, 4:z-als)') 32 parser.add_option('-c', '--color', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') 33 parser.add_option('-x', '--no-vect',action='store_false',dest='winds', default=True, help='no wind vectors') 34 parser.add_option('-m', '--min', action='append',dest='vmin', type="float", default=None, help='bounding minimum value (append)') 35 parser.add_option('-M', '--max', action='append',dest='vmax', type="float", default=None, help='bounding maximum value (append)') 36 parser.add_option('-T', '--tiled', action='store_true',dest='tile', default=False, help='draw a tiled plot (no blank zone)') 37 parser.add_option('-z', '--zoom', action='store',dest='zoom', type="float", default=None, help='zoom factor in %') 38 parser.add_option('-N', '--no-api', action='store_true',dest='nocall', default=False, help='do not recreate api file') 39 parser.add_option('-d', '--display',action='store_false',dest='display', default=True, help='do not pop up created images') 40 parser.add_option('-e', '--itstep', action='store',dest='itstep', type="int", default=None, help='stride time (def=4)') 41 parser.add_option('-H', '--hole', action='store_true',dest='hole', default=False, help='holes above max and below min') 42 parser.add_option('-S', '--save', action='store',dest='save', type="string", default="gui", help='save mode (png,eps,svg,pdf or gui)(def=gui)') 43 parser.add_option('-a', '--anomaly',action='store_true',dest='anomaly', default=False, help='compute and plot relative anomaly in %') 44 parser.add_option('-w', '--with', action='store',dest='var2', type="string", default=None, help='variable contoured') 45 parser.add_option('--div', action='store',dest='ndiv', type="int", default=10, help='number of divisions in colorbar (def: 10)') 46 parser.add_option('-F', '--first', action='store',dest='first', type="int", default=1, help='first subscript to plot (def: 1)') 47 parser.add_option('--mult', action='store',dest='mult', type="float", default=1., help='a multiplicative factor to plotted field') 48 parser.add_option('--title', action='store',dest='zetitle', type="string", default="fill",help='customize the whole title') 49 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 23 getparseroptions(parser) 24 (opt,args) = parser.parse_args() 50 25 51 parser.add_option('-O','--output', action='store',dest='output', type="string", default=None, help='Output file name') 52 parser.add_option('--res', action='store',dest='res', type="float", default=200., help='Resolution for png outputs. --save png must be specified. (def=200.)') 53 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') 54 parser.add_option('--fref', action='store',dest='fref', type="string", default=None, help='Reference namefile for the --operation option.') 55 parser.add_option('--mope', action='store',dest='vminope', type="float", default=0., help='bounding minimum value for inter-file operation') 56 parser.add_option('--Mope', action='store',dest='vmaxope', type="float", default=0., help='bounding maximum value for inter-file operation') 57 parser.add_option('--titleref', action='store',dest='titref', type="string", default="fill", help='title for the reference file. Default: title of figure (1)') 58 parser.add_option('--xmax', action='store',dest='xmax', type="float", default=None, help='Maximum value for the y-axis in contour-plots. Default is max(xaxis).') 59 parser.add_option('--ymax', action='store',dest='ymax', type="float", default=None, help='Maximum value for the y-axis in contour-plots Default is max(yaxis)') 60 parser.add_option('--xmin', action='store',dest='xmin', type="float", default=None, help='Minimum value for the y-axis in contour-plots. Default is min(xaxis).') 61 parser.add_option('--ymin', action='store',dest='ymin', type="float", default=None, help='Minimum value for the y-axis in contour-plots Default is min(yaxis)') 62 parser.add_option('--inverty', action='store_true',dest='inverty', default=False, help='Force matplotlib.pyplot to revert the y-axis. Can be of use when plotting data along pressure levels. (pyplot naturally tend to plot the z-axis with increasing values)') 63 parser.add_option('--logy', action='store_true',dest='logy', default=False, help='Set y-axis to logarithmic.') 64 65 ############# T.N. changes 66 #parser.add_option('-o','--operation',action='store',dest='operation',type="string", default=None ,help='matrix of operations between files (for now see code, sorry)') 67 parser.add_option('--lat', action='append',dest='slat',type="string", default=None, help='slices along latitude. One value, or two values separated by comas for averaging') 68 parser.add_option('--lon', action='append',dest='slon', type="string", default=None, help='slices along longitude. One value, or two values separated by comas for averaging') 69 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 ? 70 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 ? 71 72 (opt,args) = parser.parse_args() 73 if opt.namefile is None: 26 if opt.file is None: 74 27 print "I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h" 75 28 exit() … … 97 50 98 51 if opt.fref is not None: 99 if opt.operat ionis None:52 if opt.operat is None: 100 53 print "you must specify an operation when using a reference file" 101 54 exit() 102 if opt.operat ionis not None:55 if opt.operat is not None: 103 56 if opt.fref is None: 104 57 print "you must specifiy a reference file when using inter-file operations" … … 107 60 interpref=False 108 61 if opt.fref is not None: 109 if opt.operat ionis not None:110 if opt.i nterp is not None:62 if opt.operat is not None: 63 if opt.itp is not None: 111 64 interpref=True 112 65 … … 114 67 115 68 116 print " namefile, length", opt.namefile, len(opt.namefile)69 print "file, length", opt.file, len(opt.file) 117 70 118 71 zeslat = readslices(opt.slat) … … 125 78 print "stime,zestime", opt.stime, zestime 126 79 127 for i in range(len(opt. namefile)):80 for i in range(len(opt.file)): 128 81 for j in range(len(opt.var)): 129 82 130 ze namefiles = separatenames(opt.namefile[i])131 print "ze namefiles", zenamefiles83 zefiles = separatenames(opt.file[i]) 84 print "zefiles", zefiles 132 85 133 86 if opt.vmin is not None : zevmin = opt.vmin[min(i,len(opt.vmin)-1)] … … 143 96 print "var, zevar", opt.var, zevar 144 97 145 #checkcoherence(len(ze namefiles),len(opt.slat),len(opt.slon),len(opt.stime))98 #checkcoherence(len(zefiles),len(opt.slat),len(opt.slon),len(opt.stime)) 146 99 147 zefile = ze namefiles[0]100 zefile = zefiles[0] 148 101 149 #zelevel = opt. nvert102 #zelevel = opt.lvl 150 103 stralt = None 151 104 #[lschar,zehour,zehourin] = getlschar ( zefile ) ## getlschar from wrfout (or simply return "" if another file) 152 105 [lschar,zehour,zehourin] = ["",0,0] ## dummy 153 106 154 inputnvert = separatenames(opt. nvert)107 inputnvert = separatenames(opt.lvl) 155 108 if np.array(inputnvert).size == 1: 156 109 zelevel = float(inputnvert[0]) … … 164 117 ##################################################### 165 118 ### Call Fortran routines for vertical interpolations --> zrecast for GCM ? 166 # if opt.i nterp is not None:167 # if zelevel == 0. and opt.i nterp == 4: zelevel = 0.010119 # if opt.itp is not None: 120 # if zelevel == 0. and opt.itp == 4: zelevel = 0.010 168 121 # ### winds or no winds 169 122 # if opt.winds : zefields = 'uvmet' … … 178 131 # input_name = zefile, \ 179 132 # fields = zefields, \ 180 # interp_method = opt.i nterp, \133 # interp_method = opt.itp, \ 181 134 # interp_level = ze_interp_levels, \ 182 135 # onelevel = zelevel, \ … … 188 141 ### Call Fortran routines for vertical interpolations --> zrecast 189 142 190 if opt.i nterp is not None:143 if opt.itp is not None: 191 144 interpolated_files="" 192 interpolated_files=call_zrecast(interp_mode=opt.i nterp,\193 input_name=ze namefiles,\145 interpolated_files=call_zrecast(interp_mode=opt.itp,\ 146 input_name=zefiles,\ 194 147 fields=zevars) 195 148 196 ze namefiles=interpolated_files149 zefiles=interpolated_files 197 150 if interpref: 198 151 interpolated_ref="" 199 interpolated_ref=call_zrecast(interp_mode=opt.i nterp,\152 interpolated_ref=call_zrecast(interp_mode=opt.itp,\ 200 153 input_name=[opt.fref],\ 201 154 fields=zevars) … … 211 164 ############# 212 165 ### Main call 213 name = planetoplot (ze namefiles,level=int(zelevel),vertmode=opt.interp,\214 proj=opt.proj,back=opt.back,target=opt.t arget,stride=opt.stride,var=zevar,\215 numplot=opt.num plot,colorb=opt.colorb,winds=opt.winds,\166 name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\ 167 proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevar,\ 168 numplot=opt.num,colorb=opt.clb,winds=opt.winds,\ 216 169 addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ 217 170 tile=opt.tile,zoom=opt.zoom,display=opt.display,\ 218 itstep=opt.it step,hole=opt.hole,save=opt.save,\219 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.f irst,\171 itstep=opt.it,hole=opt.hole,save=opt.save,\ 172 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.frt,\ 220 173 mult=opt.mult,zetitle=opt.zetitle,\ 221 174 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ 222 outputname=opt.out put,resolution=opt.res,\223 ope=opt.operat ion,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\175 outputname=opt.out,resolution=opt.res,\ 176 ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ 224 177 invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy) 225 178 print 'Done: '+name -
trunk/UTIL/PYTHON/meso.py
r372 r377 14 14 from os import system 15 15 from planetoplot import planetoplot 16 from myscript import getparseroptions 16 17 import numpy as np 17 18 … … 19 20 ### Get options and variables 20 21 parser = OptionParser() 21 parser.add_option('-f', '--file', action='append',dest='namefile', type="string", default=None, help='[NEEDED] name of WRF file (append)') 22 parser.add_option('-l', '--level', action='store',dest='nvert', type="string", default="0", help='level or start,stop,step (def=0)(-i 2: p,mbar)(-i 3,4: z,km)') 23 parser.add_option('-p', '--proj', action='store',dest='proj', type="string", default=None, help='projection') 24 parser.add_option('-b', '--back', action='store',dest='back', type="string", default=None, help='background image (def: None)') 25 parser.add_option('-t', '--target', action='store',dest='target', type="string", default=None, help='destination folder') 26 parser.add_option('-s', '--stride', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 27 parser.add_option('-v', '--var', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 28 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default=None, help='plot number (def=2)(<0: plot LT -*numplot*)') 29 parser.add_option('-i', '--interp', action='store',dest='interp', type="int", default=None, help='interpolation (2: p, 3: z-amr, 4:z-als)') 30 parser.add_option('-c', '--color', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') 31 parser.add_option('-x', '--no-vect',action='store_false',dest='winds', default=True, help='no wind vectors') 32 parser.add_option('-m', '--min', action='append',dest='vmin', type="float", default=None, help='bounding minimum value (append)') 33 parser.add_option('-M', '--max', action='append',dest='vmax', type="float", default=None, help='bounding maximum value (append)') 34 parser.add_option('-T', '--tiled', action='store_true',dest='tile', default=False, help='draw a tiled plot (no blank zone)') 35 parser.add_option('-z', '--zoom', action='store',dest='zoom', type="float", default=None, help='zoom factor in %') 36 parser.add_option('-N', '--no-api', action='store_true',dest='nocall', default=False, help='do not recreate api file') 37 parser.add_option('-d', '--display',action='store_false',dest='display', default=True, help='do not pop up created images') 38 parser.add_option('-e', '--itstep', action='store',dest='itstep', type="int", default=None, help='stride time (def=4)') 39 parser.add_option('-H', '--hole', action='store_true',dest='hole', default=False, help='holes above max and below min') 40 parser.add_option('-S', '--save', action='store',dest='save', type="string", default="gui", help='save mode (png,eps,svg,pdf or gui)(def=gui)') 41 parser.add_option('-a', '--anomaly',action='store_true',dest='anomaly', default=False, help='compute and plot relative anomaly in %') 42 parser.add_option('-w', '--with', action='store',dest='var2', type="string", default=None, help='variable contoured') 43 parser.add_option('--div', action='store',dest='ndiv', type="int", default=10, help='number of divisions in colorbar (def: 10)') 44 parser.add_option('-F', '--first', action='store',dest='first', type="int", default=1, help='first subscript to plot (def: 1)') 45 parser.add_option('--mult', action='store',dest='mult', type="float", default=1., help='a multiplicative factor to plotted field') 46 parser.add_option('--title', action='store',dest='zetitle', type="string", default="fill",help='customize the whole title') 47 parser.add_option('--inverty', action='store_true',dest='inverty', default=False, help='Force matplotlib.pyplot to revert the y-axis. Can be of use when plotting data along pressure levels. (pyplot naturally tend to plot the z-axis with increasing values)') 48 parser.add_option('--xmax', action='store',dest='xmax', type="float", default=None, help='Maximum value for the y-axis in contour-plots. Default is max(xaxis).') 49 parser.add_option('--ymax', action='store',dest='ymax', type="float", default=None, help='Maximum value for the y-axis in contour-plots Default is max(yaxis)') 50 parser.add_option('--xmin', action='store',dest='xmin', type="float", default=None, help='Minimum value for the y-axis in contour-plots. Default is min(xaxis).') 51 parser.add_option('--ymin', action='store',dest='ymin', type="float", default=None, help='Minimum value for the y-axis in contour-plots Default is min(yaxis)') 52 parser.add_option('--logy', action='store_true',dest='logy', default=False, help='Set y-axis to logarithmic.') 53 #parser.add_option('-V', action='store', dest='comb', type="float", default=None, help='a defined combination of variables') 22 getparseroptions(parser) 23 (opt,args) = parser.parse_args() 54 24 55 ############# T.N. changes 56 #parser.add_option('-o','--operation',action='store',dest='operation',type="string", default=None ,help='matrix of operations between files (for now see code, sorry)') 57 parser.add_option('--lat', action='append',dest='slat',type="string", default=None, help='slices along latitude. One value, or two values separated by comas for averaging') 58 parser.add_option('--lon', action='append',dest='slon', type="string", default=None, help='slices along longitude. One value, or two values separated by comas for averaging') 59 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 ? 60 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 ? 61 62 ############# A.C. changes 63 parser.add_option('-O','--output', action='store' ,dest='output',type="string", default=None, help='Output file name') 64 parser.add_option('--res', action='store' ,dest='res',type="float", default=200., help='Resolution for png outputs. --save png must be specified. (def=200.)') 65 66 (opt,args) = parser.parse_args() 67 if opt.namefile is None: 25 if opt.file is None: 68 26 print "I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h" 69 27 exit() … … 86 44 vmaxtab = adjust_length (opt.vmax, zelen) 87 45 88 print " namefile, length", opt.namefile, len(opt.namefile)46 print "file, length", opt.file, len(opt.file) 89 47 90 48 zeslat = readslices(opt.slat) … … 97 55 print "stime,zestime", opt.stime, zestime 98 56 99 for i in range(len(opt. namefile)):57 for i in range(len(opt.file)): 100 58 101 zefile = opt. namefile[i]59 zefile = opt.file[i] 102 60 print zefile 103 #zelevel = opt. nvert61 #zelevel = opt.lvl 104 62 stralt = None 105 63 [lschar,zehour,zehourin] = getlschar ( zefile ) ## getlschar from wrfout (or simply return "" if another file) 106 64 107 inputnvert = separatenames(opt. nvert)65 inputnvert = separatenames(opt.lvl) 108 66 if np.array(inputnvert).size == 1: 109 67 zelevel = float(inputnvert[0]) … … 117 75 ##################################################### 118 76 ### Call Fortran routines for vertical interpolations 119 if opt.i nterp is not None:120 if zelevel == 0. and opt.i nterp == 4: zelevel = 0.01077 if opt.itp is not None: 78 if zelevel == 0. and opt.itp == 4: zelevel = 0.010 121 79 ### winds or no winds 122 80 if opt.winds : zefields = 'uvmet' … … 131 89 input_name = zefile, \ 132 90 fields = zefields, \ 133 interp_method = opt.i nterp, \91 interp_method = opt.itp, \ 134 92 interp_level = ze_interp_levels, \ 135 93 onelevel = zelevel, \ … … 140 98 if opt.var is None: zerange = [-999999] 141 99 else: zerange = range(zelen) 100 101 zexaxis=[opt.xmin,opt.xmax] 102 zeyaxis=[opt.ymin,opt.ymax] 103 142 104 for jjj in zerange: 143 105 if jjj == -999999: … … 152 114 else: zevmax = None 153 115 154 155 zexaxis=[opt.xmin,opt.xmax]156 zeyaxis=[opt.ymin,opt.ymax]157 158 159 116 ############# 160 117 ### Main call 161 name = planetoplot (zefile,level=int(zelevel),vertmode=opt.i nterp,\162 proj=opt.proj,back=opt.back,target=opt.t arget,stride=opt.stride,var=argvar,\163 numplot=opt.num plot,colorb=opt.colorb,winds=opt.winds,\118 name = planetoplot (zefile,level=int(zelevel),vertmode=opt.itp,\ 119 proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=argvar,\ 120 numplot=opt.num,colorb=opt.clb,winds=opt.winds,\ 164 121 addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ 165 122 tile=opt.tile,zoom=opt.zoom,display=opt.display,\ 166 itstep=opt.it step,hole=opt.hole,save=opt.save,\167 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.f irst,\123 itstep=opt.it,hole=opt.hole,save=opt.save,\ 124 anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.frt,\ 168 125 mult=opt.mult,zetitle=opt.zetitle,\ 169 126 slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ 170 outputname=opt.out put,resolution=opt.res,\127 outputname=opt.out,resolution=opt.res,\ 171 128 invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy) 172 129 print 'Done: '+name
Note: See TracChangeset
for help on using the changeset viewer.