antonv wrote: > Jeff, thanks for the comment on rebuilding the lons and lats! > > I have attached 2 images, one that is from the whole data in the file and > the other the zoomed version. > http://www.nabble.com/file/p23031035/basemap_all.png basemap_all.png > http://www.nabble.com/file/p23031035/basemap_zoom.png basemap_zoom.png > > What seems to be happening is that the coordinates seem to be in different > projections as the values of lats.min(),lons.min(),lats.max(),lons.max() are > 25.0,210.0,50.0,250.0 while the list I'm providing is > 32.35,-121.0,34.75,-116.75.
Anton: Try using (32.35, 239,34.75,243.25). The longitudes in your data probably go from 0 to 360, so negative longitudes are outside the region spanned by your data. -Jeff > Any ideas on why basemap seems to be reading > both coordinate lists and provides the proper land contours while contourf > seems to be off? > > Thanks, > Anton > > > > > > > Jeff Whitaker wrote: > >> antonv wrote: >> >>> Hi all, >>> >>> I have a weird thing happening with basemap and I am not sure if it's >>> basemap or me, but more than likely it's me :( >>> >>> Here is the grib file that I am using: >>> http://downloads.75ive.com/multi_1.20090321.t18z_multi_1.wc_10m.all.grb2 >>> http://downloads.75ive.com/multi_1.20090321.t18z_multi_1.wc_10m.all.grb2 >>> >>> And here is my code: >>> ############################################# >>> import matplotlib >>> import matplotlib.mpl as mpl >>> import matplotlib.pyplot as plt >>> import matplotlib.mlab as mlab >>> import numpy as np >>> import matplotlib.pylab as pylab >>> from mpl_toolkits.basemap import Basemap >>> from grib2 import Grib2Decode >>> >>> grbs = Grib2Decode('multi_1.20090321.t18z_multi_1.wc_10m.all.grb2') >>> >>> lats, lons = grbs[0].grid() >>> mapCoords = [32.35,-121.0,34.75,-116.75] >>> #mapCoords = [lats.min(),lons.min(),lats.max(),lons.max()] >>> >>> colorList = >>> [[0.,0.,205./255.],[0,102./255.,255./255.],[0,183./255.,255./255.],[0,224./255.,255./255.], >>> >>> [0,255./255.,255./255.],[0,255./255.,204./255.],[0,255./255.,153./255.],[0,255./255.,0], >>> >>> [153./255.,255./255.,0],[204./255.,255./255.,0],[255./255.,255./255.,0],[255./255.,204./255.,0], >>> >>> [255./255.,153./255.,0],[255./255.,102./255.,0],[255./255.,0,0],[176./255.,48./255.,96./255.], >>> [208./255.,32./255.,144./255.],[255./255.,0,255./255.]] >>> cmap = matplotlib.colors.ListedColormap(colorList, name = 'theColorMap', >>> N = >>> len(colorList)) >>> >>> m = Basemap(projection='merc',lat_ts = 30,\ >>> >>> llcrnrlat=mapCoords[0],llcrnrlon=mapCoords[1],urcrnrlat=mapCoords[2],urcrnrlon=mapCoords[3],\ >>> resolution='h',area_thresh=0.5, suppress_ticks = True) >>> >>> fig = plt.figure(figsize=(14.58,10.58)) >>> fig.set_dpi(100) >>> >>> nlats, nlons = grbs[0].data().shape >>> >>> x = np.linspace(lons.min(),lons.max(),nlons) >>> y = np.linspace(lats.min(),lats.max(),nlats) >>> >>> X, Y = m(*np.meshgrid(x, y)) >>> >>> z = grbs[0].data().filled(1) >>> >>> m.contourf(X,Y,z,cmap=cmap,levels=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],extend='both') >>> >>> m.fillcontinents(color='green',lake_color='b') >>> m.drawcoastlines(color='k', linewidth=0.75) >>> m.drawcountries(color='k', linewidth=0.25) >>> m.drawstates(color='k', linewidth=0.25) >>> m.drawmapboundary(linewidth=1.0, color='k') >>> >>> plt.show() >>> ############################################# >>> >>> If you look at lines 14 and 15 you can see that i have a variable called >>> mapCoords that feeds the lat/lon coordinates to the basemap object. If i >>> set >>> them up using the commented line (line 15) it will plot the map for all >>> the >>> data in the file and it will display it correctly. If i use line 14 which >>> is >>> the zoomed area that i am interested in it will display the basemap map >>> correctly zoomed in but it will not show the plotted data. Any ideas on >>> what >>> is happening here? >>> >>> Also, if you have any comments on optimizing the code I would really >>> appreciate it! >>> >>> Thanks, >>> Anton >>> >>> >>> >> Anton: Probably your data doesn't cover the zoomed region, but without >> actually having your data I can't be sure. >> >> One question: why are you rebuilding the lons and lats from scratch >> when you already have them? It seems like you can get rid of >> >> nlats, nlons = grbs[0].data().shape >> x = np.linspace(lons.min(),lons.max(),nlons) >> y = np.linspace(lats.min(),lats.max(),nlats) >> X, Y = m(*np.meshgrid(x, y)) >> >> and replace it with >> >> X,Y = m(lons, lats) >> >> >> -Jeff >> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> Meteorologist FAX : (303)497-6449 >> NOAA/OAR/PSD R/PSD1 Email : jeffrey.s.whita...@noaa.gov >> 325 Broadway Office : Skaggs Research Cntr 1D-113 >> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by: >> High Quality Requirements in a Collaborative Environment. >> Download a free trial of Rational Requirements Composer Now! >> http://p.sf.net/sfu/www-ibm-com >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> >> > > ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users