【发布时间】:2018-11-26 00:23:30
【问题描述】:
我正在进行一个尝试解码 NOAA APT 图像的项目,到目前为止,我已经到了可以从 RTLSDR 的原始 IQ 记录中获取图像的阶段。这是解码后的图像之一, Decoded NOAA APT image此图像将用作代码的输入(此处显示为 m3.png)
现在我正在努力在图像上覆盖地图边界(注意:仅在上图的左半部分)
我们知道,图像被捕获的时间和卫星信息:位置、方向等。所以,我使用卫星的位置来获取地图投影的中心和卫星的方向来适当地旋转图像.
首先我在 Basemap 中尝试过,这里是代码
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
from scipy import ndimage
im = plt.imread('m3.png')
im = im[:,85:995] # crop only the first part of whole image
rot = 198.3913296679117 # degrees, direction of sat movement
center = (50.83550180700588, 16.430852851867176) # lat long
rotated_img = ndimage.rotate(im, rot) # rotate image
w = rotated_img.shape[1]*4000*0.81 # in meters, spec says 4km per pixel, but I had to make it 81% less to get better image
h = rotated_img.shape[0]*4000*0.81 # in meters, spec says 4km per pixel, but I had to make it 81% less to get better image
m = Basemap(projection='cass',lon_0 = center[1],lat_0 = center[0],width = w,height = h, resolution = "i")
m.drawcoastlines(color='yellow')
m.drawcountries(color='yellow')
im = plt.imshow(rotated_img, cmap='gray', extent=(*plt.xlim(), *plt.ylim()))
plt.show()
结果我得到了this image,看起来还不错
我想将代码移至 Cartopy,因为它更易于安装并且正在积极开发中。我找不到类似的方法来设置边界,即以米为单位的宽度和高度。所以,我修改了most similar example。我找到了一个函数,可以将米添加到经纬度,并用它来设置边界。
这是 Cartopy 中的代码,
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
from scipy import ndimage
import cartopy.feature
im = plt.imread('m3.png')
im = im[:,85:995] # crop only the first part of whole image
rot = 198.3913296679117 # degrees, direction of sat movement
center = (50.83550180700588, 16.430852851867176) # lat long
def add_m(center, dx, dy):
# source: https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters
new_latitude = center[0] + (dy / 6371000.0) * (180 / np.pi)
new_longitude = center[1] + (dx / 6371000.0) * (180 / np.pi) / np.cos(center[0] * np.pi/180)
return [new_latitude, new_longitude]
fig = plt.figure()
img = ndimage.rotate(im, rot)
dx = img.shape[0]*4000/2*0.81 # in meters
dy = img.shape[1]*4000/2*0.81 # in meters
leftbot = add_m(center, -1*dx, -1*dy)
righttop = add_m(center, dx, dy)
img_extent = (leftbot[1], righttop[1], leftbot[0], righttop[0])
ax = plt.axes(projection=ccrs.PlateCarree())
ax.imshow(img, origin='upper', cmap='gray', extent=img_extent, transform=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='yellow', linewidth=1)
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', edgecolor='yellow')
plt.show()
Here is the result来自 Cartopy,不如 Basemap 的结果。
我有以下问题:
- 我发现无法旋转地图而不是图像,在 底图和cartopy。因此我求助于旋转图像,是 有没有办法旋转地图?
- 如何提高cartopy的输出?我认为这是进入的方式 我正在计算问题的程度。有没有办法我可以 提供米来设置图像的边界?
- 有没有更好的方法来做我想做的事情?任何特定于此类应用的投影?
- 我正在手动调整比例(我决定每像素公里数的部分),有没有办法根据 在 卫星的高度?
任何形式的输入都将受到高度赞赏。非常感谢您的宝贵时间!
如果你有兴趣可以找到项目here。
【问题讨论】:
-
投影
NearsidePerspective与适当的satellite_height,可能会产生更好的结果。 scitools.org.uk/cartopy/docs/v0.15/crs/… -
您对图像还有哪些其他元数据?例如,关于
satellite_height的任何信息? -
@swatchai 谢谢!我试试看
-
@pelson 是的!卫星高度可用,这张图片是 852 公里。
标签: matplotlib-basemap cartopy noaa