From: questions a. <que...@gm...> - 2012-02-29 22:29:11
|
I have a txt file (with an associated prj file) containing gridded weather data. Firstly how can I open this file and convert it to a numpy array? and then how to plot in matplotlib, paticularly how to use the lat, lon and nrows,ncols. ncols=886 nrows=691 longitude west=111.975, east=156.275 latitude north=-9.975, south=-44.525 cell size=0.05 My attempt below: -------------------------------------------------- onefile=open("E:/test_in/r19000117.txt", 'r') map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33, llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i') map.drawcoastlines() map.drawstates() xi=N.linspace(111.975, 156.275, 886) yi=N.linspace(-44.525, -9.975, 691) x,y=map(*N.meshgrid(xi,yi)) plt.title('rainfall') CS = map.contourf(x,y, onefile, cmap=plt.cm.jet) l,b,w,h =0.1,0.1,0.8,0.8 cax = plt.axes([l+w+0.025, b, 0.025, h]) plt.colorbar(CS,cax=cax, drawedges=True) plt.savefig((os.path.join(OutputFolder, 'rainfall.png'))) plt.show() plt.close() |