LSA-SAF卫星HDF5在Python Cartopy中绘图

LSA-SAF卫星HDF5在Python Cartopy中绘图,python,hdf5,Python,Hdf5,我有一些LSA-SAF HDF5文件数据,我希望最终能用Cartopy在Python中绘制出来。我没有使用HDF5文件的经验,所以我可能在这里选错了树,但我可以绘制数据和地图。主要的问题是预测不一致。我尝试过在子图和imshow transform参数中处理投影。由于MSG数据似乎没有地理位置,也许我不能轻易做到我所希望的 我的代码: FILE_NAME = 'HDF5_LSASAF_MSG_LAI_MSG-Disk_201806010000.h5' #LAI crs = ccrs.Geost

我有一些LSA-SAF HDF5文件数据,我希望最终能用Cartopy在Python中绘制出来。我没有使用HDF5文件的经验,所以我可能在这里选错了树,但我可以绘制数据和地图。主要的问题是预测不一致。我尝试过在子图和imshow transform参数中处理投影。由于MSG数据似乎没有地理位置,也许我不能轻易做到我所希望的

我的代码:

FILE_NAME = 'HDF5_LSASAF_MSG_LAI_MSG-Disk_201806010000.h5' #LAI

crs = ccrs.Geostationary(central_longitude=0.0,satellite_height= 35785831)
crs2 = ccrs.PlateCarree(central_longitude=0.0) #central_longitude=0.0
fig = plt.figure(figsize=(10, 12))
ax = fig.add_subplot(1, 1, 1, projection=crs)
f = h5py.File(FILE_NAME, mode='r')
key_list = f.keys()

key_list2 = []
key_list2.append(key_list[0])

for key in key_list2:
    print(key)
    matrix = f.get(key)
    ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.75)
    ax.add_feature(cfeature.BORDERS.with_scale('50m'), linewidth=0.5)
    ax.add_feature(cfeature.OCEAN.with_scale('50m'),alpha=0.2)
    cmap=cm.YlGn
    cmap.set_bad(alpha=0.0)

    img_extent = (-65,65,-65,65)

    ax.imshow(matrix[:], cmap=cmap, norm=colors.Normalize(vmin=-1.0,             
      vmax=7000.0), origin='upper',extent=img_extent,transform=crs2)

plt.show()


我在尝试绘制GOES-16数据时遇到了类似的问题,通过lat和lon的卫星高度计算得到了解决。我对HDF5文件层次结构了解不够,无法找到MSG geostationary卫星的类似数据。任何关于这是否可以实现和/或HDF5数据的见解都将不胜感激

正如tda提到的,我也成功地使用了
gdal
。在这里,我使用的是FAPAR产品

in_pathfiles = '/path/to/HDF5 files/*FAPAR*.h5' # Where .hdf5 files exist
out_pathfiles = '/path/to/new geotiff files/' # Where the new .tif file will be placed
myfiles = glob.glob(in_pathfiles) #list of all files

for f in myfiles:
    print(f),"\n"
    filename = f.split("\\")[-1]
    print "filename",out_pathfiles+filename,"\n"

    f_out = filename[:-3] + ".tif"  # splitting the .hd5 off the fileneame and making a new .tif filename
    print "f_out",out_pathfiles+f_out,"\n"

    f_rep = out_pathfiles+filename[:-3] + "_rep.tif" # create a new final .tif filename for reprojection
    print "f_rep",f_rep,"\n"

# Translating the satellite height and ellipitical values to xy values and filling the new _rep.tif file
# from the original .h5 file
os.system('gdal_translate -of GTiff -a_srs "+proj=geos +h=35785831 +a=6378169 +b=6356583.8 +no_defs"\
-a_ullr  -5568748.27576  5568748.27576 5568748.27576 -5568748.27576 "HDF5:'+ filename + '://FAPAR '+ f_out)

# Mapping the new values and filling the new _rep.tif file
os.system('gdalwarp -ot Float32 -s_srs "+proj=geos +h=35785831 +a=6378169 +b=6356583.8 +no_defs"\
-t_srs EPSG:4326 -r near -of GTiff ' + f_out + ' ' + f_rep)
绘图:

在数据为0的位置绘制新区域和遮罩阵列。这使我能够显示数据不相关的海洋和其他区域:

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

 # enable gdal exceptions (instead of the silent failure which is gdal default)
gdal.UseExceptions()

fname = "/path/to/rep.tif file/"
ds = gdal.Open(fname)

Meta = ds.GetMetadata()

Product = Meta.values()[3]
#print Product

Date = Meta.values()[38]
Date_End = Date[:8]

geotransform = ds.GetGeoTransform()
data = ds.ReadAsArray()
data = np.ma.masked_where(data <= -1, data)

crs = ccrs.Geostationary(central_longitude=0.0)
crs2 = ccrs.PlateCarree(central_longitude=0.0)

ax = fig.add_subplot(1, 1, 1, projection=crs2)
gl = ax.gridlines(crs=crs2, draw_labels=True,
    linewidth=2, color='gray', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_left = False

ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.75)
ax.add_feature(cfeature.BORDERS.with_scale('50m'), linewidth=0.5)

cmap=cm.YlGn
cmap.set_bad(alpha=0.0)

ax.set_extent([5,40,-10,8]) # Congo

img_extent = (-81.26765645410755,81.26765645410755,-74.11423113858775,74.11423113858775)

cf = ax.imshow(data, cmap="RdYlGn", origin='upper'
    ,extent=img_extent,transform=crs2)

cbar = plt.colorbar(cf, orientation='horizontal')
ax.add_feature(cfeature.OCEAN.with_scale('50m'),alpha=0.5)

plt.show()
fig=plt.figure(figsize=(10,12))
#启用gdal异常(而不是gdal默认的静默故障)
gdal.UseExceptions()
fname=“/path/to/rep.tif文件/”
ds=gdal.Open(fname)
Meta=ds.GetMetadata()
Product=Meta.values()[3]
#印刷品
日期=Meta.values()[38]
日期=日期[:8]
geotransform=ds.GetGeoTransform()
data=ds.ReadAsArray()

data=np.ma.masked_where(数据请告诉我您是否找到了解决方案。在这里也遇到了困难。在尝试将原始
HDF
文件重新投影到
GeoTiff
时,
gdal
也遇到了困难。因此,我找到了一个解决方案,首先使用
gdal
获得转换后的GeoTiff“+proj=geos+h=35785831+a=6378169+b=6356583.8+no_defs”-a_ullr-5568000 5568000 5568000-5568000 HDF5:“HDF5_LSASAF_MSG_LST_MSG-Disk_201812171515.h5"://LST LST.tif
然后
gdalwarp-t_srs EPSG:4326-wo SOURCE_EXTRA=100 LST.tif lst2.tif
。我在看MSG LST产品,但应该是一样的。我很幸运地与LandSAF的人交谈,这基本上也是他们给我的建议。我有一些不同的论点,但通过gdal是正确的选择!稍后我会发布我的更新代码。我认为我的参数基于3km的分辨率,而我认为它实际上是3.1,所以我可能有舍入错误-谢谢分享!你在使用jupyter notebok吗?gdal_translate没有创建Tiff文件
fig = plt.figure(figsize=(10, 12))

 # enable gdal exceptions (instead of the silent failure which is gdal default)
gdal.UseExceptions()

fname = "/path/to/rep.tif file/"
ds = gdal.Open(fname)

Meta = ds.GetMetadata()

Product = Meta.values()[3]
#print Product

Date = Meta.values()[38]
Date_End = Date[:8]

geotransform = ds.GetGeoTransform()
data = ds.ReadAsArray()
data = np.ma.masked_where(data <= -1, data)

crs = ccrs.Geostationary(central_longitude=0.0)
crs2 = ccrs.PlateCarree(central_longitude=0.0)

ax = fig.add_subplot(1, 1, 1, projection=crs2)
gl = ax.gridlines(crs=crs2, draw_labels=True,
    linewidth=2, color='gray', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_left = False

ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.75)
ax.add_feature(cfeature.BORDERS.with_scale('50m'), linewidth=0.5)

cmap=cm.YlGn
cmap.set_bad(alpha=0.0)

ax.set_extent([5,40,-10,8]) # Congo

img_extent = (-81.26765645410755,81.26765645410755,-74.11423113858775,74.11423113858775)

cf = ax.imshow(data, cmap="RdYlGn", origin='upper'
    ,extent=img_extent,transform=crs2)

cbar = plt.colorbar(cf, orientation='horizontal')
ax.add_feature(cfeature.OCEAN.with_scale('50m'),alpha=0.5)

plt.show()