编程语言
首页 > 编程语言> > python – 难以使用Cartopy重新投影图像

python – 难以使用Cartopy重新投影图像

作者:互联网

我在使用Cartopy重新投影图像时遇到问题.

我有以下代码(从一个例子中找到修改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()

生成以下图像

然而,当我尝试通过替换选择不同的投影时,比如Lambert Conformal

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

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

我得到以下图像:

如您所见,此图像存在问题.我究竟做错了什么?是否可以在不同的投影中显示此图像?

解决方法:

这肯定是一个bug,所以我鼓励你打开一个github问题(https://github.com/SciTools/cartopy/issues/new).

我最初认为它可能是LambertConformal投影,但同样的问题也出现在其他投影中(例如Robinson),这表明我对图像范围的定义存在问题.

不幸的是,我目前还没有解决方法.

HTH

标签:cartopy,python
来源: https://codeday.me/bug/20190723/1508454.html