You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整Cartopy海岸线偏移以匹配卫星影像数据?

Cartopy绘制HDF5卫星影像区域不匹配问题的解决方法

我尝试使用Cartopy的imshow()函数绘制HDF5文件中的卫星影像,但生成的地图与实际区域无法精确匹配。

原示例代码

import matplotlib.pyplot as plt    
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import numpy as np
import h5py

# 从HDF5文件读取数据
fn = '/home/swadhin/project/insat/3DIMG_15JUN2022_0930_L1C_ASIA_MER.h5' # HDF5文件名
with h5py.File(fn) as data:      
    # 获取影像数据
    image = 'IMG_TIR1'
    img_arr = data[image][0,:,:] 
    # 获取填充值用于数据掩膜
    img_arr_fill = data[image].attrs['_FillValue'][0] 

    # 从文件属性获取绘图范围
    left_lon = data.attrs['left_longitude'][0]
    right_lon = data.attrs['right_longitude'][0]
    lower_lat = data.attrs['lower_latitude'][0]
    upper_lat = data.attrs['upper_latitude'][0]  
    sat_long = data.attrs['Nominal_Central_Point_Coordinates(degrees)_Latitude_Longitude'][1]

img_extent_deg = (left_lon, right_lon, lower_lat, upper_lat)
print(img_extent_deg)
img_arr_m = np.ma.masked_equal(img_arr, img_arr_fill, copy=True)   
map_proj = ccrs.Mercator(central_longitude=sat_long)
ax = plt.axes(extent = img_extent_deg,projection=map_proj)
ax.coastlines(color='white')
ax.add_feature(cfeature.BORDERS, edgecolor='white', linewidth=0.5)
ax.add_feature(cfeature.STATES,edgecolor = 'red',linewidth = 0.5)
ax.gridlines(color='black', alpha=0.5, linestyle='--', linewidth=0.75, draw_labels=True)
map_extend_mer = ax.get_extent(crs=map_proj)
plt.imshow(img_arr_m, extent=map_extend_mer, cmap = 'gray')
plt.colorbar()
plt.show()

问题现象

生成的绘图范围略低于南纬10度,导致地理特征显示错误——例如本该位于古吉拉特邦上空的云,却出现在巴基斯坦边境区域。

解决方法

通过在Mercator投影初始化时添加纬度范围参数,即可解决区域匹配问题。修改后的投影代码如下:

map_proj = ccrs.Mercator(central_longitude=sat_long, min_latitude=lower_lat, max_latitude=upper_lat)

内容的提问来源于stack exchange,提问作者The Emerging Star

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 10:45:28