使用Cartopy可视化Himawari-8 NetCDF数据时空白图问题求解
Himawari-8 AHI数据Cartopy绘图空白问题解决办法
核心问题排查与解决
1. 修正投影范围变量定义
代码中img_extent使用了未定义的X/Y变量,需替换为已读取的x/y投影坐标,同时确保范围格式为(左、右、下、上):
img_extent = (x[0], x[-1], y[-1], y[0])
2. 确保RGB数组正确合成
Himawari的通道辐射值需要归一化后才能生成有效RGB图像,补充合成逻辑:
def normalize(arr): return (arr - arr.min()) / (arr.max() - arr.min()) # 按B3(红)、B2(绿)、B1(蓝)合成RGB rgb = np.dstack([normalize(b3), normalize(b2), normalize(b1)])
3. 完善Geostationary投影参数
Himawari-8的静止卫星投影必须指定sweep_axis='x'参数,否则会出现投影偏移导致图像不显示:
img_proj = ccrs.Geostationary( central_longitude=float(h8b1['geostationary'].longitude_of_projection_origin), satellite_height=float(h8b1['geostationary'].satellite_height), sweep_axis='x' )
4. 调整轴范围与投影的兼容性
设置轴显示范围时,需明确指定经纬度对应的投影(ccrs.PlateCarree()),确保数据范围与显示范围重叠:
# 设置吕宋岛的经纬度范围,指定CRS为经纬度投影 ax.set_extent([117, 125, 13, 20], crs=ccrs.PlateCarree())
完整可运行代码
from netCDF4 import Dataset import matplotlib.pyplot as plt import numpy as np import cartopy.crs as ccrs # 数据路径 h8b1_path = '0800_20160814080000-P1S-ABOM_OBS_B01-PRJ_GEOS141_2000-HIMAWARI8-AHI.nc' h8b2_path = '0800_20160814080000-P1S-ABOM_OBS_B02-PRJ_GEOS141_2000-HIMAWARI8-AHI.nc' h8b3_path = '0800_20160814080000-P1S-ABOM_OBS_B03-PRJ_GEOS141_2000-HIMAWARI8-AHI.nc' # 读取数据 h8b1 = Dataset(h8b1_path) h8b2 = Dataset(h8b2_path) h8b3 = Dataset(h8b3_path) b1 = h8b1.variables['channel_0001_scaled_radiance'][0,:,:] b2 = h8b2.variables['channel_0002_scaled_radiance'][0,:,:] b3 = h8b3.variables['channel_0003_scaled_radiance'][0,:,:] x = h8b1.variables['x'][:] y = h8b1.variables['y'][:] # 归一化并合成RGB def normalize(arr): return (arr - arr.min()) / (arr.max() - arr.min()) rgb = np.dstack([normalize(b3), normalize(b2), normalize(b1)]) # 定义Himawari-8的静止卫星投影 img_proj = ccrs.Geostationary( central_longitude=float(h8b1['geostationary'].longitude_of_projection_origin), satellite_height=float(h8b1['geostationary'].satellite_height), sweep_axis='x' ) # 创建绘图对象 plt.figure(figsize=(12,12)) ax = plt.axes(projection=ccrs.Miller(central_longitude=float(h8b1['geostationary'].longitude_of_projection_origin))) # 设置显示范围(吕宋岛区域) ax.set_extent([117, 125, 13, 20], crs=ccrs.PlateCarree()) # 绘制图像 ax.imshow(rgb, transform=img_proj, origin='upper') # 添加海岸线辅助验证 ax.coastlines(resolution='10m', color='white') plt.show()
内容的提问来源于stack exchange,提问作者CGHA
相关产品推荐
相关产品推荐

