Changeset 64cf353 in flex_extract.git for python/plot_retrieved.py
- Timestamp:
- Feb 8, 2018, 9:54:05 PM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 02c8c50
- Parents:
- 6180177
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/plot_retrieved.py
rd69b677 r64cf353 1 1 #!/usr/bin/env python 2 2 # This software is licensed under the terms of the Apache Licence Version 2.0 3 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 4 # 3 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 4 # 5 5 # Functionality provided: Simple tool for creating maps and time series of retrieved fields. 6 # 7 # Requirements: 6 # 7 # Requirements: 8 8 # in addition to a standard python 2.6 or 2.7 installation the following packages need to be installed 9 9 # ECMWF WebMARS, gribAPI with python enabled, emoslib, ecaccess web toolkit, all available from https://software.ecmwf.int/ … … 19 19 if localpythonpath not in sys.path: 20 20 sys.path.append(localpythonpath) 21 21 22 22 from matplotlib.pylab import * 23 23 import matplotlib.patches as mpatches … … 43 43 c.levels=asarray(c.levels,dtype='int') 44 44 c.area=asarray(c.area) 45 45 46 46 index_keys=["date","time","step"] 47 47 indexfile=c.inputdir+"/date_time_stepRange.idx" … … 67 67 68 68 index_vals.append(key_vals) 69 69 70 70 fdict=dict() 71 71 fmeta=dict() … … 101 101 fdatetimestep=fdatetime+datetime.timedelta(hours=step) 102 102 if len(fstamp)==0: 103 fstamp[key].append(fdatetimestamp) 103 fstamp[key].append(fdatetimestamp) 104 104 fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level)) 105 105 fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']]))) … … 118 118 fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level)) 119 119 fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']]))) 120 120 121 121 122 122 grib_release(gid) 123 123 gid = grib_new_from_index(iid) 124 124 125 125 for k in fdict.keys(): 126 126 fml=fmeta[k] 127 127 fdl=fdict[k] 128 128 129 129 for fd,fm in zip(fdl,fml): 130 130 ftitle=fm[1]+' {} '.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+' '+stats(fd) 131 131 pname='_'.join(fm[1].split())+'_{}_'.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+'.{:0>3}'.format(fm[5]) 132 132 plotmap(fd, fm,gdict,ftitle,pname+'.eps') 133 133 134 134 for k in fdict.keys(): 135 135 fml=fmeta[k] … … 143 143 lat=-20 144 144 lon=20 145 plottimeseries(fdl,fml,fsl,lat,lon, gdict, ftitle, pname+'.eps') 146 145 plottimeseries(fdl,fml,fsl,lat,lon, gdict, ftitle, pname+'.eps') 146 147 147 def plottimeseries(flist,fmetalist,ftimestamps,lat,lon,gdict,ftitle,filename): 148 148 t1=time.time() … … 158 158 plt.close(f) 159 159 print time.time()-t1,'s' 160 160 161 161 def plotmap(flist,fmetalist,gdict,ftitle,filename): 162 162 t1=time.time() 163 163 f=plt.figure(figsize=(12,6.7)) 164 mbaxes = f.add_axes([0.05, 0.15, 0.8, 0.7]) 164 mbaxes = f.add_axes([0.05, 0.15, 0.8, 0.7]) 165 165 m =Basemap(llcrnrlon=-180.,llcrnrlat=-90.,urcrnrlon=180,urcrnrlat=90.) 166 166 #if bw==0 : … … 168 168 #else: 169 169 #fill_color=rgb(0.85,0.85,0.85) 170 170 171 171 lw=0.3 172 172 m.drawmapboundary() … … 179 179 xleft=gdict['longitudeOfFirstGridPointInDegrees'] 180 180 if xleft>180.0: 181 xleft-=360. 181 xleft-=360. 182 182 x=linspace(xleft,gdict['longitudeOfLastGridPointInDegrees'],gdict['Ni']) 183 183 y=linspace(gdict['latitudeOfLastGridPointInDegrees'],gdict['latitudeOfFirstGridPointInDegrees'],gdict['Nj']) … … 186 186 s=m.contourf(xx,yy, flist) 187 187 title(ftitle,y=1.1) 188 cbaxes = f.add_axes([0.9, 0.2, 0.04, 0.6]) 188 cbaxes = f.add_axes([0.9, 0.2, 0.04, 0.6]) 189 189 cb=colorbar(cax=cbaxes) 190 190 191 191 savefig(c.outputdir+'/'+filename) 192 192 print 'created ',c.outputdir+'/'+filename … … 200 200 formatter_class=ArgumentDefaultsHelpFormatter) 201 201 202 # the most important arguments 202 # the most important arguments 203 203 parser.add_argument("--start_date", dest="start_date", 204 204 help="start date YYYYMMDD") … … 241 241 print 'Try "'+sys.argv[0].split('/')[-1]+' -h" to print usage information' 242 242 exit(1) 243 244 if args.levelist: 243 244 if args.levelist: 245 245 c.levels=args.levelist.split('/') 246 246 else: … … 250 250 else: 251 251 c.area='[0,0]' 252 252 253 253 c.paramIds=args.paramIds.split('/') 254 254 if args.start_step: … … 269 269 else: 270 270 c.outputdir=c.inputdir 271 271 272 272 return args,c 273 273 274 274 if __name__ == "__main__": 275 275 276 276 args,c=interpret_plotargs() 277 277 plot_retrieved(args,c)
Note: See TracChangeset
for help on using the changeset viewer.