简体   繁体   English

Plot map 使用带有 hdf5 数据集的 cartopy

[英]Plot map using cartopy with hdf5 dataset

I'm curently trying to plot hdf5 files after switching them from hdf4.从 hdf4 切换后,我正在尝试 plot hdf5 文件。 I got some trouble working out the longitude and latitude variables in the file, both of them have a shape (4224, 3) which I guess correspond to 1: the number of values and 2: the starting/middle/ending granule point of the satellite.我在计算文件中的经度和纬度变量时遇到了一些麻烦,它们都有一个形状 (4224, 3) 我猜对应于 1:值的数量和 2:开始/中间/结束颗粒点卫星。

My problem is that my data 'extinction_coefficient_532' have a shape (4224, 399) which do not match with my lon/lat variables.我的问题是我的数据“extinction_coefficient_532”的形状 (4224, 399) 与我的经/纬度变量不匹配。 Correct me if I'm wrong but I need to have a data file with shape (value, lon, lat) to be plotting it on a map with cartopy.如果我错了请纠正我,但我需要一个形状为 (value, lon, lat) 的数据文件才能将其绘制在带有 cartopy 的 map 上。

Is there a way to adapt the shape of the data to match the lon/lat variables?有没有办法调整数据的形状以匹配 lon/lat 变量?

f['Longitude'].shape
Out[296]: (4224, 3)

f['Latitude'].shape
Out[297]: (4224, 3)

f['Extinction_Coefficient_532'].shape
Out[298]: (4224, 399)

EDIT:编辑:

f['Extinction_Coefficient_532'].dtype
Out[122]: dtype('>f4')

Have a good day, Thomas祝你有美好的一天,托马斯

HDF5 is simply a data container. HDF5 只是一个数据容器。 The specific schema/data hierarchy depends on the creator.具体的模式/数据层次结构取决于创建者。 Ideally they provide documentation, or dataset attributes you can use to interpret the data.理想情况下,它们提供可用于解释数据的文档或数据集属性。 Without details it is hard to give specific advice.没有细节很难给出具体的建议。

That said, I found some documentation that mentions Extinction_Coefficient_532 at NASA's website for CALIPSO Data .也就是说,我在NASA 的 CALIPSO Data 网站上找到了一些提到 Extinction_Coefficient_532 的文档。 It describes the format of all 3 datasets mentioned above.它描述了上述所有 3 个数据集的格式。 Brief description provided here:此处提供的简要说明:

Latitude / Longitude纬度/经度
Geodetic latitude (/longitude), in degrees, of the laser footprint.激光足迹的大地纬度(/经度),以度为单位。 For the 5 km profile products, three values are reported:对于 5 公里剖面产品,报告了三个值:

  • Footprint latitude (/longitude) for the first pulse included in the 15 shot average 15 次射击平均值中包含的第一个脉冲的足迹纬度(/经度)
  • Footprint latitude (/longitude) at the temporal midpoint (ie, at the 8th of 15 consecutive laser shots)时间中点(即 15 次连续激光发射中的第 8 次)的足迹纬度(/经度)
  • Footprint latitude (/longitude) for the final pulse.最终脉冲的足迹纬度(/经度)。

Extinction Coefficient 532消光系数 532
Particulate extinction coefficients reported for each profile range bin in which the appropriate particulates (ie, clouds or aerosols) were detected;为检测到适当颗粒(即云或气溶胶)的每个剖面范围箱报告的颗粒消光系数; those range bins in which no particulates were detected contain fill values (-9999)那些未检测到微粒的范围箱包含填充值 (-9999)

Based on this, I conclude that you have 4224 longitude and latitude locations and matching extinction coefficients.基于此,我得出结论,你有 4224 个经纬度位置和匹配的消光系数。 If this is correct, follow the example on this page to extract the data to create your plot: More advanced mapping with cartopy and matplotlib如果这是正确的,请按照此页面上的示例提取数据以创建您的 plot: More advanced mapping with cartopy and matplotlib

It will look something like this:它看起来像这样:

import h5py
with h5py.File('yourfilename.h5','r') as h5f:
# first extract the plot data:
# 1) Latitude, 2) Longitude and 3) Extinction Coefficient           
    pulse = 0  ## to select a particular pulse, valid range 0-2
    lats = h5f['Latitude'][:,pulse]
    lons = h5f['Longitude'][:,pulse]
    bin_no = 0 ## to plot a particular profile bin, valid range 0-398
    coef = h5f['Extinction_Coefficient_532'][:, bin_no]

# lines below reference plot data extracted above
# May need to be modified to generate the plot type you want.     
    ax = plt.axes(projection=ccrs.PlateCarree())   
    plt.contourf(lons, lats, coef, 60, transform=ccrs.PlateCarree())    
    ax.coastlines()    
    plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM