Changeset 186 for trunk/MESOSCALE/PLOT/PYTHON
- Timestamp:
- Jul 3, 2011, 4:27:24 AM (14 years ago)
- Location:
- trunk/MESOSCALE/PLOT/PYTHON
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE/PLOT/PYTHON/mylib/myplot.py
r184 r186 35 35 return wlon,wlat 36 36 37 def api_onelevel ( path_to_input = None, \ 38 input_name = 'wrfout_d0?_????-??-??_??:00:00', \ 39 path_to_output = None, \ 40 output_name = 'output.nc', \ 41 process = 'list', \ 42 fields = 'tk,W,uvmet,HGT', \ 43 debug = False, \ 44 bit64 = False, \ 45 oldvar = True, \ 46 interp_method = 4, \ 47 extrapolate = 0, \ 48 unstagger_grid = False, \ 49 onelevel = 0.020 ): 50 import api 51 import numpy as np 52 if not path_to_input: path_to_input = './' 53 if not path_to_output: path_to_output = path_to_input 54 api.api_main ( path_to_input, input_name, path_to_output, output_name, \ 55 process, fields, debug, bit64, oldvar, np.arange (299), \ 56 interp_method, extrapolate, unstagger_grid, onelevel ) 57 return 58 37 59 def getproj (nc): 38 60 map_proj = getattr(nc, 'MAP_PROJ') … … 51 73 print "mercator projection" 52 74 proj="merc" 75 else: 76 proj="merc" 53 77 return proj 54 78 … … 70 94 import matplotlib.pyplot as plt 71 95 res = int(res) 72 if folder != '': name = folder+'/'+filename+str(res)+".png"73 else: name = filename+str(res)+".png"96 name = filename+"_"+str(res)+".png" 97 if folder != '': name = folder+'/'+name 74 98 plt.savefig(name,dpi=res,bbox_inches='tight',pad_inches=pad_inches_value) 75 99 if disp: display(name) -
trunk/MESOSCALE/PLOT/PYTHON/scripts/winds.py
r184 r186 24 24 import numpy as np 25 25 26 #############################27 ### Lower a bit the font size28 rcParams['font.size'] = int( rcParams['font.size'] * 2. / 3. )29 30 26 ###################### 31 27 ### Load NETCDF object … … 50 46 ## pb avec les autres (de trace derriere la sphere ?) 51 47 52 ################################################################### 53 ### For mesoscale results plot the underlying topography by default48 #################################################################### 49 #### For mesoscale results plot the underlying topography by default 54 50 if typefile in ['mesoapi','meso']: 55 if var == None: var = 'HGT'51 if var == None: back="mola" #var = 'HGT' 56 52 57 53 #################################################### … … 83 79 [u,v] = getwinds(nc,charu='U',charv='V') 84 80 metwind = False ## geometrical (wrt grid) 81 print "Beware ! Not using meteorological winds. You trust numerical grid as being (x,y)." 85 82 86 83 #################################################### … … 95 92 elif dimension == 3: field = nc.variables[var][:,:,:] 96 93 elif dimension == 4: field = nc.variables[var][:,nvert,:,:] 94 nt = len(u[:,0,0,0]) 95 96 ######################################### 97 ### Name for title and graphics save file 98 basename = "WINDS" 99 if var: 100 basename = basename + "_" + var 101 basename = basename + "_z" + str(nvert) 97 102 98 103 ################################## 99 104 ### Open a figure and set subplots 100 105 fig = figure() 101 if numplot == 4: 102 sub = 221 103 fig.subplots_adjust(wspace = 0.1, hspace = 0.3) 104 elif numplot == 2: 105 sub = 121 106 fig.subplots_adjust(wspace = 0.3) 107 elif numplot == 3: 108 sub = 131 109 fig.subplots_adjust(wspace = 0.3) 110 elif numplot == 6: 111 sub = 231 112 fig.subplots_adjust(wspace = 0.4, hspace = 0.0) 113 elif numplot == 8: 114 sub = 331 #241 115 fig.subplots_adjust(wspace = 0.1, hspace = 0.3) 116 else: 117 print "supported: 1,2,3,4,6,8" 118 exit() 119 120 ##################### 121 ### Prepare time loop 122 nt = len(u[:,0,0,0]) 123 if nt <= numplot or numplot == 1: 124 print "I am plotting only one map ",nt,numplot 125 tabrange = [0] 126 else: 127 tabrange = range(0,nt-1,int(nt/numplot)) 106 if numplot > 0: 107 if numplot == 4: 108 sub = 221 109 fig.subplots_adjust(wspace = 0.1, hspace = 0.3) 110 rcParams['font.size'] = int( rcParams['font.size'] * 2. / 3. ) 111 elif numplot == 2: 112 sub = 121 113 fig.subplots_adjust(wspace = 0.3) 114 rcParams['font.size'] = int( rcParams['font.size'] * 3. / 4. ) 115 elif numplot == 3: 116 sub = 131 117 fig.subplots_adjust(wspace = 0.3) 118 rcParams['font.size'] = int( rcParams['font.size'] * 2. / 3. ) 119 elif numplot == 6: 120 sub = 231 121 fig.subplots_adjust(wspace = 0.4, hspace = 0.0) 122 rcParams['font.size'] = int( rcParams['font.size'] * 2. / 3. ) 123 elif numplot == 8: 124 sub = 331 #241 125 fig.subplots_adjust(wspace = 0.1, hspace = 0.3) 126 rcParams['font.size'] = int( rcParams['font.size'] * 1. / 2. ) 127 elif numplot == 9: 128 sub = 331 129 fig.subplots_adjust(wspace = 0.1, hspace = 0.3) 130 rcParams['font.size'] = int( rcParams['font.size'] * 1. / 2. ) 131 elif numplot == 1: 132 pass 133 else: 134 print "supported: 1,2,3,4,6,8" 135 exit() 136 ### Prepare time loop 137 if nt <= numplot or numplot == 1: 138 tabrange = [0] 139 numplot = 1 140 else: 141 tabrange = range(0,nt,int(nt/numplot)) #nt-1 142 tabrange = tabrange[0:numplot] 143 else: 144 tabrange = range(0,nt,1) 145 sub = 99999 146 print tabrange 128 147 129 148 ################################# 130 149 ### Time loop for plotting device 150 found_lct = False 131 151 for i in tabrange: 132 152 133 print i134 135 153 ### General plot settings 136 if tabrange != [0]: subplot(sub) 137 zetitle = "WINDS" + "_" 154 if numplot > 1: 155 subplot(sub) 156 found_lct = True 157 elif numplot == 1: 158 found_lct = True 159 ### If only one local time is requested (numplot < 0) 160 elif numplot <= 0: 161 #print (ltst+i)%24, numplot, (ltst+i)%24+numplot 162 if (ltst+i)%24 + numplot != 0: continue 163 else: found_lct = True 138 164 139 165 ### Map projection … … 143 169 #### Contour plot 144 170 if var: 145 zetitle = zetitle + var + "_"146 171 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(field[i,:,:]) 147 172 elif typefile in ['gcm']: … … 158 183 key = False 159 184 if metwind: [vecx,vecy] = m.rotate_vector(vecx, vecy, lon2d, lat2d) 160 else: print "Beware ! Not using meteorological winds. You trust numerical grid as being (x,y)."161 185 vectorfield(vecx, vecy,\ 162 x, y, stride=stride, csmooth= 2,\186 x, y, stride=stride, csmooth=stride,\ 163 187 scale=15., factor=200., color='k', key=key) 188 ## or csmooth=2 164 189 165 190 ### Next subplot 166 zetitle = zetitle + "LT"+str((ltst+i)%24) 167 ptitle(zetitle) 191 ptitle( basename + "_LT"+str((ltst+i)%24) ) 168 192 sub += 1 169 193 170 194 ########################################################################## 171 195 ### Save the figure in a file in the data folder or an user-defined folder 172 if not target: zeplot = namefile+zetitle 173 else: zeplot = target+"/"+zetitle 174 makeplotpng(zeplot,pad_inches_value=0.35) 196 if not target: zeplot = namefile+"_"+basename 197 else: zeplot = target+"/"+basename 198 if numplot <= 0: zeplot = zeplot + "_LT"+str(abs(numplot)) 199 if found_lct: makeplotpng(zeplot,pad_inches_value=0.35) 200 else: print "Local time not found" 175 201 176 202 … … 196 222 import sys 197 223 from optparse import OptionParser ### to be replaced by argparse 224 from api_wrapper import api_onelevel 198 225 parser = OptionParser() 199 226 parser.add_option('-f', action='store', dest='namefile', type="string", default=None, help='name of WRF file [NEEDED]') 200 parser.add_option('-l', action='store', dest='nvert', type=" int", default=0, help='subscript for vertical level')227 parser.add_option('-l', action='store', dest='nvert', type="float", default=0, help='vertical level (def=0)') 201 228 parser.add_option('-p', action='store', dest='proj', type="string", default=None, help='projection') 202 229 parser.add_option('-b', action='store', dest='back', type="string", default=None, help='background') 203 230 parser.add_option('-t', action='store', dest='target', type="string", default=None, help='destination folder') 204 parser.add_option('-s', action='store', dest='stride', type="int", default=3, help='stride vectors ')231 parser.add_option('-s', action='store', dest='stride', type="int", default=3, help='stride vectors (def=3)') 205 232 parser.add_option('-v', action='store', dest='var', type="string", default=None, help='variable contoured') 206 parser.add_option('-n', action='store', dest='numplot', type="int", default=4, help='number of plots') 233 parser.add_option('-n', action='store', dest='numplot', type="int", default=4, help='number of plots (def=1)(if <0: 1 plot of LT -*numplot*)') 234 parser.add_option('-i', action='store', dest='interp', type="int", default=None, help='interpolation method (done at level *nvert* km)') 207 235 (opt,args) = parser.parse_args() 208 236 if opt.namefile is None: … … 210 238 exit() 211 239 print "Options:", opt 212 winds (opt.namefile,opt.nvert,proj=opt.proj,back=opt.back,target=opt.target,stride=opt.stride,var=opt.var,numplot=opt.numplot) 213 214 # if typefile in ['gcm']: 215 # if var == 'HGT': var = 'phisinit' ## default choice for GCM 216 217 240 241 zefile = opt.namefile 242 zelevel = opt.nvert 243 if opt.nvert is 0 and opt.interp: zelevel = 0.020 244 if opt.interp is not None: 245 if opt.var is None : zefields = 'uvmet' 246 else : zefields = 'uvmet,'+opt.var 247 zefile = api_onelevel ( path_to_input = '', \ 248 input_name = zefile, \ 249 path_to_output = opt.target, \ 250 fields = zefields, \ 251 interp_method = opt.interp, \ 252 onelevel = zelevel ) 253 zelevel = 0 254 255 winds (zefile,int(zelevel),proj=opt.proj,back=opt.back,target=opt.target,stride=opt.stride,var=opt.var,numplot=opt.numplot)
Note: See TracChangeset
for help on using the changeset viewer.