basemap imshow() extents

I'm having trouble with transform_scalar() and imshow() with basemap.
Essential I have data from satellite tracks that are either smaller
or larger than the map extent, so I don't want to use
Basemap.imshow() which sets the 'extent' keyword automatically.

I tried following the following suggestion, but I can't get things to
line up..
http://comments.gmane.org/gmane.comp.python.matplotlib.general/25085

I suspect I've done something wrong in the code below?:

Scott: If you use the pcolormesh or contourf Basemap methods (instead
of imshow), you can specify the map projection coordinates of your
data and it will be plotted correctly (whether or not it covers the
whole map projection region).

-Jeff

# -------------------------------
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

LL = (-68, -26)
UR = (-66, -21)
bmap = Basemap(projection='merc',
               llcrnrlat=LL[1],
               urcrnrlat=UR[1],
               llcrnrlon=LL[0],
               urcrnrlon=UR[0],
               resolution='i',
               suppress_ticks=False,
               ax=ax)
bmap.drawcountries(linewidth=1)

# Overlay image with extents that don't match map boundaries
nLon, nLat = image.shape
LL = (-69.915, -31.161)
UR = (-65.075, -17.334)
dy = -0.006666664
lats = UR[1] + dy * np.arange(nLat)
extent = (LL[0], UR[0], LL[1], UR[1])
nx = nLon; ny = nLat
image_xy = bmap.transform_scalar(image, lons, lats[::-1], nx, ny)
x, y = bmap(extent[:2],extent[2:])
extent_xy = (x[0], x[1], y[0], y[1])
im = plt.imshow(image_xy, extent=extent_xy)

--
---------------
Scott T. Henderson
http://www.geo.cornell.edu/eas/gstudent/sth54/contact.html

------------------------------------------------------------------------------

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email :Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web :Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

Thanks Jeff,

pcolormesh seems to get the georeferencing correct. Why is it that imshow doesn't work? The trouble with pcolormesh is that it's much slower, the file sizes get bigger and when zooming into detailed regions the pixels edges show up even when I set edgecolors='None'. I've attached a few screenshots for comparison.

Scott: That's weird - I don't know why the edges show. The only thing you're getting with imshow is interpolation. To use imshow, you need to have a grid that exactly fits the map projection region. You could do this with transform_scalar using the keyword masked=True, which will assign missing values to grid points outside the range of the input grid. When you plot with imshow, these areas should just show up as transparent.

-Jeff

ยทยทยท

On 8/20/12 8:21 PM, Scott Henderson wrote:

On Mon 20 Aug 2012 06:29:01 PM EDT, Jeff Whitaker wrote:

On 8/20/12 4:41 PM, Scott Henderson wrote:

# New version:
# -------------------
data_xy, x, y = bmap.transform_scalar(data[::-1], lons, lats[::-1], nx, ny, returnxy=True)
data_xym = np.ma.array(data_xy, mask=np.isnan(data_xy))
im = bmap.pcolormesh(x,y,data_xym,
                    shading='flat', #'gouraud'
                    edgecolors='None',
                    alpha=alpha,
                    vmin=cmin,
                    vmax=cmax)
plt.colorbar(im)

# Different figures attached

--
---------------
Scott T. Henderson
http://www.geo.cornell.edu/eas/gstudent/sth54/contact.html