Question

I am having a problem reprojecting an image with Cartopy.

I have the following code (modified from an example found here):

import os
import matplotlib.pyplot as plt

from cartopy import config
import cartopy.crs as ccrs
import cartopy.feature as cfeature

fig = plt.figure(figsize=(8, 10))

img_extent = (-120.67660000000001, -106.32104523100001, 13.2301484511245, 30.766899999999502)
img = plt.imread('/tmp/Miriam.A2012270.2050.2km.jpg')

ax = plt.axes(projection=ccrs.PlateCarree())
plt.title('Hurricane Miriam from the Aqua/MODIS satellite\n'
          '2012 09/26/2012 20:50 UTC')

ax.set_extent([-125, -105, 10, 35], ccrs.Geodetic())

ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='black', linewidth=1)
ax.gridlines()

plt.show()

which generates the following image PlateCarree

However, when I attempt to choose a different projection, say Lambert Conformal, by replacing

ax = plt.axes(projection=ccrs.PlateCarree())

with

ax = plt.axes(projection=ccrs.LambertConformal())

I get the following image:

LambertConformal

As you can see this image has problems. What am I doing wrong? Is it possible to display this image in a different projection?

Was it helpful?

Solution 2

This is definitely a bug, so I'd encourage you to open a github issue (https://github.com/SciTools/cartopy/issues/new).

I initially thought it might be the LambertConformal projection, but the same problem occurs with other projections too (Robinson for instance), which suggests to me there is a problem with the definition of the image's extents.

Unfortunately I don't have a workaround at this point.

HTH

OTHER TIPS

For future reference this problem was due to a bug in cartopy which has now been fixed on the master branch. The fix will be included in the 0.10.0 release. The output of Julien's script run with the fixed code is shown below:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top