Revision: 6124
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6124&view=rev
Author:   jswhit
Date:     2008-09-27 17:36:35 +0000 (Sat, 27 Sep 2008)

Log Message:
-----------
fix warpimage/bluemarble methods for 'cyl','robin','moll' and 'sinu' 
projections.

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

Modified: trunk/toolkits/basemap/Changelog
===================================================================
--- trunk/toolkits/basemap/Changelog    2008-09-26 21:52:34 UTC (rev 6123)
+++ trunk/toolkits/basemap/Changelog    2008-09-27 17:36:35 UTC (rev 6124)
@@ -1,4 +1,6 @@
 version 0.99.2 (not yet released)
+           * fix warpimage and bluemarble methods for projection = 'cyl',
+             'robin', 'moll' and 'sinu'.
            * bugfix patch for rotate_vector from David Huard.  David
              also contributed the beginnings of a test suite.
            * _geoslib.so now installed in mpl_toolkits.basemap.            

Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py
===================================================================
--- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-09-26 
21:52:34 UTC (rev 6123)
+++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-09-27 
17:36:35 UTC (rev 6124)
@@ -3210,15 +3210,22 @@
             self._bm_lons = np.arange(-180.+0.5*delta,180.,delta)
             self._bm_lats = np.arange(-90.+0.5*delta,90.,delta)
 
-        if self.projection != 'cyl':
+        bmproj = self.projection == 'cyl' and \
+                 self.llcrnrlon == -180 and self.urcrnrlon == 180
+        if not bmproj:
             if newfile or not hasattr(self,'_bm_rgba_warped'):
                 # transform to nx x ny regularly spaced native
                 # projection grid.
                 # nx and ny chosen to have roughly the 
                 # same horizontal res as original image.
-                dx = 2.*np.pi*self.rmajor/float(nlons)
-                nx = int((self.xmax-self.xmin)/dx)+1
-                ny = int((self.ymax-self.ymin)/dx)+1
+                if self.projection != 'cyl':
+                    dx = 2.*np.pi*self.rmajor/float(nlons)
+                    nx = int((self.xmax-self.xmin)/dx)+1
+                    ny = int((self.ymax-self.ymin)/dx)+1
+                else: 
+                    dx = 360./float(nlons)
+                    nx = int((self.urcrnrlon-self.llcrnrlon)/dx)+1
+                    ny = int((self.urcrnrlat-self.llcrnrlat)/dx)+1
                 self._bm_rgba_warped = np.ones((ny,nx,4),np.float64)
                 # interpolate rgba values from geographic coords (proj='cyl')
                 # to map projection coords.
@@ -3231,7 +3238,7 @@
                 # for ortho,geos mask pixels outside projection limb.
                 if self.projection in ['geos','ortho']:
                     lonsr,latsr = self(x,y,inverse=True)
-                    mask = ma.zeros((nx,ny,4),np.int8)
+                    mask = ma.zeros((ny,nx,4),np.int8)
                     mask[:,:,0] = np.logical_or(lonsr>1.e20,latsr>1.e30)
                     for k in range(1,4):
                         mask[:,:,k] = mask[:,:,0]
@@ -3239,6 +3246,28 @@
                     ma.masked_array(self._bm_rgba_warped,mask=mask)
                     # make points outside projection limb transparent.
                     self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
+                # treat mollweide, robinson and sinusoidal.
+                elif self.projection in ['moll','robin','sinu']:
+                    lonsr,latsr = self(x,y,inverse=True)
+                    mask = ma.zeros((ny,nx,4),np.int8)
+                    lon_0 = self.projparams['lon_0']
+                    lonright = lon_0+180.
+                    lonleft = lon_0-180.
+                    x1 = np.array(ny*[0.5*(self.xmax + self.xmin)],np.float)
+                    y1 = np.linspace(self.ymin, self.ymax, ny)
+                    lons1, lats1 = self(x1,y1,inverse=True)
+                    lats1 = np.where(lats1 < -89.999999, -89.999999, lats1)
+                    lats1 = np.where(lats1 > 89.999999, 89.999999, lats1)
+                    for j,lat in enumerate(lats1):
+                        xmax,ymax = self(lonright,lat)
+                        xmin,ymin = self(lonleft,lat)
+                        mask[j,:,0] = np.logical_or(x[j,:]>xmax,x[j,:]<xmin)
+                    for k in range(1,4):
+                        mask[:,:,k] = mask[:,:,0]
+                    self._bm_rgba_warped = \
+                    ma.masked_array(self._bm_rgba_warped,mask=mask)
+                    # make points outside projection limb transparent.
+                    self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
             # plot warped rgba image.
             im = self.imshow(self._bm_rgba_warped,ax=ax)
         else:


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to