Shahar
Shahar

Reputation: 886

imshow of numpy array is not working as expected with Cartopy

I'm trying to use Aster GDEM data with cartopy with no success: Say I have a numpy array for which I know the geographical extent. I should be able to plot it as a layer with say a GoogleTile from cartopy.io.img_tiles.

Sample code:

proj = ccrs.Mercator()
extent = [32, 33, 29, 30]
data = np.random.rand(10,10)

fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(111, projection=proj)
ax.set_extent(extent)
ax.imshow(data, extent=extent, origin='upper',
      transform=proj, alpha=0.5)

gg_tiles = GoogleTiles()
ax.add_image(gg_tiles, 10, alpha=0.5)

ax.coastlines('10m')
ax.set_title('data with Google Tile')
gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = None

produces:

enter image description here

data is not shown!

If I comment ax.set_extent(extent) then the data is shown but with the wrong extent:

enter image description here

any suggestions?

Upvotes: 3

Views: 1119

Answers (1)

pelson
pelson

Reputation: 21839

With cartopy, if your data is in the wrong place the first two things that I always rule out first are:

  • "Have I got the right projection?"
  • "Have I confused lons/lats with projection meters (aka eastings/northings)?"

So the first thing I did was went to the NASA ASTER site, which didn't seem to have much projection information, but the jspacesystems site (http://www.jspacesystems.or.jp/ersdac/GDEM/E/4.html) did. It tells us that we have:

The ASTER GDEM is in GeoTIFF format with geographic lat/long coordinates and a 1 arc-second (30 m) grid of elevation postings. It is referenced to the WGS84/EGM96 geoid.

This suggest to me that you would be better to use the PlateCarree projection (note, this will be using the incorrectly referenced ellipse, but will be pretty good at this resolution).

Sadly, sourcing the ASTER data is a bit of a headache, so I've not been able to test this, but simply changing proj to PlateCarree should be all that is needed in this case. (If not, please feel free to send over the image to the email address found in my github profile and I'll take a look at this specific case).

HTH

Upvotes: 2

Related Questions