Revision: 6513
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6513&view=rev
Author:   jswhit
Date:     2008-12-08 16:31:48 +0000 (Mon, 08 Dec 2008)

Log Message:
-----------
added 'scale' keyword to bluemarble and warpimage to downsample background
image (replaces 'resolution' keyword from previous commit).

Modified Paths:
--------------
    trunk/toolkits/basemap/Changelog
    trunk/toolkits/basemap/examples/warpimage.py
    trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py

Removed Paths:
-------------
    trunk/toolkits/basemap/lib/mpl_toolkits/basemap/data/bmng_low.jpg

Modified: trunk/toolkits/basemap/Changelog
===================================================================
--- trunk/toolkits/basemap/Changelog    2008-12-08 16:10:50 UTC (rev 6512)
+++ trunk/toolkits/basemap/Changelog    2008-12-08 16:31:48 UTC (rev 6513)
@@ -1,5 +1,6 @@
 version 0.99.2 (not yet released)
-           * added half resolution blue marble image (resolution='low')
+           * added 'scale' keyword to bluemarble and warpimage methods to
+             downsample image background.
            * Made lat_ts default to 0 for mercator.
            * Now can specify just lon_0 for all cylindrical projections
              (to produce global map centered on lon_0).

Modified: trunk/toolkits/basemap/examples/warpimage.py
===================================================================
--- trunk/toolkits/basemap/examples/warpimage.py        2008-12-08 16:10:50 UTC 
(rev 6512)
+++ trunk/toolkits/basemap/examples/warpimage.py        2008-12-08 16:31:48 UTC 
(rev 6513)
@@ -24,7 +24,7 @@
 fig=plt.figure()
 # define projection centered on North America.
 m = Basemap(projection='mbtfpq',lon_0=-100,resolution='l')
-m.bluemarble(resolution='low')
+m.bluemarble(scale=0.5)
 # draw coastlines.
 m.drawcoastlines(linewidth=0.5,color='0.5')
 # draw lat/lon grid lines every 30 degrees.
@@ -38,7 +38,7 @@
 # define cylindrical equidistant projection.
 m = 
Basemap(projection='cyl',llcrnrlon=-180,llcrnrlat=-90,urcrnrlon=180,urcrnrlat=90,resolution='l')
 # plot (unwarped) rgba image.
-im = m.bluemarble(resolution='low')
+im = m.bluemarble(scale=0.5)
 # draw coastlines.
 m.drawcoastlines(linewidth=0.5,color='0.5')
 # draw lat/lon grid lines.
@@ -52,7 +52,7 @@
 # define cylindrical equidistant projection.
 m = 
Basemap(projection='cyl',llcrnrlon=0,llcrnrlat=-60,urcrnrlon=360,urcrnrlat=60,resolution='l')
 # plot (unwarped) rgba image.
-im = m.bluemarble(resolution='low')
+im = m.bluemarble(scale=0.5)
 # draw coastlines.
 m.drawcoastlines(linewidth=0.5,color='0.5')
 # draw lat/lon grid lines.
@@ -81,7 +81,7 @@
 m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
             rsphere=(6378137.00,6356752.3142),lat_1=50.,lon_0=-107.,\
             resolution='i',area_thresh=1000.,projection='lcc')
-im = m.bluemarble(resolution='low')
+im = m.bluemarble(scale=0.5)
 # draw coastlines.
 m.drawcoastlines(linewidth=0.5,color='0.5')
 # draw parallels and meridians.
@@ -100,7 +100,7 @@
             resolution=None,projection='omerc',\
             lon_0=-100,lat_0=15,lon_2=-120,lat_2=65,lon_1=-50,lat_1=-55)
 # plot warped rgba image.
-im = m.bluemarble(resolution='low')
+im = m.bluemarble(scale=0.5)
 # draw lat/lon grid lines every 20 degrees.
 m.drawmeridians(np.arange(0,360,20),color='0.5')
 m.drawparallels(np.arange(-80,81,20),color='0.5')

Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py
===================================================================
--- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-12-08 
16:10:50 UTC (rev 6512)
+++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-12-08 
16:31:48 UTC (rev 6513)
@@ -3135,17 +3135,20 @@
         im = self.imshow(rgba,interpolation='nearest',ax=ax,**kwargs)
         return im
 
-    def bluemarble(self,ax=None,resolution='high'):
+    def bluemarble(self,ax=None,scale=None):
         """
         display blue marble image (from http://visibleearth.nasa.gov)
         as map background.
+        Default image size is 5400x2700, which can be quite slow and
+        use quite a bit of memory.  The ``scale`` keyword can be used
+        to downsample the image (``scale=0.5`` downsamples to 2700x1350).
         """
         if ax is not None:
-            self.warpimage(image='bluemarble',ax=ax,resolution=resolution)
+            self.warpimage(image='bluemarble',ax=ax,scale=scale)
         else:
-            self.warpimage(image='bluemarble',resolution=resolution)
+            self.warpimage(image='bluemarble',scale=scale)
 
-    def warpimage(self,image="bluemarble",resolution='high',**kwargs):
+    def warpimage(self,image="bluemarble",scale=None,**kwargs):
         """
         Display an image (filename given by ``image`` keyword) as a map 
background.
         If image is a URL (starts with 'http'), it is downloaded to a temp
@@ -3159,6 +3162,10 @@
         Works with the global images from 
         
http://earthobservatory.nasa.gov/Features/BlueMarble/BlueMarble_monthlies.php.
 
+        The ``scale`` keyword can be used to downsample (rescale) the image.
+        Values less than 1.0 will speed things up at the expense of image
+        resolution.
+
         Extra keyword ``ax`` can be used to override the default axis instance.
 
         \**kwargs passed on to :meth:`imshow`.
@@ -3181,10 +3188,7 @@
         # default image file is blue marble next generation
         # from NASA (http://visibleearth.nasa.gov).
         if image == "bluemarble":
-            if resolution == 'low':
-                file = os.path.join(basemap_datadir,'bmng_low.jpg')
-            else:
-                file = os.path.join(basemap_datadir,'bmng.jpg')
+            file = os.path.join(basemap_datadir,'bmng.jpg')
         else:
             file = image
         # if image is same as previous invocation, used cached data.
@@ -3206,6 +3210,11 @@
         # read in jpeg image to rgba array of normalized floats.
         if not hasattr(self,'_bm_rgba') or newfile:
             pilImage = Image.open(self._bm_file)
+            if scale is not None:
+                w, h = pilImage.size
+                width = int(np.round(w*scale))
+                height = int(np.round(h*scale))
+                pilImage = pilImage.resize((width,height),Image.ANTIALIAS)
             self._bm_rgba = pil_to_array(pilImage)
             # define lat/lon grid that image spans.
             nlons = self._bm_rgba.shape[1]; nlats = self._bm_rgba.shape[0]

Deleted: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/data/bmng_low.jpg
===================================================================
(Binary files differ)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to