Keep Transparency With Basemap Warpimage
Solution 1:
I think it's a bug in function warpimage. If the projection is not cylindrical the original image has to be transformed and this is the place where transparency is lost. Namely, in file mpl_toolkits/basemap/__init__.py in function warpimage:
1> 4141                 for k in range(3):
   4142                     self._bm_rgba_warped[:,:,k],x,y = \
   4143                     self.transform_scalar(self._bm_rgba[:,:,k],\
   4144                     self._bm_lons,self._bm_lats,nx,ny,returnxy=True)
Here, RGB channels (for k=0,1,2) from the original file (self._bm_rgba) are transformed and passed to the warped image but the alpha channel (with index k = 3) is not.
Solution
If you can modify your python distribution,
locate file mpl_toolkits/basemap/__init__.py, find a function warpimage and change line for k in range(3): (around line 4141 as in the code above) to
for k in range(self._bm_rgba.shape[2]):
This fixes the problem.
Line numbers may differ. I use basemap-1.0.7.
By the way, I used your jpg file for testing and noticed it didn't have the alpha channel. I hope you are aware of it.
Update
Actually, this bug was already fixed in the github version of basemap.
Post a Comment for "Keep Transparency With Basemap Warpimage"