From: <js...@us...> - 2007-12-01 13:59:08
|
Revision: 4535 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4535&view=rev Author: jswhit Date: 2007-12-01 05:59:01 -0800 (Sat, 01 Dec 2007) Log Message: ----------- update basemap examples for version 0.9.8 Modified Paths: -------------- trunk/py4science/examples/basemap1.py trunk/py4science/examples/basemap2.py trunk/py4science/examples/basemap3.py trunk/py4science/examples/basemap4.py trunk/py4science/examples/basemap5.py trunk/py4science/examples/skel/basemap1_skel.py trunk/py4science/examples/skel/basemap2_skel.py trunk/py4science/examples/skel/basemap3_skel.py trunk/py4science/examples/skel/basemap4_skel.py trunk/py4science/examples/skel/basemap5_skel.py trunk/py4science/workbook/basemap.tex Modified: trunk/py4science/examples/basemap1.py =================================================================== --- trunk/py4science/examples/basemap1.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/basemap1.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -2,9 +2,7 @@ from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying lat/lon values at corners. resolution = 'l' projection = 'lcc' @@ -18,8 +16,10 @@ resolution=resolution,projection=projection) # draw coastlines. Make liness a little thinner than default. m.drawcoastlines(linewidth=0.5) -# fill continents. -m.fillcontinents(color='coral') +# background fill color will show ocean areas. +m.drawmapboundary(fill_color='aqua') +# fill continents, lakes within continents. +m.fillcontinents(color='coral',lake_color='aqua') # draw states and countries. m.drawcountries() m.drawstates() Modified: trunk/py4science/examples/basemap2.py =================================================================== --- trunk/py4science/examples/basemap2.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/basemap2.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -2,9 +2,7 @@ from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. resolution = 'l' projection = 'lcc' @@ -15,11 +13,9 @@ m = Basemap(lon_0=lon_0,lat_0=lat_0,\ width=width,height=height,\ resolution=resolution,projection=projection) -# draw coastlines. m.drawcoastlines(linewidth=0.5) -# fill continents. -m.fillcontinents(color='coral') -# draw states and countries. +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() pylab.title('map region specified using width and height') Modified: trunk/py4science/examples/basemap3.py =================================================================== --- trunk/py4science/examples/basemap3.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/basemap3.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -2,9 +2,7 @@ from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. resolution = 'l' lon_0 = -50 @@ -37,7 +35,8 @@ pylab.text(lon_x-100000,lon_y+100000,'London',fontsize=12,\ color='k',horizontalalignment='right',fontweight='bold') m.drawcoastlines(linewidth=0.5) -m.fillcontinents(color='coral') +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() pylab.title('NY to London Great Circle') Modified: trunk/py4science/examples/basemap4.py =================================================================== --- trunk/py4science/examples/basemap4.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/basemap4.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -1,9 +1,7 @@ import pylab, numpy from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. resolution = 'l' lon_0 = -50 @@ -15,7 +13,8 @@ width=width,height=height,\ resolution=resolution,projection=projection) m.drawcoastlines(linewidth=0.5) -m.fillcontinents(color='coral') +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() # label meridians where they intersect the left, right and bottom Modified: trunk/py4science/examples/basemap5.py =================================================================== --- trunk/py4science/examples/basemap5.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/basemap5.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -1,28 +1,22 @@ from matplotlib.toolkits.basemap import Basemap, NetCDFFile import pylab, numpy -from numpy import ma # read in netCDF sea-surface temperature data +# can be a local file, a URL for a remote opendap dataset, +# or (if PyNIO is installed) a GRIB or HDF file. ncfile = NetCDFFile('data/sst.nc') -sstv = ncfile.variables['analysed_sst'] -sst = ma.masked_values(numpy.squeeze(sstv[:]), sstv._FillValue) -sst = sstv.scale_factor*sst + sstv.add_offset +sst = ncfile.variables['analysed_sst'][:] lats = ncfile.variables['lat'][:] lons = ncfile.variables['lon'][:] + print sst.shape, sst.min(), sst.max() -# make sure middle of map region is middle of data grid. -lon_0 = lons.mean() -lat_0 = lats.mean() # set colormap cmap = pylab.cm.gist_ncar -# set so masked values in an image will be black -# (i.e. continents will be painted this color) -cmap.set_bad('k') # create Basemap instance for mollweide projection. # coastlines not used, so resolution set to None to skip # continent processing (this speeds things up a bit) -m = Basemap(projection='moll',lon_0=lon_0,lat_0=lat_0,resolution=None) +m = Basemap(projection='moll',lon_0=0,lat_0=0,resolution=None) # compute map projection coordinates of grid. x, y = m(*numpy.meshgrid(lons, lats)) # plot with pcolor @@ -31,8 +25,9 @@ m.drawparallels(numpy.arange(-90.,120.,30.)) m.drawmeridians(numpy.arange(0.,420.,60.)) # draw line around map projection limb. -m.drawmapboundary() +# color map region background black (missing values will be this color) +m.drawmapboundary(fill_color='k') # draw horizontal colorbar. pylab.colorbar(orientation='horizontal') -pylab.savefig('basemap5.pdf') # eps files are too huge when pcolor used. +pylab.savefig('basemap5.pdf') pylab.savefig('basemap5.png') Modified: trunk/py4science/examples/skel/basemap1_skel.py =================================================================== --- trunk/py4science/examples/skel/basemap1_skel.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/skel/basemap1_skel.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -2,9 +2,7 @@ from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying lat/lon values at corners. projection = 'lcc' # map projection resolution = XX # resolution of boundaries ('c','l','i',or 'h') @@ -18,8 +16,10 @@ resolution=resolution,projection=projection) # draw coastlines. Make liness a little thinner than default. m.drawcoastlines(linewidth=0.5) -# fill continents. -m.fillcontinents(color='coral') +# background fill color will show ocean areas. +m.drawmapboundary(fill_color='aqua') +# fill continents, lakes within continents. +m.fillcontinents(color='coral',lake_color='aqua') # draw states and countries. m.drawcountries() m.drawstates() Modified: trunk/py4science/examples/skel/basemap2_skel.py =================================================================== --- trunk/py4science/examples/skel/basemap2_skel.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/skel/basemap2_skel.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -2,9 +2,7 @@ from matplotlib.toolkits.basemap import Basemap, supported_projections # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. projection = XX # map projection ('lcc','stere','laea','aea' etc) # 'print supported_projections' gives a list @@ -16,11 +14,9 @@ m = Basemap(lon_0=lon_0,lat_0=lat_0,\ width=width,height=height,\ resolution=resolution,projection=projection) -# draw coastlines. m.drawcoastlines(linewidth=0.5) -# fill continents. -m.fillcontinents(color='coral') -# draw states and countries. +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() pylab.title('map region specified using width and height') Modified: trunk/py4science/examples/skel/basemap3_skel.py =================================================================== --- trunk/py4science/examples/skel/basemap3_skel.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/skel/basemap3_skel.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -4,7 +4,6 @@ # create figure. # background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. resolution = 'l' lon_0 = -50 @@ -39,7 +38,8 @@ pylab.text(x2-100000,y2+100000,name2,fontsize=12,\ color='k',horizontalalignment='right',fontweight='bold') m.drawcoastlines(linewidth=0.5) -m.fillcontinents(color='coral') +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() pylab.title(name1+' to '+name2+' Great Circle') Modified: trunk/py4science/examples/skel/basemap4_skel.py =================================================================== --- trunk/py4science/examples/skel/basemap4_skel.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/skel/basemap4_skel.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -1,9 +1,7 @@ import pylab, numpy from matplotlib.toolkits.basemap import Basemap # create figure. -# background color will be used for 'wet' areas. fig = pylab.figure() -fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua') # create map by specifying width and height in km. resolution = 'l' lon_0 = -50 @@ -15,7 +13,8 @@ width=width,height=height,\ resolution=resolution,projection=projection) m.drawcoastlines(linewidth=0.5) -m.fillcontinents(color='coral') +m.drawmapboundary(fill_color='aqua') +m.fillcontinents(color='coral',lake_color='aqua') m.drawcountries() m.drawstates() # draw and label parallels. Modified: trunk/py4science/examples/skel/basemap5_skel.py =================================================================== --- trunk/py4science/examples/skel/basemap5_skel.py 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/examples/skel/basemap5_skel.py 2007-12-01 13:59:01 UTC (rev 4535) @@ -1,33 +1,24 @@ from matplotlib.toolkits.basemap import Basemap, NetCDFFile, cm import pylab, numpy -from numpy import ma # read in netCDF sea-surface temperature data +# can be a local file, a URL for a remote opendap dataset, +# or (if PyNIO is installed) a GRIB or HDF file. ncfile = NetCDFFile('data/sst.nc') -sstv = ncfile.variables['analysed_sst'] -sst = ma.masked_values(numpy.squeeze(sstv[:]), sstv._FillValue) -sst = sstv.scale_factor*sst + sstv.add_offset +sst = ncfile.variables['analysed_sst'][:] lats = ncfile.variables['lat'][:] lons = ncfile.variables['lon'][:] + print sst.shape, sst.min(), sst.max() -# make sure middle of map region is middle of data grid. -lon_0 = lons.mean() -lat_0 = lats.mean() -# set colormap -#cmap = pylab.cm.gist_ncar # Basemap comes with extra colormaps from Generic Mapping Tools # (imported as cm, pylab colormaps in pylab.cm) cmap = XX -# set so masked values in an image will be painted specified color -# (i.e. continents will be painted this color) -color = XX -cmap.set_bad(color) # create Basemap instance for mollweide projection. projection = XX # try moll, robin, sinu or ortho. # coastlines not used, so resolution set to None to skip # continent processing (this speeds things up a bit) -m = Basemap(projection=projection,lon_0=lon_0,lat_0=lat_0,resolution=None) +m = Basemap(projection=projection,lon_0=0,lat_0=0,resolution=None) # compute map projection coordinates of grid. x, y = m(*numpy.meshgrid(lons, lats)) # plot with pcolor @@ -36,7 +27,9 @@ m.drawparallels(numpy.arange(-90.,120.,30.)) m.drawmeridians(numpy.arange(0.,420.,60.)) # draw line around map projection limb. -m.drawmapboundary() +# color map region background (missing values will be this color) +color = XX +m.drawmapboundary(fill_color=color) # draw horizontal colorbar. pylab.colorbar(orientation='horizontal') pylab.show() Modified: trunk/py4science/workbook/basemap.tex =================================================================== --- trunk/py4science/workbook/basemap.tex 2007-11-30 20:06:59 UTC (rev 4534) +++ trunk/py4science/workbook/basemap.tex 2007-12-01 13:59:01 UTC (rev 4535) @@ -96,10 +96,16 @@ One of the most common uses of Basemap is to visualize earth science data, such as output from climate models. These data often come on latitude/longitude grids. One common data format for storing such -grids is NetCDF. Basemap includes a NetCDF file reader (written in -pure python by Roberto D'Almeida). There are python packages available -for reading just about every other scientific data format imaginable, -including HDF, GRIB, FITS and many others. Following is an example +grids is NetCDF. Basemap includes a NetCDF file reader (written in +pure python by Roberto D'Almeida). +You can also access remote datasets over the web using the OPeNDAP +protocol - just give the NetCDFFile function a URL instead of a local file name +and Roberto's pydap module (\texttt{http://pydap.org}) will be used. +The pydap client is included in Basemap. +If the PyNIO module (\texttt{http://www.pyngl.ucar.edu/Nio.shtml}) is installed, the +NetCDFFile function can also be used to open the formats that +PyNIO supports, like GRIB and HDF. +Following is an example of how to read sea-surface temperature data from a NetCDF file and plot it on a global mollweide projection. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |